:root {
  color-scheme: dark;
  --background: #121213;
  --panel: #19191b;
  --panel-border: #303034;
  --text: #f5f5f5;
  --muted: #a7a7ad;
  --tile-border: #56565b;
  --key: #818384;
  --key-text: #ffffff;
  --absent: #3a3a3c;
  --present: #b59f3b;
  --exact: #538d4e;
  --accent: #6aaa64;
  --danger: #ff8066;
  --focus: #8ab4f8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--background);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top, rgb(106 170 100 / 10%), transparent 30rem),
    var(--background);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

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

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 18px clamp(12px, 4vw, 28px) 40px;
}

.app-header {
  border-top: 6px solid var(--accent);
  border-bottom: 1px solid var(--panel-border);
  padding: 16px 0 18px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 14px;
  font-size: clamp(1.8rem, 8vw, 2.7rem);
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

h2 {
  font-size: 1rem;
}

.mode-switcher {
  display: inline-grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: #0d0d0e;
}

.member-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.member-bar p {
  margin: 0;
}

.text-button {
  border: 0;
  padding: 3px;
  background: transparent;
  color: var(--focus);
  cursor: pointer;
  text-decoration: underline;
}

.mode-button {
  min-width: 104px;
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 750;
}

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

.game-panel {
  padding-top: 18px;
}

.room-panel,
.history-panel {
  margin-top: 18px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 16px;
  background: rgb(25 25 27 / 88%);
}

.room-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.room-heading-row h2,
.room-heading-row p {
  margin-bottom: 0;
}

.countdown {
  min-width: 3ch;
  color: #91d78b;
  font-size: 1.8rem;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  text-align: right;
}

.roster-form fieldset {
  margin: 12px 0;
  border: 0;
  padding: 0;
}

.roster-form legend {
  margin-bottom: 8px;
  font-weight: 750;
}

.roster-options {
  display: grid;
  gap: 7px;
}

.roster-option {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  padding: 8px 10px;
  background: #121213;
}

.roster-option input {
  width: 20px;
  height: 20px;
}

.progress-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.player-progress {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) auto;
  align-items: center;
  gap: 8px 12px;
}

.player-progress-name {
  overflow: hidden;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-progress-state {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

.attempt-track {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
}

.attempt-step {
  height: 7px;
  border-radius: 999px;
  background: var(--panel-border);
}

.attempt-step.is-used {
  background: var(--key);
}

.attempt-step.is-terminal {
  background: var(--accent);
}

.danger-button {
  border-color: var(--danger);
  color: #ffb4a6;
}

.stats-summary {
  margin: 14px 0;
}

.stat-group + .stat-group {
  margin-top: 16px;
  border-top: 1px solid var(--panel-border);
  padding-top: 14px;
}

.stat-group h3,
.history-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 8px;
}

.stat-distribution,
.head-to-head p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.stat-card,
.history-card {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 11px;
  background: #121213;
}

.stat-card strong {
  display: block;
  font-size: 1.35rem;
}

.stat-card span,
.history-card p {
  color: var(--muted);
  font-size: 0.78rem;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-player {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 8px;
  margin-top: 12px;
  border-top: 1px solid var(--panel-border);
  padding-top: 10px;
  font-size: 0.85rem;
}

.history-player details {
  grid-column: 1 / -1;
}

.mini-grid {
  display: grid;
  width: 80px;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}

.mini-tile {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--absent);
}

.mini-tile.exact {
  background: var(--exact);
}

.mini-tile.present {
  background: var(--present);
}

.mini-grid-detailed {
  --mini-tile-size: clamp(26px, 7vw, 34px);
  width: 100%;
  margin: 10px 0 0;
  padding: 0;
  grid-template-columns: 1fr;
  gap: 5px;
  list-style: none;
}

.mini-guess-row {
  display: grid;
  grid-template-columns: 1.2rem minmax(0, max-content) minmax(0, 1fr);
  align-items: center;
  gap: 7px;
}

.mini-guess-number,
.mini-guess-duration {
  color: var(--muted);
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
}

.mini-guess-tiles {
  display: grid;
  grid-template-columns: repeat(5, var(--mini-tile-size));
  gap: 4px;
}

.mini-grid-detailed .mini-tile {
  display: grid;
  border-radius: 3px;
  color: var(--key-text);
  place-items: center;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.mini-guess-duration {
  text-align: right;
  white-space: nowrap;
}

.puzzle-meta {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
}

.puzzle-meta h2 {
  margin-bottom: 0;
}

.puzzle-id {
  color: var(--muted);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.status {
  display: grid;
  min-height: 2.8rem;
  margin: 8px auto 10px;
  place-items: center;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 650;
  text-align: center;
}

.status.is-success {
  color: #91d78b;
}

.board {
  display: grid;
  width: min(100%, 350px);
  margin: 0 auto;
  gap: 5px;
  touch-action: manipulation;
}

.guess-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  perspective: 900px;
}

.guess-row.is-invalid {
  animation: invalid-guess-shake 420ms ease-in-out;
}

.guess-row.is-invalid .tile:not(.exact, .present, .absent) {
  border-color: var(--danger);
}

@keyframes invalid-guess-shake {
  10%,
  90% {
    transform: translateX(-4px);
  }

  20%,
  80% {
    transform: translateX(7px);
  }

  30%,
  50%,
  70% {
    transform: translateX(-9px);
  }

  40%,
  60% {
    transform: translateX(9px);
  }
}

.tile {
  display: grid;
  aspect-ratio: 1;
  border: 2px solid var(--tile-border);
  background: rgb(18 18 19 / 88%);
  place-items: center;
  font-size: clamp(1.45rem, 8vw, 2rem);
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}

.tile.is-filled {
  border-color: #87878c;
}

.tile.is-revealing {
  animation: tile-flip-reveal 480ms ease-in-out both;
  animation-delay: var(--tile-reveal-delay, 0ms);
  transform-origin: center;
}

@keyframes tile-flip-reveal {
  0% {
    transform: rotateX(0deg);
    border-color: #87878c;
    background: rgb(18 18 19 / 88%);
    color: var(--text);
  }

  49% {
    transform: rotateX(90deg);
    border-color: #87878c;
    background: rgb(18 18 19 / 88%);
    color: var(--text);
  }

  50% {
    transform: rotateX(90deg);
    border-color: transparent;
    background: var(--tile-reveal-color);
    color: #fff;
  }

  100% {
    transform: rotateX(0deg);
    border-color: transparent;
    background: var(--tile-reveal-color);
    color: #fff;
  }
}

.tile.exact,
.tile.present,
.tile.absent {
  border-color: transparent;
  color: #fff;
}

.tile.exact,
.key.exact {
  background: var(--exact);
}

.tile.exact {
  --tile-reveal-color: var(--exact);
}

.tile.present,
.key.present {
  background: var(--present);
}

.tile.present {
  --tile-reveal-color: var(--present);
}

.tile.absent,
.key.absent {
  background: var(--absent);
}

.tile.absent {
  --tile-reveal-color: var(--absent);
}

.share-fallback label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.share-fallback input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--tile-border);
  border-radius: 7px;
  background: #0d0d0e;
  color: var(--text);
  font-size: 1.08rem;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  border-radius: 7px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 750;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #081008;
}

.secondary-button {
  border: 1px solid var(--tile-border);
  background: transparent;
}

.keyboard {
  display: grid;
  width: min(100%, 600px);
  margin: 24px auto 0;
  gap: clamp(5px, 1.5vw, 8px);
  touch-action: manipulation;
}

.keyboard-row {
  display: grid;
  gap: clamp(3px, 1vw, 6px);
}

.keyboard-row-10 {
  grid-template-columns: repeat(10, minmax(0, 1fr));
}

.keyboard-row-9 {
  grid-template-columns: repeat(9, minmax(0, 1fr));
}

.key {
  min-width: 0;
  min-height: clamp(46px, 13vw, 58px);
  border: 0;
  border-radius: 5px;
  padding: 2px;
  background: var(--key);
  color: var(--key-text);
  cursor: pointer;
  font-size: clamp(0.68rem, 2.7vw, 0.95rem);
  font-weight: 800;
  text-transform: uppercase;
  user-select: none;
}

.key[data-action] {
  font-size: clamp(0.56rem, 2.3vw, 0.76rem);
}

.result {
  width: min(100%, 500px);
  margin: 22px auto 0;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 16px;
  background: var(--panel);
  text-align: center;
}

.result h2,
.result p {
  margin-bottom: 5px;
}

.result p {
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  margin-top: 20px;
}

.share-fallback {
  width: min(100%, 500px);
  margin: 16px auto 0;
}

.share-fallback input {
  padding: 9px;
  font-size: 0.82rem;
}

noscript {
  display: block;
  padding: 30px;
  color: var(--danger);
  text-align: center;
}

@media (max-width: 420px) {
  .app-shell {
    padding-inline: 10px;
  }

  .game-panel {
    padding-top: 14px;
  }

  .member-bar {
    flex-wrap: wrap;
  }

  .mode-switcher {
    width: 100%;
  }

  .mode-button {
    min-width: 0;
  }

}

@media (prefers-reduced-motion: reduce) {
  .guess-row.is-invalid,
  .tile.is-revealing {
    animation: none;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
