/* "Find the piece" game (/{lang}/game). Loaded only by game.html, so every
   selector here is scoped under #gamePage or .game-* — nothing in this file
   can reach another page's markup. */

.game-page{
  max-width:var(--frame-max);margin:0 auto;padding-inline:var(--gutter);
}
.game-page h1{margin-bottom:6px;}
.game-lead{color:var(--muted);font-size:14.5px;max-width:70ch;margin:0 0 18px;}
.game-campaign{
  font-family:'Pretendard',sans-serif;font-size:13px;font-weight:600;color:var(--muted);
  margin-bottom:18px;
}
.game-campaign b{color:var(--text);}

/* ---------- hall of fame ---------- */
/* Site-wide standings, above the artwork list. Kept to one compact strip:
   it is context for the list, not the point of the page. */
.game-hall{
  margin:0 0 18px;padding:12px 14px;
  border:1px solid var(--border);border-radius:var(--r-md);background:var(--gray-50,var(--bg));
}
.game-hall h2{
  font-family:'Pretendard',sans-serif;font-size:12px;font-weight:700;letter-spacing:.06em;
  text-transform:uppercase;color:var(--muted);margin:0 0 8px;
}
.game-hall-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px;}
/* The name column is capped, not 1fr: with 1fr it ate the whole card and
   pushed the medal counts to the far right edge, a hand's width from the
   name they belong to. minmax lets it shrink on a phone. */
.game-hall-row{
  display:grid;grid-template-columns:22px minmax(0,190px) auto;justify-content:start;
  align-items:center;gap:10px;
  font-family:'Pretendard',sans-serif;font-size:13.5px;
}
.gh-rank{text-align:center;font-size:15px;line-height:1;}
.gh-who{display:flex;align-items:center;gap:8px;min-width:0;}
.game-hall .mini-avatar{width:26px;height:26px;font-size:12px;}
.gh-name{
  color:var(--text);font-weight:600;text-decoration:none;
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
.gh-name:hover{text-decoration:underline;}
/* Fixed-width medal cells so the three columns line up down the rows
   instead of shifting with each number. */
.gh-medals{display:flex;gap:10px;font-variant-numeric:tabular-nums;}
.gh-medal{min-width:34px;text-align:right;color:var(--text);white-space:nowrap;}

/* ---------- artwork list ---------- */
.game-toolbar{
  display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin:16px 0 14px;
}
.game-toolbar input[type="search"]{
  flex:1 1 240px;max-width:360px;font-family:inherit;font-size:14px;
  padding:9px 14px;border:1px solid var(--border-strong);border-radius:var(--r-full);
  background:var(--bg);color:var(--text);
}
.game-count{font-family:'Pretendard',sans-serif;font-size:13px;color:var(--muted);}

.game-list{display:flex;flex-direction:column;gap:12px;}
.game-card{
  /* Columns are sized to their contents and pushed left: with 1fr on the
     body the play button drifted to the far right of a wide card, an arm's
     length from the artwork it belongs to. The text column is capped so a
     long title cannot undo that. */
  display:grid;grid-template-columns:96px 320px auto;justify-content:start;
  gap:14px;align-items:center;
  padding:12px;border:1px solid var(--border);border-radius:var(--r-md);background:var(--bg);
  transition:box-shadow .15s linear,border-color .15s linear;
}
.game-card:hover{border-color:var(--border-strong);box-shadow:var(--shadow-sm);}
/* Brief highlight when coming back from a game you just played. */
.game-card.just-played{border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-soft);}
/* The thumbnail is wrapped in a link (it opens the lightbox), so the link
   is what fills the grid column now. */
.game-card-thumb-link{display:block;line-height:0;border-radius:var(--r-sm);}
.game-card-thumb-link:focus-visible{outline:2px solid var(--primary);outline-offset:2px;}
.game-card-thumb{
  width:96px;height:96px;object-fit:cover;border-radius:var(--r-sm);
  background:var(--gray-100);display:block;cursor:zoom-in;
}
/* The text column is a FIXED width, not auto: with auto, every card sized
   itself to its own title and the play buttons landed at a different x on
   each row — a ragged edge down the list. A long title wraps instead. */
.game-card-body{min-width:0;}
.game-card-title{font-family:'Pretendard',sans-serif;font-weight:700;font-size:15px;color:var(--text);}
.game-card-author{font-family:'Pretendard',sans-serif;font-size:13px;color:var(--muted);margin-top:1px;}
.game-card-pieces{font-family:'Pretendard',sans-serif;font-size:12.5px;color:var(--text);margin-top:5px;}
/* Capped: the medal rows sit under the title, and on a wide screen an
   auto-margin time column drifted to the far edge of the card, a hand's
   width away from the name it belongs to. */
.game-card-board{margin-top:7px;display:flex;flex-direction:column;gap:2px;max-width:280px;}
.gl-medal{display:flex;align-items:center;gap:7px;font-family:'Pretendard',sans-serif;font-size:12.5px;}
.gl-m{width:16px;text-align:center;}
.gl-n{color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0;}
.gl-t{margin-left:auto;font-variant-numeric:tabular-nums;font-weight:600;color:var(--text);}
.game-card-mine{
  margin-top:6px;font-family:'Pretendard',sans-serif;font-size:12.5px;font-weight:600;
  color:var(--primary);
}
.game-card-play{white-space:nowrap;}

.game-more{display:flex;justify-content:center;margin:18px 0;}

/* ---------- play screen ---------- */
.game-play{
  display:grid;grid-template-columns:minmax(0,7fr) minmax(260px,3fr);gap:16px;
  align-items:stretch;margin-top:12px;
}
.game-stage{
  position:relative;overflow:hidden;background:var(--primary-dark);
  border-radius:var(--r-lg);height:clamp(380px,70vh,780px);
  touch-action:none;   /* the stage handles its own pan/pinch */
  cursor:crosshair;
}
.game-stage canvas{
  position:absolute;left:0;top:0;transform-origin:0 0;image-rendering:pixelated;
}
.game-marks{position:absolute;left:0;top:0;transform-origin:0 0;pointer-events:none;}
.game-mark{position:absolute;box-sizing:border-box;}
.game-mark.found{
  border:2px solid #9EFFBF;box-shadow:0 0 0 2px rgba(0,0,0,.45),0 0 10px #9EFFBF;
  animation:gameFound .35s ease-out;
}
.game-mark.wrong{border:2px solid #E0534C;animation:gameWrong .4s ease-out;}
.game-mark.again{border:2px dashed rgba(247,247,245,.9);}
@keyframes gameFound{from{transform:scale(2.2);opacity:.2}to{transform:scale(1);opacity:1}}
@keyframes gameWrong{from{opacity:1}to{opacity:0}}

/* Countdown / preparing overlay */
.game-countdown{
  position:absolute;inset:0;display:flex;align-items:center;justify-content:center;
  background:rgba(15,20,17,.72);color:var(--bg);z-index:6;
  font-family:'Pretendard',sans-serif;font-weight:800;font-size:clamp(28px,9vw,84px);
  letter-spacing:-.02em;text-align:center;padding:16px;
}
/* display:flex above beats the UA [hidden] rule, so the overlay stayed on
   screen for the whole game — the player could see nothing. */
.game-countdown[hidden]{display:none;}
.game-countdown.pop{animation:gamePop .5s ease-out;}
@keyframes gamePop{from{transform:scale(.6);opacity:.3}to{transform:scale(1);opacity:1}}

/* Target artwork panel */
.game-target{
  display:flex;flex-direction:column;gap:10px;padding:14px;
  border:1px solid var(--border);border-radius:var(--r-lg);background:var(--surface);
  min-width:0;
}
.game-target-head{font-family:'Pretendard',sans-serif;font-size:12px;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:.04em;}
.game-target-figure{position:relative;display:block;margin:0 auto;line-height:0;}
.game-target-img{width:100%;height:auto;border-radius:var(--r-sm);display:block;background:var(--gray-100);}
.game-target-title{font-family:'Pretendard',sans-serif;font-weight:700;font-size:14.5px;color:var(--text);}
.game-target-author{font-family:'Pretendard',sans-serif;font-size:12.5px;color:var(--muted);}
/* Laid over the artwork itself: the piece map and the picture are the same
   thing, so stacking them saves the height that mattered most on a phone. */
.game-target-grid{
  position:absolute;inset:0;display:grid;gap:1px;
  border-radius:var(--r-sm);overflow:hidden;
}
/* Three states, never by colour alone: unused is faded and flat, in-use has
   a dashed outline, found is solid with a check mark. */
.gt-cell{position:relative;}
/* Not in this mosaic: dimmed right out, so the eye skips it. */
.gt-cell.unused{background:rgba(20,24,22,.62);}
/* Still to find: the artwork shows through, with a dashed outline over it. */
.gt-cell.in-use{background:rgba(255,255,255,.06);box-shadow:inset 0 0 0 1.5px rgba(255,255,255,.85);}
/* Found: brand green wash plus the check below. */
.gt-cell.found{background:rgba(26,60,43,.72);box-shadow:inset 0 0 0 1.5px #9EFFBF;}
.gt-cell.found::after{
  content:'✓';position:absolute;inset:0;display:flex;align-items:center;justify-content:center;
  color:#9EFFBF;font-size:13px;font-weight:700;line-height:1;text-shadow:0 1px 2px rgba(0,0,0,.6);
}
.game-stats{display:flex;flex-wrap:wrap;gap:10px;align-items:baseline;}
.game-stat-n{font-family:'Pretendard',sans-serif;font-weight:800;font-size:20px;color:var(--text);font-variant-numeric:tabular-nums;}
.game-stat-l{font-family:'Pretendard',sans-serif;font-size:12px;color:var(--muted);}
.game-progress{height:8px;border-radius:4px;background:var(--gray-200);overflow:hidden;}
.game-progress i{display:block;height:100%;background:var(--gradient-primary);width:0;transition:width .2s ease-out;}
.game-timer{
  font-family:'Pretendard',sans-serif;font-variant-numeric:tabular-nums;
  font-weight:700;font-size:22px;color:var(--text);
  background:none;border:none;padding:0;cursor:pointer;text-align:left;
}

/* ---------- result ---------- */
.game-result{position:relative;text-align:center;padding:28px 16px 40px;}
.game-result-time{
  font-family:'Pretendard',sans-serif;font-weight:800;letter-spacing:-.02em;
  font-size:clamp(40px,10vw,72px);color:var(--text);font-variant-numeric:tabular-nums;
}
.game-result-note{margin-top:8px;font-family:'Pretendard',sans-serif;font-weight:700;font-size:16px;color:var(--primary);min-height:24px;}
.game-result-actions{display:flex;gap:10px;justify-content:center;margin-top:22px;flex-wrap:wrap;}
.game-confetti{position:absolute;inset:0;pointer-events:none;overflow:hidden;}
.game-confetti canvas{position:absolute;left:0;top:0;}

/* ---------- notice screens ---------- */
.game-notice{
  padding:40px 16px;text-align:center;color:var(--muted);
  font-family:'Pretendard',sans-serif;font-size:15px;
}

/* ---------- phone: the mosaic gets the screen ---------- */
@media (max-width:900px){
  .game-play{grid-template-columns:1fr;gap:0;}
}
@media (max-width:640px){
  body.game-playing .game-page{padding:0;max-width:none;}
  body.game-playing .game-stage{
    height:100dvh;border-radius:0;
  }
  /* HUD across the top of the mosaic. */
  .game-hud{
    position:fixed;left:0;right:0;top:0;z-index:160;
    display:flex;align-items:center;gap:10px;padding:10px 12px;
    padding-top:calc(10px + env(safe-area-inset-top,0px));
    background:rgba(15,20,17,.78);color:var(--bg);
  }
  .game-hud .game-timer{color:var(--bg);font-size:16px;margin-left:auto;}
  .game-hud-stat{font-family:'Pretendard',sans-serif;font-size:13px;font-weight:600;color:var(--bg);}
  .game-hud button{
    background:none;border:none;color:var(--bg);font-size:17px;cursor:pointer;padding:4px 6px;
  }
  /* Bottom sheet: small by default, dragged/tapped up to see the artwork. */
  .game-target{
    position:fixed;left:0;right:0;bottom:0;z-index:160;
    border-radius:var(--r-lg) var(--r-lg) 0 0;border-bottom:none;
    max-height:34vh;overflow-y:auto;overscroll-behavior-y:contain;
    transition:max-height .22s ease-out;
    padding-bottom:calc(14px + env(safe-area-inset-bottom,0px));
  }
  .game-sheet-handle{
    position:sticky;top:0;align-self:center;width:44px;height:20px;
    background:none;border:none;cursor:pointer;flex-shrink:0;
  }
  .game-sheet-handle::before{
    content:'';display:block;width:40px;height:4px;border-radius:2px;
    background:var(--border-strong);margin:6px auto;
  }
  /* Collapsed sizes. The expanded ones are set inline by game.js so the
     sheet cannot be left half-open by a cascade surprise. */
  /* Artwork on the left, everything else on the right: collapsed, the sheet
     is short, and a player should not have to drag it open to see how many
     pieces are left or what the clock says. */
  .game-target{flex-direction:row;flex-wrap:wrap;align-items:flex-start;gap:12px;}
  .game-sheet-handle{order:-1;flex-basis:100%;}
  .game-target-head{display:none;}
  .game-target-figure{flex:0 0 42%;max-width:42%;}
  .game-target-img{max-height:none;width:100%;margin:0;transition:max-height .22s ease-out;}
  .game-target-info{flex:1;min-width:0;display:flex;flex-direction:column;gap:6px;}
  .game-target-info .game-stats{gap:8px;}
  .game-target-info .game-stat-n{font-size:17px;}
  /* Dragged open: back to one column so the artwork itself gets the room.
     That is the only reason to open it now — the numbers are always visible. */
  .game-target.expanded{flex-direction:column;align-items:stretch;}
  .game-target.expanded .game-target-figure{flex:none;max-width:100%;width:auto;margin:0 auto;}
  .game-target.expanded .game-target-img{max-height:52vh;width:auto;}
  .game-target.expanded .game-target-info{width:100%;}
  /* Clear of the HUD bar above it (the two overlapped). */
  body.game-playing .game-zoom-toolbar{top:calc(62px + env(safe-area-inset-top,0px));}
  .game-card{grid-template-columns:72px 1fr;}
  .game-card-thumb{width:72px;height:72px;}
  .game-card-play{grid-column:1 / -1;width:100%;}
}
@media (min-width:641px){
  .game-hud{display:none;}
  .game-sheet-handle{display:none;}
}

/* ---------- buttons ----------
   This page loads only base.css and game.css. Neither gives .admin-btn a
   size (that lives in admin.css), and .btn-primary carries colour ONLY — its
   padding comes from `.modal-actions button`, which exists just inside
   dialogs. Used outside one, as the result screen does, a button falls back
   to the browser default: 22px tall, unreadable and hard to hit on a phone.
   So the game's buttons are sized here, scoped to .game-page. */
.game-page .admin-btn,
.game-page .btn-primary{
  appearance:none;cursor:pointer;font-family:'Pretendard',sans-serif;
  font-size:13.5px;font-weight:600;line-height:1.2;
  padding:10px 18px;border-radius:var(--r-full);
  border:1px solid var(--border-strong);background:var(--bg);color:var(--text);
  min-height:42px;
  transition:background .12s linear,opacity .12s linear;
}
.game-page .admin-btn:hover{background:var(--surface);}
.game-page .admin-btn.primary,
.game-page .btn-primary{background:var(--gradient-primary);color:#fff;border-color:transparent;}
.game-page .admin-btn.primary:hover,
.game-page .btn-primary:hover{opacity:.92;}
.game-page .admin-btn:disabled{opacity:.5;cursor:default;}
/* The mute control is an icon, so it only needs to be a comfortable target. */
.game-page .game-target-info .admin-btn{padding:8px 12px;min-height:38px;}

/* The result screen's actions are the one thing a finished player reaches
   for, and on a phone they were 22px tall. Full width, thumb-sized. */
.game-page .game-result-actions button{font-size:15px;padding:14px 26px;min-height:52px;}
@media (max-width:640px){
  .game-result-actions{flex-direction:column;gap:10px;}
  .game-page .game-result-actions button{width:100%;font-size:16px;min-height:56px;padding:16px 20px;}
}

/* ---------- sector hint ----------
   A coarse box over the area that still holds a piece — never the cell
   itself. It fades in, holds, and leaves on its own. */
.game-hint-box{
  position:absolute;box-sizing:border-box;pointer-events:none;
  border:3px solid #E8B84B;
  background:rgba(232,184,75,.16);
  box-shadow:0 0 0 2px rgba(0,0,0,.35), 0 0 22px rgba(232,184,75,.55);
  border-radius:2px;
  animation:gameHint .4s ease-out;
}
@keyframes gameHint{from{opacity:0;transform:scale(1.06)}to{opacity:1;transform:scale(1)}}
@media (prefers-reduced-motion: reduce){ .game-hint-box{animation:none;} }

/* ---------- minimap ----------
   Only shown while something is off screen (game.js updateMinimap). The box
   is where you are; the shrunk canvas is the whole mosaic. */
.game-minimap{
  position:absolute;right:12px;bottom:12px;z-index:5;
  border:1px solid rgba(247,247,245,.35);border-radius:4px;overflow:hidden;
  background:rgba(15,20,17,.6);box-shadow:0 2px 10px rgba(0,0,0,.4);
  line-height:0;pointer-events:none;
}
.game-minimap canvas{display:block;}
.gm-view{
  position:absolute;box-sizing:border-box;
  border:2px solid #9EFFBF;background:rgba(158,255,191,.18);
  min-width:3px;min-height:3px;
}
@media (max-width:640px){
  .game-minimap{bottom:auto;top:calc(112px + env(safe-area-inset-top,0px));right:10px;}
}

/* Two across on a wide screen. One column left most of a 1400px frame empty
   and made the list twice as long to scroll. The text column becomes 1fr
   here instead of the fixed 320px: the two grid columns are equal, so the
   play buttons still line up down each column — which is what the fixed
   width was for. */
@media (min-width:1100px){
  .game-list{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));align-items:start;}
  .game-card{grid-template-columns:96px minmax(0,1fr) auto;}
}

/* The signed-in player, under the podium. Same three-column rhythm as a
   podium row so the medal counts stay in one line down the block, with a
   rule above it to say "this part is about you". */
.game-hall-me{
  display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:10px;
  margin-top:8px;padding-top:8px;border-top:1px solid var(--border);
  font-family:'Pretendard',sans-serif;font-size:13.5px;
}
.game-hall-me[hidden]{display:none;}
.gh-me-rank{font-weight:700;color:var(--text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}

/* ---------- game chooser ----------
   /{lang}/game opens on a choice between the two games (2026-09-20). One
   card is a button (the find-the-piece half lives on this page), the other
   a link to /coloring. Same card either way. */
.game-choose{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:14px;margin:18px 0 28px;max-width:1140px;}
/* The sky card is not a game — a night tint sets it apart from the two. */
.game-choice-stars .game-choice-icon{color:#E8B84B;}
.game-choice-stars:hover{border-color:#E8B84B;}
.game-choice{
  appearance:none;cursor:pointer;text-align:left;text-decoration:none;
  display:flex;flex-direction:column;gap:6px;padding:20px 20px 18px;
  border:1px solid var(--border);border-radius:var(--r-lg);background:var(--bg);color:var(--text);
  font-family:'Pretendard',sans-serif;
  transition:box-shadow .15s linear,border-color .15s linear,transform .14s ease-out;
}
.game-choice:hover{border-color:var(--border-strong);box-shadow:var(--shadow-md);transform:translateY(-1px);}
.game-choice:focus-visible{outline:2px solid var(--primary);outline-offset:2px;}
.game-choice-icon{
  display:flex;align-items:center;justify-content:center;width:46px;height:46px;border-radius:14px;
  background:var(--primary-soft);font-size:22px;line-height:1;margin-bottom:4px;
}
.game-choice-color .game-choice-icon{background:#E8ECFF;}
.game-choice-title{font-size:18px;font-weight:800;letter-spacing:-.01em;}
.game-choice-desc{font-size:13.5px;color:var(--muted);line-height:1.5;}
.game-choice-status{margin-top:6px;font-size:12.5px;font-weight:700;color:var(--primary);min-height:18px;}
.game-back-choose{
  appearance:none;border:none;background:none;cursor:pointer;padding:0;margin:0 0 10px;
  font-family:'Pretendard',sans-serif;font-size:13px;font-weight:600;color:var(--muted);
}
.game-back-choose:hover{color:var(--text);text-decoration:underline;}
@media (prefers-reduced-motion: reduce){ .game-choice{transition:none;} .game-choice:hover{transform:none;} }

/* ---------- recent games ----------
   Under the hall of fame on the list screen, and per artwork on the result
   screen. One compact row per finished run; a medal only when the artwork
   has enough recorders (the rules in supabase_game_medal_rules.sql). */
.game-card-medal-note{font-size:11px;color:var(--muted);margin-top:3px;}
.game-recent{
  margin:0 0 18px;padding:12px 14px;
  border:1px solid var(--border);border-radius:var(--r-md);background:var(--gray-50,var(--bg));
}
.game-recent[hidden]{display:none;}
.game-recent h2{
  font-family:'Pretendard',sans-serif;font-size:12px;font-weight:700;letter-spacing:.06em;
  text-transform:uppercase;color:var(--muted);margin:0 0 8px;
}
.game-recent-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px;}
.game-recent-row{
  display:grid;grid-template-columns:26px minmax(0,150px) minmax(0,1fr) auto auto 20px;
  grid-template-areas:"av name art time ago st";
  align-items:center;gap:6px 10px;font-family:'Pretendard',sans-serif;font-size:13.5px;
  padding:4px 6px;border-radius:var(--r-sm);
}
.game-recent-row>.mini-avatar{grid-area:av;}
.gr-name{grid-area:name;}
.gr-art{grid-area:art;}
.gr-time{grid-area:time;}
.gr-ago{grid-area:ago;}
.gr-st{grid-area:st;text-align:center;}
.game-recent-row.clickable{cursor:pointer;}
.game-recent-row.clickable:hover{background:var(--surface);}
.game-recent-row.me{background:var(--primary-soft);}
.game-recent .mini-avatar{width:26px;height:26px;font-size:12px;}
.gr-name{color:var(--text);font-weight:600;text-decoration:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.gr-name:hover{text-decoration:underline;}
.gr-art{display:flex;align-items:center;gap:8px;min-width:0;color:var(--muted);text-decoration:none;}
.gr-art img{width:26px;height:26px;object-fit:cover;border-radius:4px;background:var(--gray-100);flex-shrink:0;}
.gr-art span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.gr-time{font-variant-numeric:tabular-nums;font-weight:700;color:var(--text);white-space:nowrap;}
.gr-time small{font-weight:500;color:var(--muted);margin-left:4px;}
.gr-ago{color:var(--muted);font-size:12px;white-space:nowrap;}
.gr-medal{font-size:14px;line-height:1;}
.gr-rank{font-size:11.5px;font-weight:700;color:var(--muted);}
.game-recent-result{margin:18px auto 0;max-width:560px;text-align:left;}
.game-recent-result .game-recent-row{
  grid-template-columns:26px minmax(0,1fr) auto auto 20px;
  grid-template-areas:"av name time ago st";
}
@media (max-width:640px){
  /* Two lines: who + time, then the artwork + when. */
  .game-recent-row{
    grid-template-columns:26px minmax(0,1fr) auto 20px;
    grid-template-areas:"av name time st" "av art ago st";row-gap:2px;
  }
  .game-recent-result .game-recent-row{
    grid-template-columns:26px minmax(0,1fr) auto auto 20px;
    grid-template-areas:"av name time ago st";
  }
}
