:root {
  color-scheme: dark;
  --ink: #f7f3e7;
  --muted: #b9c5bc;
  --panel: rgba(11, 18, 17, 0.78);
  --panel-strong: rgba(16, 22, 20, 0.92);
  --edge: rgba(240, 211, 120, 0.42);
  --gold: #f0c95a;
  --teal: #5fd0b2;
  --red: #e4544f;
  --green: #7fbf6a;
  --charcoal: #101413;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.castle-siege-lock {
  margin: 0;
  overflow: hidden;
  background: var(--charcoal);
}

body.castle-siege-lock button,
body.castle-siege-lock input {
  font: inherit;
}

#siegeCanvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
}

.hud {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(760px, calc(100vw - 32px));
  pointer-events: none;
}

.stat {
  min-width: 104px;
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.stat strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1.1;
}

.leaderboard {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 6;
  width: min(270px, calc(100vw - 32px));
  padding: 12px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.leaderboard h2 {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.95rem;
}

.leaderboard-current {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  padding: 8px;
  color: var(--ink);
  background: rgba(240, 201, 90, 0.14);
  border: 1px solid rgba(240, 201, 90, 0.35);
  border-radius: 8px;
}

.leaderboard-current span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.leaderboard-current strong {
  color: var(--gold);
  font-size: 1.25rem;
  line-height: 1;
}

.score-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  font-size: 0.88rem;
}

.score-list li {
  padding-left: 4px;
}

.score-list strong {
  color: var(--ink);
}

.score-list .player-score {
  margin-left: -4px;
  padding: 5px 6px;
  color: var(--ink);
  background: rgba(95, 208, 178, 0.16);
  border: 1px solid rgba(95, 208, 178, 0.4);
  border-radius: 8px;
}

.score-list .player-score strong {
  color: var(--teal);
}

.leaderboard-points {
  color: var(--ink);
  font-weight: 800;
}

.leaderboard-detail {
  color: var(--muted);
  font-size: 0.78rem;
}

.leaderboard-break,
.leaderboard-message {
  list-style: none;
  color: var(--muted);
}

.final-leaderboard {
  margin: 14px 0;
  padding: 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
}

.final-leaderboard h2 {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.95rem;
}

.final-leaderboard .score-list {
  max-height: 128px;
  overflow: auto;
}

.word-rail {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  z-index: 7;
  display: grid;
  gap: 8px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(8, 13, 12, 0.5), rgba(8, 13, 12, 0.86));
  border: 1px solid var(--edge);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.34);
}

.word-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.active-word {
  display: flex;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-wrap: wrap;
  color: var(--ink);
}

.word-char {
  display: inline-grid;
  width: 34px;
  height: 42px;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  font-size: 1.38rem;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
  transition:
    transform 140ms ease,
    color 140ms ease,
    background 140ms ease;
}

.word-char.typed {
  color: #171612;
  background: var(--gold);
  transform: translateY(-4px);
}

.word-char.next {
  color: var(--teal);
  border-color: rgba(95, 208, 178, 0.7);
  box-shadow: 0 0 18px rgba(95, 208, 178, 0.28);
}

.word-char.wrong {
  color: #fff;
  background: var(--red);
}

.word-queue {
  display: flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow: hidden;
}

.queue-word {
  max-width: 170px;
  overflow: hidden;
  padding: 5px 8px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  font-size: 0.82rem;
  text-transform: uppercase;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(4, 6, 5, 0.58);
}

.modal.is-open {
  display: flex;
}

.modal-panel {
  width: min(520px, 100%);
  padding: 22px;
  background: var(--panel-strong);
  border: 1px solid var(--edge);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}

.modal-panel h1 {
  margin: 0 0 10px;
  font-size: 2rem;
  line-height: 1;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.lede {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.primary-button,
.ghost-button {
  min-height: 42px;
  padding: 10px 14px;
  cursor: pointer;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  color: #14130f;
  background: var(--gold);
  border: 0;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: #ffe07a;
}

.ghost-button {
  width: 100%;
  margin-top: 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.final-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.final-stats div {
  padding: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  color: var(--muted);
}

.final-stats strong {
  display: block;
  color: var(--ink);
}

.score-form {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.score-form label {
  color: var(--muted);
  font-size: 0.9rem;
}

.score-input-row {
  display: flex;
  gap: 8px;
}

.score-input-row input {
  width: 104px;
  min-height: 42px;
  color: var(--ink);
  text-align: center;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  font-size: 1.25rem;
  font-weight: 900;
}

.submit-message {
  min-height: 20px;
  margin: 0;
  color: var(--teal);
  font-size: 0.88rem;
}

@media (max-width: 780px) {
  .leaderboard {
    top: auto;
    right: 10px;
    bottom: 142px;
    width: min(230px, calc(100vw - 20px));
    max-height: 122px;
    overflow: hidden;
    padding: 8px;
  }

  .leaderboard h2 {
    margin-bottom: 5px;
    font-size: 0.8rem;
  }

  .leaderboard .score-list {
    gap: 3px;
    padding-left: 18px;
    font-size: 0.74rem;
  }

  .leaderboard .score-list li:nth-child(n+4):not(.player-score) {
    display: none;
  }

  .hud {
    top: 10px;
    left: 10px;
    max-width: calc(100vw - 20px);
  }

  .stat {
    min-width: 82px;
    padding: 7px 8px;
  }

  .stat strong {
    font-size: 0.9rem;
  }

  .word-rail {
    right: 10px;
    bottom: 10px;
    left: 10px;
    padding: 10px;
  }

  .word-char {
    width: 28px;
    height: 36px;
    font-size: 1.08rem;
  }

  .modal-panel h1 {
    font-size: 1.5rem;
  }
}

@media (max-height: 560px) {
  .hud {
    top: 10px;
    left: 10px;
  }

  .hud .stat:not(:first-child) {
    display: none;
  }

  .leaderboard {
    top: 10px;
    right: 10px;
    bottom: auto;
    width: min(190px, calc(100vw - 20px));
    max-height: 84px;
  }

  .leaderboard-current {
    padding: 6px;
    margin-bottom: 5px;
  }

  .leaderboard-current strong {
    font-size: 1rem;
  }

  .leaderboard .score-list li:nth-child(n+3):not(.player-score) {
    display: none;
  }

  .word-char {
    width: 26px;
    height: 32px;
    font-size: 0.98rem;
  }

  .word-queue {
    display: none;
  }
}
