/* ==========================================================================
   Matchy Matchy — the class game at /games/.
   Palette is inherited from style.css; nothing is redefined here.
   Built for a projector: big type, high contrast, no hover-only affordances.
   ========================================================================== */

/* The two team colours. Chosen to hold up on a projector against the navy
   slope, and to stay distinguishable for red-green colour blindness (the
   pair is red/blue, not red/green). */
:root {
    --mm-red:  #F06A5A;
    --mm-blue: #60A8F0;
}

.mm-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- intro ---------- */

.mm-setup { display: flex; flex-wrap: wrap; gap: 16px; margin: 14px 0 22px; }
.mm-setup label {
    display: flex; flex-direction: column; gap: 5px;
    font-size: .74rem; text-transform: uppercase; letter-spacing: .09em;
    font-weight: 700; color: var(--navy-soft);
}
.mm-setup input {
    font: inherit; font-size: 1rem; color: var(--ink);
    padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
    background: var(--white); min-width: 190px;
}
.mm-setup input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.mm-setup input[type="number"] { min-width: 120px; }

/* ---------- the game shell ---------- */

.mm-game {
    background: var(--navy-deep);
    color: var(--ivory);
    padding: 20px 22px 26px;
    margin-top: 30px;
}
.mm-game :focus-visible { outline: 3px solid var(--gold-soft); outline-offset: 2px; }

/* .btn sets display:inline-flex, which outranks the UA rule for [hidden] — so
   Reveal, Right and Wrong all showed at once. Put the attribute back in charge. */
.matchy [hidden] { display: none !important; }

/* In full screen the shell owns the viewport and the board takes the slack.
   Safari (iPadOS included) only matches the -webkit- pseudo-class, and a
   selector list is dropped whole if any selector in it is unknown — so these
   have to be separate rules, not one comma-separated one. */
.mm-game:fullscreen {
    margin: 0; padding: 18px 26px 22px;
    display: flex; flex-direction: column; justify-content: space-between;
}
.mm-game:-webkit-full-screen {
    margin: 0; padding: 18px 26px 22px;
    display: flex; flex-direction: column; justify-content: space-between;
}
.mm-game:fullscreen .mm-board { flex: 1 1 auto; align-content: center; }
.mm-game:-webkit-full-screen .mm-board { flex: 1 1 auto; align-content: center; }

/* Touch: no hover states to rely on, and stop iOS double-tap zoom eating a
   card tap. */
@media (hover: none) {
    .mm-board.mm-live .mm-card:not(.mm-up):not(.mm-done):hover .mm-face-back { background: var(--navy); }
}
.mm-card, .mm-console .btn { touch-action: manipulation; }

/* ---------- the arena: a climb each side, the game in the middle ---------- */

.mm-arena {
    max-width: 1500px; margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(0, 3.4fr) minmax(150px, 1fr);
    gap: 18px; align-items: stretch;
}
.mm-center { display: flex; flex-direction: column; min-width: 0; }

.mm-climb { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.mm-climb-svg {
    display: block; width: 100%; height: auto; flex: 1 1 auto; min-height: 0;
    border-radius: var(--r);
    box-shadow: inset 0 0 0 1px rgba(232,182,90,.22), 0 10px 30px rgba(0,0,0,.28);
}
/* The right-hand climb mirrors the left, so the two summits lean toward each
   other. Nothing inside carries text, so mirroring is safe — the team name and
   score live in HTML underneath. */
.mm-climb-1 .mm-climb-svg { transform: scaleX(-1); }

.mm-drip { animation: mm-drip 2.4s ease-in-out infinite; }
@keyframes mm-drip { 0%,100% { opacity: .35; } 50% { opacity: 1; } }

.mm-hiker {
    transition: transform .85s cubic-bezier(.34,.9,.38,1);
    stroke-linejoin: round;
}
.mm-hiker .mm-legs,
.mm-hiker .mm-staff { stroke: var(--ivory); }
.mm-hiker .mm-head  { fill: #F5DCC0; }
.mm-hiker .mm-shadow { fill: #0A1630; opacity: .3; }
.mm-hiker-0 .mm-shirt, .mm-hiker-0 .mm-pack { fill: var(--mm-red); }
.mm-hiker-0 .mm-arms  { stroke: var(--mm-red); }
.mm-hiker-1 .mm-shirt, .mm-hiker-1 .mm-pack { fill: var(--mm-blue); }
.mm-hiker-1 .mm-arms  { stroke: var(--mm-blue); }

/* The cheer runs on the INNER group. A CSS transform replaces the SVG
   transform attribute outright, so animating the outer group — the one the
   script positions — flung the winning hiker to the corner. */
.mm-hiker.mm-arrived .mm-hiker-body { animation: mm-cheer .62s ease-in-out 4; }
@keyframes mm-cheer { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-11px); } }

.mm-trail { animation: mm-trail-crawl 14s linear infinite; }
@keyframes mm-trail-crawl { to { stroke-dashoffset: -64; } }

.mm-stations .mm-milestone { fill: #E8B65A; opacity: .8; }
.mm-stations .mm-milestone-post { stroke: #E8B65A; opacity: .55; }

/* the team plate under each climb */
.mm-score {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 10px 12px; border-radius: var(--r); text-align: center;
    background: rgba(255,255,255,.06); border: 2px solid rgba(255,255,255,.09);
    transition: border-color .25s, background .25s, transform .25s;
}
.mm-score.mm-active { transform: translateY(-2px); }
.mm-score-0.mm-active { border-color: var(--mm-red);  background: rgba(240,106,90,.16); }
.mm-score-1.mm-active { border-color: var(--mm-blue); background: rgba(96,168,240,.16); }
.mm-team-name { font-family: var(--serif); font-size: 1.24rem; line-height: 1.15; }
.mm-score-0 .mm-team-name { color: var(--mm-red); }
.mm-score-1 .mm-team-name { color: var(--mm-blue); }
.mm-points { font-size: .8rem; opacity: .72; }
.mm-points b {
    font-size: 2.1rem; font-weight: 700; opacity: 1; margin-right: .12em;
    font-variant-numeric: tabular-nums;
}

/* ---------- the question ---------- */

.mm-stage { max-width: var(--wrap-wide); margin: 22px auto 0; }
.mm-center .mm-q { margin-top: 0; }

.mm-q {
    position: relative; overflow: hidden;
    background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.05));
    border: 1px solid rgba(255,255,255,.16);
    border-radius: var(--r);
    padding: 20px 24px 22px;
    box-shadow: 0 8px 26px rgba(0,0,0,.24);
    transition: opacity .3s;
}
/* a colour rail down the left in whichever team is up */
.mm-q::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
    background: var(--mm-red); transition: background .25s;
}
.mm-q.mm-turn-1::before { background: var(--mm-blue); }

/* the category badge takes the colour of its subject */
.mm-cat-gospel  { background: #DCE7F8; color: #1B3A73; }
.mm-cat-ot      { background: #FBE9CB; color: #7A5410; }
.mm-cat-history { background: #EADCF3; color: #4A2A63; }
.mm-q.mm-dim { opacity: .42; }
.mm-q-top { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.mm-turn { font-size: .78rem; text-transform: uppercase; letter-spacing: .09em; font-weight: 700; opacity: .72; }
.mm-clock {
    margin-left: auto;
    font-family: var(--serif); font-size: 2.1rem; font-weight: 600;
    min-width: 2.6ch; text-align: center; line-height: 1;
    font-variant-numeric: tabular-nums;
    padding: 6px 12px; border-radius: 100px;
    border: 2px solid rgba(255,255,255,.18);
}
.mm-clock.mm-low { border-color: var(--gold); animation: mm-pulse 1s ease-in-out infinite; }
@keyframes mm-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.09); } }
.mm-clock.mm-low { color: var(--gold-soft); }
.mm-clock.mm-out { color: #E88A7F; border-color: #E88A7F; animation: none; }
.mm-clock.mm-off { opacity: .2; animation: none; }

.mm-q-text {
    font-family: var(--serif); font-size: 2rem; line-height: 1.28;
    margin: 0; color: var(--white); text-wrap: balance;
}
.mm-a-text {
    font-size: 1.28rem; line-height: 1.45; margin: .9rem 0 0;
    color: var(--gold-soft); border-top: 1px solid rgba(255,255,255,.16); padding-top: .9rem;
    animation: mm-rise .32s ease-out;
}
@keyframes mm-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.mm-ref { margin: .4rem 0 0; color: rgba(253,246,232,.6); font-size: .95rem; }

.mm-hint {
    text-align: center; margin: 14px 0 0;
    font-size: .82rem; text-transform: uppercase; letter-spacing: .09em;
    font-weight: 700; color: rgba(253,246,232,.55);
}

/* ---------- the board ---------- */

.mm-board {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
    margin: 16px 0 0;
}
.mm-board.mm-live .mm-card:not(.mm-up):not(.mm-done) { cursor: pointer; }
.mm-board.mm-live .mm-card:not(.mm-up):not(.mm-done):hover .mm-face-back { background: var(--navy-soft); }

.mm-card {
    all: unset;
    display: block; position: relative;
    aspect-ratio: 3 / 4;
    perspective: 900px;
    cursor: default;
}
.mm-card-inner {
    position: absolute; inset: 0;
    transform-style: preserve-3d;
    transition: transform .45s cubic-bezier(.4,.9,.35,1);
    border-radius: var(--r);
}
.mm-card.mm-up .mm-card-inner,
.mm-card.mm-done .mm-card-inner { transform: rotateY(180deg); }

.mm-face {
    position: absolute; inset: 0;
    backface-visibility: hidden; -webkit-backface-visibility: hidden;
    border-radius: var(--r);
    display: flex; align-items: center; justify-content: center;
    border: 2px solid transparent;
    box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
.mm-face-back {
    background:
        radial-gradient(circle at 50% 42%, rgba(232,182,90,.16), transparent 62%),
        linear-gradient(160deg, #22386B, #14264C);
    border-color: rgba(200,144,31,.36);
}
.mm-face-back svg { width: 42%; height: 42%; fill: rgba(200,144,31,.45); stroke: rgba(200,144,31,.45); }
.mm-face-front {
    background: linear-gradient(170deg, #FFFCF4, var(--ivory));
    transform: rotateY(180deg); flex-direction: column; gap: 4px;
    border-color: rgba(21,42,91,.10);
}
.mm-face-front svg { width: 54%; height: 54%; fill: var(--navy); stroke: var(--navy); }

/* stroke is set on the <svg> itself, not on a descendant selector. <use> draws
   the symbol into shadow DOM, which page rules cannot select into — only
   inherited properties cross that boundary. fill did; a `svg [fill="none"]`
   rule matched nothing, and the stroked icons (the hiker, the stall, the card
   back) rendered as a bare dot. */
.mm-face-front .mm-label {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
    font-weight: 700; color: var(--navy-soft);
}

.mm-card.mm-done .mm-face-front {
    background: linear-gradient(170deg, #F5CE86, var(--gold));
    border-color: rgba(21,42,91,.22);
}
.mm-card.mm-done .mm-face-front svg { fill: var(--navy-deep); stroke: var(--navy-deep); }
.mm-card.mm-done { opacity: 1; }
.mm-card.mm-done .mm-card-inner { transform: rotateY(180deg) scale(.94); }
.mm-card.mm-up   .mm-card-inner { box-shadow: 0 0 0 3px var(--gold-soft); border-radius: var(--r); }
.mm-card.mm-miss .mm-face-front { background: #F6DAD5; }
.mm-card.mm-miss .mm-card-inner { animation: mm-shake .4s ease-in-out; }
@keyframes mm-shake { 0%,100% { } 25% { transform: rotateY(180deg) translateX(-5px); }
                      75% { transform: rotateY(180deg) translateX(5px); } }

/* ---------- the console ---------- */

.mm-console {
    max-width: 1500px; margin: 20px auto 0;
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
}
.mm-console .btn { cursor: pointer; font: inherit; font-weight: 650; font-size: .95rem; }
.mm-console-sep { flex: 1 1 auto; }
.mm-console .mm-right { background: #2E9A6B; color: #fff; }
.mm-console .mm-right:hover { background: #37B37E; color: #fff; }
.mm-console .btn[disabled] { opacity: .35; cursor: not-allowed; }

/* ---------- the win banner ---------- */

.mm-win {
    max-width: 1500px; margin: 22px auto 0;
    background: linear-gradient(135deg, #F5CE86, var(--gold) 55%, #B87E15);
    color: var(--navy-deep);
    border-radius: var(--r); padding: 30px 24px; text-align: center;
    box-shadow: 0 12px 34px rgba(0,0,0,.3);
    animation: mm-rise .45s ease-out;
}
.mm-win-team { font-family: var(--serif); font-size: 3rem; margin: 0; line-height: 1.1; }
.mm-win-line { font-size: 1.15rem; margin: .2rem 0 1rem; }
.mm-win-verse { color: var(--navy); margin: 0 0 1.2rem; }
.mm-win .btn { background: var(--navy); color: var(--ivory); cursor: pointer; font: inherit; font-weight: 650; }
.mm-win .btn:hover { background: var(--navy-deep); color: var(--ivory); }


/* ---------- the standalone play window ---------- */

/* No site header, no nav, no footer. The page is the game. */
body.bare { background: var(--navy-deep); color: var(--ivory); }
body.bare #main { min-height: 100vh; display: flex; }
.matchy-bare {
    flex: 1; display: flex; flex-direction: column;
    min-height: 100vh; padding: 0;
}

.mm-topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 10px 22px;
    border-bottom: 1px solid rgba(255,255,255,.10);
}
.mm-wordmark {
    font-family: var(--serif); font-size: 1.05rem; color: var(--gold-soft);
    letter-spacing: .01em;
}
.mm-topbar-sep { flex: 1 1 auto; }
.mm-topbar-link {
    font-size: .78rem; text-transform: uppercase; letter-spacing: .09em;
    font-weight: 700; color: rgba(253,246,232,.5); text-decoration: none;
}
.mm-topbar-link:hover { color: var(--gold-soft); }

/* the setup screen, centred in the window */
.matchy-bare #mm-intro {
    flex: 1; display: flex; align-items: center; justify-content: center;
    padding: 28px 22px;
}
.mm-intro-card {
    width: 100%; max-width: 620px; text-align: center;
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: var(--r);
    padding: 34px 32px 30px;
}
.mm-intro-card h1 {
    font-family: var(--serif); font-size: 2.6rem; margin: 0 0 .4rem;
    color: var(--white); font-weight: 600;
}
.mm-intro-line { font-size: 1.1rem; line-height: 1.5; margin: 0 0 1.6rem; color: rgba(253,246,232,.8); }
.mm-intro-card h2 { display: none; }
.mm-intro-card .mm-setup { justify-content: center; }
.mm-intro-card .mm-setup label { color: rgba(253,246,232,.6); }
.mm-intro-card .mm-setup input {
    background: rgba(255,255,255,.08); color: var(--ivory);
    border-color: rgba(255,255,255,.18); text-align: center;
}
.mm-intro-card .cta { margin: 1.4rem 0 0; }
.mm-intro-card .btn { cursor: pointer; font: inherit; font-weight: 650; font-size: 1rem; padding: 13px 26px; }
.mm-intro-card .fine { color: rgba(253,246,232,.45); margin: 1rem 0 0; }

/* the game fills the rest of the window */
.matchy-bare .mm-game {
    flex: 1; display: flex; flex-direction: column; justify-content: space-between;
    margin-top: 0; padding: 18px 22px 20px;
}
.matchy-bare .mm-arena { flex: 1 1 auto; min-height: 0; }


/* ---------- fit the window, never scroll ---------- */

/* The play window shows the whole game at once. Nothing here scrolls: the board
   is sized from the space left over, not the other way round. 100dvh rather
   than 100vh because iPadOS Safari counts its chrome in the dynamic unit. */
body.bare, html:has(body.bare) { height: 100%; overflow: hidden; }
body.bare #main { min-height: 0; height: 100dvh; }
.matchy-bare { height: 100dvh; min-height: 0; overflow: hidden; }

.matchy-bare .mm-game { flex: 1 1 auto; min-height: 0; padding: 14px 18px 16px; }
.matchy-bare .mm-arena { flex: 1 1 auto; min-height: 0; }
.matchy-bare .mm-climb { min-height: 0; }
.matchy-bare .mm-climb-svg {
    height: 100%; width: 100%; min-height: 0;
    /* The svg is anchored to the bottom of a taller column, so it is
       letterboxed at the top. Paint that band the sky's own top colour
       so the seam does not show. */
    background: #1B3668;
}
.matchy-bare .mm-center { min-height: 0; }

.matchy-bare .mm-board {
    flex: 1 1 auto; min-height: 0;
    grid-template-rows: repeat(4, minmax(0, 1fr));
    gap: 10px; margin-top: 12px;
}
/* The card fills its grid cell instead of dictating its own height. */
.matchy-bare .mm-card { aspect-ratio: auto; height: 100%; min-height: 0; }
.matchy-bare .mm-hint { margin: 10px 0 0; }
.matchy-bare .mm-console { margin-top: 14px; }

/* the win banner floats over the board rather than pushing it off-screen */
.matchy-bare .mm-win {
    position: fixed; inset: auto 0 0 0; z-index: 20;
    max-width: 640px; margin: 0 auto 26px;
}

/* ---------- narrower screens ---------- */

@media (max-width: 900px) {
    /* Side-by-side climbs need real height; below this they go above the board
       as a short pair instead. */
    .mm-arena { grid-template-columns: 1fr 1fr; gap: 12px; }
    .mm-center { grid-column: 1 / -1; order: 2; }
    .mm-climb-0 { order: 0; }
    .mm-climb-1 { order: 1; }
    .mm-climb-svg { max-height: 230px; }
    .mm-q-text { font-size: 1.45rem; }
}
@media (max-width: 560px) {
    .mm-game { padding: 16px 16px 20px; }
    .mm-board { grid-template-columns: repeat(4, 1fr); gap: 7px; }
    .mm-q-text { font-size: 1.2rem; }
    .mm-clock { font-size: 1.5rem; }
    .mm-console-sep { display: none; }
    .mm-console { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
    .mm-hiker, .mm-card-inner { transition: none; }
    .mm-drip, .mm-hiker.mm-arrived { animation: none; }
}
