@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;600;700&family=Playfair+Display:ital,wght@1,700&display=swap');

:root {
    color-scheme: dark;
    --ink: #f7efe2;
    --muted: #aaa1b7;
    --violet: #a978ff;
    --gold: #f6c865;
    --night: #100d1a;
    --panel: rgba(28, 21, 43, .92);
    --line: rgba(255, 255, 255, .1);
    --danger: #ed6678;
    --success: #71d09a;
}

* { box-sizing: border-box; }
html { min-height: 100%; }

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    color: var(--ink);
    background:
        radial-gradient(circle at 78% 8%, rgba(130, 77, 185, .22), transparent 30rem),
        radial-gradient(circle at 14% 55%, rgba(82, 53, 116, .16), transparent 32rem),
        var(--night);
    font-family: "DM Sans", system-ui, sans-serif;
}

body::before {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        repeating-linear-gradient(37deg, rgba(255, 255, 255, .018) 0 1px, transparent 1px 7px),
        repeating-linear-gradient(123deg, rgba(0, 0, 0, .025) 0 1px, transparent 1px 9px);
    content: "";
    opacity: .45;
    pointer-events: none;
}

button, a { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
h1, h2, h3, p { margin-top: 0; }

.site-shell {
    width: min(1050px, calc(100% - 32px));
    margin: 0 auto;
    padding: 42px 0 36px;
}

.masthead {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(260px, .95fr);
    align-items: center;
    gap: 12px;
    min-height: 340px;
}

.masthead-copy { position: relative; z-index: 1; }

.eyebrow, .section-label, .escape-kicker, .result-kicker {
    margin: 0 0 12px;
    color: var(--gold);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .19em;
    text-transform: uppercase;
}

.eyebrow { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.eyebrow span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--violet);
    box-shadow: 0 0 14px var(--violet);
}

h1 {
    max-width: 650px;
    margin-bottom: 5px;
    font-size: clamp(3.25rem, 8vw, 6rem);
    line-height: .9;
    letter-spacing: -.065em;
}

h1 em { color: var(--violet); font-family: "Playfair Display", Georgia, serif; font-weight: 700; }

.subtitle {
    margin-bottom: 20px;
    color: var(--gold);
    font-size: clamp(1rem, 2vw, 1.3rem);
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.lede { max-width: 520px; margin-bottom: 0; color: var(--muted); font-size: 1.05rem; line-height: 1.7; }

.mascot {
    display: block;
    width: min(510px, 49vw);
    height: auto;
    justify-self: end;
    filter: drop-shadow(0 28px 30px rgba(0, 0, 0, .5));
    animation: breathe 5s ease-in-out infinite;
}

.game-card {
    position: relative;
    overflow: hidden;
    padding: clamp(20px, 4vw, 38px);
    border: 1px solid var(--line);
    border-radius: 28px;
    background: linear-gradient(145deg, rgba(255, 255, 255, .045), transparent 48%), var(--panel);
    box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
    backdrop-filter: blur(16px);
}

.game-card::before {
    position: absolute;
    top: -130px;
    right: -110px;
    width: 330px;
    height: 330px;
    border-radius: 50%;
    background: rgba(169, 120, 255, .09);
    content: "";
    pointer-events: none;
}

.game-topbar, .instructions, .escape-route {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.game-topbar h2 { margin-bottom: 0; font-size: clamp(1.65rem, 4vw, 2.35rem); letter-spacing: -.035em; }

.hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 24px 0 20px; }
.stat {
    padding: 12px 14px;
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 14px;
    background: rgba(255, 255, 255, .035);
}
.stat-label {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .11em;
    text-transform: uppercase;
}
.stat strong { font-size: 1.1rem; }

.instructions > p { max-width: 510px; margin-bottom: 0; color: var(--muted); font-size: .9rem; line-height: 1.55; }
.instructions strong { color: var(--ink); }

.mode-switch {
    display: flex;
    flex: 0 0 auto;
    gap: 7px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(8, 6, 13, .45);
}

.mode-button, .secondary-button, .primary-button, .level-button { border: 0; cursor: pointer; }
.mode-button {
    padding: 9px 12px;
    border-radius: 10px;
    color: var(--muted);
    background: transparent;
    font-size: .8rem;
    font-weight: 700;
}
.mode-button.active {
    color: var(--ink);
    background: rgba(169, 120, 255, .18);
    box-shadow: inset 0 0 0 1px rgba(169, 120, 255, .25);
}
.mode-icon { margin-right: 5px; }
.treasure-gem { color: var(--gold); }
.suspicious-eye { color: var(--violet); text-shadow: 0 0 9px var(--violet); }

.secondary-button, .primary-button, .portal-button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    padding: 10px 17px;
    border-radius: 12px;
    font-size: .78rem;
    font-weight: 700;
    text-decoration: none;
}
.secondary-button { border: 1px solid var(--line); color: var(--muted); background: rgba(255, 255, 255, .035); }
.secondary-button:hover { color: var(--ink); background: rgba(255, 255, 255, .07); }
.primary-button, .portal-button {
    color: #160f20;
    background: linear-gradient(135deg, var(--gold), #e8a84d);
    box-shadow: 0 10px 25px rgba(208, 139, 47, .18);
}
.primary-button:hover, .portal-button:hover { transform: translateY(-1px); filter: brightness(1.06); }

.game-message {
    min-height: 24px;
    margin: 20px 0 14px;
    color: #d6ccdf;
    font-size: .85rem;
    text-align: center;
}
.game-message.danger { color: #ff9cab; }
.game-message.success { color: #8de3af; }

/* The board is a top-down stone dungeon map: thick walls, dark mortar and torch glow. */
.board-wrap {
    position: relative;
    width: min(100%, 760px);
    min-height: 300px;
    margin: 0 auto;
    padding: clamp(14px, 3vw, 28px);
    border-radius: 28px;
    background:
        linear-gradient(90deg, transparent 48%, rgba(0, 0, 0, .18) 50%, transparent 52%),
        linear-gradient(transparent 48%, rgba(0, 0, 0, .18) 50%, transparent 52%),
        #18151c;
    background-size: 56px 56px;
    box-shadow: inset 0 0 55px #050407, 0 18px 42px rgba(0, 0, 0, .32);
}

.board-wrap::before {
    position: absolute;
    inset: 4px;
    border: clamp(7px, 1.5vw, 13px) solid #3a3540;
    border-radius: 24px;
    content: "";
    box-shadow:
        inset 0 0 0 2px #161319,
        inset 0 0 0 5px rgba(255, 255, 255, .035),
        0 0 0 2px #09070c;
    pointer-events: none;
}

.board-wrap::after {
    position: absolute;
    inset: 10px;
    border: 2px dashed rgba(130, 120, 139, .22);
    border-radius: 18px;
    content: "";
    pointer-events: none;
}

.torch-glow {
    position: absolute;
    top: 44%;
    z-index: 0;
    width: 80px;
    height: 150px;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(246, 177, 73, .25), transparent 68%);
    filter: blur(8px);
    pointer-events: none;
}
.torch-glow-left { left: -20px; }
.torch-glow-right { right: -20px; background: radial-gradient(ellipse, rgba(169, 120, 255, .24), transparent 68%); }

.board {
    --cols: 5;
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    gap: clamp(3px, .7vw, 7px);
    width: min(100%, calc(var(--cols) * 52px));
    margin: 0 auto;
    padding: clamp(8px, 1.5vw, 14px);
    border: 2px solid #4c4651;
    border-radius: 10px;
    background:
        radial-gradient(circle at 20% 25%, rgba(246, 200, 101, .07), transparent 24%),
        radial-gradient(circle at 82% 72%, rgba(169, 120, 255, .08), transparent 26%),
        #0a090d;
    box-shadow:
        inset 0 0 0 4px #211e25,
        inset 0 0 32px rgba(0, 0, 0, .72),
        0 0 0 4px #111014,
        0 12px 22px rgba(0, 0, 0, .38);
}
.board.shake { animation: shake .38s ease both; }

.tile {
    position: relative;
    display: grid;
    min-width: 0;
    aspect-ratio: 1;
    place-items: center;
    overflow: hidden;
    border: 1px solid #49434e;
    border-radius: clamp(3px, .6vw, 6px);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, .04), transparent 46%),
        linear-gradient(25deg, transparent 70%, rgba(0, 0, 0, .2) 71%),
        #29262d;
    box-shadow:
        inset 2px 2px 0 rgba(255, 255, 255, .025),
        inset -3px -3px 0 rgba(0, 0, 0, .2);
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease, filter .12s ease;
}
.tile:nth-child(3n) { background-color: #25232a; }
.tile:nth-child(4n + 1) { background-color: #2d2931; }
.tile:not(.opened):hover {
    z-index: 2;
    border-color: rgba(246, 200, 101, .65);
    filter: brightness(1.18);
    transform: translateY(-2px);
}
.tile.opened {
    border-color: #3a3540;
    background: #1b191e;
    box-shadow: inset 0 0 12px rgba(0, 0, 0, .4);
    cursor: default;
}
.tile.opened.treasure {
    color: var(--number-color, var(--gold));
    background:
        radial-gradient(circle, rgba(246, 200, 101, .13), transparent 62%),
        #1b191e;
}
.tile.opened.mimic-cell {
    border-color: rgba(237, 102, 120, .45);
    background: radial-gradient(circle, rgba(237, 102, 120, .22), #28131d);
}
.tile.wrong-mark::after {
    position: absolute;
    inset: 12%;
    display: grid;
    place-items: center;
    color: var(--danger);
    content: "×";
    font-size: clamp(.9rem, 3vw, 1.55rem);
    font-weight: 700;
}

.chest-icon {
    width: 92%;
    height: 92%;
    background: url('/assets/chest-closed.webp') center / contain no-repeat;
    filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .48));
}
.tile.marked::before {
    position: absolute;
    z-index: 2;
    top: 5%;
    right: 5%;
    display: grid;
    width: clamp(14px, 42%, 23px);
    aspect-ratio: 1;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .65);
    border-radius: 50%;
    color: white;
    background: var(--violet);
    box-shadow: 0 0 10px rgba(169, 120, 255, .85);
    content: "!";
    font-size: clamp(.55rem, 1.5vw, .78rem);
    font-weight: 800;
}

.treasure-content {
    position: relative;
    width: 96%;
    height: 96%;
    background: url('/assets/chest-treasure.webp') center / contain no-repeat;
    filter: drop-shadow(0 3px 5px rgba(246, 200, 101, .25));
}
.treasure-number {
    position: absolute;
    right: 0;
    bottom: 0;
    display: grid;
    width: clamp(16px, 42%, 25px);
    aspect-ratio: 1;
    place-items: center;
    border: 1px solid currentColor;
    border-radius: 50%;
    color: var(--number-color, var(--gold));
    background: rgba(15, 11, 20, .92);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .55);
    font-size: clamp(.58rem, 1.65vw, .82rem);
    font-weight: 800;
}

.mimic-icon {
    width: 98%;
    height: 98%;
    background: url('/assets/chest-mimic.webp') center / contain no-repeat;
    filter: drop-shadow(0 3px 6px rgba(237, 102, 120, .4));
}

.result-panel {
    position: absolute;
    inset: clamp(14px, 3vw, 28px);
    z-index: 5;
    display: grid;
    place-content: center;
    justify-items: center;
    padding: 25px;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 15px;
    background: rgba(14, 10, 23, .95);
    text-align: center;
    backdrop-filter: blur(13px);
}
.result-panel[hidden] { display: none; }
.result-panel img {
    width: min(230px, 52vw);
    max-height: 230px;
    height: auto;
    object-fit: contain;
    margin-bottom: -4px;
    filter: drop-shadow(0 15px 20px rgba(0, 0, 0, .45));
}
.result-panel h3 { margin-bottom: 8px; font-size: clamp(1.8rem, 5vw, 2.6rem); letter-spacing: -.045em; }
.result-panel > p:not(.result-kicker) { max-width: 430px; margin-bottom: 18px; color: var(--muted); line-height: 1.55; }
.result-actions { display: flex; gap: 9px; }

.level-picker { display: flex; align-items: center; gap: 16px; margin-top: 23px; }
.level-picker-label {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
}
.level-buttons { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; width: 100%; }
.level-button {
    min-width: 0;
    aspect-ratio: 1;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--muted);
    background: rgba(255, 255, 255, .035);
    font-size: .72rem;
    font-weight: 700;
}
.level-button:hover:not(:disabled) { color: var(--ink); border-color: rgba(169, 120, 255, .45); }
.level-button.current { color: #170e24; border-color: var(--violet); background: var(--violet); }
.level-button.completed::after { color: var(--success); content: " ✓"; }
.level-button:disabled { cursor: not-allowed; opacity: .3; }

.escape-route {
    margin-top: 28px;
    padding: clamp(24px, 4vw, 38px);
    border: 1px solid rgba(246, 200, 101, .14);
    border-radius: 24px;
    background: linear-gradient(110deg, rgba(98, 60, 33, .22), rgba(64, 37, 91, .24));
}
.escape-route h2 { margin-bottom: 7px; font-size: clamp(1.6rem, 4vw, 2.3rem); letter-spacing: -.04em; }
.escape-route p:not(.escape-kicker) { margin-bottom: 0; color: var(--muted); }
.portal-button { flex: 0 0 auto; min-height: 50px; padding-inline: 22px; }

footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 0 24px 28px;
    color: #716a7d;
    font-size: .72rem;
}

@keyframes breathe {
    0%, 100% { transform: translateY(0) rotate(-.35deg); }
    50% { transform: translateY(-7px) rotate(.35deg); }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    50% { transform: translateX(7px); }
    75% { transform: translateX(-4px); }
}

@media (max-width: 760px) {
    .site-shell { width: min(100% - 22px, 650px); padding-top: 25px; }
    .masthead { grid-template-columns: 1fr; gap: 0; min-height: auto; text-align: center; }
    .eyebrow { justify-content: center; }
    .masthead-copy { grid-row: 1; }
    .mascot { grid-row: 2; width: min(390px, 82vw); margin: 4px auto 6px; justify-self: center; }
    .lede { margin-inline: auto; }
    .game-topbar, .instructions, .escape-route { align-items: stretch; flex-direction: column; }
    .game-topbar { gap: 14px; }
    .game-topbar .secondary-button { align-self: flex-start; }
    .instructions { gap: 14px; }
    .mode-switch { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
    .hud { grid-template-columns: repeat(2, 1fr); }
    .escape-route { text-align: center; }
    .portal-button { width: 100%; }
}

@media (max-width: 520px) {
    h1 { font-size: clamp(3rem, 16vw, 4.8rem); }
    .subtitle { font-size: .88rem; }
    .game-card { padding: 18px 12px 22px; border-radius: 20px; }
    .board-wrap { min-height: 255px; padding: 18px 12px; border-radius: 18px; }
    .board-wrap::before { border-width: 7px; border-radius: 16px; }
    .board-wrap::after { border-radius: 12px; }
    .board { gap: 3px; padding: 6px; border-radius: 7px; }
    .tile { border-radius: 3px; }
    .result-panel { inset: 18px 12px; }
    .level-picker { align-items: stretch; flex-direction: column; gap: 9px; }
    .level-buttons { grid-template-columns: repeat(5, 1fr); }
    .level-button { min-height: 34px; aspect-ratio: auto; }
    .result-actions { flex-direction: column; width: min(260px, 100%); }
    footer { flex-wrap: wrap; gap: 6px; text-align: center; }
    footer span:last-child { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
