/* Committed to a single light look, like the classic Mini itself --
   no dark-mode palette, always white. */
:root {
  --page-bg: #ffffff;
  --ink: #1a1a1a;
  --muted: #767676;
  --rule: #e2e2e2;
  --paper: #ffffff;
  --paper-ink: #1a1a1a;
  --block: #000000;
  --grid-border: #8a8a8a;
  --button-bg: #1a1a1a;
  --button-text: #ffffff;
  --hover-bg: #cfe4fb;
  --focus: #1669c1;
  --active-word: #cfe4fb;
  --active-cell: #ffd85e;
  --wrong: #b3261e;
  --wrong-bg: #ffd7d2;
  /* Crossword tiles on the recent-crosswords page: a soft, muted blue. */
  --tile-bg: #e8eef4;
  --tile-border: #d0dae5;
  --tile-hover: #dce5ee;
}

/* Joyig for all Tibetan script. unicode-range limits it to the Tibetan
   block, so listing it first in every font stack below only affects
   Tibetan characters -- Latin text still falls through to the next font. */
@font-face {
  font-family: "Joyig";
  src: url("fonts/Joyig_Regular_v1_d784851e4ea2b83a1f5b70123e5ec03c.ttf") format("truetype");
  font-display: swap;
  unicode-range: U+0F00-0FFF;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--page-bg);
  color: var(--ink);
  font-family:
    "Joyig", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  margin: 0;
  padding: clamp(20px, 5vw, 48px) 16px 64px;
}

.tibetan {
  font-family:
    "Joyig", "Noto Sans Tibetan", "Kailasa", "Microsoft Himalaya", "Jomolhari",
    "Qomolangma-Uchen Sarchen", sans-serif;
}

.page {
  max-width: 900px;
  margin: 0 auto;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 24px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 16px;
  margin-bottom: 20px;
}

.masthead {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

h1 {
  font-family: "Joyig", Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-weight: 800;
  font-size: clamp(1.9rem, 4.4vw, 2.7rem);
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
  color: var(--ink);
}

.title-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.date {
  font-size: clamp(1.1rem, 2.4vw, 1.35rem);
  color: #4a4a4a;
  font-variant-numeric: tabular-nums;
}

.byline {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.meta {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-bottom: 3px;
}

.page-nav {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
}

.page-nav-link {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 13px;
  border-radius: 2px;
  border: 1px solid var(--rule);
}

.page-nav-link:hover {
  color: var(--ink);
}

.page-nav-link.is-active {
  color: var(--ink);
  border-color: var(--ink);
}

.page-nav-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 28px;
}

#english-hints {
  padding: 9px 15px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 2px;
  cursor: pointer;
}

#english-hints[aria-pressed="true"] {
  background: var(--button-bg) !important;
  color: var(--button-text) !important;
  border-color: var(--button-bg) !important;
}

.timer {
  font-size: 0.9rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

button#new-puzzle {
  appearance: none;
  border: none;
  background: var(--button-bg);
  color: var(--button-text);
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 11px 22px;
  border-radius: 2px;
  cursor: pointer;
  transition: opacity 0.12s ease;
}

button#new-puzzle:hover:not(:disabled) {
  opacity: 0.82;
}

button#new-puzzle:disabled {
  opacity: 0.45;
  cursor: default;
}

button#new-puzzle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 440px) 1fr;
  gap: clamp(24px, 4vw, 48px);
  align-items: start;
}

.layout[hidden] {
  display: none;
}

@media (max-width: 680px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.board {
  position: relative;
}

.grid {
  display: grid;
  width: 100%;
  background: var(--grid-border);
  gap: 1px;
  border: 2px solid var(--grid-border);
  min-height: 120px;
}

.cell {
  position: relative;
  background: var(--paper);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell.block {
  background: var(--block);
}

.cell .num {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: clamp(0.52rem, 1.15vw, 0.65rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--paper-ink);
  font-family:
    "Joyig", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
}

.cell .letter {
  color: var(--paper-ink);
  font-size: clamp(1rem, 2.6vw, 1.5rem);
  line-height: 1;
}

.cell input.letter-input {
  appearance: none;
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  padding: 0;
  text-align: center;
  color: var(--paper-ink);
  font-family: inherit;
  font-size: clamp(1rem, 2.6vw, 1.5rem);
  line-height: 1;
  caret-color: var(--focus);
}

.cell input.letter-input:focus {
  outline: none;
}

.cell input.letter-input:read-only {
  color: var(--muted);
  caret-color: transparent;
}

.cell input.letter-input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.cell.active-word {
  background: var(--active-word);
}

.cell.active-cell {
  background: var(--active-cell);
}

.cell.wrong input.letter-input {
  color: var(--wrong);
}

.board-caption {
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.clues {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 32px;
}

@media (max-width: 560px) {
  .clues {
    grid-template-columns: 1fr;
  }
}

.clue-group h2 {
  font-family:
    "Joyig", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}

.clue-group + .clue-group {
  margin-top: 26px;
}

@media (min-width: 561px) {
  .clue-group + .clue-group {
    margin-top: 0;
  }
}

ol.clue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 1.5em;
}

ol.clue-list li {
  display: grid;
  grid-template-columns: 1.5em 1fr;
  gap: 4px 8px;
  padding: 7px 6px;
  margin: 0 -6px;
  border-radius: 2px;
}

ol.clue-list li:hover {
  background: var(--hover-bg);
}

.clue-list.interactive li {
  cursor: pointer;
}

.clue-list.interactive li.is-active {
  background: var(--active-word);
}

.clue-list.interactive li:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.clue-number {
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  padding-top: 0.15em;
}

.clue-word {
  font-size: 1.02rem;
  line-height: 1.3;
  color: var(--ink);
}

.clue-def {
  grid-column: 2;
  color: #4a4a4a;
  font-size: 0.98rem;
  line-height: 1.5;
}

.clue-en {
  display: none;
  grid-column: 2;
  margin-top: 2px;
  color: var(--focus);
  font-size: 0.9rem;
  font-style: italic;
  line-height: 1.45;
}

.clues.show-en .clue-en:not(:empty) {
  display: block;
}

footer {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: 0.78rem;
  color: var(--muted);
}

footer code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.92em;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--page-bg);
  border-radius: 4px;
  padding: 34px 30px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.5);
}

.modal-eyebrow {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.modal h2 {
  font-family: "Joyig", Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 1.7rem;
  margin: 0 0 10px;
  color: var(--ink);
}

.modal-time {
  margin: 0 0 24px;
  font-size: 0.9rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.modal button {
  appearance: none;
  border: none;
  background: var(--button-bg);
  color: var(--button-text);
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 11px 22px;
  border-radius: 2px;
  cursor: pointer;
}

.modal button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.modal-text {
  margin: 0 0 24px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* The "back out" choice: outlined rather than filled, so the filled button
   stays the one that does something. */
.modal button.modal-secondary {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

/* .page-nav-link is styled as an <a> above; reset button-only defaults so
   it also works as a <button> (used for the Today/Yesterday tabs). */
button.page-nav-link {
  appearance: none;
  background: none;
  font: inherit;
  cursor: pointer;
}

.link-button {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-button:hover {
  color: var(--ink);
}

.link-button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.date-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}

#show-solution {
  appearance: none;
  border: none;
  background: none;
  color: var(--focus);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 6px 4px;
  margin-left: 4px;
}

#show-solution:disabled {
  opacity: 0.5;
  cursor: default;
  text-decoration: none;
}

#show-solution:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---- login / admin: shared form controls ---------------------------- */

.page-narrow {
  max-width: 420px;
}

.auth-card {
  max-width: 360px;
  margin: 40px auto 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-card h2 {
  font-family: "Joyig", Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 1.3rem;
  margin: 0;
  color: var(--ink);
}

.auth-field,
.admin-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-field input,
.admin-field input,
.admin-field textarea {
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 10px 12px;
  resize: vertical;
}

.admin-field textarea {
  font-size: 1.1rem;
  line-height: 1.6;
}

.auth-field input:focus-visible,
.admin-field input:focus-visible,
.admin-field textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.auth-card button[type="submit"] {
  appearance: none;
  border: none;
  background: var(--button-bg);
  color: var(--button-text);
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 12px 20px;
  border-radius: 2px;
  cursor: pointer;
}

.auth-card button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: default;
}

.auth-card button[type="submit"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.admin-controls {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 520px;
  margin-bottom: 32px;
}

.admin-actions {
  display: flex;
  gap: 12px;
}

.admin-actions button {
  appearance: none;
  border: none;
  background: var(--button-bg);
  color: var(--button-text);
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 11px 20px;
  border-radius: 2px;
  cursor: pointer;
}

.admin-actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

.admin-actions button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---- builder: hand-built crossword editor -------------------------- */

.size-controls {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.size-controls .admin-field {
  width: 84px;
}

.size-controls button,
.publish-box .admin-actions button {
  appearance: none;
  border: none;
  background: var(--button-bg);
  color: var(--button-text);
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 10px 18px;
  border-radius: 2px;
  cursor: pointer;
}

.size-controls button:disabled,
.publish-box .admin-actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

.size-controls button:focus-visible,
.publish-box .admin-actions button:focus-visible,
.mode-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.ghost-btn {
  background: none !important;
  color: var(--ink) !important;
  border: 1px solid var(--rule) !important;
}

.mode-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-btn {
  appearance: none;
  background: none;
  border: 1px solid var(--rule);
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 9px 15px;
  border-radius: 2px;
  cursor: pointer;
}

.mode-btn.is-active {
  color: var(--button-text);
  background: var(--button-bg);
  border-color: var(--button-bg);
}

.mode-hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.2em;
}

.grid.mode-letter .cell:not(.block) {
  cursor: text;
}

.grid.mode-block .cell,
.grid.mode-tsheg .cell:not(.block) {
  cursor: pointer;
}

.grid.mode-block .cell input.letter-input,
.grid.mode-tsheg .cell input.letter-input {
  pointer-events: none;
}

.cell input.letter-input.is-tsheg {
  color: var(--muted);
}

.build-side {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

ol.entry-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

ol.entry-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--rule);
}

.entry-head {
  font-family: "Joyig", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--ink);
  padding-top: 0.15em;
}

.entry-word {
  font-size: 1.05rem;
  color: var(--ink);
}

.entry-note {
  grid-column: 2;
  font-size: 0.9rem;
  line-height: 1.45;
  color: #4a4a4a;
}

.warn {
  color: var(--wrong);
}

.publish-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}

.publish-box .admin-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ---- the "Words" definition editor -------------------------------- */

.admin-controls .admin-field input[type="search"] {
  font-size: 1.15rem;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.checkbox-field input {
  width: 16px;
  height: 16px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.pager button {
  padding: 7px 14px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 2px;
  cursor: pointer;
}

.pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

ol.def-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.def-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
}

.def-row.is-flagged {
  border-left: 3px solid var(--wrong);
  padding-left: 14px;
}

.def-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.def-word {
  font-size: 1.35rem;
  color: var(--ink);
}

.def-label {
  font-family: "Joyig", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.def-badge {
  font-family: "Joyig", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--focus);
}

.def-badge.warn {
  color: var(--wrong);
}

textarea.def-input {
  font-family: inherit;
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 10px 12px;
  resize: vertical;
}

textarea.def-input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.def-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.def-actions button {
  appearance: none;
  border: none;
  background: var(--button-bg);
  color: var(--button-text);
  font: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 16px;
  border-radius: 2px;
  cursor: pointer;
}

.def-actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

.def-actions button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.def-status {
  font-size: 0.82rem;
  color: var(--muted);
}

/* --- play.html date bar ---------------------------------------------------- */

.puzzle-day {
  font-size: 0.95rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* --- week.html ------------------------------------------------------------- */

.week-heading {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  margin: 0 0 8px;
}

ol.week-tiles {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

/* Phones: one horizontal deck -- one tile in full view and a quarter of
   the next peeking in, which shows there's more to swipe to. A tile is w
   wide where w + gap + w/4 = 100%. */
@media (max-width: 560px) {
  ol.week-tiles {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - 12px) / 1.25);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    padding-bottom: 8px;
  }

  ol.week-tiles > li {
    scroll-snap-align: start;
  }
}

.week-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  padding: 16px 10px 14px;
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  border-radius: 4px;
  color: var(--ink);
  text-decoration: none;
  text-align: center;
}

a.week-tile:hover {
  border-color: var(--ink);
  background: var(--tile-hover);
}

a.week-tile:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.week-tile.is-today {
  border-color: var(--ink);
  border-width: 2px;
  padding: 15px 9px 13px;
}

/* No crossword that day: same colour as the rest, but greyed text and a
   dashed border mark it as not playable. */
.week-tile.is-unavailable {
  color: var(--muted);
  border-style: dashed;
}

.tile-day-dz {
  font-size: 1.15rem;
  line-height: 1.3;
}

.tile-day-en {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.tile-date {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tile-status {
  font-size: 0.78rem;
  font-weight: 700;
}

.tile-time {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* A tiny 3x3 "grid" whose fill shows the player's status on that day. */
.tile-icon {
  --icon-cell: var(--paper);
  --icon-fill: var(--paper);
  display: inline-block;
  flex: none;
  width: 34px;
  height: 34px;
  margin: 8px 0 4px;
  border: 2px solid var(--grid-border);
  background:
    linear-gradient(var(--grid-border), var(--grid-border)) 33.33% 0 / 1px 100% no-repeat,
    linear-gradient(var(--grid-border), var(--grid-border)) 66.66% 0 / 1px 100% no-repeat,
    linear-gradient(var(--grid-border), var(--grid-border)) 0 33.33% / 100% 1px no-repeat,
    linear-gradient(var(--grid-border), var(--grid-border)) 0 66.66% / 100% 1px no-repeat,
    linear-gradient(to bottom, var(--icon-fill) 50%, var(--icon-cell) 50%);
}

.tile-icon.is-in-progress {
  --icon-fill: var(--active-word);
}

.tile-icon.is-solved {
  --icon-cell: var(--active-cell);
  --icon-fill: var(--active-cell);
  border-color: var(--ink);
}

/* Solved with English hints: half gold, half hint-blue. */
.tile-icon.is-solved-hints {
  --icon-fill: var(--active-cell);
  --icon-cell: var(--active-word);
  border-color: var(--focus);
}

.tile-icon.is-revealed {
  --icon-cell: #cfcfcf;
  --icon-fill: #cfcfcf;
}

.tile-icon.is-locked {
  opacity: 0.35;
}

ul.week-legend {
  list-style: none;
  margin: 28px 0 0;
  padding: 14px 0 0;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  font-size: 0.78rem;
  color: var(--muted);
}

ul.week-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

ul.week-legend .tile-icon {
  width: 18px;
  height: 18px;
  margin: 0;
  border-width: 1px;
}

/* Phones: the recent crosswords fill the screen -- header at the top, the
   deck centred in the space below it, and bigger tiles to tap. */
@media (max-width: 560px) {
  body.week-page {
    padding-bottom: 24px;
  }

  /* The body's top (20px) + bottom (24px) padding, taken off the screen
     height so the page fits exactly. dvh tracks the phone's browser bars. */
  body.week-page .page {
    min-height: calc(100vh - 44px);
    min-height: calc(100dvh - 44px);
    display: flex;
    flex-direction: column;
  }

  .week-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* Sit a little above true centre, where it reads as balanced. */
    padding-bottom: 6vh;
  }

  .week-heading {
    font-size: 1.1rem;
    margin-bottom: 12px;
  }

  .week-tile {
    justify-content: center;
    gap: 8px;
    min-height: min(46vh, 380px);
    padding: 26px 14px 24px;
  }

  .week-tile.is-today {
    padding: 25px 13px 23px;
  }

  .tile-day-dz {
    font-size: 2.1rem;
  }

  .tile-day-en {
    font-size: 1rem;
  }

  .tile-date {
    font-size: 1.25rem;
  }

  .week-tile .tile-icon {
    width: 76px;
    height: 76px;
    margin: 14px 0 10px;
  }

  .tile-status {
    font-size: 1.3rem;
  }

  .tile-time {
    font-size: 1.15rem;
  }

  .tile-hint {
    font-size: 1rem;
  }

  /* The status key under the deck. */
  ul.week-legend {
    margin-top: 28px;
    padding-top: 18px;
    gap: 12px 22px;
    font-size: 1rem;
  }

  ul.week-legend li {
    gap: 10px;
  }

  ul.week-legend .tile-icon {
    width: 24px;
    height: 24px;
  }
}

/* --- play.html clue bar (phones) -------------------------------------------- */

.clue-bar {
  display: none;
}

@media (max-width: 680px) {
  .clue-bar:not([hidden]) {
    display: grid;
    grid-template-columns: 40px 1fr 40px;
    align-items: stretch;
    margin-top: 10px;
    background: var(--active-word);
    border-radius: 2px;
  }

  .clue-bar button {
    appearance: none;
    border: none;
    background: none;
    font: inherit;
    color: var(--ink);
    cursor: pointer;
  }

  .clue-bar button:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: -2px;
  }

  .clue-bar-step {
    font-size: 1.6rem;
    line-height: 1;
  }

  .clue-bar-body {
    display: flex;
    flex-direction: column;
    /* Room between "4 DOWN", the clue, and the English hint. */
    gap: 8px;
    min-height: 64px;
    justify-content: center;
    padding: 12px 4px;
    text-align: left;
  }

  .clue-bar-label {
    font-size: 0.85rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .clue-bar-text {
    font-size: 1.25rem;
    line-height: 1.5;
  }

  .clue-bar-en {
    color: var(--focus);
    font-size: 1.05rem;
    font-style: italic;
    line-height: 1.4;
  }

  .clue-bar-en:empty {
    display: none;
  }

  /* The bar replaces the full clue lists and the desktop instructions. */
  .play-layout .clues,
  .play-layout .board-caption {
    display: none;
  }
}

/* --- stats.html ------------------------------------------------------------ */

dl.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 10px 0 0;
}

dl.stats-grid[hidden] {
  display: none;
}

@media (max-width: 560px) {
  dl.stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat {
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 16px 12px 14px;
  text-align: center;
}

.stat dt {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat dd {
  margin: 6px 0 0;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* --- play.html on-screen Dzongkha keyboard ----------------------------------- */
/* Laid out like the iOS Tibetan keyboard, in the light palette: a pale
   grey tray, white letter keys, grey function keys. */

.osk {
  --osk-gap: 6px;
  --osk-key-w: calc((100% - 9 * var(--osk-gap)) / 10);
  --osk-tray: #d3d6dc;
  --osk-fn: #adb3bd;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
  padding: 8px 4px 8px;
  background: var(--osk-tray);
  border-radius: 6px;
  user-select: none;
  -webkit-user-select: none;
}

.osk[hidden] {
  display: none;
}

.osk-row {
  display: flex;
  justify-content: center;
  gap: var(--osk-gap);
}

.osk-key {
  appearance: none;
  border: none;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
  font: inherit;
  line-height: 1;
  height: 46px;
  min-width: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.osk-key svg {
  width: 26px;
  height: 26px;
}

.osk-key:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.osk-letter {
  flex: 0 0 var(--osk-key-w);
  font-size: 1.45rem;
}

.osk-letter:active {
  background: var(--osk-fn);
}

/* Vowel marks sit on a dotted circle, the usual way to show a combining
   mark on its own. */
.osk-mark-glyph {
  position: relative;
  display: inline-block;
  width: 0.62em;
  height: 1em;
  text-align: center;
}

.osk-mark-glyph::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0.5em;
  height: 0.5em;
  transform: translate(-50%, -30%);
  border: 1.5px dotted var(--muted);
  border-radius: 50%;
}

/* ུ / ཱ hang below: lift the circle and drop the glyph so they don't
   collide. */
.osk-mark-glyph.is-below {
  top: 0.3em;
}

.osk-mark-glyph.is-below::before {
  transform: translate(-50%, -140%);
}

.osk-fn {
  background: var(--osk-fn);
}

.osk-fn:active {
  background: var(--paper);
}

.osk-stack {
  flex: 0 0 var(--osk-key-w);
}

/* Shift and delete flank the 7-key third row, with a little air between
   them and the letters, as on iOS. */
.osk-side {
  flex: 1 1 0;
  max-width: calc(var(--osk-key-w) * 1.35);
}

.osk-row:nth-child(3) .osk-side:first-child {
  margin-right: auto;
}

.osk-row:nth-child(3) .osk-side:last-child {
  margin-left: auto;
}

.osk-stack[aria-pressed="true"],
.osk-side[aria-pressed="true"] {
  background: var(--paper);
  --shift-fill: currentColor;
}

/* While Stack is on, the consonant keys tint to show the next one goes
   underneath. */
.osk.is-stacking .osk-letter:not(.osk-mark) {
  background: var(--active-word);
}

/* Phones: pin the keyboard to the bottom of the screen, like a system
   keyboard, and leave room so the page can scroll clear of it.

   --osk-lift raises the keys clear of anything the browser floats over the
   bottom of the page; the grey tray still runs down behind it, so the
   keyboard reads as one piece. env(safe-area-inset-bottom) is the iPhone's
   home-indicator strip (needs viewport-fit=cover, set in play.html). */
@media (max-width: 680px) {
  /* Enough to clear the host's floating badge (Netlify's "Powered by
     Netlify", ~40px tall near the bottom edge) on any phone. */
  :root {
    --osk-lift: 56px;
  }

  .osk {
    --osk-gap: 5px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    margin: 0;
    padding: 8px 3px calc(8px + var(--osk-lift) + env(safe-area-inset-bottom));
    border-radius: 0;
    gap: 11px;
  }

  .osk-key {
    height: 44px;
    border-radius: 5px;
  }

  .osk-letter {
    font-size: 1.3rem;
  }

  body.has-osk {
    padding-bottom: calc(195px + var(--osk-lift) + env(safe-area-inset-bottom));
  }
}

/* iPhone Safari also floats its address bar over the bottom of the page,
   with the badge sitting on top of it -- lift the keys above both.
   (-webkit-touch-callout is only supported on iOS.) */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 680px) {
    :root {
      --osk-lift: 84px;
    }
  }
}

/* --- header: home link, profile icon + sign out ------------------------------ */

.home-link {
  color: inherit;
  text-decoration: none;
}

.home-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.account {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.profile-link {
  display: inline-flex;
  color: var(--muted);
  border-radius: 50%;
}

.profile-link svg {
  width: 30px;
  height: 30px;
}

.profile-link:hover,
.profile-link.is-active {
  color: var(--ink);
}

.profile-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Players have no tabs left to show; hide the empty bar entirely. Admins
   still get Customize / Build / Words. */
.page-nav:not(:has(> a:not([hidden]))) {
  display: none;
}

/* --- stats.html profile ------------------------------------------------------ */

.profile {
  margin-bottom: 32px;
}

.profile-email {
  margin: 0 0 6px;
  font-size: 1rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.password-form {
  margin: 16px 0 0;
}

.password-form[hidden] {
  display: none;
}

.tile-hint {
  font-size: 0.7rem;
  color: var(--focus);
  font-style: italic;
  line-height: 1.2;
}

/* --- English / Dzongkha toggle (header) -------------------------------------- */

.lang-toggle {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 2px;
  overflow: hidden;
}

.lang-option {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 4px 9px;
  cursor: pointer;
}

.lang-option.tibetan {
  font-size: 0.85rem;
  letter-spacing: 0;
}

.lang-option + .lang-option {
  border-left: 1px solid var(--rule);
}

.lang-option[aria-pressed="true"] {
  background: var(--button-bg);
  color: var(--button-text);
}

.lang-option:hover:not([aria-pressed="true"]) {
  color: var(--ink);
}

.lang-option:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

/* --- guests ------------------------------------------------------------------ */

.profile-link[hidden] {
  display: none;
}

/* "Sign in to save your progress" on the play page, for guests. */
.guest-note {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--focus);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.guest-note:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.auth-card a.link-button {
  align-self: center;
}

/* --- phones: header on every page, play page layout ------------------------ */

@media (max-width: 560px) {
  /* The header, scaled up for a phone screen. */
  h1 {
    font-size: 2.6rem;
  }

  .date {
    font-size: 1.3rem;
  }

  .byline {
    font-size: 0.9rem;
  }

  .profile-link svg {
    width: 40px;
    height: 40px;
  }

  .account .link-button {
    font-size: 0.95rem;
  }

  /* The bar above the grid, in two rows instead of one squeezed one:
       ← All crosswords              Show solution
       གཟའ་པ་སངས · ༠༣/༡༢/༢༠༢༦                       */
  .date-tabs {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "back solution"
      "day  day";
    align-items: center;
    /* Row gap: space under the "← All crosswords" button. */
    gap: 22px 12px;
    margin-bottom: 20px;
  }

  .date-tabs > .page-nav-link {
    grid-area: back;
    justify-self: start;
    white-space: nowrap;
    font-size: 0.85rem;
    padding: 9px 14px;
  }

  #show-solution {
    grid-area: solution;
    white-space: nowrap;
    font-size: 0.95rem;
    margin: 0;
  }

  .puzzle-day {
    grid-area: day;
    font-size: 1.45rem;
    line-height: 1.4;
  }

  /* English hints on the left, the timer on the right. */
  .controls {
    gap: 10px 16px;
    margin-bottom: 22px;
  }

  #english-hints {
    font-size: 0.88rem;
    padding: 11px 16px;
  }

  .timer {
    margin-left: auto;
    font-size: 1.4rem;
    color: var(--ink);
  }

  /* Guests' "Sign in to save your progress" gets its own line underneath,
     so it doesn't squeeze the hints button and timer. */
  .guest-note {
    order: 1;
    flex-basis: 100%;
    font-size: 0.95rem;
  }

  .controls .status {
    order: 2;
    flex-basis: 100%;
    font-size: 0.95rem;
  }
}

/* --- sign-in: forgot password, reset page ------------------------------------ */

.auth-card[hidden] {
  display: none;
}

/* "Forgot password?" sits just under the password field, to the right. */
.forgot-link {
  align-self: flex-end;
  margin-top: -8px;
  font-size: 0.78rem;
  text-transform: none;
  letter-spacing: 0;
}

/* Password boxes: a plain system font, not the page's Joyig-first stack.
   iPhone Safari draws the hidden-password dots with the first font in the
   list, ignoring Joyig's Tibetan-only range -- and Joyig's glyph for that
   dot is a striped block, so passwords showed as "≡≡≡" instead of "•••".
   Covers the login, reset and profile (change password) forms. */
input[type="password"] {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}
