/* ============================================================
   Arcade — shared design system (Clean minimal light)
   ============================================================ */

:root {
  /* palette */
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e6e8f0;
  --text: #1a1d29;
  --text-soft: #5a6072;
  --text-faint: #9aa0b4;
  --accent: #5b6cff;
  --accent-soft: #eaeefe;
  --accent-press: #4351e8;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --success: #16a34a;

  /* game tints for accents on cards */
  --tint-sudoku: #6366f1;
  --tint-tetris: #0ea5e9;
  --tint-snake: #16a34a;

  /* shape */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 49, 0.05), 0 1px 3px rgba(20, 24, 49, 0.06);
  --shadow: 0 4px 14px rgba(20, 24, 49, 0.06), 0 2px 6px rgba(20, 24, 49, 0.04);
  --shadow-lg: 0 12px 34px rgba(20, 24, 49, 0.1), 0 4px 12px rgba(20, 24, 49, 0.06);

  --maxw: 1080px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }

/* ---- top bar ----------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-right));
  background: rgba(246, 247, 251, 0.82);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__home {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
  font-size: 1.05rem;
}
.topbar__logo {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.topbar__title { letter-spacing: -0.02em; }

/* ---- buttons ----------------------------------------------------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.94rem;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.04s ease, background 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--accent-press); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn--ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--border);
}
.btn--ghost:hover { background: var(--accent-soft); border-color: var(--accent-soft); }

.btn--soft {
  background: var(--accent-soft);
  color: var(--accent-press);
}
.btn--soft:hover { background: #dde3fd; }

.btn--icon {
  display: inline-grid;
  place-items: center;
  width: 42px; height: 42px;
  padding: 0;
  border-radius: 11px;
}
.btn--sm { padding: 6px 12px; font-size: 0.86rem; }
.btn--hidden { display: none; }

/* ---- home screen ------------------------------------------------- */
.home {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 18px 60px;
}
.home__hero { margin-bottom: 22px; }
.home__heading { font-size: clamp(1.7rem, 4vw, 2.3rem); }
.home__sub { color: var(--text-soft); margin-top: 8px; max-width: 52ch; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  color: inherit;
  text-decoration: none;
  transition: transform 0.08s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: #d8dcea;
}
.card:active { transform: translateY(0); }
.card__icon {
  width: 54px; height: 54px;
  display: grid; place-items: center;
  border-radius: 13px;
  color: #fff;
}
.card__icon--sudoku { background: var(--tint-sudoku); }
.card__icon--tetris { background: var(--tint-tetris); }
.card__icon--snake  { background: var(--tint-snake); }
.card__title { font-size: 1.2rem; }
.card__desc { color: var(--text-soft); font-size: 0.92rem; margin-top: 4px; }
.card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
}
.tag {
  font-size: 0.8rem;
  color: var(--text-faint);
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: 999px;
}
.tag strong { color: var(--text-soft); }
.card__arrow { color: var(--text-faint); font-size: 1.1rem; transition: transform 0.15s ease, color 0.15s ease; }
.card:hover .card__arrow { transform: translateX(4px); color: var(--accent); }

.home__foot {
  margin-top: 34px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.82rem;
}

/* ---- generic game layout ---------------------------------------- */
.game {
  max-width: 980px;
  margin: 0 auto;
  padding: 18px 16px calc(40px + env(safe-area-inset-bottom));
}
.game__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.game__title { font-size: 1.35rem; }
.game__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.backlink {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-soft); text-decoration: none; font-size: 0.9rem; font-weight: 600;
}
.backlink:hover { color: var(--accent); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---- stats / hud ------------------------------------------------- */
.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  min-width: 78px;
}
.stat__label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.stat__value { font-size: 1.15rem; font-weight: 650; letter-spacing: -0.01em; }
.stat--accent .stat__value { color: var(--accent); }

/* ---- segmented control ------------------------------------------ */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.segmented button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ---- overlay (modal-ish game states) ---------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border-radius: inherit;
  z-index: 6;
  text-align: center;
}
.overlay--hidden { display: none; }
.overlay__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 22px 26px;
  max-width: 320px;
}
.overlay__title { font-size: 1.25rem; }
.overlay__text { color: var(--text-soft); margin: 8px 0 16px; font-size: 0.94rem; }
.overlay__actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---- toast ------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.86rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast--show { opacity: 1; transform: translate(-50%, 0); }

/* ---- on-screen controls (mobile) -------------------------------- */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  justify-content: center;
}
.dpad button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  font-size: 1.3rem;
  color: var(--text-soft);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}
.dpad button:active { background: var(--accent-soft); color: var(--accent); }
.dpad__up    { grid-column: 2; grid-row: 1; }
.dpad__left  { grid-column: 1; grid-row: 2; }
.dpad__right { grid-column: 3; grid-row: 2; }
.dpad__down  { grid-column: 2; grid-row: 3; }

/* ---- responsive helpers ----------------------------------------- */
.stage-wrap { position: relative; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
