:root {
  --paper: #f5f0e6;
  --paper-2: #ece5d6;
  --ink: #1c1a17;
  --ink-2: #57514a;
  --line: #2a2723;
  --accent: #b5321f;
  --accent-ink: #fff;
  --clue: #e4ddcd;
  --blank: #cbc3b2;
  --hl: #fbe7a6;
  --hl-cur: #f6c94c;
  --ok: #2f6b3a;
  --radius: 10px;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

a { color: var(--accent); }

.masthead {
  border-bottom: 3px double var(--ink);
  background: var(--paper);
}
.masthead-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 20px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  font-family: var(--serif);
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.brand span { color: var(--accent); }
.masthead nav a {
  color: var(--ink-2);
  text-decoration: none;
  font-size: 14px;
  margin-left: 16px;
}
.masthead nav a:hover { color: var(--ink); text-decoration: underline; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.lead {
  font-family: var(--serif);
  font-size: 19px;
  color: var(--ink-2);
  max-width: 62ch;
  margin: 0 0 24px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

.card {
  background: #fffdf8;
  border: 1px solid #d9d0be;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
}
.card + .card { margin-top: 20px; }
.card h2 {
  font-family: var(--serif);
  font-size: 22px;
  margin: 0 0 4px;
}
.card .sub { color: var(--ink-2); font-size: 14px; margin: 0 0 16px; }
.step {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  margin-right: 8px;
  vertical-align: 3px;
}

label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
label .hint { font-weight: 400; color: var(--ink-2); }
input[type='text'], input[type='password'], input[type='number'], select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #c9bfab;
  border-radius: 8px;
  padding: 10px 12px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  border-color: var(--ink);
}
textarea {
  min-height: 300px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
}
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.row > .shrink { flex: 0 0 auto; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin-top: 14px; }
.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--ink); }

.btn {
  appearance: none;
  border: 1px solid var(--ink);
  background: #fff;
  color: var(--ink);
  font: 600 14px var(--sans);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--paper-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #000; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: #9a2817; }
.btn-big { padding: 14px 20px; font-size: 16px; width: 100%; justify-content: center; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--paper-2); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.meta { font-size: 13px; color: var(--ink-2); margin-top: 8px; }

.notice {
  border-left: 4px solid var(--ink);
  background: var(--paper-2);
  padding: 10px 14px;
  border-radius: 0 8px 8px 0;
  font-size: 14px;
  margin: 12px 0;
}
.notice.error { border-color: var(--accent); background: #f8e1dc; }
.notice.ok { border-color: var(--ok); background: #e2efe2; }
.hidden { display: none !important; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink-2);
  font-size: 13px;
  margin: 18px 0 4px;
}
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid #d9d0be; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- puzzle ---------- */
.puzzle-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.puzzle-head h1 {
  font-family: var(--serif);
  font-size: clamp(28px, 4.5vw, 44px);
  margin: 0;
  line-height: 1.1;
}

.grid-wrap { overflow-x: auto; padding-bottom: 6px; }
.grid {
  --cell: 52px;
  display: grid;
  border: 3px solid var(--line);
  background: var(--line);
  gap: 1px;
  width: max-content;
  margin: 0 auto;
  user-select: none;
}
.cell {
  width: var(--cell);
  height: var(--cell);
  position: relative;
  background: #fff;
}
.cell.blank {
  background: repeating-linear-gradient(135deg, var(--blank) 0 4px, #d6cfbf 4px 8px);
}
.cell.clue {
  background: var(--clue);
  display: flex;
  flex-direction: column;
  cursor: pointer;
}
.cell.clue .clue {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2px 2px;
  font-size: calc(var(--cell) * 0.19);
  line-height: 1.08;
  font-weight: 600;
  hyphens: auto;
  -webkit-hyphens: auto;
  overflow-wrap: anywhere;
  overflow: hidden;
  color: var(--ink);
}
.cell.clue .clue + .clue { border-top: 1px solid var(--line); }
.cell.clue .clue.hl { background: var(--hl); }
.cell.letter input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  text-align: center;
  font: 700 calc(var(--cell) * 0.52) / 1 var(--sans);
  text-transform: uppercase;
  color: var(--ink);
  caret-color: transparent;
  cursor: pointer;
  border-radius: 0;
}
.cell.letter input:focus { outline: none; }
.cell.letter.hl { background: var(--hl); }
.cell.letter.cur { background: var(--hl-cur); }
.cell.letter.wrong input { color: var(--accent); }
.cell.letter.revealed input { color: #1f5f8b; }
.cell.letter.sol::before {
  content: '';
  position: absolute;
  inset: 10%;
  border: 2px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
}
.cell .solnum {
  position: absolute;
  right: 2px;
  bottom: 0;
  font: 700 calc(var(--cell) * 0.2) / 1 var(--sans);
  color: var(--accent);
  pointer-events: none;
}
.cell svg.arrow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.solution-bar {
  margin: 22px auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
.solution-bar .lbl { font-family: var(--serif); font-size: 18px; font-weight: 700; }
.solution-boxes { display: flex; gap: 4px; flex-wrap: wrap; }
.solution-boxes .box {
  width: 40px;
  height: 44px;
  border: 2px solid var(--line);
  background: #fff;
  position: relative;
  display: grid;
  place-items: center;
  font: 700 22px var(--sans);
}
.solution-boxes .box small {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: 10px;
  color: var(--accent);
}

.export-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th, table.list td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #e3dccd; }
table.list th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); }

.solved-banner {
  text-align: center;
  font-family: var(--serif);
  font-size: 22px;
  color: var(--ok);
  margin-top: 16px;
}

footer.site {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 32px;
  color: var(--ink-2);
  font-size: 13px;
}

@media print {
  .masthead, .toolbar, .no-print, footer.site { display: none !important; }
  body { background: #fff; }
  .cell.letter.cur, .cell.letter.hl, .cell.clue .clue.hl { background: #fff; }
}
.cell.letter input::selection { background: transparent; }
.cur-clue {
  position: sticky;
  top: 0;
  z-index: 5;
  max-width: 760px;
  margin: 0 auto 12px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}
.cur-clue b { color: var(--hl-cur); margin-right: 6px; }
.cur-clue span { opacity: 0.6; font-weight: 400; }
@media (max-width: 520px) {
  main { padding: 16px 8px 48px; }
  .masthead-inner { padding: 14px 12px 10px; }
  .card { padding: 16px; }
}
.prompt-box {
  margin-top: 16px;
  padding: 14px;
  border: 1px dashed #c9bfab;
  border-radius: 8px;
  background: #faf6ed;
}
.prompt-head { margin-bottom: 10px; font-size: 14px; }
.prompt-head .hint { display: block; color: var(--ink-2); }
.prompt-box details { margin-top: 10px; font-size: 14px; }
.prompt-box summary { cursor: pointer; color: var(--ink-2); }
.prompt-box textarea { min-height: 220px; margin-top: 8px; font-size: 13px; background: #fff; }
