:root {
  /* Shared design tokens: most colors and fonts are named here once. */
  color-scheme: light;
  --paper: #f7f7f4;
  --ink: #101010;
  --muted: #707070;
  --line: #d8d8d1;
  --soft: #ecece6;
  --accent: #0e6f72;
  --warn: #b5442d;
  --ok: #247047;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.shell {
  /* The shell constrains the app on large screens while keeping a small gutter on phones. */
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 26px 0 40px;
}

.masthead {
  border-bottom: 1px solid var(--ink);
  padding-bottom: 24px;
}

.masthead-compact {
  border-bottom: 0;
  padding-bottom: 0;
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  column-gap: 22px;
  row-gap: 10px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 36px;
}

.masthead-compact .top-nav {
  margin-bottom: 16px;
}

.top-nav button,
.top-nav a {
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0;
  font-size: 0.82rem;
  font-weight: 900;
  text-decoration: none;
  text-transform: uppercase;
  appearance: none;
}

.top-nav button:hover,
.top-nav a:hover,
.top-nav button[aria-pressed="true"],
.top-nav a[aria-current="page"] {
  color: var(--accent);
}

.top-nav .nav-brand {
  font-size: 0.95rem;
}

.text-button,
.drawer button {
  border: 1px solid var(--ink);
  border-radius: 999px;
  min-height: 34px;
  padding: 0 14px;
  font-size: 0.82rem;
  font-weight: 700;
}

.text-button:hover,
.drawer button:hover {
  background: var(--ink);
  color: var(--paper);
}

.intro {
  display: block;
}

.intro p {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
}

.page-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
}

.intro h2 {
  margin: 0;
  font-size: clamp(2.1rem, 6vw, 4.5rem);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
}

.daily-date {
  color: var(--ink);
  font-size: inherit;
  font-weight: inherit;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(4.2rem, 12vw, 10rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
}

.status-strip {
  /* Two status cells: progress and remaining error allowance. */
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  border-bottom: 1px solid var(--ink);
}

.status-strip > span {
  min-height: 54px;
  border-right: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding-left: 16px;
  font-size: 0.92rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-strip > span:last-child {
  border-right: 0;
}

.error-cell {
  gap: 10px;
}

.error-cell i {
  display: inline-flex;
  gap: 5px;
  font-style: normal;
}

.error-cell i span {
  width: 10px;
  height: 10px;
  min-height: 0;
  border: 1px solid var(--ink);
  border-radius: 50%;
}

.error-cell i span.spent {
  background: var(--warn);
}

.game-layout {
  /* Desktop uses board + side panel. The media query below stacks them on narrow screens. */
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 28px;
  padding-top: 28px;
}

.board {
  /* 4x4 grid: top/left criteria frame a 3x3 answer board. */
  display: grid;
  grid-template-columns: minmax(104px, 0.7fr) repeat(3, minmax(118px, 1fr));
  grid-template-rows: minmax(96px, auto) repeat(3, 126px);
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}

.corner,
.criterion,
.cell {
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  min-width: 0;
}

.corner {
  position: relative;
  display: grid;
  padding: 12px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.corner::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top right, transparent calc(50% - 0.5px), rgba(247, 247, 244, 0.42) 50%, transparent calc(50% + 0.5px));
  pointer-events: none;
}

.corner span {
  position: relative;
  z-index: 1;
  line-height: 1;
}

.corner-column {
  align-self: start;
  justify-self: end;
  text-align: right;
}

.corner-row {
  align-self: end;
  justify-self: start;
}

.criterion {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  min-height: 96px;
  padding: 12px;
  text-align: left;
  background: var(--paper);
}

.criterion:hover {
  background: var(--soft);
}

.criterion span {
  font-size: clamp(0.88rem, 1.4vw, 1.12rem);
  font-weight: 800;
  line-height: 1.08;
  overflow-wrap: normal;
  word-break: normal;
}

.criterion small {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
}

.cell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  min-height: 0;
  overflow: hidden;
  padding: 10px;
  text-align: left;
  background: var(--paper);
}

.cell:hover,
.cell.selected {
  background: #fff;
}

.cell.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.cell.locked {
  background: #f2f7f3;
}

.cell-index {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.cell-answer {
  align-self: center;
  display: grid;
  gap: 4px;
  min-width: 0;
}

.cell-code {
  display: block;
  align-self: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.2rem;
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: 0;
}

.cell-name {
  display: block;
  min-width: 0;
  font-size: 0.56rem;
  font-weight: 800;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.cell.locked .cell-code {
  color: var(--ok);
}

.feedback {
  min-height: 26px;
  margin: 14px 0 0;
  color: var(--muted);
}

.feedback p {
  margin: 0;
}

.feedback-details {
  display: grid;
  gap: 5px;
  margin: 8px 0 0;
  padding: 0;
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.35;
  list-style: none;
}

.feedback-details li {
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}

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

.search-panel {
  border-top: 1px solid var(--ink);
  padding-top: 14px;
}

.search-panel label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.search-row input {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.04rem;
  outline: 0;
}

.search-row input:focus {
  border-bottom-width: 3px;
}

.search-panel p,
.meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.meta-stack {
  display: grid;
  gap: 4px;
}

.suggestions {
  /* Search results are real buttons so keyboard and pointer users submit the same way. */
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.suggestions button {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 2px 10px;
  align-items: center;
  min-height: 58px;
  border: 1px solid var(--line);
  padding: 9px 0;
  text-align: left;
}

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

.suggestions span {
  grid-row: span 2;
  color: var(--accent);
  font-weight: 900;
  text-align: center;
}

.suggestions strong {
  min-width: 0;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.suggestions small {
  color: var(--muted);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.drawer {
  /* Criteria explanations float above the game without navigating away. */
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  width: min(420px, calc(100vw - 48px));
  border: 1px solid var(--ink);
  background: var(--paper);
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.14);
}

.drawer button {
  float: right;
}

.drawer small {
  color: var(--accent);
  font-weight: 900;
}

.drawer h2 {
  margin: 18px 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: 0;
}

.drawer p {
  color: var(--muted);
  line-height: 1.5;
}

.end-card {
  border: 1px solid var(--ink);
  padding: 16px;
}

.end-card h2 {
  margin: 0 0 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 400;
}

.end-card dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

.end-card div {
  min-width: 0;
}

.end-card dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.end-card dd {
  margin: 2px 0 0;
  font-weight: 800;
}

.end-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
}

.end-actions button,
.modal button {
  border: 1px solid var(--ink);
  border-radius: 999px;
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
  font-weight: 800;
}

.end-actions button:hover,
.modal button:hover {
  background: var(--ink);
  color: var(--paper);
}

.modal-backdrop {
  /* Modals are used for surrender confirmation and revealed answer lists. */
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(247, 247, 244, 0.74);
  backdrop-filter: blur(6px);
}

.modal {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--ink);
  background: var(--paper);
  padding: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.18);
}

.modal h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.2rem;
  font-weight: 400;
}

.modal p {
  color: var(--muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-close {
  float: right;
  border: 1px solid var(--ink);
  border-radius: 999px;
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
  font-weight: 800;
}

.modal-close:hover {
  background: var(--ink);
  color: var(--paper);
}

.modal-kicker {
  display: block;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.answer-modal {
  width: min(620px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  overflow: auto;
}

.answer-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.answer-list article {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  align-items: center;
  min-width: 0;
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.answer-list article:last-child {
  border-bottom: 1px solid var(--line);
}

.answer-list span {
  color: var(--accent);
  font-weight: 900;
}

.answer-list div {
  min-width: 0;
}

.answer-list strong,
.answer-list small {
  display: block;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.answer-list small {
  color: var(--muted);
  margin-top: 2px;
}

.archive-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  width: 100%;
  min-height: 26px;
  text-align: left;
}

.archive-item:hover {
  color: var(--accent);
}

.archive-date,
.solved-tag {
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.solved-tag {
  border: 1px solid var(--ok);
  border-radius: 999px;
  color: var(--ok);
  padding: 6px 9px;
}

.empty-archive {
  color: var(--muted);
}

.static-page {
  display: grid;
  gap: 30px;
  max-width: 780px;
  padding-top: 28px;
}

.static-section {
  border-top: 1px solid var(--ink);
  padding-top: 18px;
}

.static-section-flush {
  border-top: 0;
  padding-top: 0;
}

.static-section h2 {
  margin: 0 0 10px;
  font-size: clamp(1.45rem, 4vw, 2.35rem);
  line-height: 1.05;
}

.static-section p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.static-list {
  display: grid;
  margin: 0;
  padding: 0;
  border-bottom: 1px solid var(--line);
  list-style: none;
}

.static-list li {
  border-top: 1px solid var(--line);
  padding: 16px 0;
}

.static-list strong {
  display: block;
  margin-bottom: 5px;
  font-size: 0.86rem;
  font-weight: 900;
  text-transform: uppercase;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 46px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
  gap: 14px;
}

.site-footer a,
.site-footer button {
  color: var(--muted);
  font-size: inherit;
  font-weight: inherit;
  text-decoration: none;
  text-transform: uppercase;
}

.site-footer a:hover,
.site-footer button:hover {
  color: var(--accent);
}

.loading {
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
}

@media (max-width: 920px) {
  /* Mobile keeps the same board model but shrinks rows, labels, and side layout. */
  .intro,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .top-nav {
    margin-bottom: 24px;
  }

  .status-strip {
    grid-template-columns: 1fr;
  }

  .status-strip span {
    min-height: 42px;
    border-right: 0;
  }

  .board {
    grid-template-columns: minmax(82px, 0.7fr) repeat(3, minmax(68px, 1fr));
    grid-template-rows: minmax(82px, auto) repeat(3, 90px);
  }

  .corner,
  .criterion,
  .cell {
    padding: 8px;
  }

  .criterion {
    min-height: 82px;
  }

  .criterion span {
    font-size: 0.76rem;
  }

  .criterion small {
    display: none;
  }

  .cell {
    min-height: 0;
  }

  .cell-code {
    font-size: 1.24rem;
  }

  .cell-name {
    font-size: 0.46rem;
    line-height: 1;
  }

  .answer-list strong,
  .answer-list small {
    white-space: normal;
  }

  .archive-item {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .solved-tag {
    justify-self: start;
  }

  .footer-links {
    justify-content: flex-end;
  }
}
