:root {
  font-family: var(--font-serif);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overflow-x: hidden; color: var(--ink); }
body {
  background-color: var(--paper);
  background-image:
    radial-gradient(1100px 520px at 8% -12%, var(--paper-wash) 0%, transparent 52%),
    radial-gradient(800px 380px at 108% 8%, var(--paper-shade) 0%, transparent 48%);
}

.app { max-width: 980px; width: 100%; margin: 0 auto; padding: 28px 20px 48px; }

.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.brand { display: flex; gap: 12px; align-items: center; }
.mark {
  width: 36px; height: 36px; border-radius: 10px;
  background:
    linear-gradient(var(--gold), var(--gold)) 32% 50% / 8px 2px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 32% 38% / 2px 12px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 32% 62% / 2px 12px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 68% 38% / 10px 2px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 68% 50% / 10px 2px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 68% 62% / 10px 2px no-repeat,
    var(--gold-wash);
  box-shadow: inset 0 0 0 1px var(--mark-stroke);
}
h1 { font-size: 1.45rem; letter-spacing: 0.04em; margin: 0; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; letter-spacing: 0.12em; text-transform: uppercase; }
.nav { display: flex; gap: 14px; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; letter-spacing: 0.06em; font-size: 0.9rem; }
.nav a:hover { color: var(--ink); }
.meta { display: flex; gap: 8px; }
.pill {
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px;
  font-size: 0.85rem; letter-spacing: 0.04em; background: var(--bg-2);
}
.pill.quiet { color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 22px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.75rem; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.field.grow { flex: 1; min-width: 0; }
select, input, button { max-width: 100%; }
select, input[type="text"] {
  font: inherit; color: var(--ink); background: var(--bg-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 11px;
}
button {
  font: inherit; color: var(--ink); background: var(--btn);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--btn-hover-line); background: var(--btn-hover); }
button.primary { background: var(--gold-fill); color: var(--ink-button); border-color: var(--gold-border); font-weight: 600; }
button.primary:hover { background: var(--gold-hover); border-color: var(--gold-border); }
button.ghost { opacity: 0.7; }
button.active { border-color: var(--sel); color: var(--gold); background: var(--gold-active); }

.play { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 28px; align-items: start; }
.board-wrap { position: relative; min-width: 0; width: min(100%, 540px); max-width: 100%; }
.board {
  display: grid;
  grid-template-columns: repeat(var(--n, 8), minmax(0, 1fr));
  grid-template-rows: repeat(var(--n, 8), minmax(0, 1fr));
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1; background: var(--grid-strong); border-radius: 6px;
  box-shadow: var(--shadow);
  border: 3px solid var(--grid-strong);
}
.cell {
  position: relative; display: grid; place-items: center;
  min-width: 0; min-height: 0; overflow: hidden;
  background: var(--cell);
  border-right: 1px solid var(--grid-thin);
  border-bottom: 1px solid var(--grid-thin);
  font-size: clamp(1.15rem, 4.2vw, 1.7rem); cursor: pointer; user-select: none;
  color: var(--ink);
  line-height: 1;
}
.cell.given { color: var(--ink-strong); font-weight: var(--weight-given); }
.cell.entry { color: var(--entry); font-weight: var(--weight-entry); }
.cell.hi { background: var(--hi); }
.cell.same { background: var(--same); }
.cell.hint-unit { background: var(--hint-unit); }
.cell.hint-witness { background: var(--hint-witness); }
.cell.hint-place { box-shadow: inset 0 0 0 2px var(--gold-hint-ring); background: var(--hint-place); }
.cell.sel { box-shadow: inset 0 0 0 2px var(--sel); background: var(--sel-bg); }
.cell.bad { color: var(--bad); }

.side { display: flex; flex-direction: column; gap: 14px; }
.clock { display: flex; align-items: baseline; justify-content: space-between; font-size: 1.8rem; letter-spacing: 0.04em; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button { padding: 12px 0; background: var(--bg-2); min-height: 44px; }
.toggles, .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.92rem; }
.hint-why { min-height: 2.4em; color: var(--ink); font-size: 0.98rem; margin: 0; line-height: 1.4; }
.status { min-height: 1.4em; color: var(--muted); font-size: 0.95rem; margin: 0; }
.rules { margin: 0; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }
.win {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(246, 241, 232, 0.72); border-radius: 6px;
}
.win-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 26px; text-align: center; box-shadow: var(--shadow); max-width: 280px;
  color: var(--ink);
}
.win-card h2 { margin: 0 0 8px; letter-spacing: 0.08em; }
.hidden { display: none !important; }

.foot { margin-top: 28px; display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 0.85rem; flex-wrap: wrap; }
.muted { color: var(--muted); }
.key-legend { margin-left: auto; letter-spacing: 0.04em; opacity: 0.7; font-size: 0.78rem; }
.lab { font-size: 0.75rem; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.55; background: transparent; }
.debug {
  margin-top: 16px; padding: 16px 18px; background: var(--debug-bg); border: 1px dashed var(--line);
  border-radius: 12px; font-family: var(--font-mono); font-size: 0.8rem;
  color: var(--debug-ink);
}
.debug h3 { margin: 0 0 10px; font-size: 0.75rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--debug-label); }
.debug dl { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; margin: 0; }
.debug dt { color: var(--muted); }
.debug dd { margin: 0; }

@media (max-width: 760px) {
  .app { padding: 16px 12px 32px; max-width: 100%; }
  .play { grid-template-columns: 1fr; }
  .board-wrap { width: min(100%, 100vw - 24px); }
  .board { width: 100%; }
  .side { order: 2; }
  .keypad { grid-template-columns: repeat(3, 1fr); }
  .keypad button { min-height: 44px; }
  .debug dl { grid-template-columns: 1fr; }
  .key-legend { margin-left: 0; }
}
