:root {
  --bg-linen: #f7efe2;
  --bg-linen-deep: #eedfcb;
  --wood-outer: #7e5034;
  --wood-mid: #9a6544;
  --wood-dark: #573420;
  --board-felt: #eadbc6;
  --board-felt-line: rgba(126, 80, 52, 0.08);
  --ink-dark: #452c1e;
  --ink-muted: #7f5f4a;
  --ivory: #fffdf7;
  --ivory-lip: #d4c0a7;
  --accent-coral: #ee6c4d;
  --accent-coral-dark: #c94c31;
  --accent-honey: #f3b53f;
  --accent-matcha: #58a96c;
  --accent-matcha-dark: #3b824d;
  --accent-sky: #4ba3d9;
  --shadow-soft: 0 10px 28px rgba(87, 52, 32, 0.14);
  --font-display: 'ZCOOL KuaiLe', 'Fredoka', 'Hiragino Maru Gothic ProN', 'Yuanti SC', 'PingFang SC', sans-serif;
  --font-num: 'Fredoka', 'Noto Sans SC', sans-serif;
  --font-body: 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  font-family: var(--font-body);
  color: var(--ink-dark);
  background:
    radial-gradient(circle at 14% 12%, rgba(255, 248, 224, 0.95) 0%, rgba(255, 248, 224, 0) 42%),
    radial-gradient(circle at 86% 88%, rgba(247, 214, 186, 0.65) 0%, rgba(247, 214, 186, 0) 46%),
    repeating-radial-gradient(circle at 20px 20px, rgba(164, 120, 82, 0.055) 0 2px, transparent 2px 26px),
    linear-gradient(155deg, var(--bg-linen) 0%, var(--bg-linen-deep) 100%);
  user-select: none;
  -webkit-user-select: none;
}

.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.24;
  background-image: radial-gradient(rgba(87, 52, 32, 0.12) 0.7px, transparent 0.7px);
  background-size: 14px 14px;
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  padding:
    max(12px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  gap: 10px;
}

/* ==================== TOP HUD HEADER ==================== */
.hud-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 252, 244, 0.92);
  border: 2px solid #dec9af;
  border-radius: 20px;
  padding: 8px 14px;
  box-shadow: 0 4px 0 #d6bfa2, 0 8px 20px rgba(87, 52, 32, 0.09);
  flex-shrink: 0;
}

/* On desktop, unwrap the mobile card wrappers so Brand / Score / Tools / Icons sit in one crisp row */
.hud-top-card,
.hud-row-primary {
  display: contents;
}

.brand-cluster {
  order: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.score-cluster {
  order: 2;
  margin: 0 auto;
}

.tools-cluster {
  order: 3;
}

.util-icons-mobile {
  order: 4;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.brand-badge {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  overflow: hidden;
  border: 2.5px solid var(--wood-outer);
  box-shadow: 0 3px 0 rgba(87, 52, 32, 0.22);
  flex-shrink: 0;
  background: #fff3b0;
}

.brand-badge img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.38rem;
  line-height: 1.1;
  letter-spacing: 0.03em;
  color: var(--ink-dark);
}

.wave-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.wave-pill {
  font-size: 0.74rem;
  font-weight: 700;
  background: var(--accent-coral);
  color: #fff;
  padding: 2px 9px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.shift-pill {
  font-size: 0.72rem;
  font-weight: 700;
  background: #f2e4d0;
  color: var(--wood-dark);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #dcc4a6;
}

/* Score & Combo Cluster */
.score-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
}

.score-card {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 4px 12px;
  border-radius: 14px;
  background: #fbf4e8;
  border: 1.5px solid #e4d1b8;
  min-width: 106px;
}

.score-card--primary {
  background: linear-gradient(180deg, #fffaf0 0%, #fcebd0 100%);
  border-color: #e6ba74;
  min-width: 126px;
}

.score-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ink-muted);
  line-height: 1.1;
}

.score-value {
  font-family: var(--font-num);
  font-size: 1.48rem;
  font-weight: 700;
  line-height: 1.12;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dark);
}

.score-card--primary .score-value {
  color: #c94c31;
}

.combo-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 5px 12px;
  border-radius: 14px;
  background: #f8f0e4;
  border: 1.5px solid #e2ceb5;
  min-width: 108px;
  transition: transform 0.16s ease, border-color 0.2s ease, background 0.2s ease;
}

.combo-card.is-hot {
  background: linear-gradient(135deg, #fff3cc 0%, #ffd9a8 100%);
  border-color: #f0923b;
}

.combo-card.is-fever {
  background: linear-gradient(135deg, #ffe28a 0%, #ff9966 100%);
  border-color: #d94e34;
  box-shadow: 0 0 16px rgba(238, 108, 77, 0.42);
  animation: feverPulse 0.7s ease-in-out infinite alternate;
}

@keyframes feverPulse {
  from { transform: scale(1); }
  to { transform: scale(1.04); }
}

.combo-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.combo-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.combo-card.is-fever .combo-label {
  color: #7c2010;
}

.combo-value {
  font-family: var(--font-num);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.05;
  color: var(--accent-coral-dark);
}

.combo-bar-track {
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: rgba(87, 52, 32, 0.14);
  margin-top: 4px;
  overflow: hidden;
}

.combo-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f3b53f, #ee6c4d);
  transition: width 0.06s linear;
}

.fever-tag {
  position: absolute;
  top: -10px;
  right: 6px;
  font-family: var(--font-num);
  font-size: 0.62rem;
  font-weight: 700;
  background: #c93b23;
  color: #fff8d6;
  padding: 1px 6px;
  border-radius: 999px;
  opacity: 0;
  transform: translateY(4px) scale(0.85);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.combo-card.is-fever .fever-tag {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Tool Buttons */
.tools-cluster {
  display: flex;
  align-items: center;
  gap: 7px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 40px;
  padding: 0 11px;
  border: 2px solid #d5bca0;
  border-radius: 13px;
  background: var(--ivory);
  color: var(--ink-dark);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 #cbb294;
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease;
}

@media (hover: hover) {
  .tool-btn:hover:not(:disabled) {
    background: #fff9ea;
    transform: translateY(-1px);
    box-shadow: 0 4px 0 #cbb294;
  }
}

.tool-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #cbb294;
}

.tool-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tool-btn--icon {
  padding: 0;
  width: 40px;
  justify-content: center;
  font-size: 1rem;
}

.tool-btn--ghost {
  background: #f9efe1;
}

.tool-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-coral);
  color: #fff;
  font-family: var(--font-num);
  font-size: 0.74rem;
  font-weight: 700;
}

/* ==================== STATUS STRIP ==================== */
.status-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 252, 245, 0.86);
  border: 1.5px solid #e1ccb0;
  border-radius: 16px;
  padding: 7px 14px;
  flex-shrink: 0;
}

.timer-block {
  flex: 1 1 280px;
  min-width: 180px;
}

.timer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 5px;
}

.timer-title {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.timer-num {
  font-family: var(--font-num);
  font-size: 1.02rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dark);
}

.timer-block.is-low .timer-num {
  color: #d63d28;
  animation: timerWarn 0.55s ease-in-out infinite alternate;
}

@keyframes timerWarn {
  from { transform: scale(1); }
  to { transform: scale(1.1); }
}

.timer-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: #e7d8c2;
  border: 1.5px solid #d5bfa2;
  overflow: hidden;
  padding: 1px;
}

.timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6dc47e 0%, #8cd978 100%);
  transition: width 0.08s linear, background 0.3s ease;
}

.timer-block.is-mid .timer-fill {
  background: linear-gradient(90deg, #f3a938 0%, #fbd157 100%);
}

.timer-block.is-low .timer-fill {
  background: linear-gradient(90deg, #df4833 0%, #ff7b5c 100%);
}

/* Four-Cat Collection Strip */
.squad-bonus-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px;
  border-radius: 13px;
  background: #f9f1e4;
  border: 1.5px dashed #d8be9e;
  flex-shrink: 0;
}

.squad-bonus-head {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.squad-bonus-title {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--ink-dark);
}

.squad-bonus-reward {
  font-family: var(--font-num);
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent-coral-dark);
}

.squad-avatars {
  display: flex;
  align-items: center;
  gap: 6px;
}

.squad-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  opacity: 0.42;
  filter: grayscale(0.55);
  transform: scale(0.94);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.squad-chip img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #c9b296;
  display: block;
}

.squad-chip span {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.squad-chip.is-lit {
  opacity: 1;
  filter: none;
  transform: scale(1.06);
}

.squad-chip.is-lit img {
  border-color: #f3a62f;
  box-shadow: 0 0 0 2.5px rgba(243, 181, 63, 0.35);
}

.squad-chip.is-lit span {
  color: var(--ink-dark);
}

.progress-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 12px;
  border-radius: 12px;
  background: #f5ead9;
  border: 1.5px solid #dec7aa;
  min-width: 78px;
  flex-shrink: 0;
}

.progress-label {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.progress-value {
  font-family: var(--font-num);
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--ink-dark);
}

/* ==================== WOODEN GAME TRAY & BOARD ==================== */
.board-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 0;
}

.wood-tray {
  position: relative;
  padding: 13px;
  border-radius: 26px;
  background: linear-gradient(150deg, #9d6846 0%, #7d4f33 52%, #673e26 100%);
  border: 3px solid #53301c;
  box-shadow:
    inset 0 2px 3px rgba(255, 228, 196, 0.35),
    inset 0 -3px 6px rgba(45, 22, 10, 0.35),
    0 10px 0 #4f2e1a,
    0 18px 34px rgba(69, 44, 30, 0.25);
  transition: box-shadow 0.3s ease;
  max-width: 100%;
  max-height: 100%;
}

.wood-tray.is-fever {
  box-shadow:
    inset 0 2px 4px rgba(255, 236, 179, 0.6),
    0 10px 0 #4f2e1a,
    0 0 28px rgba(243, 181, 63, 0.65),
    0 18px 36px rgba(238, 108, 77, 0.32);
}

.board-bed {
  position: relative;
  border-radius: 17px;
  padding: 12px;
  background:
    linear-gradient(0deg, var(--board-felt-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--board-felt-line) 1px, transparent 1px),
    radial-gradient(circle at 50% 35%, #f3e8d8 0%, #e4d3ba 100%);
  background-size: 24px 24px, 24px 24px, 100% 100%;
  box-shadow: inset 0 4px 10px rgba(74, 46, 28, 0.22);
}

.tile-grid {
  position: relative;
  display: grid;
  gap: var(--tile-gap, 6px);
  z-index: 2;
}

.tile-grid.is-masked .tile-btn {
  opacity: 0;
  pointer-events: none;
}

.tile-slot {
  width: var(--tile-size, 62px);
  height: var(--tile-size, 62px);
  position: relative;
}

.tile-btn {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 3px;
  border: 2px solid #d5bfa5;
  border-radius: 13px;
  background: var(--ivory);
  cursor: pointer;
  display: block;
  touch-action: manipulation;
  box-shadow:
    0 4px 0 var(--ivory-lip),
    0 6px 10px rgba(74, 46, 28, 0.14);
  transition:
    transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.12s ease,
    border-color 0.15s ease,
    opacity 0.18s ease;
  overflow: hidden;
}

.tile-grid.is-compact .tile-btn {
  padding: 2px;
  border-width: 1.5px;
  border-radius: 9px;
  box-shadow:
    0 2.5px 0 var(--ivory-lip),
    0 4px 6px rgba(74, 46, 28, 0.13);
}

.tile-grid.is-compact .tile-btn img {
  border-radius: 6px;
}

@media (hover: hover) {
  .tile-btn:hover {
    transform: translateY(-2px) scale(1.03);
    border-color: #c29e74;
    box-shadow:
      0 6px 0 var(--ivory-lip),
      0 10px 14px rgba(74, 46, 28, 0.18);
    z-index: 3;
  }
}

.tile-btn:active {
  transform: translateY(2px) scale(0.97);
  box-shadow: 0 2px 0 var(--ivory-lip);
}

.tile-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 9px;
  display: block;
  pointer-events: none;
}

/* Selected State */
.tile-btn.is-selected {
  transform: translateY(-3px) scale(1.06);
  border-color: #ee6c4d;
  background: #fff6e0;
  box-shadow:
    0 5px 0 #d95d3e,
    0 0 0 3.5px rgba(238, 108, 77, 0.34),
    0 10px 16px rgba(238, 108, 77, 0.25);
  z-index: 6;
}

/* Hint State */
.tile-btn.is-hint {
  border-color: #3da868;
  box-shadow:
    0 4px 0 #2d8751,
    0 0 0 4px rgba(88, 169, 108, 0.45);
  animation: hintBounce 0.65s ease-in-out infinite alternate;
  z-index: 5;
}

@keyframes hintBounce {
  from { transform: translateY(-1px) scale(1.01); }
  to { transform: translateY(-5px) scale(1.07); }
}

/* Mismatch Shake */
.tile-btn.is-wrong {
  border-color: #d94336;
  animation: tileShake 0.32s ease;
}

@keyframes tileShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px) rotate(-3deg); }
  45% { transform: translateX(5px) rotate(3deg); }
  70% { transform: translateX(-4px) rotate(-2deg); }
}

/* Match Pop Out */
.tile-btn.is-matching {
  animation: tilePopOut 0.22s ease forwards;
  pointer-events: none;
  z-index: 7;
}

@keyframes tilePopOut {
  0% { transform: scale(1.08); opacity: 1; }
  45% { transform: scale(1.18); opacity: 0.9; }
  100% { transform: scale(0.35); opacity: 0; }
}

/* Spawn / Shuffle Pop In */
.tile-btn.is-spawn {
  animation: tilePopIn 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

@keyframes tilePopIn {
  from { transform: scale(0.65); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Canvas & Floating Effects Layer */
.fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.float-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  overflow: visible;
}

.float-score {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  text-shadow:
    0 2px 0 #5b331c,
    0 -1px 0 #5b331c,
    2px 0 0 #5b331c,
    -2px 0 0 #5b331c,
    0 4px 10px rgba(87, 52, 32, 0.35);
  white-space: nowrap;
  animation: floatRise 0.85s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.float-score--combo {
  font-size: 1.28rem;
  color: #ffe76e;
}

.float-score--squad {
  font-family: var(--font-display);
  font-size: 1.42rem;
  color: #ffef8c;
}

@keyframes floatRise {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, -55%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -145%) scale(0.95); }
}

/* Toast Banner Inside Board */
.toast-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.86);
  padding: 10px 24px;
  border-radius: 999px;
  background: rgba(69, 44, 30, 0.92);
  color: #fff6df;
  border: 2.5px solid #f3b53f;
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  box-shadow: 0 12px 28px rgba(45, 24, 12, 0.32);
  opacity: 0;
  pointer-events: none;
  z-index: 15;
  white-space: nowrap;
  transition: opacity 0.22s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast-banner.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ==================== FOOTER ==================== */
.hud-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.74rem;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.hud-footer kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--ivory);
  border: 1px solid #d5bfa2;
  box-shadow: 0 1px 0 #ccb393;
  font-family: var(--font-num);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink-dark);
}

/* ==================== MODALS ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(54, 33, 21, 0.56);
  backdrop-filter: blur(5px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.modal-backdrop--active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #d4bca0 transparent;
  background: var(--ivory);
  border: 3px solid var(--wood-outer);
  border-radius: 26px;
  padding: 22px 24px;
  box-shadow: 0 10px 0 #5b3822, 0 24px 50px rgba(45, 24, 12, 0.34);
  text-align: center;
  transform: translateY(14px) scale(0.96);
  transition: transform 0.24s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-card::-webkit-scrollbar {
  width: 7px;
}

.modal-card::-webkit-scrollbar-track {
  background: transparent;
  margin: 14px 0;
}

.modal-card::-webkit-scrollbar-thumb {
  background: #d5bda0;
  border-radius: 999px;
}

.modal-backdrop--active .modal-card {
  transform: translateY(0) scale(1);
}

.polaroid-frame {
  position: relative;
  background: #fff;
  padding: 8px 8px 10px;
  border-radius: 18px;
  border: 2px solid #e4d0b6;
  box-shadow: 0 6px 16px rgba(87, 52, 32, 0.14);
  margin-bottom: 14px;
}

.banner-img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}

.polaroid-sticker {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--accent-coral);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.88rem;
  padding: 4px 12px;
  border-radius: 999px;
  border: 2px solid #fffdf7;
  box-shadow: 0 4px 10px rgba(87, 52, 32, 0.24);
  transform: rotate(3deg);
}

.modal-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.65rem;
  color: var(--ink-dark);
}

.modal-subtitle {
  margin: 0 0 14px;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--ink-muted);
}

.feature-pills {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.feature-pill {
  background: #faf2e6;
  border: 1.5px solid #e5d2b8;
  border-radius: 14px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.feature-pill strong {
  font-size: 0.84rem;
  color: var(--ink-dark);
}

.feature-pill span {
  font-size: 0.7rem;
  color: var(--ink-muted);
}

.start-best-row {
  margin-bottom: 14px;
  padding: 7px 14px;
  border-radius: 12px;
  background: #fff5d9;
  border: 1.5px solid #ecd08b;
  font-size: 0.84rem;
  color: #7c4a12;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-btn {
  flex: 1 1 180px;
  height: 48px;
  padding: 0 22px;
  border: 2.5px solid #a93b23;
  border-radius: 16px;
  background: linear-gradient(180deg, #f57c5e 0%, #e45c3e 100%);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 5px 0 #a93b23, 0 8px 18px rgba(228, 92, 62, 0.3);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #a93b23, 0 10px 22px rgba(228, 92, 62, 0.35);
}

.primary-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #a93b23;
}

.secondary-btn {
  flex: 1 1 150px;
  height: 48px;
  padding: 0 18px;
  border: 2px solid #d4bba0;
  border-radius: 16px;
  background: #f9efe1;
  color: var(--ink-dark);
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 #cbb294;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.secondary-btn:hover {
  transform: translateY(-1px);
  background: #fff7eb;
}

.secondary-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #cbb294;
}

/* Pause Modal */
.modal-card--compact {
  max-width: 400px;
}

.pause-cat-row img {
  width: 96px;
  height: 96px;
  border-radius: 22px;
  border: 3px solid #d5bfa2;
  box-shadow: 0 5px 0 #cbb294;
  margin-bottom: 10px;
}

.pause-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.pause-stats > div {
  background: #faf2e6;
  border: 1.5px solid #e4d1b8;
  border-radius: 12px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pause-stats span {
  font-size: 0.7rem;
  color: var(--ink-muted);
}

.pause-stats strong {
  font-family: var(--font-num);
  font-size: 1.05rem;
  color: var(--ink-dark);
}

/* Game Over Modal */
.modal-card--over {
  max-width: 540px;
}

.record-ribbon {
  display: inline-block;
  margin-bottom: 10px;
  padding: 4px 16px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffce54, #ff9948);
  color: #5b2509;
  font-weight: 800;
  font-size: 0.86rem;
  box-shadow: 0 3px 10px rgba(243, 165, 63, 0.35);
}

.over-header {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #fbf3e6;
  border: 2px solid #e6d2b6;
  border-radius: 18px;
  padding: 12px 16px;
  margin-bottom: 14px;
  text-align: left;
}

.over-thumb {
  width: 148px;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid #d7bfa1;
  flex-shrink: 0;
}

.over-score-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.over-score-num {
  font-family: var(--font-num);
  font-size: 2.35rem;
  font-weight: 700;
  line-height: 1.05;
  color: var(--accent-coral-dark);
  margin: 2px 0 4px;
}

.over-rank-badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  background: #ffe9be;
  color: #7c4910;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid #e8c783;
}

.over-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.metric-tile {
  background: #faf2e6;
  border: 1.5px solid #e5d2b8;
  border-radius: 13px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.metric-label {
  font-size: 0.68rem;
  color: var(--ink-muted);
  font-weight: 700;
}

.metric-value {
  font-family: var(--font-num);
  font-size: 1.02rem;
  color: var(--ink-dark);
}

.leaderboard-box {
  background: #faf3e8;
  border: 1.5px solid #e5d2b8;
  border-radius: 16px;
  padding: 10px 14px;
  margin-bottom: 16px;
  text-align: left;
}

.leaderboard-head {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--ink-dark);
  margin-bottom: 6px;
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 9px;
  background: rgba(255, 253, 247, 0.75);
}

.leaderboard-item.is-current {
  background: #ffefd0;
  border: 1px solid #eab967;
  font-weight: 700;
}

.lb-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lb-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e7d5bc;
  font-family: var(--font-num);
  font-size: 0.72rem;
  font-weight: 700;
}

.leaderboard-item:first-child .lb-rank {
  background: #f5bf42;
  color: #5b3107;
}

.lb-score {
  font-family: var(--font-num);
  font-weight: 700;
  color: var(--accent-coral-dark);
}

/* Codex Modal */
.modal-card--codex {
  max-width: 780px;
  text-align: left;
  padding: 20px 22px;
}

.codex-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.close-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 2px solid #d5bca0;
  background: #f9efe1;
  color: var(--ink-dark);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.close-btn:hover {
  background: #f2e0c8;
}

.codex-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.codex-group {
  background: #faf2e6;
  border: 1.5px solid #e4d1b8;
  border-radius: 18px;
  padding: 12px 14px;
}

.codex-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.codex-group-title {
  font-family: var(--font-display);
  font-size: 1.08rem;
  color: var(--ink-dark);
}

.codex-group-desc {
  font-size: 0.76rem;
  color: var(--ink-muted);
}

.codex-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.codex-tile {
  background: var(--ivory);
  border: 1.5px solid #dfcab0;
  border-radius: 14px;
  padding: 8px;
  text-align: center;
  box-shadow: 0 3px 0 #d8c4aa;
}

.codex-tile img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  margin-bottom: 6px;
}

.codex-tile-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-dark);
}

.codex-tile-stat {
  font-size: 0.68rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* ==================== RESPONSIVE ADJUSTMENTS ==================== */
@media (max-width: 960px) {
  .app-shell {
    padding:
      max(8px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
    gap: 7px;
  }

  .hud-header {
    gap: 8px;
    padding: 7px 10px;
  }

  .brand-title {
    font-size: 1.15rem;
  }

  .score-card {
    min-width: 82px;
    padding: 3px 8px;
  }

  .score-value {
    font-size: 1.18rem;
  }

  .combo-card {
    min-width: 84px;
    padding: 4px 8px;
  }

  .tool-label {
    display: none;
  }

  .hud-footer {
    display: none;
  }

  .codex-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ==================== MOBILE PORTRAIT LAYOUT (<= 680px) ==================== */
@media (max-width: 680px) {
  .app-shell {
    padding:
      max(6px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
    gap: 6px;
  }

  /* Unwrap header so top HUD stays at order 1 while tools dock drops to bottom thumb zone (order 4)! */
  .hud-header {
    display: contents;
  }

  .hud-top-card {
    order: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: rgba(255, 252, 244, 0.94);
    border: 1.5px solid #dec9af;
    border-radius: 16px;
    padding: 7px 10px;
    box-shadow: 0 3px 0 #d6bfa2, 0 5px 14px rgba(87, 52, 32, 0.08);
    flex-shrink: 0;
  }

  .hud-row-primary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .brand-cluster {
    order: 0;
    gap: 7px;
  }

  .brand-badge {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border-width: 2px;
  }

  .brand-title {
    font-size: 1.02rem;
  }

  .wave-meta {
    margin-top: 2px;
    gap: 4px;
  }

  .wave-pill,
  .shift-pill {
    font-size: 0.64rem;
    padding: 1px 7px;
  }

  .util-icons-mobile {
    order: 0;
    gap: 5px;
  }

  .util-icons-mobile .tool-btn--icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 0.9rem;
    box-shadow: 0 2px 0 #cbb294;
  }

  .score-cluster {
    order: 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1.15fr 0.95fr 0.95fr;
    gap: 6px;
    width: 100%;
  }

  .score-card {
    min-width: 0;
    align-items: center;
    padding: 3px 6px;
    border-radius: 10px;
  }

  .score-label {
    font-size: 0.6rem;
  }

  .score-value {
    font-size: 1.1rem;
  }

  .combo-card {
    min-width: 0;
    padding: 3px 7px;
    border-radius: 10px;
  }

  .combo-label {
    font-size: 0.6rem;
  }

  .combo-value {
    font-size: 1.02rem;
  }

  .fever-tag {
    top: -8px;
    right: 4px;
    font-size: 0.54rem;
    padding: 0 5px;
  }

  /* Compact 2-line Status Strip */
  .status-strip {
    order: 2;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
    padding: 6px 10px;
    border-radius: 14px;
  }

  .timer-block {
    flex: none;
    min-width: 0;
  }

  .timer-head {
    margin-bottom: 3px;
  }

  .timer-title {
    font-size: 0.68rem;
  }

  .timer-num {
    font-size: 0.88rem;
  }

  .timer-track {
    height: 9px;
  }

  /* Second row inside status-strip: 4-cat avatars + pairs remaining side by side */
  .status-strip {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "timer timer"
      "squad pairs";
    align-items: center;
  }

  .timer-block {
    grid-area: timer;
  }

  .squad-bonus-block {
    grid-area: squad;
    padding: 3px 8px;
    gap: 6px;
    border-radius: 10px;
    justify-content: space-between;
  }

  .squad-bonus-head {
    display: flex;
  }

  .squad-bonus-title {
    font-size: 0.64rem;
  }

  .squad-bonus-reward {
    font-size: 0.58rem;
  }

  .squad-avatars {
    gap: 5px;
  }

  .squad-chip img {
    width: 24px;
    height: 24px;
    border-width: 1.5px;
  }

  .squad-chip span {
    display: none;
  }

  .progress-chip {
    grid-area: pairs;
    padding: 3px 9px;
    min-width: 62px;
    border-radius: 10px;
  }

  .progress-label {
    font-size: 0.58rem;
  }

  .progress-value {
    font-size: 0.84rem;
  }

  /* Maximum Portrait Board Space */
  .board-stage {
    order: 3;
    padding: 0;
  }

  .wood-tray {
    padding: 7px;
    border-radius: 18px;
    border-width: 2.5px;
    box-shadow:
      inset 0 2px 3px rgba(255, 228, 196, 0.3),
      0 6px 0 #4f2e1a,
      0 12px 22px rgba(69, 44, 30, 0.22);
  }

  .board-bed {
    padding: 6px;
    border-radius: 12px;
  }

  .toast-banner {
    font-size: 0.96rem;
    padding: 8px 16px;
  }

  /* Dedicated Bottom Thumb Action Dock */
  .tools-cluster {
    order: 4;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    background: rgba(255, 252, 244, 0.94);
    border: 1.5px solid #dec9af;
    border-radius: 16px;
    padding: 6px 8px;
    box-shadow: 0 3px 0 #d6bfa2;
    flex-shrink: 0;
  }

  .tools-cluster .tool-btn {
    justify-content: center;
    height: 40px;
    padding: 0 8px;
    font-size: 0.82rem;
    border-radius: 12px;
  }

  .tools-cluster .tool-label {
    display: inline;
  }

  /* Mobile Modal Polish */
  .modal-backdrop {
    padding: 12px;
  }

  .modal-card {
    padding: 16px 15px;
    border-radius: 22px;
    max-height: 90dvh;
  }

  .modal-title {
    font-size: 1.32rem;
  }

  .modal-subtitle {
    font-size: 0.8rem;
    margin-bottom: 10px;
  }

  .feature-pills {
    gap: 6px;
    margin-bottom: 10px;
  }

  .feature-pill {
    padding: 6px 4px;
    border-radius: 11px;
  }

  .feature-pill strong {
    font-size: 0.74rem;
  }

  .feature-pill span {
    font-size: 0.62rem;
  }

  .primary-btn,
  .secondary-btn {
    height: 44px;
    font-size: 0.96rem;
    border-radius: 14px;
  }

  .over-header {
    flex-direction: column;
    text-align: center;
    gap: 10px;
    padding: 10px 12px;
  }

  .over-thumb {
    width: 100%;
    max-width: 220px;
  }

  .over-score-num {
    font-size: 1.95rem;
  }

  .over-metrics {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .codex-group {
    padding: 10px;
  }

  .codex-group-head {
    flex-direction: column;
    gap: 2px;
  }
}
