:root {
  color-scheme: light;
  --paper: #edf3ef;
  --paper-strong: #ffffff;
  --ink: #151713;
  --muted: #667066;
  --line: #cbd8d1;
  --panel: #ffffff;
  --night: #171b21;
  --teal: #2e9d88;
  --blue: #3558b8;
  --coral: #e96854;
  --gold: #c88f2d;
  --green: #247a58;
  --shadow: 0 18px 60px rgba(21, 23, 19, 0.14);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(21, 23, 19, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 23, 19, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 30px 30px;
  color: var(--ink);
}

button,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button {
  min-height: 44px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 850;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.44;
  transform: none;
}

h1,
h2,
p,
ol {
  margin: 0;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 13px;
}

.brand-art {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border: 1px solid rgba(21, 23, 19, 0.22);
  border-radius: 12px;
  background: #ffffff;
  object-fit: contain;
  box-shadow: 0 10px 22px rgba(21, 23, 19, 0.12);
}

h1 {
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.field-label,
.brand p,
.hud span,
.panel-heading span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud {
  display: grid;
  grid-template-columns: auto repeat(3, minmax(74px, 1fr));
  min-width: min(100%, 470px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.86);
  box-shadow: var(--shadow);
}

.hud > div {
  display: grid;
  align-content: center;
  min-height: 62px;
  padding: 10px 13px;
}

.hud > div + div {
  border-left: 1px solid var(--line);
}

.hud strong {
  display: block;
  margin-top: 3px;
  font-size: 1.45rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hearts {
  display: flex;
  align-items: center;
  gap: 6px;
}

.heart {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border: 1px solid rgba(21, 23, 19, 0.18);
  border-radius: 999px;
  background: var(--coral);
  color: #ffffff;
  font-size: 0;
  transition: transform 150ms ease, opacity 150ms ease;
}

.heart::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 6px 0 0 #ffffff, 3px 5px 0 2px #ffffff;
  transform: rotate(45deg) translate(-1px, 1px);
}

.heart.is-empty {
  background: transparent;
  opacity: 0.45;
}

.heart.is-empty::before {
  background: var(--muted);
  box-shadow: 6px 0 0 var(--muted), 3px 5px 0 2px var(--muted);
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 326px;
  gap: 16px;
  align-items: start;
}

.play-surface,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.play-surface {
  overflow: hidden;
}

.run-meter {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-strong);
}

.run-meter strong {
  display: block;
  margin-top: 2px;
  font-size: 1.06rem;
  line-height: 1;
}

.progress-track {
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #dfe8e3;
  overflow: hidden;
}

.progress-track span,
.speed-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  transition: width 120ms linear;
}

.progress-track span {
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--coral));
}

.chain-ribbon-wrap {
  border-bottom: 1px solid var(--line);
  background: #e8f1ec;
  overflow: hidden;
}

.chain-ribbon {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 58px;
  overflow-x: auto;
  padding: 11px 16px;
  list-style: none;
  scrollbar-width: none;
}

.chain-ribbon::-webkit-scrollbar {
  display: none;
}

.chain-pill,
.chain-arrow {
  flex: 0 0 auto;
}

.chain-pill {
  border: 1px solid #bdb5a0;
  border-radius: 999px;
  padding: 7px 12px;
  background: #ffffff;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.chain-pill.is-start {
  border-color: rgba(53, 88, 184, 0.35);
  background: rgba(53, 88, 184, 0.1);
  color: var(--blue);
}

.chain-pill.is-next {
  border-color: rgba(46, 157, 136, 0.42);
  background: rgba(46, 157, 136, 0.12);
  color: var(--green);
}

.chain-arrow {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.chain-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 5;
  min-height: 190px;
  background: var(--night);
}

.stage {
  display: grid;
  justify-items: center;
  gap: 13px;
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.from-word {
  display: block;
  margin-top: 4px;
  font-size: clamp(2.5rem, 6vw, 4.8rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.answer-mask {
  display: flex;
  justify-content: center;
  gap: 7px;
  min-height: 56px;
  max-width: 100%;
  flex-wrap: wrap;
}

.tile {
  display: grid;
  width: 46px;
  height: 52px;
  place-items: center;
  border: 2px solid #d7cfba;
  border-radius: 8px;
  background: #fbfdfa;
  color: var(--ink);
  font-size: 1.5rem;
  font-weight: 950;
  line-height: 1;
}

.tile.is-given {
  border-color: rgba(53, 88, 184, 0.45);
  background: rgba(53, 88, 184, 0.12);
  color: var(--blue);
}

.tile.is-hinted {
  border-color: rgba(200, 143, 45, 0.55);
  background: rgba(200, 143, 45, 0.13);
  color: #8b5d13;
}

.tile.is-typed {
  border-color: rgba(46, 157, 136, 0.55);
  background: #ffffff;
}

.tile.is-cursor {
  border-color: var(--teal);
}

.speed-track {
  width: min(280px, 100%);
  height: 8px;
  border-radius: 999px;
  background: #dce8e1;
  overflow: hidden;
}

.speed-track span {
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.assist-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 28px;
  flex-wrap: wrap;
}

.category-chip {
  border: 1px solid rgba(21, 23, 19, 0.12);
  border-radius: 999px;
  padding: 5px 12px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.keyboard {
  display: grid;
  gap: 7px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #eaf2ed;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.key {
  width: min(8.6vw, 42px);
  min-width: 28px;
  height: 46px;
  min-height: 46px;
  border-color: rgba(21, 23, 19, 0.18);
  background: #ffffff;
  color: var(--ink);
  font-size: 0.92rem;
}

.key.is-wide {
  width: min(16vw, 68px);
  font-size: 0.78rem;
}

.action-row {
  display: grid;
  grid-template-columns: 106px 106px 118px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 15px 16px;
}

.action-row button {
  background: var(--ink);
  color: #ffffff;
}

.action-row button:first-child {
  background: var(--gold);
  color: var(--ink);
}

.action-row button:nth-child(2) {
  background: var(--blue);
}

.status-line {
  min-width: 0;
  color: var(--muted);
  font-weight: 800;
}

.status-line::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--muted);
  vertical-align: 1px;
}

.play-surface[data-feedback="accepted"] .status-line,
.play-surface[data-feedback="won"] .status-line {
  color: var(--green);
}

.play-surface[data-feedback="accepted"] .status-line::before,
.play-surface[data-feedback="won"] .status-line::before {
  background: var(--green);
}

.play-surface[data-feedback="miss"] .status-line,
.play-surface[data-feedback="lost"] .status-line {
  color: var(--coral);
}

.play-surface[data-feedback="miss"] .status-line::before,
.play-surface[data-feedback="lost"] .status-line::before {
  background: var(--coral);
}

.play-surface[data-feedback="hint"] .status-line::before,
.play-surface[data-feedback="skipped"] .status-line::before,
.play-surface[data-feedback="draft"] .status-line::before {
  background: var(--gold);
}

.side-rail {
  display: grid;
  gap: 13px;
}

.panel {
  padding: 14px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel h2 {
  font-size: 1rem;
}

.panel select {
  max-width: 138px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 0 8px;
  font-weight: 850;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  min-height: 38px;
  border: 0;
  border-radius: 0;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.84rem;
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

.segmented button[aria-pressed="true"] {
  background: var(--teal);
  color: #ffffff;
}

.method-summary {
  min-height: 34px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
  line-height: 1.35;
}

.scorecard-list {
  display: grid;
  gap: 9px;
}

.scorecard-row {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) minmax(76px, 0.8fr) 42px;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 5px 7px;
}

.scorecard-row.is-active {
  border-color: rgba(46, 157, 136, 0.28);
  background: rgba(46, 157, 136, 0.08);
}

.scorecard-copy {
  min-width: 0;
}

.scorecard-copy strong,
.scorecard-row > span {
  font-size: 0.84rem;
}

.scorecard-copy strong,
.scorecard-copy span {
  display: block;
}

.scorecard-copy span {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.15;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.meter {
  height: 9px;
  border-radius: 999px;
  background: #dfe8e3;
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  background: var(--green);
}

.scorecard-row:nth-child(2) .meter span {
  background: var(--blue);
}

.scorecard-row:nth-child(3) .meter span {
  background: var(--coral);
}

.history-panel,
.leaderboard-panel {
  max-height: 380px;
  overflow: auto;
}

.history-list,
.leaderboard-list {
  display: grid;
  gap: 8px;
  padding: 0;
  list-style: none;
}

.history-list li,
.leaderboard-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 36px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.history-list li:first-child,
.leaderboard-row:first-child {
  border-color: rgba(36, 122, 88, 0.35);
}

.history-list li.is-skipped strong {
  color: var(--muted);
}

.history-list strong,
.leaderboard-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-list span,
.leaderboard-row span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.end-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 27, 33, 0.78);
}

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

.end-card {
  width: min(430px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.28);
  padding: 22px;
  text-align: center;
}

.end-card h2 {
  margin-top: 3px;
  font-size: 2rem;
}

.end-score {
  display: block;
  margin: 10px 0 3px;
  color: var(--teal);
  font-size: 3.5rem;
  line-height: 0.95;
}

.end-meta {
  color: var(--muted);
  font-weight: 850;
}

.end-chain {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f1f7f4;
  padding: 12px;
  font-size: 0.9rem;
  font-weight: 850;
  line-height: 1.6;
  word-break: break-word;
}

.share-box {
  width: 100%;
  height: 88px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px;
  resize: none;
}

.end-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.end-actions button:first-child {
  background: #ffffff;
  color: var(--ink);
}

@media (max-width: 960px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .hud {
    width: 100%;
    min-width: 0;
  }

  .game-grid {
    grid-template-columns: 1fr;
  }

  .side-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .brand-art {
    width: 56px;
    height: 56px;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .hud > div:nth-child(3) {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .hud > div:nth-child(4) {
    border-top: 1px solid var(--line);
  }

  .run-meter {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
  }

  .chain-canvas {
    aspect-ratio: 4 / 2.35;
    min-height: 176px;
  }

  .stage {
    padding: 20px 12px 16px;
  }

  .answer-mask {
    gap: 5px;
  }

  .tile {
    width: clamp(31px, 10.5vw, 42px);
    height: clamp(40px, 13vw, 50px);
    font-size: clamp(1.05rem, 5vw, 1.38rem);
  }

  .keyboard {
    padding: 13px 10px;
  }

  .key-row {
    gap: 4px;
  }

  .key {
    width: min(8.5vw, 36px);
    min-width: 25px;
    height: 43px;
    min-height: 43px;
    padding: 0;
    font-size: 0.78rem;
  }

  .key.is-wide {
    width: min(14vw, 58px);
    font-size: 0.68rem;
  }

  .action-row {
    grid-template-columns: repeat(3, 1fr);
    padding: 13px 12px;
  }

  .status-line {
    grid-column: 1 / -1;
  }

  .side-rail {
    grid-template-columns: 1fr;
  }

  .scorecard-row {
    grid-template-columns: minmax(96px, 1fr) minmax(82px, 1fr) 40px;
  }
}
