*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --ink: #1c1c1a;
  --muted: #6d6d68;
  --line: #d6d6cf;
  --correct: #2f7d4f;
  --present: #a67c00;
  --absent: #787c82;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  width: min(100% - 2rem, 34rem);
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

h1 {
  margin: 0 0 1.5rem;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

h3 {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.screen {
  display: none;
}

body[data-screen="home"] #screen-home,
body[data-screen="lobby"] #screen-lobby,
body[data-screen="game"] #screen-game {
  display: block;
}

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

.label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.9rem;
}

.field label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

input {
  font: inherit;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: #fff;
  color: inherit;
  min-width: 0;
}

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

.btn {
  font: inherit;
  font-weight: 500;
  padding: 0.6rem 0.9rem;
  border-radius: 0.45rem;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  background: #34342f;
}

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

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn.ghost:hover:not(:disabled) {
  background: #ecece7;
}

.btn.small {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.join {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.join .field {
  flex: 1;
  margin-bottom: 0;
}

.error {
  min-height: 1.3rem;
  margin: 0.9rem 0 0;
  color: #a4231f;
  font-size: 0.85rem;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.9rem;
  margin-bottom: 1.1rem;
  border-bottom: 1px solid var(--line);
}

.bar-actions {
  display: flex;
  gap: 0.4rem;
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.15rem;
  letter-spacing: 0.16em;
}

.teams {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.team {
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.75rem;
  background: #fff;
}

.count {
  color: var(--muted);
  font-weight: 400;
}

.seats {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.seats li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.3rem 0.35rem;
  border-radius: 0.3rem;
  font-size: 0.9rem;
}

.seats li.me {
  background: #eceae2;
}

.seats li.empty {
  color: var(--line);
}

.seat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--line);
  flex: none;
}

.dot.on {
  background: var(--correct);
}

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

.lobby-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.score-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}

.score-bar .side {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-bar .side:last-child {
  text-align: right;
}

.score-bar .score {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.15rem;
  font-weight: 600;
}

.score-center {
  text-align: center;
}

.series {
  display: block;
  font-size: 0.6rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.series[hidden] {
  display: none;
}

.series-line {
  margin: 0 0 0.9rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.series-line[hidden] {
  display: none;
}

.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.boards {
  display: grid;
  gap: 1rem;
  margin: 0.75rem 0 0.5rem;
}

.boards[data-mode="duel"] {
  grid-template-columns: 1fr 1fr;
  align-items: start;
}

.boards[data-mode="team"] {
  grid-template-columns: minmax(0, 1fr);
}

.board-panel {
  min-width: 0;
}

#panel-you .board {
  width: min(100%, 18rem);
  margin: 0 auto;
}

.boards[data-mode="duel"] #panel-you .board {
  width: 100%;
}

.board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.board-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.others {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.75rem;
  align-items: start;
}

.boards[data-mode="duel"] .others {
  grid-template-columns: minmax(0, 1fr);
}

.board {
  display: grid;
  gap: 0.35rem;
  width: 100%;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
}

.tile {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: clamp(0.95rem, 3.6vw, 1.35rem);
  font-weight: 600;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  background: #fff;
}

.mini .board,
.mini .row {
  gap: 0.22rem;
}

.mini .tile {
  border-radius: 0.15rem;
}

.mini .tile.correct::after,
.mini .tile.present::after {
  top: 0.15rem;
  right: 0.15rem;
  width: 0.2rem;
  height: 0.2rem;
}

.mini.gone {
  opacity: 0.45;
}

.tile.filled {
  border-color: #a8a8a0;
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}

.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: #fff;
}

.tile.correct::after,
.tile.present::after {
  content: "";
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  width: 0.3rem;
  height: 0.3rem;
  background: rgba(255, 255, 255, 0.9);
}

.tile.correct::after {
  border-radius: 1px;
}

.tile.present::after {
  border-radius: 50%;
}

@keyframes reveal {
  0% {
    transform: rotateX(0deg);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

.row.reveal .tile {
  animation: reveal 0.45s ease-out both;
  animation-delay: calc(var(--i) * 80ms);
}

.status {
  min-height: 1.3rem;
  margin: 0 0 0.6rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: center;
}

.krow {
  display: flex;
  gap: 0.25rem;
  width: 100%;
  justify-content: center;
}

.key {
  position: relative;
  flex: 1 1 0;
  max-width: 2.6rem;
  height: 2.6rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  background: #e9e9e3;
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  text-transform: uppercase;
  cursor: pointer;
}

.key:active {
  transform: translateY(1px);
}

.key.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
}

.key.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}

.key.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: #fff;
}

.key.wide {
  flex: 1.6 1 0;
  max-width: 4.2rem;
  font-size: 0.65rem;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(28, 28, 26, 0.55);
}

.overlay[hidden] {
  display: none;
}

.panel {
  width: min(100%, 24rem);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 0.75rem;
  padding: 1.2rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.panel h2 {
  margin: 0 0 0.25rem;
  font-size: 1.2rem;
}

.revealed {
  margin: 0.2rem 0 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.9rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.round-boards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.round-boards li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
  padding: 0.3rem 0;
  border-top: 1px solid var(--line);
}

.result-score {
  margin: 0 0 0.9rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.2rem;
}

.recap {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.recap th,
.recap td {
  text-align: left;
  padding: 0.3rem 0.35rem;
  border-bottom: 1px solid var(--line);
}

.recap th {
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.recap tr.me td {
  font-weight: 600;
}

.banner {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  background: var(--ink);
  color: var(--bg);
  border-radius: 0.5rem;
  font-size: 0.85rem;
}

.banner[hidden] {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  top: 1rem;
  transform: translateX(-50%);
  z-index: 30;
  max-width: 90vw;
  padding: 0.55rem 0.8rem;
  background: var(--ink);
  color: var(--bg);
  border-radius: 0.45rem;
  font-size: 0.85rem;
}

.toast[hidden] {
  display: none;
}

@media (max-width: 420px) {
  .app {
    width: min(100% - 1rem, 34rem);
  }

  .boards,
  .boards[data-mode="duel"] {
    gap: 0.6rem;
  }

  .others {
    grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  }

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