:root {
  --ink: #1c1915;
  --paper: #f4efe4;
  --paper-deep: #e7e0d1;
  --line: #2a261f;
  --gold: #f0c84b;
  --word: #c5dff5;
  --correct: #2f6fad;
  --wrong: #f3c1bc;
  --muted: #8a8174;
  --green: #1f3d32;
  --cell: 32px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: Georgia, "Iowan Old Style", Palatino, "Palatino Linotype", serif;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(5.5rem + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}

button, input {
  font: inherit;
  color: inherit;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  padding: 0.85rem 1rem 0.4rem;
  background: var(--green);
  color: #f6f1e6;
}

.kicker {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.72rem;
}

.kicker a {
  color: inherit;
}

.skeleton-page {
  padding-bottom: 2rem;
}

.skeleton-page .clues {
  display: grid;
  position: static;
  grid-template-columns: 1fr 1fr;
  max-height: none;
  box-shadow: none;
}

h1, h2 { font-weight: 600; }

h1 {
  margin: 0.1rem 0 0;
  font-size: 1.45rem;
}

.timer {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 1.2rem;
}

.cluebar {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0.45rem 0.6rem;
  background: #fffdf8;
  border-bottom: 1px solid #ddd4c4;
}

.cluebar button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

#prev, #next {
  width: 2.4rem;
  font-size: 1.6rem;
  line-height: 1;
}

#clue-text {
  flex: 1;
  text-align: left;
  font-size: 1.05rem;
  line-height: 1.35;
  padding: 0.35rem 0.2rem;
  touch-action: pan-y;
}

.layout {
  display: grid;
  gap: 1rem;
  padding: 0.8rem;
}

.zoombar, .assists, .share-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.zoombar { justify-content: center; }

.layout-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.9rem;
}

.layout-bar p { margin: 0; }
.layout-bar .lengths { color: var(--muted); }

.creator-page .creator-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: flex-end;
  margin-bottom: 0.6rem;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.88rem;
}

.creator-field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.creator-field input,
.creator-field select {
  border: 1px solid #cfc5b2;
  border-radius: 0.45rem;
  padding: 0.35rem 0.5rem;
  min-width: 7rem;
  background: #fffdf8;
}

.creator-bar button {
  border: 1px solid #cfc5b2;
  background: #fffdf8;
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}

.creator-page .clues button {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem;
  align-items: center;
  text-align: left;
}

.clue-edit {
  width: 100%;
  border: 1px solid #ddd4c4;
  border-radius: 0.35rem;
  padding: 0.25rem 0.4rem;
  font: inherit;
  background: #fff;
}

.cell.locked.word {
  outline: 2px solid #1f3d32;
  outline-offset: -2px;
}

.zoombar button, .assists button, .share button, .clues-toggle, .done button, .layout-bar button {
  border: 1px solid #cfc5b2;
  background: #fffdf8;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.92rem;
  cursor: pointer;
}

.viewport {
  overflow: auto;
  max-width: 100%;
  margin: 0.7rem 0;
  touch-action: none;
}

.grid {
  display: grid;
  width: max-content;
  margin: 0 auto;
  background: var(--line);
  border: 2px solid var(--line);
  gap: 1px;
  user-select: none;
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 0;
  background: #fff;
  cursor: pointer;
}

.cell.black {
  background: var(--ink);
  cursor: default;
}

.cell.word { background: var(--word); }
.cell.active { background: var(--gold); }
.cell.wrong { background: var(--wrong); }
.cell.correct .letter { color: var(--correct); }
.cell.revealed .letter { color: var(--correct); font-style: italic; }

.num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: max(8px, calc(var(--cell) * 0.26));
  line-height: 1;
}

.letter {
  display: block;
  margin-top: 0.28em;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-weight: 650;
  font-size: calc(var(--cell) * 0.52);
  line-height: 1;
}

.clues {
  display: none;
  gap: 1rem;
}

.clues.open {
  display: grid;
  position: fixed;
  z-index: 4;
  left: 0.6rem;
  right: 0.6rem;
  bottom: calc(4.2rem + env(safe-area-inset-bottom));
  max-height: 55vh;
  overflow: auto;
  padding: 0.8rem;
  background: #fffdf8;
  border: 1px solid #ddd4c4;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(28, 25, 21, 0.18);
}

.clues h2 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.clues ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.clues button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.28rem 0.2rem;
  cursor: pointer;
}

.clues button.filled { color: var(--muted); }
.clues button.selected { background: var(--word); }
.clue-num { font-family: "Segoe UI", system-ui, sans-serif; font-weight: 650; }

.share {
  padding: 0 1rem 1rem;
}

.share h2 { font-size: 1rem; }

.share input {
  flex: 1;
  min-width: 12rem;
  border: 1px solid #cfc5b2;
  background: #fff;
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  font-family: "Segoe UI", system-ui, sans-serif;
}

#share-msg {
  min-height: 1.2em;
  margin: 0.4rem 0 0;
}

.clues-toggle {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: calc(0.7rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--green);
  color: #f6f1e6;
  border-color: var(--green);
}

#keycatch {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  font-size: 16px;
}

.done {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-content: center;
  gap: 0.8rem;
  background: rgba(28, 25, 21, 0.35);
  text-align: center;
}

.done[hidden] { display: none; }

.done p {
  margin: 0;
  padding: 1.2rem 1.6rem 0;
  background: #fffdf8;
  font-size: 1.8rem;
}

.done button { margin: 0 1.6rem 1.2rem; }

@media (min-width: 900px) {
  body { padding-bottom: 2rem; }
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
    align-items: start;
  }
  .clues, .clues.open {
    display: grid;
    position: static;
    max-height: calc(100vh - 8rem);
    grid-template-columns: 1fr 1fr;
    box-shadow: none;
  }
  .clues-toggle { display: none; }
}
