/* ─── Reset & tokens ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg:        #0a1628;
  --surface:   #121e33;
  --surface2:  #1a2a44;
  --cyan:      #00e5cc;
  --cyan-dim:  rgba(0,229,204,0.15);
  --text:      #e8edf5;
  --muted:     rgba(232,237,245,0.5);
  --border:    rgba(232,237,245,0.08);
  --err:       #f87171;
  --ok:        #4ade80;

  --cell:      min(64px, (100vw - 96px) / 4);
  --gap:       16px;
  --radius:    10px;
}

html, body {
  height: 100%;
  background: var(--bg);
  overscroll-behavior: none;
}

body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
}

a { color: inherit; text-decoration: none; }

/* ─── Page layout ────────────────────────────────────────── */
.page {
  width: 100%;
  max-width: 480px;
  padding: 16px 16px env(safe-area-inset-bottom, 16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  flex: 1;
}

/* ─── Top bar ────────────────────────────────────────────── */
.top-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.back-btn {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  transition: color 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.back-btn:hover { color: var(--text); }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 0.15s, border-color 0.15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--cyan); }

/* ─── Header ─────────────────────────────────────────────── */
.header { text-align: center; }
.title  { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.5px; }
.subtitle { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

/* ─── Board (CSS Grid) ───────────────────────────────────── */
.board {
  display: grid;
  /* 4 cells + 3 gaps */
  grid-template-columns: var(--cell) var(--gap) var(--cell) var(--gap) var(--cell) var(--gap) var(--cell);
  grid-template-rows:    var(--cell) var(--gap) var(--cell) var(--gap) var(--cell) var(--gap) var(--cell);
}

/* ─── Cells ──────────────────────────────────────────────── */
.cell {
  width: var(--cell);
  height: var(--cell);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color 0.15s, background 0.15s;
  touch-action: manipulation;
}
.cell:hover { border-color: rgba(232,237,245,0.2); }
.cell:active { background: var(--surface2); }

.cell.prefilled {
  background: var(--surface2);
  cursor: default;
  opacity: 0.85;
}

.cell svg {
  width: 55%;
  height: 55%;
  color: var(--text);
}
.cell.prefilled svg { color: var(--muted); }

/* ─── Gaps (clue containers) ─────────────────────────────── */
.gap {
  display: grid;
  place-items: center;
}

.gap-corner {
  /* empty intersection spacer — truly invisible */
}

/* ─── Bridge-capsule clue marks ──────────────────────────── */
.clue-mark {
  border-radius: 999px;
}

/* Horizontal capsule: wide, short */
.clue-h {
  width: 40%;
  height: 5px;
}

/* Vertical capsule: tall, narrow */
.clue-v {
  width: 5px;
  height: 40%;
}

/* same-shape = outlined capsule */
.clue-outline {
  background: transparent;
  border: 1.75px solid var(--cyan);
}

/* same-fill = solid capsule */
.clue-solid {
  background: var(--cyan);
  border: none;
}

/* ─── Actions ────────────────────────────────────────────── */
.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.status {
  font-size: 0.9rem;
  font-weight: 700;
  min-height: 1.4em;
  text-align: center;
}

.btn-row {
  display: flex;
  gap: 10px;
}

.btn {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 10px 24px;
  border-radius: 999px;
  border: 1px solid var(--cyan);
  background: var(--cyan-dim);
  color: var(--cyan);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.btn:hover { background: rgba(0,229,204,0.25); }
.btn:active { transform: scale(0.97); }
.btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.btn-muted {
  border-color: var(--border);
  background: transparent;
  color: var(--muted);
}
.btn-muted:hover { background: var(--surface2); }

/* ─── Footer ─────────────────────────────────────────────── */
.footer {
  margin-top: auto;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  padding-bottom: 8px;
}

/* ─── Help modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  max-width: 380px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h2 {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 12px;
}

.modal p {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 8px;
}

.modal strong { color: var(--text); }

.clue-legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0;
}

.clue-legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text);
}

.clue-sample {
  width: 28px;
  height: 6px;
  border-radius: 999px;
  flex-shrink: 0;
}
.clue-sample.outline {
  border: 1.75px solid var(--cyan);
  background: transparent;
}
.clue-sample.solid {
  background: var(--cyan);
}

.symbol-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 10px 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text);
}

.legend-item .sym {
  width: 22px; height: 22px;
  color: var(--cyan);
  flex-shrink: 0;
}

/* ─── Result modal ───────────────────────────────────────── */
.result-modal-inner { text-align: center; }

.result-tier {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  color: var(--cyan);
  margin-bottom: 4px;
}

.result-date {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.result-pill {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  margin-bottom: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-bottom: 22px;
}

.result-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.result-stat-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
}

.result-stat-label {
  font-size: 0.67rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.result-btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.btn-hard {
  border-color: #a78bfa;
  background: rgba(167,139,250,0.1);
  color: #a78bfa;
}
.btn-hard:hover { background: rgba(167,139,250,0.22); }

.result-footer {
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.8;
}

/* ─── Win animation ──────────────────────────────────────── */
@keyframes win-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(0,229,204,0.4); }
  70%  { box-shadow: 0 0 0 10px rgba(0,229,204,0); }
  100% { box-shadow: 0 0 0 10px rgba(0,229,204,0); }
}

.cell.win {
  border-color: var(--ok);
  animation: win-pulse 0.6s ease-out;
}
