/* ═══════════════════════════════════════════════════════════════════
   COLOUR PALETTE — edit CSS variables here to retheme everything.
   ═══════════════════════════════════════════════════════════════════ */
:root {
  --bg:          #F5F0E8;   /* page background */
  --paper:       #FDFAF4;   /* card / button surface */
  --ink:         #1A1612;   /* primary text */
  --ink-faint:   #9C9080;   /* muted labels / hints */
  --cell-even:   #FDFAF4;   /* even-region cell fill */
  --cell-odd:    #C8BFB0;   /* odd-region cell fill */
  --border-thin: #D4CAB8;   /* faint lines within regions */
  --border-thick:#1A1612;   /* thick lines between regions */
  --accent:      #C4622D;   /* burnt-orange accent */
  --accent-dim:  #E8B99A;   /* soft accent background */
  --good:        #4A7C59;   /* success green */
  --good-dim:    #A8C9B2;
  --dot-fill:    #1A1612;
  --dash-fill:   #9C9080;
  --radius:      3px;
  --shadow:      0 2px 12px rgba(26,22,18,0.10);
  --shadow-deep: 0 8px 32px rgba(26,22,18,0.18);
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'DM Mono', monospace;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100dvh;
  overflow: hidden;
  padding: 0 12px;
}

/* ── Header ────────────────────────────────────────────────────── */
header {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 12px;
  border-bottom: 1.5px solid var(--border-thin);
  margin-bottom: 12px;
  flex-shrink: 0;
}

.wordmark {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-size: 2rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-style: italic;
}
.wordmark span { color: var(--accent); }

.header-right { display: flex; align-items: center; gap: 8px; }

.hdr-btn {
  font-family: 'DM Mono', monospace;
  font-size: 0.80rem;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--border-thin);
  background: var(--paper);
  color: var(--ink-faint);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.hdr-btn:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ── Toolbar ───────────────────────────────────────────────────── */
.toolbar {
  width: 100%;
  max-width: 640px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.toolbar button {
  width: 100%;
  text-align: center;
  padding: 7px 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button {
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  border: 1.5px solid var(--border-thin);
  background: var(--paper);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  appearance: none;
  -webkit-appearance: none;
  white-space: nowrap;
}
button:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
button:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.guess-btn.active {
  background: #4A6FA5;
  color: #fff;
  border-color: #4A6FA5;
}
.guess-btn.active:hover { background: #3A5A8A; border-color: #3A5A8A; }

.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.primary:hover { background: var(--accent); border-color: var(--accent); }

button:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

/* ── Difficulty badges ─────────────────────────────────────────── */
.badge {
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 2px;
  font-weight: 500;
}
.badge.easy   { background: var(--good-dim); color: var(--good); }
.badge.hard   { background: #D4CAFF;          color: #5040B0; }
.badge.expert { background: #FFD9C8;          color: var(--accent); }

.meta-timer {
  font-size: 0.68rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

/* ── Puzzle wrapper ────────────────────────────────────────────── */
#puzzle-wrap {
  width: 100%;
  max-width: 640px;
  display: flex;
  justify-content: center;
  position: relative;
}

/* ── Status / error messages ───────────────────────────────────── */
#status {
  width: 100%;
  max-width: 640px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
  font-size: 0.72rem;
}
.status-msg { padding: 8px 18px; border-radius: var(--radius); }
.status-msg.info  { background: var(--paper); border: 1.5px solid var(--border-thin); color: var(--ink-faint); }
.status-msg.error { background: #FFE8E0; border: 1.5px solid #F0B0A0; color: #B03020; }

/* ── Loading spinner ───────────────────────────────────────────── */
.spinner {
  width: 24px; height: 24px;
  border: 2.5px solid var(--border-thin);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop     { 0% { transform: scale(0.95); } 60% { transform: scale(1.03); } 100% { transform: scale(1); } }

/* ── Puzzle SVG ────────────────────────────────────────────────── */
#puzzle-svg {
  display: block;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  image-rendering: crisp-edges;
}

/* ══════════════════════════════════════════════════════════════════
   MODAL BASE
   ══════════════════════════════════════════════════════════════════ */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(245,240,232,0.85);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.show { display: flex; animation: fadeIn 0.2s ease; }

.modal-card {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 4px;
  box-shadow: var(--shadow-deep);
  padding: 32px 36px 28px;
  max-width: 380px;
  width: calc(100% - 40px);
  animation: slideUp 0.22s ease;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px; right: 14px;
  font-size: 1.1rem;
  color: var(--ink-faint);
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 2px;
  transition: color 0.15s;
}
.modal-close:hover { color: var(--ink); background: none; }

.modal-title {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--ink);
  margin-bottom: 20px;
  letter-spacing: -0.01em;
}

.modal-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* ── Help modal ────────────────────────────────────────────────── */
.help-entries { display: flex; flex-direction: column; gap: 16px; }
.help-entry   { display: flex; align-items: center; gap: 14px; }

.help-vis {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.help-vis svg { display: block; }

.help-text { flex: 1; }

.help-label {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 3px;
  letter-spacing: 0.04em;
}

.help-desc { font-size: 0.68rem; color: var(--ink-faint); line-height: 1.55; }
.help-desc strong { color: var(--ink); font-weight: 600; }

/* ── Settings modal ────────────────────────────────────────────── */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.settings-label {
  font-size: 0.72rem;
  color: var(--ink);
  letter-spacing: 0.04em;
}

select {
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  border: 1.5px solid var(--border-thin);
  background: var(--paper);
  color: var(--ink);
  padding: 7px 28px 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239C9080'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 8px;
  transition: border-color 0.15s;
}
select:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Reveal confirm modal ──────────────────────────────────────── */
.confirm-body {
  font-size: 0.78rem;
  color: var(--ink-faint);
  line-height: 1.6;
}

.btn-danger {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-danger:hover { background: #A04820; border-color: #A04820; }

/* ── Completion overlay ────────────────────────────────────────── */
#complete-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(245,240,232,0.88);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 16px;
}
#complete-overlay.show { display: flex; animation: fadeIn 0.3s ease; }

.complete-card {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 28px 28px 24px;
  text-align: center;
  box-shadow: var(--shadow-deep);
  max-width: 420px;
  width: calc(100% - 16px);
  animation: pop 0.25s ease;
}

.complete-title {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-size: 2.2rem;
  font-style: italic;
  color: var(--ink);
  margin-bottom: 4px;
}
.complete-sub {
  font-size: 0.68rem;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 18px;
}

/* ── Daily progress grid ───────────────────────────────────────── */
.progress-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.progress-col-header {
  font-size: 0.60rem;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-thin);
}

.progress-cell {
  border: 1.5px solid var(--border-thin);
  border-radius: var(--radius);
  padding: 8px 6px 7px;
  background: var(--paper);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.progress-cell.unsolved:hover {
  background: var(--bg);
  border-color: var(--ink-faint);
}
.progress-cell.solved-cell {
  cursor: default;
  background: #EFF8F2;
  border-color: var(--good);
}
.progress-cell.revealed-cell {
  cursor: default;
  background: #FEF0EE;
  border-color: var(--accent);
}
.progress-cell.active-cell {
  border-color: var(--accent);
  background: #FEF3EC;
}

.progress-cell-size {
  font-size: 0.58rem;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.progress-cell-time {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--good);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.progress-cell-unsolved {
  font-size: 0.70rem;
  color: var(--border-thin);
  font-style: italic;
}
.progress-cell-revealed {
  font-size: 0.70rem;
  color: #C0300A;
  font-style: italic;
  font-weight: 500;
}

.complete-total {
  font-size: 0.70rem;
  color: var(--ink-faint);
  border-top: 1px solid var(--border-thin);
  padding-top: 10px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.complete-total-time {
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.complete-tomorrow {
  font-size: 0.62rem;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

.complete-btns { display: flex; gap: 10px; justify-content: center; }

/* ── Footer ────────────────────────────────────────────────────── */
footer {
  text-align: center;
  font-size: 0.60rem;
  color: var(--ink-faint);
  padding: 8px 0 12px;
  flex-shrink: 0;
}