/* Shared look for GameHub. Colors come from themes.css via custom properties. */
@import url("motion.css");

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button, .tile, .card, .pile, .slot, .pad, .face {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  color: var(--fg);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: 28px 20px calc(28px + env(safe-area-inset-bottom));
}
.wrap { max-width: 760px; margin: 0 auto; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.back { color: var(--muted); text-decoration: none; font-size: .9rem; }
.back:hover { color: var(--accent); }
h1 { margin: 0 0 6px; font-size: 1.7rem; letter-spacing: -.02em; font-weight: 650; }
.sub { margin: 0 0 28px; color: var(--muted); font-size: .95rem; }

/* --- hub tiles ---------------------------------------------------------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
a.tile {
  display: flex; flex-direction: column; gap: 8px;
  padding: 20px; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); text-decoration: none; color: inherit;
  transition: transform var(--t-base) var(--ease-out),
              border-color var(--t-base) var(--ease-out),
              box-shadow var(--t-base) var(--ease-out);
}
a.tile:hover, a.tile:focus-visible {
  transform: translateY(-3px); border-color: var(--accent); outline: none;
  box-shadow: 0 2px 4px rgba(16,19,26,.06), 0 14px 32px rgba(16,19,26,.10);
}
a.tile:active { transform: translateY(-1px) scale(.985); transition-duration: var(--t-fast); }
.row { display: flex; align-items: center; gap: 9px; }
.icon { font-size: 1.5rem; line-height: 1; transition: transform var(--t-slow) var(--ease-pop); }
a.tile:hover .icon, a.tile:focus-visible .icon { transform: scale(1.14) rotate(-5deg); }
.name { font-size: 1.05rem; font-weight: 620; }
.desc { color: var(--muted); font-size: .88rem; }
.best {
  margin-left: auto; font-size: .7rem; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: var(--line); color: var(--muted);
}
.badge-new {
  font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: 1px 7px; border-radius: 999px;
  background: var(--accent); color: var(--bg);
}
.genre-tag {
  font-size: .7rem; color: var(--muted);
  padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--line);
}

/* --- genre filter bar --------------------------------------------------- */
.genre-bar {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.genre-btn {
  font: inherit; cursor: pointer;
  padding: 5px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--muted); font-size: .85rem; font-weight: 550;
  transition: border-color var(--t-base) var(--ease-out),
              color var(--t-base) var(--ease-out),
              background var(--t-base) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.genre-btn:hover { border-color: var(--accent); color: var(--accent); }
.genre-btn.active {
  border-color: var(--accent); background: var(--accent); color: var(--bg);
}

/* --- game pages --------------------------------------------------------- */
.stage {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 18px; display: flex;
  flex-direction: column; align-items: center; gap: 14px;
}
.scores { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; width: 100%; }
.score {
  flex: 1 1 100px; min-width: 92px; text-align: center;
  background: var(--board); border-radius: 12px; padding: 8px 12px;
}
.score .label { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.score .value {
  display: block; font-size: 1.35rem; font-weight: 650;
  font-variant-numeric: tabular-nums;
  transition: transform .12s ease, color .12s ease;
}
.score .value.bump { animation: bump .32s var(--ease-pop); color: var(--accent); }
@keyframes bump {
  40% { transform: scale(1.28) translateY(-2px); }
}
.score { position: relative; overflow: visible; }
.gain {
  position: absolute; left: 50%; top: 2px;
  transform: translateX(-50%);
  font-size: .85rem; font-weight: 700; color: var(--accent);
  pointer-events: none;
  animation: gain-up .7s ease forwards;
}
@keyframes gain-up {
  from { opacity: 0; transform: translate(-50%, 6px) scale(.8); }
  25%  { opacity: 1; }
  to   { opacity: 0; transform: translate(-50%, -26px) scale(1.05); }
}
.btn {
  font: inherit; cursor: pointer;
  padding: 9px 20px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--fg); font-size: .9rem; font-weight: 560;
  transition: border-color var(--t-base) var(--ease-out),
              color var(--t-base) var(--ease-out),
              transform var(--t-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover, .btn:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.btn:active:not(:disabled) { transform: scale(.95); }
.status { color: var(--muted); font-size: .9rem; min-height: 1.5em; text-align: center; }
.hint { color: var(--muted); font-size: .82rem; text-align: center; margin-top: 16px; }
.player { color: var(--muted); font-size: .85rem; text-align: center; }
.player b { color: var(--fg); font-weight: 620; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* --- modals (name prompt + scores screen) -------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8,10,15,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade-in .18s ease;
}
.modal {
  background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  padding: 22px; width: min(100%, 420px);
  max-height: 85dvh; display: flex; flex-direction: column; gap: 14px;
  animation: modal-in var(--t-base) var(--ease-pop);
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
}
.scores-table tbody tr { animation: row-in .26s var(--ease-out) backwards; }
.scores-table tbody tr:nth-child(1)    { animation-delay: .02s; }
.scores-table tbody tr:nth-child(2)    { animation-delay: .05s; }
.scores-table tbody tr:nth-child(3)    { animation-delay: .08s; }
.scores-table tbody tr:nth-child(4)    { animation-delay: .11s; }
.scores-table tbody tr:nth-child(5)    { animation-delay: .14s; }
.scores-table tbody tr:nth-child(6)    { animation-delay: .17s; }
.scores-table tbody tr:nth-child(7)    { animation-delay: .20s; }
.scores-table tbody tr:nth-child(8)    { animation-delay: .23s; }
.scores-table tbody tr:nth-child(9)    { animation-delay: .26s; }
.scores-table tbody tr:nth-child(n+10) { animation-delay: .29s; }
@keyframes row-in { from { opacity: 0; transform: translateX(-8px); } }
.modal h2 { margin: 0; font-size: 1.2rem; font-weight: 650; letter-spacing: -.01em; }
.modal-sub { margin: 0; color: var(--muted); font-size: .88rem; }
.modal-body { overflow-y: auto; }
.modal-input {
  font: inherit; width: 100%;
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
}
.modal-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn.primary { border-color: var(--accent); color: var(--accent); }
.btn.danger { border-color: var(--line); color: #ef4444; }
.btn.danger:hover:not(:disabled) { border-color: currentColor; }
.btn:disabled { opacity: .45; cursor: default; }

.scores-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.scores-table th {
  text-align: left; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); font-weight: 600;
  padding: 0 8px 6px; border-bottom: 1px solid var(--line);
}
.scores-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); }
.scores-table tr:last-child td { border-bottom: none; }
.scores-table td.num { font-variant-numeric: tabular-nums; font-weight: 620; }
.scores-table th:first-child, .scores-table td:first-child { color: var(--muted); width: 2.2em; }

/* --- saved games --------------------------------------------------------- */
.save-row {
  display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.save-row:last-child { border-bottom: none; }
.save-row .slot { font-weight: 620; font-size: .9rem; min-width: 3.6em; }
.save-row .what {
  color: var(--muted); font-size: .84rem;
  flex: 1 1 8em; font-variant-numeric: tabular-nums;
}
.save-acts { display: flex; gap: 6px; margin-left: auto; }
.save-acts .btn { padding: 5px 12px; font-size: .8rem; }
.scores-table th:last-child, .scores-table td:last-child { color: var(--muted); text-align: right; }

.grid a.tile { animation: tile-in .38s var(--ease-out) backwards; }
.grid a.tile:nth-child(2) { animation-delay: .05s; }
.grid a.tile:nth-child(3) { animation-delay: .10s; }
.grid a.tile:nth-child(4) { animation-delay: .15s; }
.grid a.tile:nth-child(5) { animation-delay: .20s; }
.grid a.tile:nth-child(6) { animation-delay: .25s; }
.grid a.tile:nth-child(n+7) { animation-delay: .30s; }
@keyframes tile-in { from { opacity: 0; transform: translateY(12px); } }

.shake { animation: shake .38s var(--ease-out); }
@keyframes shake {
  10%, 50%, 90% { transform: translateX(-4px); }
  30%, 70%      { transform: translateX(4px); }
}

canvas { touch-action: none; max-width: 100%; border-radius: 12px; background: var(--board); }
