@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Refined American palette */
  --navy:       #0F2147;
  --navy-dark:  #081530;
  --navy-soft:  #1E3A6B;
  --red:        #DC2626;
  --red-soft:   #FCA5A5;
  --red-bg:     #FEF2F2;
  --gold:       #F59E0B;
  --green:      #059669;
  --green-soft: #6EE7B7;
  --green-bg:   #ECFDF5;

  /* Neutrals */
  --bg:         #FAFAF9;
  --surface:    #FFFFFF;
  --surface-2:  #F5F5F4;
  --surface-3:  #E7E5E4;
  --border:     #E5E5E5;
  --border-med: #D4D4D4;
  --border-strong: #A3A3A3;

  /* Text */
  --text:       #0A0A0A;
  --text-2:     #525252;
  --text-3:     #A3A3A3;
  --text-inv:   #FAFAFA;

  /* Radii & shadows */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --shadow-sm:  0 1px 2px rgba(15, 33, 71, 0.05);
  --shadow-md:  0 4px 12px rgba(15, 33, 71, 0.08);
  --shadow-lg:  0 12px 32px rgba(15, 33, 71, 0.12);
  --shadow-xl:  0 24px 64px rgba(15, 33, 71, 0.18);

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --d-fast: 150ms;
  --d-med:  220ms;
  --d-slow: 360ms;

  --font: 'Inter', -apple-system, system-ui, sans-serif;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* Screen-reader-only — for SEO h1 + a11y labels not shown visually */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* Faint stars watermark in background */
  background-image:
    radial-gradient(circle at 20% 15%, rgba(15,33,71,0.03) 1px, transparent 2px),
    radial-gradient(circle at 85% 40%, rgba(220,38,38,0.025) 1px, transparent 2px),
    radial-gradient(circle at 50% 75%, rgba(15,33,71,0.03) 1px, transparent 2px),
    radial-gradient(circle at 15% 90%, rgba(245,158,11,0.04) 1px, transparent 2px);
  background-size: 220px 220px;
}
body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
}

/* ─────────────────── Header ─────────────────── */
header {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; height: 56px;
  /* Subtle stars-and-stripes pattern in the navy field */
  background-image:
    radial-gradient(circle at 12% 50%, rgba(255,255,255,0.06) 0.5px, transparent 1.5px),
    radial-gradient(circle at 28% 30%, rgba(255,255,255,0.05) 0.5px, transparent 1.5px),
    radial-gradient(circle at 22% 75%, rgba(255,255,255,0.05) 0.5px, transparent 1.5px);
  background-size: 80px 80px;
  position: sticky;
}

/* Red/white/blue stripe accent below header */
header::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -3px;
  height: 3px;
  background: linear-gradient(to right,
    var(--red) 0%, var(--red) 33.33%,
    #fff 33.33%, #fff 66.66%,
    var(--navy) 66.66%, var(--navy) 100%);
  z-index: 1;
}

.logo {
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: -0.025em;
  color: #fff;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 9px;
  line-height: 1;
}
.logo::before {
  content: '';
  width: 28px; height: 28px;
  background-image: url('/logo-mark.svg');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
  transition: transform var(--d-fast) var(--ease);
}
.logo:hover::before { transform: rotate(-6deg) scale(1.08); }
.logo em {
  color: var(--red);
  font-style: normal;
  position: relative;
}
.logo em::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -3px;
  height: 2px;
  background: var(--gold);
  border-radius: 2px;
}

.nav-actions { display: flex; gap: 8px; align-items: center; }

.lang-switcher {
  display: flex; gap: 2px; padding: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: var(--r-sm);
}
.lang-btn {
  border: none; background: transparent; cursor: pointer;
  padding: 4px 9px; border-radius: 6px;
  font: 700 0.7rem/1 var(--font);
  color: rgba(255,255,255,0.55);
  text-transform: uppercase; letter-spacing: 0.08em;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}
.lang-btn:hover { color: #fff; }
.lang-btn.active {
  background: rgba(255,255,255,0.18);
  color: #fff;
}

.icon-btn {
  width: 36px; height: 36px;
  border: none;
  background: rgba(255,255,255,0.08);
  cursor: pointer;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.8);
  font-size: 0.95rem; font-weight: 700;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }
.icon-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ─────────────────── Score bar ─────────────────── */
.score-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem; font-weight: 600;
  color: var(--text-2);
  max-width: 520px;
  width: 100%;
  margin: 8px auto 0;
  border-left: 3px solid var(--navy);
  border-right: 3px solid var(--red);
  border-radius: 2px;
  position: relative;
}

.score-date {
  font-size: 0.75rem; font-weight: 500;
  color: var(--text-3); text-transform: capitalize;
  letter-spacing: 0.01em;
}

#score-display {
  font-weight: 800;
  color: var(--text);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

#error-display {
  display: inline-flex; gap: 6px;
  font-variant-numeric: tabular-nums;
}
.err-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--surface-3);
  transition: background var(--d-fast) var(--ease);
}
.err-dot.used { background: var(--red); }

/* ─────────────────── Main ─────────────────── */
main {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 24px 16px 64px;
  gap: 24px;
  position: relative;
}

#loading {
  margin-top: 80px;
  color: var(--text-3);
  font-size: 0.9rem;
  font-style: italic;
}

#game-wrap {
  display: none;
  flex-direction: column; align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 480px;
}

/* ─────────────────── Grid ─────────────────── */
.grid-wrapper {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.grid-outer {
  display: grid;
  grid-template-columns: 88px repeat(3, minmax(0, 1fr));
  grid-template-rows: auto repeat(3, minmax(96px, 1fr));
  gap: 1px;
  background: var(--border);
}

.grid-corner {
  background: var(--navy);
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 6px;
  overflow: hidden;
}
.grid-corner .us-flag {
  width: 100%; height: auto;
  max-width: 64px; max-height: 36px;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  display: block;
}
.grid-corner::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, transparent 60%, rgba(255,255,255,0.08) 100%);
  pointer-events: none;
}

/* Constraint labels */
.col-label, .row-label {
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  padding: 10px 8px;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.06em;
  color: var(--navy);
  text-transform: uppercase;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}
.col-label {
  min-height: 52px;
  background: linear-gradient(to bottom, #EAEEF7, var(--surface));
  border-top: 2px solid var(--navy);
}
.col-label:nth-child(3) { border-top-color: var(--red); }
.col-label:nth-child(4) { border-top-color: var(--gold); }
.row-label {
  background: linear-gradient(to right, #EAEEF7, var(--surface));
  border-left: 2px solid var(--navy);
}
.row-label#row-label-1 { border-left-color: var(--red); }
.row-label#row-label-2 { border-left-color: var(--gold); }

/* Cells */
.cell {
  background: var(--surface);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  padding: 10px 6px;
  min-height: 96px;
  cursor: pointer;
  position: relative;
  transition: background var(--d-fast) var(--ease);
}
.cell:hover:not(.locked) { background: #F5F8FF; }

.cell.selected {
  background: #EEF3FF;
  outline: 2px solid var(--navy);
  outline-offset: -2px;
  z-index: 1;
}

.cell.empty::after {
  content: '★';
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--border-med);
  transition: color var(--d-fast) var(--ease), transform var(--d-fast) var(--ease);
  opacity: 0.55;
}
.cell.empty:hover::after {
  color: var(--navy);
  opacity: 1;
  transform: scale(1.15) rotate(15deg);
}

.cell-abbr {
  font-size: 1rem; font-weight: 800;
  letter-spacing: 0.04em; line-height: 1;
}
.cell-name {
  font-size: 0.62rem; font-weight: 600;
  text-align: center; line-height: 1.2;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cell.correct {
  background: linear-gradient(135deg, var(--green-bg) 0%, #FFFFFF 100%);
  color: var(--green);
  cursor: default;
  animation: cellPop 0.35s var(--ease-out);
}
.cell.correct.locked { cursor: not-allowed; }
.cell.correct .cell-abbr { color: var(--green); }
.cell.correct::before {
  content: '★';
  position: absolute; top: 4px; right: 6px;
  font-size: 0.7rem;
  color: var(--green);
  line-height: 1;
  animation: starSpin 0.55s var(--ease-out);
}
@keyframes cellPop {
  0%   { transform: scale(0.92); }
  60%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}
@keyframes starSpin {
  0%   { transform: scale(0) rotate(-180deg); opacity: 0; }
  60%  { transform: scale(1.3) rotate(20deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.cell.wrong {
  background: var(--red-bg);
  color: var(--red);
}
.cell.wrong .cell-abbr { color: var(--red); }

.cell.shake { animation: shake 0.4s var(--ease); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  40%  { transform: translateX(6px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(4px); }
}

/* ─────────────────── Search Panel ─────────────────── */
/* Invisible overlay — captures outside clicks to close the panel, but
   does NOT darken or blur the rest of the page (Metrodoku-style). */
#sp-overlay {
  display: none;
  position: fixed; inset: 0;
  background: transparent;
  z-index: 40;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#search-panel {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 50;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-xl);
  padding: 16px 16px 0;
  animation: slideUp var(--d-med) var(--ease-out);
  max-width: 540px;
  margin: 0 auto;
}
@media (min-width: 580px) {
  #search-panel {
    left: 50%; right: auto;
    transform: translateX(-50%);
    width: 480px;
    bottom: 24px;
    border-radius: var(--r-lg);
  }
}

#search-panel.open { display: block; }
#search-panel.open ~ #sp-overlay { display: block; }

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

#sp-tags {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.sp-tag {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--navy);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 5px 11px 5px 8px;
  border-radius: 100px;
  border-left: 3px solid var(--red);
}
.sp-tag::before {
  content: '★';
  color: var(--gold);
  font-size: 0.75rem;
  line-height: 1;
}
.sp-sep {
  color: var(--gold);
  font-size: 0.95rem;
  font-weight: 700;
}

#sp-input {
  width: 100%;
  border: 1.5px solid var(--border-med);
  border-radius: var(--r-md);
  padding: 12px 16px;
  font: 500 1rem var(--font);
  color: var(--text);
  outline: none;
  background: var(--surface);
  transition: border-color var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease);
}
#sp-input:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 4px rgba(15, 33, 71, 0.08);
}

#sp-dropdown {
  list-style: none;
  display: none;
  margin: 8px 0 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow-y: auto;
  max-height: 280px;
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}
#sp-dropdown { padding-bottom: env(safe-area-inset-bottom, 0); }
#search-panel { padding-bottom: max(16px, env(safe-area-inset-bottom, 16px)); }

.sp-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  transition: background var(--d-fast) var(--ease);
}
.sp-item:last-child { border-bottom: none; }
.sp-item:hover { background: var(--surface-2); }
.sp-item.sp-used {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.sp-abbr {
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--text-2);
  min-width: 30px;
}
.sp-sname { flex: 1; font-weight: 500; }

.sp-no-result {
  padding: 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 0.875rem;
  font-style: italic;
}

.sp-hint {
  padding: 16px 18px;
  text-align: center;
  color: var(--text-2);
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--surface-2);
  border-left: 3px solid var(--gold);
  list-style: none;
}

/* ─────────────────── Solved & Game Over Banners ─────────────────── */
#solved-banner, #gameover-banner {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 28px 24px;
  text-align: center;
  width: 100%;
  animation: fadeUp var(--d-slow) var(--ease-out);
  box-shadow: var(--shadow-md);
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

#solved-banner {
  border: 2px solid var(--green);
  background: linear-gradient(180deg, var(--surface) 0%, var(--green-bg) 100%);
  position: relative;
}
#solved-banner::before, #solved-banner::after {
  content: '★ ★ ★';
  position: absolute; left: 0; right: 0;
  font-size: 0.6rem; letter-spacing: 0.3em;
  color: var(--green); opacity: 0.4;
  text-align: center;
}
#solved-banner::before { top: 8px; }
#solved-banner::after  { bottom: 8px; }

#gameover-banner {
  border: 2px solid var(--red);
  background: linear-gradient(180deg, var(--surface) 0%, var(--red-bg) 100%);
}

.banner-icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.banner-icon svg { width: 32px; height: 32px; }
.banner-icon-success {
  background: var(--green);
  animation: pop 0.6s var(--ease-out);
}
.banner-icon-fail { background: var(--red); }
@keyframes pop {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

#solved-banner h3, #gameover-banner h3 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
#solved-banner h3 { color: var(--green); }
#gameover-banner h3 { color: var(--red); }
#solved-banner p, #gameover-banner p {
  font-size: 0.9rem;
  color: var(--text-2);
  line-height: 1.5;
}
.banner-sub {
  margin-top: 8px;
  font-size: 0.82rem !important;
  color: var(--text-3) !important;
}

#gameover-solution {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
  margin-top: 4px;
}
.gos-cell {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 6px;
  display: flex; flex-direction: column;
  align-items: center; gap: 3px;
}
.gos-abbr {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--navy);
  letter-spacing: 0.04em;
}
.gos-name {
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: center;
  line-height: 1.2;
}

.btn-share {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  padding: 12px 26px;
  font: 800 0.875rem var(--font);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background var(--d-fast) var(--ease), transform var(--d-fast) var(--ease);
  box-shadow: 0 4px 12px rgba(15,33,71,0.25), inset 0 -2px 0 var(--red);
}
.btn-share:hover { background: var(--navy-soft); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(15,33,71,0.3), inset 0 -2px 0 var(--red); }
.btn-share:active { transform: translateY(0) scale(0.97); }
.btn-share svg { width: 16px; height: 16px; }

/* ─────────────────── Modals ─────────────────── */
.modal {
  display: none;
  position: fixed; inset: 0;
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}
.modal.open { display: flex; }
@media (min-width: 600px) {
  .modal { align-items: center; }
}

.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(15, 33, 71, 0.4);
  backdrop-filter: blur(4px);
  animation: fadeIn var(--d-med) var(--ease);
}
.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  animation: slideUp var(--d-med) var(--ease-out);
}
@media (min-width: 600px) {
  .modal-content {
    border-radius: var(--r-lg);
    animation: fadeUp var(--d-med) var(--ease-out);
  }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  flex: 1;
}
.modal-close {
  width: 32px; height: 32px;
  background: var(--surface-2);
  border: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-2);
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}
.modal-close:hover { background: var(--surface-3); color: var(--text); }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 20px;
}
.stat-box {
  display: flex; flex-direction: column;
  align-items: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px 8px;
}
.stat-value {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.stat-label {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: center;
}

/* How to play */
.howto-content {
  padding: 20px;
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text-2);
  overflow-y: auto;
}
.howto-content p { margin-bottom: 12px; }
.howto-content strong { color: var(--text); font-weight: 700; }
.howto-content em { font-style: normal; font-weight: 700; color: var(--navy); }
.howto-example {
  background: var(--surface-2);
  border-left: 3px solid var(--navy);
  padding: 12px 14px;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: 0.85rem;
  margin-top: 10px;
}

/* ─────────────────── Toast ─────────────────── */
#toast {
  position: fixed; bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 22px;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: transform var(--d-med) var(--ease-out), opacity var(--d-med) var(--ease-out);
  white-space: nowrap;
  z-index: 200;
  box-shadow: var(--shadow-lg);
}
#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ─────────────────── Footer ─────────────────── */
footer {
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  text-align: center;
  font-size: 0.74rem;
  color: var(--text-3);
  background: var(--surface);
  position: relative;
}
footer::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(to right,
    var(--navy) 0%, var(--navy) 33.33%,
    #fff 33.33%, #fff 66.66%,
    var(--red) 66.66%, var(--red) 100%);
}
footer a {
  color: var(--navy);
  font-weight: 700;
  text-decoration: none;
}
footer a:hover { color: var(--red); text-decoration: underline; }

/* ─────────────────── Archive (calendar) ─────────────────── */
.archive-main {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 32px 16px 64px;
}
.archive-page {
  max-width: 600px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 32px 28px 28px;
  box-shadow: var(--shadow-sm);
}
.archive-page h1 {
  font-size: 1.85rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 4px;
}
.archive-intro {
  color: var(--text-2);
  font-size: 0.9rem;
  line-height: 1.55;
  margin-bottom: 18px;
}

.archive-legend {
  display: flex; flex-wrap: wrap;
  gap: 14px 18px;
  font-size: 0.72rem;
  color: var(--text-2);
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  margin-bottom: 18px;
}
.archive-legend > span {
  display: inline-flex; align-items: center; gap: 6px;
}
.archive-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.archive-dot-solved   { background: var(--green); }
.archive-dot-lost     { background: var(--red); }
.archive-dot-progress { background: var(--gold); }
.archive-dot-empty    { background: var(--border-med); }

.archive-nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.archive-nav h2 {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -0.01em;
  flex: 1;
  text-align: center;
  text-transform: capitalize;
}
.archive-nav button {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--navy);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease);
}
.archive-nav button:hover { background: var(--surface-3); }
.archive-nav button:active { transform: scale(0.95); }

.archive-calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.arc-dow {
  text-align: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 0 4px;
}
.arc-blank { aspect-ratio: 1 / 1; }

.arc-day {
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  border-radius: var(--r-sm);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
  border: 1.5px solid transparent;
  transition: transform var(--d-fast) var(--ease), background var(--d-fast) var(--ease);
  background: var(--surface-2);
}
.arc-day .arc-num { z-index: 1; }
.arc-day:hover { transform: scale(1.05); }
.arc-day:active { transform: scale(0.95); }

.arc-empty   { background: var(--surface-2); color: var(--text-2); }
.arc-empty:hover { background: #EEF3FF; color: var(--navy); }

.arc-progress { background: rgba(245, 158, 11, 0.15); color: var(--gold); }
.arc-progress::after {
  content: '';
  position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--gold);
}

.arc-solved { background: var(--green-bg); color: var(--green); }
.arc-solved::after {
  content: '★';
  position: absolute; bottom: 2px; right: 4px;
  font-size: 0.55rem; color: var(--green);
}

.arc-lost { background: var(--red-bg); color: var(--red); }
.arc-lost::after {
  content: '';
  position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--red);
}

.arc-today {
  border-color: var(--navy) !important;
  font-weight: 800;
  box-shadow: 0 0 0 1px var(--navy) inset;
}

.arc-future, .arc-pre-epoch {
  background: transparent;
  color: var(--text-3);
  opacity: 0.4;
  cursor: not-allowed;
}
.arc-future:hover, .arc-pre-epoch:hover { transform: none; }

.archive-meta {
  margin-top: 20px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-2);
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
}
.archive-meta strong { color: var(--navy); font-weight: 800; }

@media (max-width: 480px) {
  .archive-main { padding: 16px 10px 48px; }
  .archive-page { padding: 22px 18px 18px; border-radius: var(--r-md); }
  .archive-page h1 { font-size: 1.45rem; }
  .archive-legend { font-size: 0.66rem; gap: 8px 12px; padding: 10px; }
  .arc-day { font-size: 0.78rem; }
  .arc-dow { font-size: 0.58rem; }
  .archive-nav h2 { font-size: 0.95rem; }
  .archive-nav button { width: 32px; height: 32px; }
}

/* ─────────────────── SEO intro block (homepage) ─────────────────── */
.seo-intro {
  max-width: 520px;
  width: 100%;
  margin: 28px auto 0;
  padding: 22px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text-2);
}
.seo-intro h2 {
  font-size: 1rem;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}
.seo-intro p { margin-bottom: 10px; }
.seo-intro p:last-child { margin-bottom: 0; }
.seo-intro strong { color: var(--text); font-weight: 700; }
.seo-intro em { color: var(--navy); font-style: normal; font-weight: 600; }
.seo-intro a {
  color: var(--navy);
  text-decoration: none;
  font-weight: 700;
  border-bottom: 2px solid transparent;
  transition: border-color var(--d-fast) var(--ease);
}
.seo-intro a:hover { border-bottom-color: var(--gold); }
@media (max-width: 480px) {
  .seo-intro {
    padding: 18px 18px;
    font-size: 0.82rem;
    border-radius: var(--r-sm);
  }
  .seo-intro h2 { font-size: 0.92rem; }
}

/* ─────────────────── Legal pages (Privacy / Terms) ─────────────────── */
.legal-body { background: var(--bg); }
.legal-main {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 32px 16px 64px;
}
.legal-page {
  max-width: 720px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 40px 36px 32px;
  box-shadow: var(--shadow-sm);
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--text-2);
}
.legal-page h1 {
  font-size: 1.85rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 6px;
}
.legal-page h2 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--navy);
  margin: 28px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--surface-2);
}
.legal-page h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin: 16px 0 6px;
}
.legal-page p { margin-bottom: 12px; }
.legal-page ul { margin: 8px 0 12px 22px; }
.legal-page li { margin-bottom: 4px; }
.legal-page strong { color: var(--text); font-weight: 700; }
.legal-page em { color: var(--text); font-weight: 600; font-style: normal; }
.legal-page a {
  color: var(--navy);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
}
.legal-page a:hover { color: var(--red); }

.legal-meta {
  display: inline-block;
  font-size: 0.78rem !important;
  color: var(--text-3);
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: 100px;
  font-weight: 600;
  margin-bottom: 24px !important;
}

.legal-back {
  margin-top: 32px !important;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.9rem;
}

@media (max-width: 480px) {
  .legal-main { padding: 16px 10px 48px; }
  .legal-page { padding: 24px 20px 20px; border-radius: var(--r-md); font-size: 0.9rem; }
  .legal-page h1 { font-size: 1.45rem; }
  .legal-page h2 { font-size: 1.05rem; margin-top: 22px; }
  .legal-page h3 { font-size: 0.9rem; }
}

/* ─────────────────── Dev Panel (superadmin) ─────────────────── */
#dev-fab {
  position: fixed; bottom: 20px; right: 20px; z-index: 300;
  width: 48px; height: 48px;
  border: none; border-radius: 50%;
  background: linear-gradient(135deg, #FBBF24, #F59E0B);
  color: var(--navy-dark);
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease);
}
#dev-fab:hover { transform: scale(1.1); box-shadow: 0 8px 24px rgba(245, 158, 11, 0.6); }
#dev-fab:active { transform: scale(0.95); }

#dev-panel {
  position: fixed; bottom: 80px; right: 20px; z-index: 299;
  width: 360px; max-width: calc(100vw - 40px);
  max-height: calc(100dvh - 120px);
  background: var(--navy);
  color: #fff;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xl);
  opacity: 0; pointer-events: none;
  transform: translateY(10px) scale(0.98);
  transition: opacity var(--d-med) var(--ease), transform var(--d-med) var(--ease);
  font-family: var(--font);
  border: 1px solid var(--gold);
  display: flex; flex-direction: column;
}
#dev-panel.open {
  opacity: 1; pointer-events: auto;
  transform: translateY(0) scale(1);
}

.dev-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  background: linear-gradient(to right, rgba(245,158,11,0.15), transparent);
}
.dev-head strong {
  color: var(--gold);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  font-weight: 800;
}
.dev-close {
  background: transparent; border: none;
  color: rgba(255,255,255,0.6); cursor: pointer;
  font-size: 1rem; padding: 2px 6px;
}
.dev-close:hover { color: #fff; }

.dev-body {
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.dev-row {
  display: flex; flex-direction: column; gap: 4px;
}
.dev-row > span {
  font-size: 0.65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: rgba(255,255,255,0.6);
}
.dev-row input[type="date"] {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  outline: none;
  color-scheme: dark;
}
.dev-row input[type="date"]:focus { border-color: var(--gold); }

.dev-buttons {
  flex-direction: row; gap: 6px;
}
.dev-buttons button {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #fff;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.72rem;
  padding: 8px 6px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease);
  white-space: nowrap;
}
.dev-buttons button:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.25);
}
.dev-buttons button.danger {
  background: rgba(220, 38, 38, 0.2);
  border-color: rgba(220, 38, 38, 0.4);
  color: #FCA5A5;
}
.dev-buttons button.danger:hover {
  background: rgba(220, 38, 38, 0.35);
}

.dev-info {
  margin-top: 4px;
  padding: 10px 12px;
  background: rgba(0,0,0,0.25);
  border-radius: var(--r-sm);
  font-size: 0.7rem;
  line-height: 1.55;
  color: rgba(255,255,255,0.75);
  font-family: ui-monospace, Menlo, monospace;
  word-break: break-word;
}
.dev-info strong { color: var(--gold); font-weight: 700; }

/* Dev-panel tabs */
.dev-tabs {
  display: flex; gap: 2px;
  padding: 0 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.15);
}
.dev-tab {
  background: transparent; border: none;
  color: rgba(255,255,255,0.55);
  font: 700 0.7rem/1 var(--font);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease);
}
.dev-tab:hover { color: #fff; }
.dev-tab.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.dev-body { overflow-y: auto; flex: 1; min-height: 0; }
#dev-tab-constraints { padding: 12px 14px; }

/* Constraints tab */
.dev-cstr-toolbar {
  display: flex; gap: 8px; align-items: center;
  margin-bottom: 10px;
}
#dev-cstr-search {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  outline: none;
}
#dev-cstr-search:focus { border-color: var(--gold); }
#dev-cstr-search::placeholder { color: rgba(255,255,255,0.4); }
.dev-mini {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.85);
  font: 600 0.65rem/1 var(--font);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 6px 9px;
  border-radius: var(--r-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--d-fast) var(--ease);
}
.dev-mini:hover { background: rgba(255,255,255,0.18); }

.dev-cstr-summary {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.7);
  margin-bottom: 10px;
  padding: 7px 10px;
  background: rgba(0,0,0,0.2);
  border-radius: var(--r-sm);
  line-height: 1.45;
}
.dev-cstr-summary strong { color: var(--gold); font-weight: 800; }

.dev-cstr-cat {
  margin-bottom: 8px;
  background: rgba(0,0,0,0.18);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.dev-cstr-cat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font: 700 0.68rem/1 var(--font);
  color: var(--gold);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.dev-cstr-cat-head > span:first-child { flex: 1; }
.dev-cstr-cat-count {
  color: rgba(255,255,255,0.55);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.dev-cstr-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.92);
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background var(--d-fast) var(--ease);
}
.dev-cstr-item:last-child { border-bottom: none; }
.dev-cstr-item:hover { background: rgba(255,255,255,0.04); }
.dev-cstr-item.off { color: rgba(255,255,255,0.4); }
.dev-cstr-item.off .dev-cstr-meta { opacity: 0.5; }
.dev-cstr-item input[type="checkbox"] {
  appearance: none;
  width: 16px; height: 16px;
  border: 1.5px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  background: transparent;
  transition: background var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease);
}
.dev-cstr-item input[type="checkbox"]:checked {
  background: var(--gold);
  border-color: var(--gold);
}
.dev-cstr-item input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px; top: 0;
  width: 5px; height: 9px;
  border-right: 2px solid var(--navy-dark);
  border-bottom: 2px solid var(--navy-dark);
  transform: rotate(45deg);
}
.dev-cstr-label { flex: 1; }
.dev-cstr-meta {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(245, 158, 11, 0.12);
  padding: 2px 7px;
  border-radius: 100px;
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  text-align: center;
}

.dev-cstr-hint {
  margin-top: 12px;
  padding: 9px 11px;
  font-size: 0.7rem;
  line-height: 1.5;
  color: rgba(255,255,255,0.65);
  background: rgba(245, 158, 11, 0.08);
  border-left: 2px solid var(--gold);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.dev-cstr-hint strong { color: var(--gold); }

/* Dev panel — feature flag rows */
.dev-section-title {
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font: 700 0.65rem/1 var(--font);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold);
}
.dev-flag-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
  cursor: pointer;
  font-size: 0.78rem;
}
.dev-flag-row > span { flex: 1; }
.dev-flag-row strong { color: #fff; }
.dev-flag-row small { color: rgba(255,255,255,0.5); font-size: 0.7rem; }
.dev-flag-row input[type="checkbox"] {
  appearance: none;
  width: 36px; height: 20px;
  background: rgba(255,255,255,0.15);
  border-radius: 100px;
  position: relative;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease);
  flex-shrink: 0;
}
.dev-flag-row input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--d-fast) var(--ease);
}
.dev-flag-row input[type="checkbox"]:checked {
  background: var(--gold);
}
.dev-flag-row input[type="checkbox"]:checked::after {
  transform: translateX(16px);
}

/* ─────────────────── Admin password modal ─────────────────── */
#admin-modal {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.admin-modal-overlay {
  position: absolute; inset: 0;
  background: rgba(15,33,71,0.65);
  backdrop-filter: blur(8px);
  animation: fadeIn var(--d-med) var(--ease);
}
.admin-modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 32px 28px 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
  text-align: center;
  border-top: 3px solid var(--gold);
  animation: fadeUp var(--d-med) var(--ease-out);
}
.admin-modal-content.shake { animation: shake 0.4s var(--ease); }

.admin-modal-icon {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--gold);
  display: flex; align-items: center; justify-content: center;
}
.admin-modal-icon svg { width: 28px; height: 28px; }

.admin-modal-content h3 {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--navy);
}
.admin-modal-content > p {
  font-size: 0.85rem;
  color: var(--text-2);
  margin: 6px 0 18px;
}
#admin-password {
  width: 100%;
  border: 1.5px solid var(--border-med);
  border-radius: var(--r-md);
  padding: 12px 16px;
  font: 600 1rem var(--font);
  color: var(--text);
  background: var(--surface);
  outline: none;
  letter-spacing: 0.1em;
  text-align: center;
  transition: border-color var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease);
}
#admin-password:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 4px rgba(15,33,71,0.08);
}
.admin-modal-actions {
  display: flex; gap: 8px;
  margin-top: 16px;
}
.admin-btn {
  flex: 1;
  padding: 11px 16px;
  border: none;
  border-radius: var(--r-md);
  font: 800 0.85rem var(--font);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease), transform var(--d-fast) var(--ease);
}
.admin-btn-secondary {
  background: var(--surface-2);
  color: var(--text-2);
}
.admin-btn-secondary:hover { background: var(--surface-3); }
.admin-btn-primary {
  background: var(--navy);
  color: #fff;
}
.admin-btn-primary:hover { background: var(--navy-soft); }
.admin-btn-primary:active { transform: scale(0.97); }

.admin-modal-error {
  margin-top: 12px !important;
  color: var(--red) !important;
  font-size: 0.78rem !important;
  font-weight: 700;
  min-height: 1em;
}

/* ─────────────────── Ads ─────────────────── */
/* Hidden by default. Shown only when body has .ads-active (set by ads.js when ADS_ENABLED=true). */
.ad-container { display: none; }
body.ads-active .ad-container {
  width: 100%;
  max-width: 728px;
  margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  overflow: hidden;
}
body.ads-active .ad-container:empty { display: none; }
body.ads-active .ad-top    { min-height: 90px;  margin-top: 4px; }
body.ads-active .ad-bottom { min-height: 250px; margin: 16px auto 0; }
body.ads-active .ad-solved { min-height: 90px; margin-bottom: 6px; max-width: 100%; }

/* Consent banner: hidden by default with visibility too (double safety) */
#consent-bar {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
body.ads-active #consent-bar {
  display: flex !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

.ad-placeholder {
  width: 100%;
  min-height: 90px;
  background: repeating-linear-gradient(
    45deg,
    rgba(15,33,71,0.04),
    rgba(15,33,71,0.04) 10px,
    rgba(15,33,71,0.07) 10px,
    rgba(15,33,71,0.07) 20px
  );
  border: 1px dashed var(--border-med);
  border-radius: var(--r-md);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 14px;
  text-align: center;
  font-family: ui-monospace, Menlo, monospace;
}
.ad-placeholder span {
  font-size: 0.7rem; font-weight: 800;
  color: var(--navy); letter-spacing: 0.1em;
  text-transform: uppercase;
}
.ad-placeholder small {
  font-size: 0.65rem;
  color: var(--text-3); margin-top: 4px;
  letter-spacing: 0.04em;
}

/* ─────────────────── Consent banner ─────────────────── */
#consent-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 250;
  background: var(--navy);
  color: #fff;
  padding: 14px 16px max(14px, env(safe-area-inset-bottom, 14px));
  display: flex; flex-direction: column; gap: 12px;
  align-items: center;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.25);
  border-top: 3px solid var(--gold);
  animation: slideUp var(--d-slow) var(--ease-out);
}
@media (min-width: 760px) {
  #consent-bar {
    flex-direction: row;
    justify-content: space-between;
    padding: 16px 24px;
  }
}

.consent-text {
  font-size: 0.82rem;
  line-height: 1.5;
  color: rgba(255,255,255,0.92);
  max-width: 720px;
}
.consent-text strong { color: var(--gold); font-weight: 800; }
.consent-text a {
  color: var(--gold);
  text-decoration: underline;
  margin-left: 4px;
  font-weight: 600;
}

.consent-actions {
  display: flex; gap: 8px;
  flex-shrink: 0;
}
.consent-btn {
  font: 800 0.78rem var(--font);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 9px 18px;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--d-fast) var(--ease), transform var(--d-fast) var(--ease);
}
.consent-reject {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.18);
}
.consent-reject:hover { background: rgba(255,255,255,0.15); }
.consent-accept {
  background: var(--gold);
  color: var(--navy-dark);
}
.consent-accept:hover { background: #FBBF24; transform: translateY(-1px); }
.consent-accept:active { transform: scale(0.97); }

/* ═════════════════════════════════════════════════════════════════════════
   MOBILE-FIRST OPTIMIZATIONS (Metrodoku-style)
   ═════════════════════════════════════════════════════════════════════════ */

/* Disable iOS tap-highlight (we have custom :active states) */
a, button, .cell, .lang-btn, .icon-btn, .modal-close, .sp-item, .consent-btn {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* eliminates 300ms tap delay + double-tap zoom */
}

/* No accidental text selection inside the game grid */
.cell, .col-label, .row-label, .grid-corner, .score-bar, header, .err-dot {
  -webkit-user-select: none;
  user-select: none;
}

/* Dev FAB respects iPhone home indicator */
#dev-fab {
  bottom: max(20px, env(safe-area-inset-bottom));
}
@media (max-width: 480px) {
  #dev-fab { width: 44px; height: 44px; right: 14px; }
  #dev-panel {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    max-height: calc(100dvh - 100px);
  }
}

/* Prevent overscroll bounce on iOS while keeping page scrollable */
html, body { overscroll-behavior-y: none; }

/* Safe-area insets (notch, home indicator) */
header {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
footer, main, .score-bar {
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}

/* ───────── ≤ 480 px (phones) — the primary target ───────── */
@media (max-width: 480px) {

  /* Compact header */
  header {
    height: 48px;
    padding-top: 0; padding-bottom: 0;
  }
  header::after { bottom: -2px; height: 2px; }
  .logo { font-size: 1.15rem; gap: 7px; }
  .logo::before { width: 24px; height: 24px; }
  .lang-btn { padding: 4px 7px; font-size: 0.65rem; }
  .icon-btn { width: 32px; height: 32px; }
  .icon-btn svg { width: 16px; height: 16px; }
  .nav-actions { gap: 4px; }
  .lang-switcher { padding: 2px; }

  /* Slim score bar — sticky just below header for context-on-scroll */
  .score-bar {
    margin: 0; max-width: none;
    padding: 9px 14px;
    border-radius: 0;
    border-left: none; border-right: none;
    border-bottom: 2px solid var(--navy);
    position: sticky; top: 48px; z-index: 15;
    background: var(--surface);
  }
  .score-date { font-size: 0.7rem; }
  #score-display { font-size: 0.9rem; }
  .err-dot { width: 8px; height: 8px; }

  /* Edge-to-edge main with minimal padding */
  main {
    padding: 10px 8px 60px;
    gap: 12px;
  }
  #game-wrap { gap: 12px; }

  /* Grid: edge-to-edge, fluid */
  .grid-wrapper {
    border-radius: var(--r-md);
    border-left: 0; border-right: 0;
    margin-left: -8px; margin-right: -8px;
    width: calc(100% + 16px);
    box-shadow: var(--shadow-sm);
  }
  /* Make row labels slimmer to give cells more breathing room */
  .grid-outer {
    grid-template-columns: 64px repeat(3, minmax(0, 1fr));
    grid-template-rows: 46px repeat(3, 1fr);
  }
  .col-label, .row-label {
    padding: 5px 4px;
    font-size: clamp(0.52rem, 2.6vw, 0.65rem);
    line-height: 1.18;
    letter-spacing: 0.03em;
  }
  .col-label { min-height: 46px; }

  /* Bigger, square-ish cells */
  .cell {
    min-height: clamp(72px, 24vw, 100px);
    padding: 6px 4px;
    gap: 2px;
  }
  .cell-abbr { font-size: clamp(0.9rem, 4vw, 1.15rem); letter-spacing: 0.03em; }
  .cell-name {
    font-size: clamp(0.52rem, 2.4vw, 0.62rem);
    line-height: 1.15;
    letter-spacing: 0.02em;
  }
  .cell.empty::after { font-size: 1.3rem; }
  .cell.correct::before { top: 3px; right: 4px; font-size: 0.6rem; }

  /* Grid corner: smaller flag */
  .grid-corner { padding: 4px; }
  .grid-corner .us-flag { max-width: 50px; max-height: 28px; }

  /* Press-down feedback for cells (replaces tap highlight) */
  .cell:active:not(.locked):not(.correct) {
    background: #E8EFFF;
    transform: scale(0.97);
    transition: transform 0.08s ease-out, background 0.08s ease-out;
  }

  /* Bottom-sheet search panel: full width, larger input */
  #search-panel {
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 14px 12px 0;
    max-width: 100%;
  }
  #sp-input {
    padding: 13px 16px;
    font-size: 1rem; /* ≥16px prevents iOS zoom on focus */
  }
  .sp-tag {
    font-size: 0.66rem;
    padding: 4px 9px 4px 7px;
  }
  .sp-item { padding: 12px 14px; font-size: 0.92rem; min-height: 48px; }
  .sp-abbr { font-size: 0.74rem; min-width: 26px; }
  #sp-dropdown { max-height: 50dvh; }

  /* Banners: slimmer padding, edge-to-edge */
  #solved-banner, #gameover-banner {
    padding: 22px 18px;
    border-radius: var(--r-md);
    gap: 10px;
  }
  .banner-icon { width: 48px; height: 48px; }
  .banner-icon svg { width: 26px; height: 26px; }
  #solved-banner h3, #gameover-banner h3 { font-size: 1.25rem; }
  #solved-banner p, #gameover-banner p { font-size: 0.85rem; }
  #solved-banner::before, #solved-banner::after { font-size: 0.55rem; }

  .gos-cell { padding: 8px 4px; gap: 2px; }
  .gos-abbr { font-size: 0.85rem; }
  .gos-name { font-size: 0.52rem; }

  /* Bigger CTA */
  .btn-share { padding: 13px 28px; font-size: 0.9rem; }

  /* Modals: full bottom-sheet on phones */
  .modal-content {
    max-width: 100%;
    max-height: 90dvh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
  .modal-header { padding: 14px 16px; }
  .modal-header h3 { font-size: 0.95rem; }
  .stats-grid { padding: 14px; gap: 8px; }
  .stat-box { padding: 12px 4px; }
  .stat-value { font-size: 1.4rem; }
  .stat-label { font-size: 0.56rem; }
  .howto-content { padding: 16px; font-size: 0.85rem; }

  /* Footer hidden — gain space for game */
  footer {
    padding: 10px 14px;
    font-size: 0.65rem;
  }
  footer::before { height: 1.5px; }

  /* Toast */
  #toast {
    bottom: max(70px, env(safe-area-inset-bottom));
    padding: 9px 18px;
    font-size: 0.78rem;
  }
}

/* ───────── Very narrow phones (≤ 360 px) — extra slim ───────── */
@media (max-width: 360px) {
  .grid-outer {
    grid-template-columns: 58px repeat(3, minmax(0, 1fr));
  }
  .col-label, .row-label {
    font-size: clamp(0.5rem, 2.4vw, 0.6rem);
    padding: 4px 3px;
  }
  header { padding-left: 12px; padding-right: 12px; }
  main { padding-left: 6px; padding-right: 6px; }
  .grid-wrapper { margin-left: -6px; margin-right: -6px; width: calc(100% + 12px); }
}

/* ───────── Tablet portrait (481–767 px) ───────── */
@media (min-width: 481px) and (max-width: 767px) {
  main { padding: 16px 16px 48px; }
  .cell { min-height: 96px; }
  .cell-abbr { font-size: 1.05rem; }
  .cell-name { font-size: 0.64rem; }
  .grid-outer { grid-template-columns: 84px repeat(3, minmax(0, 1fr)); }
}

/* ───────── Desktop (≥ 768 px) ───────── */
@media (min-width: 768px) {
  .cell { min-height: 104px; }
  .cell-abbr { font-size: 1.1rem; }
  .cell-name { font-size: 0.66rem; }
}

/* ───────── Landscape phones ───────── */
@media (max-height: 480px) and (orientation: landscape) {
  main { padding: 8px 12px 32px; }
  .score-bar { padding: 6px 14px; }
  .cell { min-height: 60px; }
  .grid-outer { grid-template-rows: 38px repeat(3, 1fr); }
  .col-label { min-height: 38px; }
  footer { display: none; }
}

/* ───────── PWA / standalone display ───────── */
@media (display-mode: standalone) {
  header { padding-top: env(safe-area-inset-top); height: calc(48px + env(safe-area-inset-top)); }
}

/* ───────── Pointer-fine (mouse): preserve hover; coarse: no hover ───────── */
@media (hover: none) {
  .cell:hover:not(.locked) { background: var(--surface); }
  .cell.empty:hover::after { color: var(--border-med); transform: none; }
  .sp-item:hover { background: var(--surface); }
}
