/* =================================================================
   xwords — single stylesheet (list page + editor)
   Tuned for a laptop screen (>= 1280x720).
   ================================================================= */

:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --border: #e2e5ee;
  --border-strong: #cbd1e0;
  --text: #1b2030;
  --text-soft: #626b83;
  --text-faint: #8b93a8;

  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-border: #c7cbfb;
  --focus: #fcd34d;
  --word: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #15803d;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;

  /* Priority scale (word "strength") */
  --s1: #c4b5fd;
  --s2: #8b5cf6;
  --s3: #6d28d9;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 18px 48px rgba(16, 24, 40, 0.18);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
a { color: var(--accent); }
a.plain { text-decoration: none; color: inherit; }
code { font-family: var(--mono); font-size: 0.92em; }

.hidden { display: none !important; }

/* ------------------------------- Top bar ------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 60px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #7c6df2);
  color: #fff; font-size: 17px; line-height: 1;
}
.brand h1 { font-size: 17px; }
.brand .sub { color: var(--text-faint); font-size: 13px; }

.spacer { flex: 1; }

.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-soft); text-decoration: none;
  padding: 6px 10px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; white-space: nowrap;
}
.back-link:hover { background: var(--surface-2); color: var(--text); }

/* ------------------------------- Buttons ------------------------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  font: inherit; font-size: 14px; font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s, transform 0.06s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.35);
}
.btn.primary:hover { background: #4338ca; border-color: #4338ca; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--danger); border-color: #f3c9c9; background: var(--danger-soft); }
.btn.danger:hover { background: #fde8e8; border-color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* ------------------------------- Inputs -------------------------- */

input[type="text"], input[type="number"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
input:disabled { background: var(--surface-2); color: var(--text-soft); }
input:focus-visible, select:focus-visible, textarea:focus-visible,
.btn:focus-visible, [tabindex]:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-soft); font-weight: 550; }
label.field .opt { font-weight: 400; color: var(--text-faint); }

.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--text-soft); cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-soft);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #fde9b8; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #b7ecd2; }
.badge.clickable { cursor: pointer; }
.badge.clickable:hover { border-color: var(--ok); }

/* =================================================================
   List page
   ================================================================= */

.container { max-width: 1180px; margin: 0 auto; padding: 28px 20px 64px; }

.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.page-head h2 { font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--text-soft); font-size: 14px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: var(--border-strong); }

.card-preview {
  display: grid;
  gap: 1px;
  padding: 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  justify-content: center;
}
.card-preview i { background: #fff; border: 1px solid var(--border); border-radius: 1px; }
.card-preview i.b { background: var(--text); border-color: var(--text); }
.card-preview i.f { background: var(--accent-soft); border-color: var(--accent-border); }

.card-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.card-title { font-size: 16px; font-weight: 650; word-break: break-word; }
.card-theme { font-size: 12.5px; color: var(--text-soft); }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.card-file { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }

.bar { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }
.bar.green > span { background: var(--ok); }
.progress-row { display: flex; flex-direction: column; gap: 4px; }
.progress-row .lbl { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-soft); }

.card-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--surface-2); }

.empty {
  text-align: center;
  padding: 72px 20px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-soft);
}
.empty h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.empty p { margin: 0 0 18px; }

/* Modal */

dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow-lg);
  max-width: 460px; width: calc(100% - 32px);
  color: var(--text);
}
dialog::backdrop { background: rgba(16, 24, 40, 0.45); backdrop-filter: blur(2px); }
dialog h3 { padding: 18px 20px 0; font-size: 17px; }
dialog form { display: flex; flex-direction: column; gap: 15px; padding: 16px 20px 18px; }
dialog .row { display: flex; gap: 12px; }
dialog .row > * { flex: 1; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }
dialog .hint { font-size: 12.5px; color: var(--text-faint); margin: 8px 0 0; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; }

/* =================================================================
   Editor
   ================================================================= */

.editor-body { height: 100%; display: flex; flex-direction: column; overflow: hidden; }

.title-input {
  font-size: 16px; font-weight: 650;
  border-color: transparent; background: transparent;
  min-width: 180px; max-width: 320px;
  padding: 7px 10px;
}
.theme-input {
  font-size: 13.5px;
  border-color: transparent; background: transparent;
  color: var(--text-soft);
  width: 150px;
  padding: 7px 10px;
}
.title-input:hover, .theme-input:hover { background: var(--surface-2); border-color: var(--border); }
.title-input:focus, .theme-input:focus { background: #fff; border-color: var(--accent); }

.save-status { font-size: 13px; color: var(--text-faint); min-width: 140px; text-align: right; }
.save-status.dirty { color: var(--warn); }
.save-status.saved { color: var(--ok); }
.save-status.error { color: var(--danger); }

.editor-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  overflow: hidden;
}

/* ---- Left column: the grid ---- */

.grid-pane { display: flex; flex-direction: column; overflow: auto; padding: 16px 20px 28px; }

.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}
.toolbar .sep { width: 1px; height: 24px; background: var(--border); }
.toolbar .size-fields { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-soft); }
.toolbar input[type="number"] { width: 62px; padding: 6px 8px; }

.grid-wrap { display: flex; justify-content: center; }

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  border: 2px solid var(--text);
  background: var(--text);
  border-radius: 3px;
  user-select: none;
  outline: none;
}
.grid:focus-visible { box-shadow: 0 0 0 3px var(--accent-border); }

.cell {
  position: relative;
  background: #fff;
  border-right: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
  display: grid; place-items: center;
  font-size: calc(var(--cell) * 0.52);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-transform: uppercase;
}

.cell.black { background: var(--text); border-color: var(--text); }
.cell.word { background: var(--word); }
.cell.cursor { background: var(--focus); }
.cell.orphan { background: repeating-linear-gradient(45deg, #fff, #fff 4px, #fecaca 4px, #fecaca 8px); }

/* Word priority, projected on the cells it covers */
.cell.s1 { box-shadow: inset 0 0 0 2px var(--s1); }
.cell.s2 { box-shadow: inset 0 0 0 2px var(--s2); }
.cell.s3 { box-shadow: inset 0 0 0 3px var(--s3); }

.cell .num {
  position: absolute; top: 1px; left: 3px;
  font-size: calc(var(--cell) * 0.26);
  font-weight: 600;
  color: var(--text-faint);
  pointer-events: none;
}
.cell.cursor .num, .cell.word .num { color: var(--text-soft); }

.grid-footer { margin-top: 16px; display: flex; justify-content: center; }
.legend {
  display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center;
  max-width: 760px;
  font-size: 12.5px; color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.legend b { color: var(--text); font-weight: 600; }
.legend kbd {
  font-family: var(--mono); font-size: 11px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; color: var(--text);
}

.current-word-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px; padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-height: 56px;
}
.current-word-bar .num-chip {
  display: inline-grid; place-items: center;
  min-width: 30px; height: 26px; padding: 0 6px;
  border-radius: 6px; background: var(--accent-soft); color: var(--accent);
  font-size: 13px; font-weight: 700;
}
.current-word-bar .letters { font-family: var(--mono); font-size: 15px; letter-spacing: 3px; font-weight: 600; }
.current-word-bar input { flex: 1; min-width: 180px; }
.current-word-bar .muted { color: var(--text-faint); font-size: 13.5px; }

/* Priority controls */

.prio-seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.prio-btn {
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 6px 9px;
  border: none; border-left: 1px solid var(--border);
  background: var(--surface); color: var(--text-soft);
  cursor: pointer; line-height: 1.2;
}
.prio-btn:first-child { border-left: none; }
.prio-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.prio-btn:disabled { cursor: not-allowed; opacity: 0.6; }
.prio-btn.active { color: #fff; background: var(--text-faint); }
.prio-btn.active.s1 { background: var(--s1); color: #3b2f7a; }
.prio-btn.active.s2 { background: var(--s2); }
.prio-btn.active.s3 { background: var(--s3); }

.prio-chip {
  font: inherit; font-size: 11px; font-weight: 700; line-height: 1;
  padding: 3px 6px; min-width: 22px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--text-faint);
  cursor: pointer;
}
.prio-chip:hover:not(:disabled) { border-color: var(--s2); color: var(--s2); }
.prio-chip.on.s1 { background: #f1ecff; border-color: var(--s1); color: #5b45c7; }
.prio-chip.on.s2 { background: #ede5ff; border-color: var(--s2); color: var(--s2); }
.prio-chip.on.s3 { background: var(--s3); border-color: var(--s3); color: #fff; }

/* ---- Right column: clues ---- */

.side-pane {
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  padding: 16px 16px 40px;
  display: flex; flex-direction: column; gap: 16px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  /* The side pane is a scrolling flex column: without this the panels shrink
     and clip their own content instead of letting the pane scroll. */
  flex: 0 0 auto;
}
.panel > header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 650; color: var(--text-soft);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.panel > header .count { margin-left: auto; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--text-faint); }
.panel > header .count.done { color: var(--ok); }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 19px; font-weight: 680; }
.stat .k { font-size: 12px; color: var(--text-soft); }
.stat.full { grid-column: 1 / -1; }

.issues { padding: 6px; display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.issue {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  padding: 7px 9px; border-radius: var(--radius-sm);
  border: none; background: transparent; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--text);
}
.issue:hover { background: var(--warn-soft); }
.issue .tag {
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  background: var(--warn-soft); color: var(--warn);
  border: 1px solid #fde9b8; border-radius: 4px; padding: 1px 5px;
  min-width: 30px; text-align: center;
}
.issue .txt { color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.issues .ok-msg { padding: 10px; font-size: 13px; color: var(--ok); }
.issues .more { padding: 8px 10px; font-size: 12.5px; color: var(--text-faint); }

.def-list { list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; gap: 3px; }
.def-item {
  display: grid;
  grid-template-columns: 32px 1fr;
  grid-template-areas: "num head" "num input";
  gap: 4px 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
}
.def-item:hover { background: var(--surface-2); }
.def-item.active { background: var(--accent-soft); border-color: var(--accent-border); }
.def-item.incomplete .word { color: var(--warn); }

.def-item .n {
  grid-area: num;
  display: grid; place-items: center;
  height: 24px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 700; color: var(--text-soft);
}
.def-item.active .n { background: #fff; border-color: var(--accent-border); color: var(--accent); }

.def-item .head { grid-area: head; display: flex; align-items: center; gap: 7px; min-width: 0; }
.def-item .word {
  font-family: var(--mono); font-size: 12.5px; font-weight: 700; letter-spacing: 1.5px;
  color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.def-item .len { font-size: 11.5px; color: var(--text-faint); margin-left: auto; white-space: nowrap; }

.def-item input {
  grid-area: input;
  width: 100%;
  border: 1px solid transparent;
  background: var(--surface-2);
  padding: 5px 8px;
  font-size: 13.5px;
  border-radius: 6px;
}
.def-item input::placeholder { color: var(--text-faint); font-style: italic; }
.def-item input:hover { border-color: var(--border); }
.def-item input:focus { background: #fff; border-color: var(--accent); }
.def-item.missing input { background: var(--warn-soft); }

/* ---- Wishlist: the words the author wants to place ---- */

.wish-form { display: flex; gap: 6px; padding: 8px 8px 2px; }
.wish-form input {
  flex: 1; min-width: 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: 6px 9px;
  font: inherit; font-family: var(--mono); font-size: 13px; font-weight: 700;
  letter-spacing: 1.5px; text-transform: uppercase;
}
.wish-form input::placeholder {
  font-family: var(--font); font-weight: 400; font-style: italic;
  letter-spacing: 0; text-transform: none; color: var(--text-faint);
}
.wish-form input:focus { background: #fff; border-color: var(--accent); outline: none; }

.wish-list { list-style: none; margin: 0; padding: 6px 8px 8px; display: flex; flex-direction: column; gap: 2px; }
.wish-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: var(--radius-sm);
  border: 1px solid transparent;
}
.wish-item .mark { width: 12px; text-align: center; color: var(--ok); font-weight: 700; font-size: 12px; }
.wish-item .w {
  font-family: var(--mono); font-size: 13px; font-weight: 700; letter-spacing: 1.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wish-item .len { margin-left: auto; font-size: 11.5px; color: var(--text-faint); }
.wish-item.placed { background: var(--ok-soft); cursor: pointer; }
.wish-item.placed:hover { border-color: #bbe7cf; }
.wish-item.placed .w { color: var(--text-faint); text-decoration: line-through; }
.wish-item.placed .len { color: var(--ok); }

.wish-del {
  border: none; background: transparent; cursor: pointer;
  font: inherit; font-size: 16px; line-height: 1;
  padding: 0 3px; border-radius: 4px; color: var(--text-faint);
}
.wish-del:hover { color: var(--danger); background: var(--danger-soft); }

/* ---- End-of-game message: the author's word to the player ---- */

.message-field { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.message-input {
  width: 100%; resize: vertical; min-height: 62px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: 7px 9px;
  font: inherit; font-size: 13px; line-height: 1.45;
}
.message-input::placeholder { font-style: italic; color: var(--text-faint); }
.message-input:focus { background: #fff; border-color: var(--accent); }
.message-input:disabled { background: var(--surface-2); color: var(--text-soft); }
.message-field .hint { margin: 0; font-size: 12px; color: var(--text-faint); }

.panel .empty-msg { padding: 14px; font-size: 13px; color: var(--text-faint); text-align: center; margin: 0; }

/* Toasts */

.toasts {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 60;
  pointer-events: none;
}
.toast {
  background: var(--text); color: #fff;
  padding: 9px 16px; border-radius: 999px;
  font-size: 13.5px; box-shadow: var(--shadow-lg);
  animation: toast-in 0.18s ease-out;
}
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 1180px) {
  .editor-layout { grid-template-columns: minmax(0, 1fr) 340px; }
  .theme-input { display: none; }
}

/* =================================================================
   Solve mode (play.html)

   Same grid, same shortcuts as the editor — but the layout is driven by
   the free space: the grid box is a `flex: 1 1 0` item, so it measures
   what the toolbar, the clue bar and the on-screen keyboard leave, and
   play.js derives the cell size from it. That is what makes the page
   work on a phone as well as on a laptop.
   ================================================================= */

.play-body {
  height: 100%;
  height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
}

.play-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.play-head h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play-head .sub { font-size: 13px; color: var(--text-faint); white-space: nowrap; }

.timer {
  font-family: var(--mono); font-size: 15px; font-weight: 650;
  color: var(--text-soft); font-variant-numeric: tabular-nums;
  min-width: 52px; text-align: right;
}
.timer.done { color: var(--ok); }

.only-mobile { display: none; }

/* Single-grid deployment: the page is the whole site, nowhere to navigate to.
   The "read-only" badge goes too — it warns an *author* that grids cannot be
   edited, which means nothing to someone who came here to solve one. */
.solo .back-link, .solo #edit-link, .solo #mode-badge { display: none; }
.solo .play-head { margin-left: 4px; }

.play-layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
}

.play-body .grid-pane {
  overflow: hidden;
  min-height: 0;
  padding: 12px 16px 14px;
  gap: 0;
}

.play-toolbar { margin-bottom: 10px; padding: 7px 10px; }
.play-toolbar .spacer { flex: 1; }
.play-toolbar .btn.on { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }

/* Dropdown built on <details>: no JS state, no dependency. */
.menu { position: relative; }
.menu > summary { list-style: none; display: inline-flex; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-body {
  position: absolute; z-index: 30; top: calc(100% + 5px); left: 0;
  min-width: 170px; padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px;
}
.menu-item {
  font: inherit; font-size: 13.5px; text-align: left;
  padding: 7px 9px; border: none; border-radius: 6px;
  background: transparent; color: var(--text); cursor: pointer;
}
.menu-item:hover { background: var(--accent-soft); color: var(--accent); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }

/* ---- The selected definition, front and center ---- */

.clue-bar {
  display: flex; align-items: stretch; gap: 8px;
  margin-bottom: 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-height: 62px;
  padding: 8px 8px 8px 12px;
}
.clue-bar .muted { color: var(--text-soft); align-self: center; font-size: 14px; }

.clue-main { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.clue-head { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.clue-bar .num-chip {
  display: inline-grid; place-items: center;
  min-width: 32px; height: 24px; padding: 0 7px;
  border-radius: 6px; background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 700;
}
.clue-def { font-size: 17px; font-weight: 600; line-height: 1.25; color: var(--text); }
.clue-def.none { font-weight: 400; font-style: italic; color: var(--text-faint); }

.clue-sub { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12.5px; }
.clue-sub .letters { font-family: var(--mono); font-weight: 700; letter-spacing: 3px; color: var(--accent); }
.clue-sub .muted { font-size: 12.5px; color: var(--text-faint); }

.clue-cross {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0;
  font: inherit; font-size: 12.5px; text-align: left;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--accent-border); background: rgba(255, 255, 255, 0.7);
  color: var(--text-soft); cursor: pointer;
}
.clue-cross:hover { background: #fff; color: var(--text); }
.clue-cross .n { font-weight: 700; color: var(--accent); }
.clue-cross .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34ch; }

.clue-nav {
  flex: 0 0 auto; width: 34px;
  font: inherit; font-size: 22px; line-height: 1;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.6); color: var(--accent);
  cursor: pointer;
}
.clue-nav:hover { background: #fff; border-color: var(--accent-border); }

/* ---- The grid box takes whatever room is left ---- */

.play-body .grid-wrap {
  flex: 1 1 0;
  min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.play-body .cell { touch-action: manipulation; }
.play-body .cell.black { cursor: default; }
.play-body .grid.solved { border-color: var(--ok); background: var(--ok); }

.cell.wrong { color: var(--danger); background: #fee2e2; }
.cell.wrong.cursor { background: #fca5a5; }
.cell.wrong::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(to top left, transparent calc(50% - 1px), var(--danger) 50%, transparent calc(50% + 1px));
  opacity: 0.55; pointer-events: none;
}
.cell.revealed { color: var(--accent); }
.cell.revealed .ltr { font-style: italic; }

.play-body .grid-footer { margin-top: 10px; }
.play-body .legend { padding: 8px 14px; font-size: 12px; }

/* ---- On-screen keyboard (touch) ---- */

.keyboard {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 10px;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  user-select: none;
}
.key-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1 1 0; max-width: 56px;
  height: 44px;
  font: inherit; font-size: 17px; font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}
.key:active { background: var(--accent-soft); border-color: var(--accent); transform: translateY(1px); }
.key.wide { flex: 1.4 1 0; max-width: 74px; font-size: 18px; color: var(--accent); }

/* ---- Clue lists ---- */

.clue-list { list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.clue-item {
  display: grid; grid-template-columns: 30px 1fr auto;
  align-items: baseline; gap: 9px;
  padding: 7px 9px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
}
.clue-item:hover { background: var(--surface-2); }
.clue-item.active { background: var(--accent-soft); border-color: var(--accent-border); font-weight: 600; }
.clue-item .n { font-weight: 700; font-size: 12.5px; color: var(--text-soft); text-align: right; }
.clue-item.active .n { color: var(--accent); }
.clue-item .txt { min-width: 0; }
.clue-item .txt.none { color: var(--text-faint); font-style: italic; }
.clue-item .len { font-size: 11.5px; color: var(--text-faint); }
.clue-item.done .txt { color: var(--text-faint); }
.clue-item.done.active .txt { color: var(--text); }

.sheet-handle { display: none; }
.sheet-backdrop { display: none; }

/* ---- Win dialog ---- */

.win-dialog { max-width: 460px; text-align: center; }
.win-card { padding: 26px 24px 20px; display: flex; flex-direction: column; gap: 10px; }
.win-card .win-emoji { font-size: 44px; line-height: 1; }
.win-card h3 { font-size: 20px; }
.win-card p { margin: 0; color: var(--text-soft); font-size: 14px; }
/* Three actions on one row on a laptop; on a narrow phone they wrap and share
   the width instead of leaving one button stranded on its own line. */
.win-card .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.win-card .actions .btn { flex: 1 1 auto; justify-content: center; }

/* The author's own words: quoted, left-aligned, line breaks kept. */
.win-card .win-note {
  margin-top: 4px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--accent-border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 13.5px; text-align: left;
  white-space: pre-line; overflow-wrap: anywhere;
  max-height: 34vh; overflow-y: auto;
}

/* ---- Phones and small tablets ---- */

@media (max-width: 860px) {
  .play-body .topbar { height: 52px; padding: 0 10px; gap: 8px; }
  .play-body .topbar .back-link .lbl { display: none; }
  .play-body .topbar .btn .lbl { display: none; }
  .play-head h1 { font-size: 15px; max-width: 40vw; }
  .play-head .sub { display: none; }

  .only-mobile { display: inline-flex; }

  .play-layout { grid-template-columns: 1fr; }
  .play-body .grid-pane { padding: 8px 8px 6px; }

  /* One scrolling row instead of a wrapping block that eats the grid. */
  .play-toolbar {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin-bottom: 8px; padding: 6px 8px; border-radius: var(--radius-sm);
  }
  .play-toolbar::-webkit-scrollbar { display: none; }
  .play-toolbar .switch { white-space: nowrap; }
  .play-toolbar .spacer { flex: 0 0 4px; }

  /* The clue sits between the grid and the keyboard, thumb-side. */
  .play-body .grid-pane { display: flex; flex-direction: column; }
  .play-body .toolbar { order: 1; }
  .play-body .grid-wrap { order: 2; }
  .clue-bar { order: 3; margin: 8px 0 0; min-height: 54px; padding: 7px 6px 7px 10px; }
  .keyboard { order: 4; margin-top: 8px; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-radius: var(--radius) var(--radius) 0 0; }
  .play-body .grid-footer { display: none; }

  .clue-def { font-size: 15.5px; }
  .clue-sub .letters { display: none; }
  .clue-cross .txt { max-width: 22ch; }
  .clue-nav { width: 30px; font-size: 20px; }

  .key { height: 42px; font-size: 16px; max-width: none; }

  /* The clue list becomes a bottom sheet. */
  .play-body .side-pane {
    position: fixed; z-index: 50;
    left: 0; right: 0; bottom: 0;
    max-height: 72vh;
    border-left: none;
    border-top-left-radius: 16px; border-top-right-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 0 10px 16px;
    transform: translateY(101%);
    transition: transform 0.22s ease-out;
    overscroll-behavior: contain;
  }
  .clues-open .side-pane { transform: none; }
  .clues-open .sheet-backdrop {
    display: block; position: fixed; inset: 0; z-index: 45;
    background: rgba(16, 24, 40, 0.35);
  }
  .sheet-handle {
    display: flex; align-items: center; gap: 8px;
    position: sticky; top: 0; z-index: 2;
    margin: 0 -10px 10px; padding: 12px 14px 10px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    font-size: 13px; font-weight: 650; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--text-soft);
  }
  .sheet-handle .btn { margin-left: auto; }
  .clue-item { padding: 10px 9px; font-size: 15px; }
}
