/* Dash Go — app.css (11 §1). Portrait mobile-first; ≥ 360×640 no scroll
   (FR-073); desktop letterboxed. Reduced-motion handled in JS anim layer. */
:root {
  --bg: #16324f;
  --bg2: #1d3557;
  --panel: #f4f0e6;
  --ink: #1c2b3a;
  --accent: #ffd54a;
  --accent2: #e0533d;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100dvh; }
@supports not (height: 100dvh) {
  html, body { height: 100vh; }
}
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* App background (task.txt §1–§3): cover + center, never stretched.
     - Image layer: var(--bg-image) driven at runtime by js/backgrounds.js,
       the SINGLE source of truth — absolute URLs resolved from the JS
       module location (menu = background.*, gameplay = background_game.*,
       WebP full/small by viewport, PNG fallback). This stylesheet contains
       ZERO asset paths and ZERO upper-level (../) references: every public
       URL stays inside the dashgo folder tree.
     - Fallback is `none`: pre-JS first paint shows the scrim gradient over
       --bg2 (never a broken/partial image); JS sets the image at boot.
     - Top layer: vertical scrim — darker at HUD/actions edges, clearer in the
       middle where the transparent canvas board sits (GameRenderer clearRect,
       .board-wrap/#board transparent). HUD stays DOM-above-canvas.
     - background-color fallback = --bg2 while images load (no black bars:
       cover always fills the viewport; cropping removes edges first, the
       clear-sky center is preserved on desktop / tablet / mobile).
     No hardcoded pixel sizes here — sizing is viewport-relative (cover,
     100dvh, min()/vw); tile geometry stays dynamic in GameRenderer
     (getBoundingClientRect + min(devicePixelRatio,2) + computeLayout). */
  background-color: var(--bg2);
  background-image:
    linear-gradient(180deg, rgba(10, 25, 45, 0.62) 0%, rgba(10, 25, 45, 0.28) 30%, rgba(10, 25, 45, 0.16) 50%, rgba(10, 25, 45, 0.30) 72%, rgba(10, 25, 45, 0.60) 100%),
    var(--bg-image, none);
  background-size: cover, cover;
  background-position: center center, center center;
  background-repeat: no-repeat, no-repeat;
  color: var(--panel);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* screens — dvh keeps board inside dynamic viewport (mobile address bar).
   Transparent so the body background shows through on every screen
   (background.png on loading/home/end, background_game.png on game —
   switched via --bg-image by js/backgrounds.js). The body scrim above is
   the ONLY overlay — no per-screen background, so the frame stays
   continuous. Layer order (task.txt §2): HUD (DOM) > tiles (canvas base) >
   effects (canvas fx) > background image > transparent base canvas. */
.screen {
  position: fixed; inset: 0; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  height: 100dvh;
  background: transparent;
}
@supports not (height: 100dvh) {
  .screen { height: 100vh; }
}
.screen.active { display: flex; }

/* loading */
.loading-wrap { text-align: center; width: min(78vw, 320px); }
.logo-img {
  width: min(60vw, 240px); height: auto; display: block; margin: 0 auto;
  aspect-ratio: 1176 / 625; /* reserve space — no CLS before image decode */
}
.logo-img.big { width: min(72vw, 300px); margin-bottom: 12px; }
.logo-img.end { width: min(40vw, 160px); margin: 0 auto 10px; }
.loading-track { height: 8px; border-radius: 4px; background: rgba(255,255,255,0.18); overflow: hidden; }
.loading-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s ease; }

/* home */
#screen-home { overflow-y: auto; overscroll-behavior-y: contain; }
.home-wrap { text-align: center; width: min(100%, 1040px); padding: 24px clamp(16px, 3vw, 36px); margin: auto; }
.home-sub { margin: 8px auto 20px; opacity: 0.92; max-width: 40ch; text-shadow: 0 1px 8px rgba(5, 15, 30, 0.85); }
.profile-panel { display: grid; gap: 8px; width: min(100%, 360px); margin: 12px auto 0; padding: 14px 16px; border: 1px solid rgba(233,243,255,.2); border-radius: 12px; background: rgba(10,27,47,.76); text-align: left; }
.profile-panel[hidden], .profile-form[hidden] { display: none; }
.profile-panel h2 { color: var(--accent); font-size: .86rem; letter-spacing: .06em; text-transform: uppercase; }
.profile-current, .profile-message { color: rgba(231,239,248,.76); font-size: .82rem; line-height: 1.4; overflow-wrap: anywhere; }
.profile-form { display: grid; grid-template-columns: minmax(0,1fr) auto auto; align-items: end; gap: 8px; }
.profile-form label, .profile-form .profile-message { grid-column: 1 / -1; }
.profile-form label { color: #f5f7fa; font-size: .84rem; font-weight: 650; }
.profile-form input { min-width: 0; width: 100%; min-height: 38px; padding: 7px 10px; border: 1px solid rgba(236,244,252,.3); border-radius: 8px; background: rgba(255,255,255,.1); color: #fff; font: inherit; }
.profile-form input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.profile-form .profile-message { margin: 0; }
.profile-form button:disabled { cursor: wait; opacity: .65; }
.history-panel { margin: 20px auto 0; width: 100%; display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(240px, .9fr); gap: 14px; text-align: left; }
.score-card { min-width: 0; padding: clamp(14px, 2vw, 20px); border: 1px solid rgba(233, 243, 255, .2); border-top-color: rgba(255,255,255,.34); border-radius: var(--radius); background: rgba(10, 27, 47, .76); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); box-shadow: 0 12px 32px rgba(3, 14, 27, .2), inset 0 1px rgba(255,255,255,.04); }
.score-card h2, .history-dialog h2 { color: var(--accent); font-size: .9rem; font-weight: 750; letter-spacing: .075em; line-height: 1.3; text-transform: uppercase; }
.leaderboard-list, .recent-list { display: grid; gap: 4px; list-style: none; margin: 10px 0 0; }
.leaderboard-row { display: grid; grid-template-columns: 2rem minmax(0, 1fr) auto; align-items: center; column-gap: 10px; padding: 8px 10px; border: 1px solid transparent; border-radius: 10px; transition: background-color .15s ease, border-color .15s ease; }
.leaderboard-row:hover { background: rgba(255,255,255,.075); border-color: rgba(255,255,255,.12); }
.leaderboard-row:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.leaderboard-rank { display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: rgba(211,228,245,.1); color: rgba(242,247,252,.85); font-size: .85rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.leaderboard-row.rank-1 .leaderboard-rank { color: #332500; background: #f4cc60; }
.leaderboard-row.rank-2 .leaderboard-rank { color: #263445; background: #c4d0dc; }
.leaderboard-row.rank-3 .leaderboard-rank { color: #442b19; background: #d79a68; }
.leaderboard-name { display: block; min-width: 0; overflow: hidden; color: #f5f7fa; font-size: .95rem; font-weight: 680; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-time { display: block; margin-top: 2px; color: rgba(231,239,248,.68); font-size: .76rem; font-variant-numeric: tabular-nums; }
.leaderboard-score { color: #fff; font-size: 1rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.personal-card { display: flex; flex-direction: column; }
.personal-best-content { display: flex; flex: 1; flex-direction: column; justify-content: center; gap: 8px; padding-top: 12px; }
.personal-player-name, .history-owner-label { color: rgba(231,239,248,.76); font-size: .78rem; overflow-wrap: anywhere; }
.history-owner-label { margin-top: 3px; }
.personal-score { color: #fff; font-size: clamp(1.8rem, 4vw, 2.4rem); font-weight: 820; font-variant-numeric: tabular-nums; letter-spacing: -.035em; line-height: 1.05; }
.personal-completed, .personal-rank, .personal-empty-copy { color: rgba(231,239,248,.76); font-size: .85rem; line-height: 1.45; }
.personal-rank { color: var(--accent); font-weight: 650; }
.recent-card { grid-column: 1 / -1; }
.card-heading, .dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.recent-list-preview { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.recent-row { min-width: 0; padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.055); }
.recent-status { color: #f5f7fa; font-size: .9rem; font-weight: 700; text-transform: capitalize; }
.recent-status.won::before, .recent-status.lost::before { display: inline-block; width: .48rem; height: .48rem; margin-right: 7px; border-radius: 50%; vertical-align: .08em; content: ''; }
.recent-status.won::before { background: #81d49a; }
.recent-status.lost::before { background: #ff9b89; }
.recent-meta { display: flex; flex-wrap: wrap; gap: 4px 9px; margin-top: 3px; color: rgba(231,239,248,.68); font-size: .78rem; font-variant-numeric: tabular-nums; }
.recent-meta time { white-space: nowrap; }
.panel-message { padding: 8px 4px; color: rgba(231,239,248,.76); font-size: .85rem; line-height: 1.45; }
.text-button { min-height: 36px; padding: 6px 10px; border: 1px solid rgba(236,244,252,.24); border-radius: 9px; background: rgba(255,255,255,.08); color: #f4f7fb; font: inherit; font-size: .8rem; font-weight: 650; cursor: pointer; }
.text-button:hover { background: rgba(255,255,255,.15); }
.text-button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.history-error { grid-column: 1 / -1; padding: 9px 12px; border: 1px solid rgba(255,255,255,.17); border-radius: 10px; background: rgba(10,27,47,.88); color: rgba(245,247,250,.88); font-size: .85rem; }
.history-error .text-button { margin-left: 8px; }
.history-dialog { width: min(92vw, 600px); max-width: none; max-height: min(78dvh, 680px); margin: auto; padding: clamp(16px, 3vw, 24px); overflow: auto; border: 1px solid rgba(233,243,255,.25); border-radius: var(--radius); background: rgba(10,27,47,.97); color: var(--panel); box-shadow: 0 24px 80px rgba(0,0,0,.48); scrollbar-width: thin; scrollbar-color: rgba(218,231,245,.42) rgba(255,255,255,.05); }
.history-dialog::backdrop { background: rgba(5,14,26,.7); backdrop-filter: blur(3px); }
.history-dialog::-webkit-scrollbar { width: 8px; }
.history-dialog::-webkit-scrollbar-track { background: rgba(255,255,255,.05); border-radius: 8px; }
.history-dialog::-webkit-scrollbar-thumb { border: 2px solid transparent; border-radius: 8px; background: rgba(218,231,245,.42); background-clip: padding-box; }
.history-dialog::-webkit-scrollbar-thumb:hover { background-color: rgba(218,231,245,.62); }
.recent-list-all .recent-row { background: rgba(255,255,255,.045); }
.game-pending { position: absolute; top: 76px; z-index: 3; padding: 8px 14px; border-radius: 999px; background: rgba(15,30,50,.88); }
.loading-label { margin: 18px 0 10px; font-size: 1rem; text-shadow: 0 1px 8px rgba(5, 15, 30, 0.85); }

/* CTA (reference: yellow CTA) */
.cta {
  display: inline-block; min-width: 200px; padding: 14px 26px;
  background: var(--accent); color: #3b2c00; border: none; border-radius: 999px;
  font-size: 1.1rem; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 0 #c9a227; transition: transform 0.05s ease;
  min-height: 44px; /* tap target (FE-010) */
}
.cta:active { transform: translateY(2px); box-shadow: 0 2px 0 #c9a227; }
.cta.secondary { background: #40607f; color: var(--panel); box-shadow: 0 4px 0 #2b4258; }
.cta.hidden, .hidden { display: none !important; }

/* HUD */
.hud {
  display: flex; justify-content: space-around; align-items: center;
  width: 100%; padding: max(10px, env(safe-area-inset-top)) 12px 8px;
  gap: 8px;
}
.hud-item { text-align: center; text-shadow: 0 1px 8px rgba(5, 15, 30, 0.85); }
.hud-label { display: block; font-size: 0.62rem; letter-spacing: 0.08em; opacity: 0.85; }
.hud-value { display: block; font-size: 1.15rem; font-weight: 700; color: var(--accent); min-width: 3.5em; text-shadow: 0 1px 8px rgba(5, 15, 30, 0.9); }
#hud-combo .hud-value { color: var(--panel); }
#hud-combo.active .hud-value { color: #7bd389; }
#hud-combo.active::after { content: ' ×2'; color: #7bd389; font-size: 0.8rem; }
/* Decorative HUD icons: one consistent line-icon over each top metric. */
.hud-icon { display: block; width: 18px; height: 18px; margin: 0 auto 2px; object-fit: contain; opacity: 1; }
/* combo icon = combo-STATE indicator only: hidden unless combo is active —
   never a permanent decoration of the SCORE item */
#hud-combo .hud-icon-combo { display: none; }
#hud-combo.active .hud-icon-combo { display: block; }

/* board — flex center keeps computed-layout centered; min-height 0 lets flex shrink.
   Transparent: GameRenderer clearRect lets body background.png show through
   around the tiles. No board background — tiles float over the sky center. */
.board-wrap { flex: 1 1 auto; width: 100%; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; background: transparent; }
#board { width: 100%; height: 100%; max-width: 100%; max-height: 100%; display: block; touch-action: manipulation; background: transparent; }

/* actions */
.actions {
  display: flex; justify-content: center; gap: 14px;
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  width: 100%;
}
.action-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 999px;
  background: rgba(15, 30, 50, 0.55); color: var(--panel);
  font-size: 1rem; font-weight: 600; cursor: pointer; min-height: 44px;
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  text-shadow: 0 1px 6px rgba(5, 15, 30, 0.8);
}
.action-btn:disabled { opacity: 0.4; }
.action-btn .badge {
  background: var(--accent); color: #3b2c00; border-radius: 999px;
  font-size: 0.8rem; padding: 1px 8px; font-weight: 700;
}
/* P4 opsi A: circular artwork as the button visual (added at runtime when the
   asset is ready); the pill styles above remain the fail-soft fallback. */
.action-btn.art {
  width: 64px; height: 64px; min-width: 44px; min-height: 44px;
  padding: 0; border-radius: 50%; position: relative;
  background: var(--btn-art) center / contain no-repeat;
}
.action-btn.art > span:not(.badge) {
  /* label stays in the accessible name — visually hidden, not removed */
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.action-btn.art .badge { position: absolute; top: -4px; right: -6px; }
.action-btn.art:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* Sound toggle: icon state and accessible label track the saved preference. */
.action-btn.sound-btn { width: 58px; min-width: 58px; height: 58px; min-height: 58px; padding: 0; justify-content: center; }
.sound-icon { display: block; width: 30px; height: 30px; }
.action-btn.sound-btn .badge { display: none; }
.action-btn.sound-btn.muted { opacity: 0.5; }


/* end */
.end-wrap { text-align: center; padding: 24px; width: min(90vw, 420px); text-shadow: 0 1px 8px rgba(5, 15, 30, 0.85); }
.end-title { font-size: 1.9rem; color: var(--accent); margin-bottom: 6px; text-shadow: 0 2px 10px rgba(5, 15, 30, 0.9); }
.end-detail { opacity: 0.9; margin-bottom: 4px; }
.end-stats { margin-bottom: 18px; font-weight: 600; }
.score-breakdown { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 8px auto 18px; max-width: 280px; text-align: left; font-size: .95rem; }
.score-breakdown dt:last-of-type, .score-breakdown dd:last-of-type { border-top: 1px solid rgba(255,255,255,.55); padding-top: 6px; font-weight: 800; color: var(--accent); }
@media (max-width: 720px) {
  #screen-home { justify-content: flex-start; }
  .home-wrap { padding: 18px 16px 24px; }
  .history-panel { grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 16px; }
  .recent-card { grid-column: auto; }
  .personal-best-content { min-height: 112px; }
}
@media (max-width: 480px) {
  .home-wrap { padding-inline: 12px; }
  .logo-img.big { width: min(64vw, 250px); }
  .home-sub { margin-bottom: 16px; font-size: .9rem; }
  .score-card { padding: 13px; }
  .leaderboard-row { grid-template-columns: 1.8rem minmax(0, 1fr) auto; column-gap: 8px; padding: 7px 5px; }
  .leaderboard-score { font-size: .9rem; }
  .leaderboard-name { font-size: .88rem; }
  .leaderboard-time { font-size: .72rem; }
  .recent-list-preview { grid-template-columns: minmax(0,1fr); gap: 5px; }
  .recent-row { padding: 8px 10px; }
}
.end-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.reward-wrap { margin: 18px auto; padding: 16px; background: rgba(255,255,255,0.1); border-radius: var(--radius); }
.reward-label { font-size: 0.8rem; opacity: 0.8; margin-bottom: 6px; letter-spacing: 0.06em; }
.reward-code {
  font-family: ui-monospace, 'Cascadia Mono', monospace; font-size: 1.4rem;
  font-weight: 700; color: var(--accent); letter-spacing: 0.12em;
  padding: 10px 14px; border: 2px dashed var(--accent); border-radius: 10px;
}

/* toast (reference: covered-tile toast) */
.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%) translateY(16px);
  background: #2b2b2bee; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 0.95rem; opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  max-width: 86vw; text-align: center;
}
.toast.active { opacity: 1; transform: translateX(-50%) translateY(0); }

/* interstitial (FR-021) */
.interstitial {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(10, 22, 36, 0.88); z-index: 50; text-align: center; padding: 24px;
}
.interstitial.active { display: flex; }
.interstitial-text { font-size: 1.2rem; font-weight: 600; color: var(--accent); }

/* desktop letterbox (FR-073) — background covers full viewport, play column
   scales responsively (min(92vw, 720px)) centered over the clear sky center
   so side foliage frames it. The two-axis canvas fit takes over as the
   height guard on shorter viewports. */
@media (min-width: 720px) {
  body { background-position: center center, center center; }
  .screen { padding: 0; }
  .board-wrap, .hud, .actions { max-width: min(92vw, 720px); margin: 0 auto; }
  .hud, .actions { width: 100%; }
}

/* Desktop gets a wide, independently composed play area; tablets keep the
   denser portrait/landscape composition above. */
@media (min-width: 1025px) {
  .board-wrap, .hud, .actions { max-width: min(94vw, 1120px); }
}

/* tablet portrait (e.g. 768x1024): cover + center keeps sky center visible,
   foliage crops symmetrically — no extra rule needed beyond base, pinned
   here as the verified contract. */
@media (min-width: 600px) and (max-width: 1024px) and (orientation: portrait) {
  body {
    background-size: cover, cover;
    background-position: center center, center center;
  }
}

/* tablet landscape (e.g. 1024x768): same cover-center contract. */
@media (min-width: 600px) and (max-width: 1180px) and (orientation: landscape) {
  body {
    background-size: cover, cover;
    background-position: center center, center center;
  }
}

/* mobile portrait narrow (≤380px): reclaim horizontal space, keep tile tappable.
   Background: cover crops side tiles first; center sky + clouds stay behind
   the board. Position center guarantees the play area never lands on foliage. */
@media (max-width: 380px) {
  body {
    background-size: cover, cover;
    background-position: center center, center center;
  }
  .hud { padding: max(8px, env(safe-area-inset-top)) 8px 6px; gap: 6px; }
  .hud-value { font-size: 1rem; min-width: 3em; }
  .actions { gap: 10px; padding: 8px 8px max(8px, env(safe-area-inset-bottom)); }
}

/* mobile landscape (height-constrained): HUD/actions shrink so board keeps 44px touch target.
   Background stays cover-center so the wide sky spans the short viewport. */
@media (orientation: landscape) and (max-height: 500px) {
  body {
    background-size: cover, cover;
    background-position: center center, center center;
  }
  .hud { padding: 6px 10px 4px; gap: 6px; }
  .hud-label { font-size: 0.58rem; }
  .hud-value { font-size: 1rem; }
  .hud-icon { width: 16px; height: 16px; margin-bottom: 1px; }
  .actions { padding: 6px 10px max(6px, env(safe-area-inset-bottom)); gap: 10px; }
  .action-btn { padding: 8px 16px; min-height: 44px; }
  .board-wrap { min-height: 160px; }
  #board { min-height: 160px; }
}

/* coarse pointer: guarantee 44px+ tap target even if board is tiny */
@media (pointer: coarse) {
  .action-btn { min-height: 44px; min-width: 44px; }
  .cta { min-height: 44px; }
}

.home-actions { display:flex; flex-direction:column; gap:16px; align-items:center; }
.home-actions .cta { width:min(100%,320px); font-size:1rem; }
.auth-notice { max-width:330px; margin:22px auto 0; font-size:.85rem; line-height:1.5; }
.cta:disabled { opacity:.6; cursor:default; }
