:root {
  --ink: #1c1915;
  --muted: #4e4942;
  --paper: #efe6d6;
  --card: #fffaf1;
  --line: #d9d0c0;
  --teal: #0f5e56;
  --teal-soft: #e7f3ef;
  --amber: #9a3412;
  --bad: #8f1d2c;
  --bad-bg: #f8d5d8;
  --solved: #e4f2e8;
  --hint: #fff1d6;
  --shadow: 0 1px 0 rgba(28, 25, 21, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overflow-x: hidden; }
body {
  margin: 0;
  min-width: 0;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 ui-sans-serif, "Avenir Next", "Helvetica Neue", sans-serif;
}
img, svg, canvas, video { max-width: 100%; }
a { color: var(--teal); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.skip {
  position: absolute;
  left: 8px;
  top: -40px;
  background: var(--card);
  padding: 8px 12px;
  z-index: 5;
}
.skip:focus { top: 8px; }

.top {
  background: var(--ink);
  color: var(--paper);
  padding: 8px 12px 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--paper);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.brand span { font-size: 0.98rem; }
.mark { width: 28px; height: 28px; flex: 0 0 auto; }
.tool-menu { margin-top: 8px; }
.tool-menu summary {
  color: var(--paper);
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}
.tool-menu summary::-webkit-details-marker { display: none; }
.desktop-nav { display: none; }
.tools {
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
  margin: 8px 0 0;
  overflow: visible;
}
details[open] > .mobile-nav {
  display: flex;
  flex-wrap: wrap;
  overflow: visible;
}
.tools a {
  color: var(--paper);
  text-decoration: none;
  white-space: nowrap;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.86rem;
}
.tools a[aria-current="page"] { background: var(--paper); color: var(--ink); }

.wrap {
  width: min(1080px, calc(100% - 24px));
  margin: 0 auto;
  padding: 12px 0 40px;
}
h1 {
  font-family: Georgia, "Iowan Old Style", Palatino, "Palatino Linotype", serif;
  font-size: 1.7rem;
  line-height: 1.15;
  margin: 0 0 6px;
  font-weight: 700;
}
h2 { font-size: 1.25rem; margin: 1.4rem 0 0.6rem; }
h3 { font-size: 1rem; margin: 0.8rem 0 0.3rem; }
.lede { margin: 0 0 10px; font-size: 1.02rem; }

.tool-wrap {
  display: grid;
  gap: 10px;
  min-width: 0;
}
.where {
  margin: 0;
  background: var(--teal-soft);
  border: 1px solid #b7d5cc;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.92rem;
}
.tool {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  min-width: 0;
  box-shadow: var(--shadow);
}
.pair, .field, .paste { min-width: 0; }
.pair { display: grid; gap: 10px; }
label, .field-label { display: block; font-weight: 700; margin-bottom: 4px; }
textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  max-width: 100%;
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid #b7ad9c;
  border-radius: 10px;
  padding: 8px 10px;
}
textarea { min-height: 5.2rem; resize: vertical; }
.symbols { font-family: "Puzzle Cipher Symbols", sans-serif; font-size: 1.35rem; line-height: 1.45; }
.hint, .limits, .fine { color: var(--muted); font-size: 0.92rem; margin: 6px 0 0; }
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px;
  max-width: 100%;
  margin-top: 10px;
}
@media (max-width: 799px) {
  .actions .btn.primary {
    flex: 1 1 100%;
    justify-content: center;
  }
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--ink);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
}
.btn.primary { background: var(--amber); border-color: var(--amber); color: #fff; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.btn:disabled { opacity: 0.65; cursor: progress; }
.ico { width: 18px; height: 18px; flex: 0 0 auto; }
.modes, .choices, .sliders { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; align-items: center; }
.modes { margin-top: 0; }
#morse-unknown:empty { display: none; }
.choices input[type="number"], .controls input[type="number"] { width: 6.5rem; min-height: 44px; }
.choices label, .sliders label { font-weight: 600; }
input[type="range"] { width: min(100%, 180px); }
.note, .status, .count { min-height: 1.3em; }
.error { color: var(--bad); font-weight: 700; }
.results { min-height: 3rem; }
.words { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0 0 8px; padding: 0; }
.word {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  cursor: pointer;
  min-height: 44px;
}
.wild { text-decoration: underline; text-decoration-thickness: 2px; font-weight: 700; color: var(--teal); }
.len { color: var(--muted); font-size: 0.85rem; }

.sudoku-layout { display: grid; gap: 8px; min-width: 0; position: relative; }
.sudoku-layout .status { order: 1; }
.sudoku-layout .grid { order: 2; }
.sudoku-layout .paste { order: 3; }
.sudoku-layout .nums { order: 4; }
.sudoku-layout .actions { order: 5; }
.sudoku-layout .limits { order: 6; }
.paste-toggle { display: none; }
.sudoku-key {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
}
.grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  width: min(100%, 420px);
  border-top: 2px solid var(--ink);
  border-left: 2px solid var(--ink);
  background: var(--card);
}
.cell {
  aspect-ratio: 1;
  border: 0;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  background: #fff;
  font: inherit;
  font-size: clamp(14px, 4.2vw, 22px);
  padding: 0;
  color: var(--ink);
}
.cell.b3 { border-right-width: 2px; }
.cell.r3 { border-bottom-width: 2px; }
.cell.given { font-weight: 800; }
.cell.solved { background: var(--solved); font-weight: 500; }
.cell.hinted { background: var(--hint); font-weight: 700; }
.cell.bad { background: var(--bad-bg); color: var(--bad); box-shadow: inset 0 0 0 2px var(--bad); }
.cell.selected { box-shadow: inset 0 0 0 3px var(--teal); }
.nums { display: flex; flex-wrap: wrap; gap: 6px; }
.nums .btn { min-width: 44px; justify-content: center; padding-inline: 8px; }

.how ol, .cards {
  display: grid;
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.how li, .card, .faq details, .chart li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.how li { display: flex; gap: 10px; padding: 12px; align-items: flex-start; }
.how .step-icon { width: 36px; height: 36px; flex: 0 0 auto; color: var(--teal); }
.how p, .card p { margin: 0; }
.example table { width: 100%; border-collapse: collapse; table-layout: fixed; background: var(--card); }
.example th, .example td { border: 1px solid var(--line); padding: 8px; vertical-align: top; word-break: break-word; }
.example th { text-align: left; }
.example pre { margin: 0; white-space: pre-wrap; font: 0.95rem/1.4 ui-monospace, monospace; }
.example td.symbols pre { font-family: "Puzzle Cipher Symbols", sans-serif; font-size: 1.35rem; }
.faq details { padding: 10px 12px; margin-top: 8px; }
.faq summary { cursor: pointer; font-weight: 700; }
.card { padding: 12px; }
.card a { font-weight: 700; text-decoration: none; }
.chart {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.chart li { padding: 8px 10px; display: grid; gap: 2px; }
.chart .glyph { font-size: 1.4rem; }
.tag { font-size: 0.78rem; color: var(--muted); }
.tag.common { color: var(--amber); font-weight: 700; }
.prose { max-width: 68ch; }
.prose p, .prose li { margin: 0.5rem 0; }
.legal {
  white-space: pre-wrap;
  font: 0.78rem/1.4 ui-monospace, monospace;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  overflow: visible;
  max-width: 100%;
}
.foot {
  border-top: 1px solid var(--line);
  padding: 18px 12px 28px;
  color: var(--muted);
  font-size: 0.92rem;
}
.foot .inner { width: min(1080px, 100%); margin: 0 auto; }
.foot nav { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-bottom: 8px; }
.foot a { color: var(--ink); }
.trade { margin: 8px 0 0; }

@media (min-width: 800px) {
  .pair { grid-template-columns: 1fr 1fr; }
  .how ol, .cards { grid-template-columns: repeat(3, 1fr); }
  textarea { min-height: 8rem; }
}
@media (min-width: 960px) {
  .top { display: flex; align-items: flex-start; gap: 18px; padding: 10px 20px; }
  .desktop-nav {
    display: flex;
    flex: 1;
    flex-wrap: wrap;
    min-width: 0;
    margin: 0;
    overflow: visible;
  }
  .tool-menu { display: none; }
  .tool-wrap { grid-template-columns: 200px minmax(0, 1fr); align-items: start; }
  .sudoku-layout {
    grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
    grid-template-areas:
      "grid status"
      "grid actions"
      "grid nums"
      "grid paste"
      "grid limits";
    column-gap: 16px;
    align-items: start;
  }
  .sudoku-layout .grid { grid-area: grid; order: 0; }
  .sudoku-layout .status { grid-area: status; }
  .sudoku-layout .actions { grid-area: actions; }
  .sudoku-layout .nums { grid-area: nums; }
  .sudoku-layout .paste { grid-area: paste; }
  .sudoku-layout .limits { grid-area: limits; }
  h1 { font-size: 2rem; }
}
.subtitle { margin: 0 0 4px; color: var(--teal); font-weight: 700; }
.sheet { min-height: 3.2rem; }
@media (max-width: 799px) {
  .tool textarea { min-height: 4.4rem; }
  .where { padding: 8px 10px; }
}
@media (max-width: 959px) {
  .sudoku-layout { gap: 6px; }
  .sudoku-layout .status { order: 6; }
  .sudoku-layout .limits { order: 7; }
  .sudoku-layout .actions { margin-top: 0; }
  .sudoku-layout .paste-head { margin-bottom: 0; }
  .sudoku-layout .paste-toggle { display: flex; flex: 1 1 40%; width: auto; justify-content: center; }
  .sudoku-layout .paste label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .sudoku-layout .paste:not(.open) textarea,
  .sudoku-layout .paste:not(.open) .hint { display: none; }
}
.paste-head { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 6px; }
.paste-head .btn { flex: 1 1 auto; justify-content: center; }
.print-title { display: none; }
.found-word { text-decoration: line-through; color: var(--muted); }
.maze-board { max-width: 100%; }
.maze-canvas, .letter-grid { width: min(100%, 420px); max-width: 100%; height: auto; background: #fff; touch-action: none; user-select: none; }
@media (max-width: 799px) {
  .maze-board { overflow: auto; max-height: 70vh; }
  .maze-board .maze-canvas { width: max(100%, calc(var(--cols, 10) * 28px)); max-width: none; }
}
.letter-grid { display: grid; gap: 1px; }
.letter-grid span {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  background: #fff;
  border: 1px solid var(--line);
  font-size: clamp(8px, 2.4vw, 15px);
}
.letter-grid span.hit { box-shadow: inset 0 0 0 2px #111; font-weight: 700; }
.letter-grid span.drag { background: var(--hint); }
.letter-grid span.circled { border-radius: 50%; box-shadow: inset 0 0 0 2px var(--teal); }
.print-answer { display: block; break-before: page; page-break-before: always; }
.answer-only { display: none; }
.boxes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.boxes input { width: 40px; height: 44px; text-align: center; padding: 0; }
.answer { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-top: 8px; }
.controls input[type="number"] { width: 6.5rem; }
@media print {
  .top, .where, .how, .example, .faq, .more, .foot, .actions, .paste, .nums, .modes, .sliders, .choices, .skip, .controls, .limits, .fine, .status {
    display: none !important;
  }
  body { background: #fff; }
  .tool, .grid { box-shadow: none; }
  .cell.solved { background: #fff; }
  .print-answer, .answer-only {
    display: block !important;
    break-before: page !important;
    page-break-before: always !important;
  }
  #ws-answer .letter-grid span.hit { box-shadow: inset 0 0 0 2px #000; }
  #ws-puzzle span.circled, #ws-puzzle span.drag { box-shadow: none !important; background: #fff !important; border-radius: 0 !important; }
  .found-word { text-decoration: none !important; color: inherit !important; }
  .maze-board { overflow: visible !important; max-height: none !important; }
  .maze-board .maze-canvas { width: 100% !important; max-width: 100% !important; }
  .print-title:not([hidden]) {
    display: block !important;
    font: 700 1.7rem Georgia, "Iowan Old Style", Palatino, serif;
    margin: 0 0 8px;
  }
  body:has(.print-title:not([hidden])) h1 { display: none !important; }
}
