:root {
  --bg: #14120e;
  --bg-2: #1c1914;
  --ink: #f3ead7;
  --ink-dim: #b9ae97;
  --rule: #3a3428;
  --tile: #efe6d4;
  --tile-ink: #1c160e;
  --tile-lock: #e2d5b8;
  --gold: #c9a227;
  --gold-soft: rgba(201, 162, 39, 0.28);
  --green: #2d6a4f;
  --green-ink: #f4fff6;
  --purple: #5c3d7a;
  --purple-ink: #f7efff;
  --danger: #b33a3a;
  --btn: #2a251c;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 8px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f6f0e4;
  --bg-2: #efe6d4;
  --ink: #1c160e;
  --ink-dim: #6a614f;
  --rule: #d7cdb6;
  --tile: #fffaf0;
  --tile-ink: #1c160e;
  --tile-lock: #f1e6cc;
  --gold: #8a6a10;
  --gold-soft: rgba(138, 106, 16, 0.22);
  --green: #1f5a40;
  --green-ink: #f4fff6;
  --purple: #5c3d7a;
  --purple-ink: #f7efff;
  --danger: #9a2a2a;
  --btn: #fffaf0;
  --shadow: 0 10px 30px rgba(60, 40, 10, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", "Iowan Old Style", Georgia, serif;
  min-height: 100%;
  min-height: 100dvh;
}
body {
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}
button, input {
  font: inherit;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#app {
  max-width: 28rem;
  margin: 0 auto;
  min-height: calc(100dvh - var(--safe-t) - var(--safe-b));
  display: flex;
  flex-direction: column;
  padding: 0.4rem 0.9rem 1.2rem;
}
#app[hidden] { display: none !important; }

.mast {
  display: grid;
  grid-template-columns: 2.4rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0 0.7rem;
  border-bottom: 1px solid var(--rule);
}
.brand { text-align: center; }
.brand h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: 0.14em;
  font-weight: 700;
  text-transform: uppercase;
}
.dateline {
  margin: 0.05rem 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.mast-right {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}
.scoreboard {
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  white-space: nowrap;
  padding-right: 0.15rem;
}
.scoreboard #score { color: var(--gold); font-weight: 700; }
.scoreboard.hidden { visibility: hidden; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover, .icon-btn:focus-visible {
  background: var(--gold-soft);
  outline: none;
}

.board-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  padding: 1rem 0 0.4rem;
}

.grid {
  --gap: 0.45rem;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--gap);
  width: min(100%, 22rem);
}
.tile {
  aspect-ratio: 1;
  border: 0;
  border-radius: var(--radius);
  background: var(--tile);
  color: var(--tile-ink);
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  font-weight: 700;
  font-size: clamp(1.4rem, 8vw, 2rem);
  letter-spacing: 0;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 1px 0 rgba(0,0,0,0.18), 0 6px 12px rgba(0,0,0,0.08);
  position: relative;
  touch-action: manipulation;
  transition: background-color 160ms ease, color 160ms ease, transform 180ms ease;
}
.tile.col0 {
  background: var(--tile-lock);
  cursor: default;
}
.tile.col0::after {
  content: "";
  position: absolute;
  left: 0;
  top: 14%;
  bottom: 14%;
  width: 3px;
  border-radius: 2px;
  background: var(--gold);
  opacity: 0.7;
}
.tile.selected {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  transform: translateY(-2px);
  z-index: 2;
}
.tile.word {
  background: var(--green);
  color: var(--green-ink);
  box-shadow: none;
}
.tile.revealed {
  background: var(--purple);
  color: var(--purple-ink);
  cursor: default;
  box-shadow: none;
}
.tile.word.revealed {
  background: var(--purple);
  color: var(--purple-ink);
}
.tile.swapping { z-index: 3; }
.tile:disabled { cursor: default; }

.hint {
  min-height: 2.4em;
  margin: 0;
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.95rem;
  max-width: 22rem;
  line-height: 1.35;
}
.hint.hidden { visibility: hidden; }

.actions { display: flex; gap: 0.5rem; }
.btn {
  appearance: none;
  border: 1px solid var(--rule);
  background: var(--btn);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.55rem 1.05rem;
  cursor: pointer;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
}
.btn:hover, .btn:focus-visible {
  border-color: var(--gold);
  outline: none;
}
.btn-primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #1c160e;
  font-weight: 700;
}
.btn-reveal[aria-pressed="true"] {
  background: var(--purple);
  border-color: var(--purple);
  color: var(--purple-ink);
}

/* display is set only when the hidden attribute is absent. An author
   "display: flex" rule otherwise overrides the hidden attribute in some
   browsers, which stacked every dialog on load and left the Solved
   sheet (last in the DOM) blocking all clicks. */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 6, 3, 0.62);
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  padding-bottom: max(1rem, var(--safe-b));
  z-index: 20;
}
.overlay:not([hidden]) { display: flex; }
.overlay .panel {
  background: var(--bg-2);
  color: var(--ink);
  width: min(26rem, 100%);
  max-height: min(92dvh, 40rem);
  overflow: auto;
  border-radius: 16px 16px 12px 12px;
  padding: 1.2rem 1.2rem 1.3rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--rule);
}
.overlay .panel.wide { width: min(28rem, 100%); }
.overlay h2 {
  margin: 0 0 0.6rem;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
}
.overlay h3 {
  margin: 1rem 0 0.3rem;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}
.overlay p { margin: 0 0 0.7rem; line-height: 1.45; color: var(--ink); }
.overlay .btn { margin: 0.25rem 0.25rem 0 0; }
.overlay input[type="password"] {
  width: 100%;
  padding: 0.7rem 0.8rem;
  margin: 0.3rem 0 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--ink);
}

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin: 0.55rem 0;
  line-height: 1.3;
  cursor: pointer;
}
.toggle input { margin-top: 0.2rem; accent-color: var(--gold); }
.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.9rem 0 0.6rem;
}
.form-error { color: #ffb4a8; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.7rem;
  margin: 0 0 1rem;
}
.stats-grid dt {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.stats-grid dd {
  margin: 0.15rem 0 0;
  font-size: 1.6rem;
  font-weight: 700;
}
.share-preview {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.8rem;
  white-space: pre;
  font-family: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, monospace;
  font-size: 0.95rem;
  overflow: auto;
}

@media (min-width: 640px) {
  .overlay { align-items: center; }
  .overlay .panel { border-radius: 16px; }
}


/* The HTML hidden attribute must always win over display:flex/grid on
   #app, .overlay, and anything else. */
[hidden] {
  display: none !important;
}
