:root {
  --ink: #2b6460;
  --mid: #558380;
  --mist: #d5e0df;
  --paper: #f7f8f4;
  --tile: #fffdf5;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; }
.landscape-art { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: .64; }
.mountain-far { fill: #d5e0df; }
.mountain-mid { fill: #aac1bf; }
.mountain-near { fill: url(#near-hill); }
.river { fill: url(#river-mist); }
.river-light { fill: #eef4f2; opacity: .7; }
.shore { fill: #80a2a0; stroke: #80a2a0; stroke-width: 5; opacity: .5; }
#app {
  position: relative;
  max-width: 570px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  margin: auto;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
header, .setup { display: flex; align-items: center; gap: 8px; }
header { justify-content: space-between; }
.eyebrow { font-size: 11px; letter-spacing: .18em; }
.eyebrow { text-transform: uppercase; }
.intro { text-align: center; margin: 7px 0 14px; }
.intro p { margin: 4px 0; }
h1 { font: 400 clamp(38px, 8vw, 64px)/1.05 Georgia, serif; margin: 3px 0; }
.game {
  background: #fbfaf4f2;
  border: 1px solid var(--mist);
  border-radius: 19px;
  padding: clamp(8px, 2vw, 16px);
  box-shadow: 0 12px 38px #2b646014;
}
button, select {
  color: inherit;
  font: inherit;
  background: #fffdf8;
  border: 1px solid #aac1bf;
  border-radius: 9px;
  padding: 4px 9px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible, select:focus-visible { outline: 3px solid var(--mid); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }
.primary, button[aria-pressed="true"] { background: var(--ink); color: white; border-color: var(--ink); }
.primary { margin-left: auto; }
.progress, #status { text-align: center; margin: 5px 0; font-size: 13px; min-height: 20px; }
#board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
}
.cell {
  position: relative;
  border: 0;
  border-right: 1px solid #aac1bf;
  border-bottom: 1px solid #aac1bf;
  border-radius: 0;
  padding: 0;
  min-height: 0;
  font-size: clamp(18px, 5vw, 29px);
  background: var(--tile);
}
.cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--ink); }
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+19):nth-child(-n+27), .cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--ink); }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell.given { background: #e9ede4; font-weight: 700; color: #183c39; }
.cell.related { background: #e3eeea; }
.cell.conflict { background: #f4ded6; color: #852e24; }
.cell.selected { z-index: 1; box-shadow: inset 0 0 0 3px var(--ink); }
.cell:focus-visible { outline-offset: -5px; z-index: 2; }
.candidates { position: absolute; inset: 1px; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); align-items: center; font-size: clamp(8px, 2vw, 12px); line-height: 1; }
#keypad, .actions { display: grid; gap: 4px; margin-top: 8px; }
#keypad { grid-template-columns: repeat(9, minmax(0, 1fr)); }
#keypad button { padding: 0; font-size: 18px; font-weight: 650; }
#keypad .digit-complete { background: #e9ede4; color: #536963; font-weight: 400; }
.actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.actions button { padding-inline: 2px; font-size: clamp(11px, 2.8vw, 14px); }
#status:empty { display: none; }
#help-dialog p { text-align: left; }
dialog {
  width: min(380px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 22px;
  border: 1px solid var(--mist);
  border-radius: 19px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 16px 50px #183c3933;
}
dialog::backdrop { background: #183c3960; }
dialog h2 { margin: 0 0 8px; font: 400 32px/1.1 Georgia, serif; }
.dialog-actions { display: grid; gap: 8px; margin-top: 16px; }
.dialog-actions button { width: 100%; }
#stats-levels {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 20px;
  text-align: left;
}
#stats-levels dd { margin: 0; font-weight: 700; }
.brand {
  margin-top: auto;
  padding-top: 18px;
  text-align: center;
}
.brand a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 20px;
  border: 1px solid var(--mist);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-size: clamp(17px, 4vw, 22px);
  font-weight: 650;
  letter-spacing: .08em;
  text-decoration: none;
}
.brand a:focus-visible { outline: 3px solid var(--mid); outline-offset: 2px; }

@media (max-width: 600px), (max-height: 850px) {
  #app {
    --safe-top: max(8px, env(safe-area-inset-top));
    --safe-bottom: max(8px, env(safe-area-inset-bottom));
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
  }
  .intro { margin: 4px 0 8px; }
  .intro p { display: none; }
  h1 { font-size: clamp(28px, 7vw, 38px); }
  #board {
    width: min(100%, max(252px, calc(100dvh - 312px - var(--safe-top) - var(--safe-bottom))));
    margin-inline: auto;
  }
  .brand { padding-top: 8px; }
}
