/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f0f0f;
  --surface:     #1a1a1a;
  --surface-2:   #232323;
  --border:      #2e2e2e;
  --border-soft: #1f1f1f;

  --text:        #e8e6e0;
  --text-dim:    #6b6b6b;
  --text-muted:  #3a3a3a;

  --accent:      #c8a97e;       /* warm amber — ink on old paper */
  --accent-dim:  #7a6248;

  --hint-bg:     #0f1e0f;
  --hint-text:   #6bcb77;
  --hint-border: #2a5a2a;

  --highlight-bg:     #1a1a2e;
  --highlight-border: #3a3a6e;

  /* conflict — same plain letter assigned to two cipher letters */
  --conflict-bg:     #2e1c05;
  --conflict-border: #b5781f;
  --conflict-text:   #ffb454;

  /* guess — a player's entry that doesn't conflict */
  --guess-bg:     #11203a;
  --guess-border: #3b6fb5;
  --guess-text:   #79b0ff;

  --font-mono: 'Courier New', Courier, monospace;
  --font-ui:   system-ui, -apple-system, sans-serif;

  --cell-size: 2rem;
  --gap: 0.2rem;
}

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Layout ───────────────────────────────────────────────────────────────── */
.page-wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.site-logo {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
}

.site-nav a {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  transition: color 0.15s;
  margin-left: 1.5rem;
}
.site-nav a:hover { color: var(--text); }
.site-nav a.active { color: var(--accent); }

/* ── Puzzle header ────────────────────────────────────────────────────────── */
.puzzle-header {
  margin-bottom: 2rem;
}

#puzzle-date {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 0.3rem;
}

#puzzle-title {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  color: var(--accent);
  letter-spacing: 0.04em;
}

/* ── Puzzle board ─────────────────────────────────────────────────────────── */
#puzzle-board {
  margin-bottom: 2.5rem;
}

.puzzle-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1.4rem;
  align-items: flex-end;
}

.puzzle-word {
  display: flex;
  gap: var(--gap);
  align-items: flex-end;
}

/* ── Letter cell ──────────────────────────────────────────────────────────── */
.letter-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  width: var(--cell-size);
}

.letter-input {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
  cursor: pointer;
  outline: none;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 2px;
  padding: 0;
  caret-color: transparent;
}

.letter-input:focus {
  border-color: var(--accent-dim);
  background: var(--surface-2);
}

/* Hint (pre-revealed) */
.letter-input.hint {
  background: var(--hint-bg);
  border-color: var(--hint-border);
  color: var(--hint-text);
  cursor: not-allowed;
}

.cipher-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1;
  padding-top: 0.1rem;
}

/* ── Cell states ──────────────────────────────────────────────────────────── */
.letter-cell.highlighted .letter-input:not(.hint) {
  background: var(--highlight-bg);
  border-color: var(--highlight-border);
}
.letter-cell.highlighted .cipher-label {
  color: var(--accent-dim);
}

.letter-cell.conflict .letter-input {
  background: var(--conflict-bg);
  border-color: var(--conflict-border);
  color: var(--conflict-text);
}

.letter-cell.guess .letter-input {
  background: var(--guess-bg);
  border-color: var(--guess-border);
  color: var(--guess-text);
}

/* ── Punctuation ──────────────────────────────────────────────────────────── */
.punct-char {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--text-dim);
  line-height: var(--cell-size);
  padding-bottom: 1.1rem; /* align baseline with cipher labels */
  min-width: 0.5rem;
  text-align: center;
}

/* ── Alphabet bar ─────────────────────────────────────────────────────────── */
.alphabet-section {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.alphabet-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}

.alphabet-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.alpha-letter {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  width: 1.6rem;
  height: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 2px;
  transition: all 0.15s;
}

.alpha-letter.used {
  color: var(--text-muted);
  border-color: var(--border-soft);
  background: transparent;
}

/* ── Win banner ───────────────────────────────────────────────────────────── */
#win-banner {
  display: none;
  margin-top: 2rem;
  padding: 1.25rem 1.5rem;
  background: var(--hint-bg);
  border: 1px solid var(--hint-border);
  border-radius: 3px;
  font-family: var(--font-mono);
  color: var(--hint-text);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
}
#win-banner.visible { display: block; }

/* ── Archive page ─────────────────────────────────────────────────────────── */
.archive-header {
  margin-bottom: 2rem;
}

.archive-header h1 {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#archive-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.archive-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.archive-item:hover {
  border-color: var(--accent-dim);
  background: var(--surface-2);
}

.archive-item-left {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.archive-date {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}

.archive-title {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text);
}

.archive-item-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.progress-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  padding: 0.15rem 0.4rem;
  border-radius: 2px;
}

.archive-arrow {
  color: var(--text-dim);
  font-size: 0.9rem;
  transition: color 0.15s;
}
.archive-item:hover .archive-arrow { color: var(--accent); }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.error-msg {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--conflict-text);
  padding: 1rem;
  border: 1px solid var(--conflict-border);
  border-radius: 3px;
}

.empty-msg {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  :root {
    --cell-size: 1.75rem;
  }

  .puzzle-line {
    gap: 0.35rem 0.6rem;
    margin-bottom: 1.1rem;
  }

  .letter-input {
    font-size: 0.85rem;
  }

  .cipher-label {
    font-size: 0.62rem;
  }

  .alpha-letter {
    width: 1.35rem;
    height: 1.35rem;
    font-size: 0.7rem;
  }
}

/* ── Reduced motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
