:root {
  --bg: #eef3f8;
  --bg-2: #f8fbff;
  --surface: #ffffff;
  --surface-soft: #f4f7fb;
  --text: #142033;
  --muted: #68758a;
  --line: #dce5ef;
  --accent: #177ddc;
  --accent-strong: #0e5ea8;
  --vowel: #fff1bf;
  --vowel-text: #805400;
  --consonant: #dff3ff;
  --consonant-text: #075677;
  --hit: #dbf8df;
  --hit-text: #176b28;
  --miss: #ffe1df;
  --miss-text: #a42922;
  --danger: #d63d36;
  --shadow: 0 16px 42px rgba(31, 48, 74, 0.14);
  --shadow-soft: 0 8px 22px rgba(31, 48, 74, 0.10);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.dark {
  --bg: #0d1118;
  --bg-2: #121a26;
  --surface: #151d2a;
  --surface-soft: #1b2636;
  --text: #edf4ff;
  --muted: #9aa8bc;
  --line: #293548;
  --accent: #5aa7ff;
  --accent-strong: #9dccff;
  --vowel: #42370f;
  --vowel-text: #ffe28a;
  --consonant: #103247;
  --consonant-text: #9be0ff;
  --hit: #153c24;
  --hit-text: #91eea5;
  --miss: #451c1d;
  --miss-text: #ffaaa5;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.32);
  --shadow-soft: 0 10px 26px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(23, 125, 220, 0.14), transparent 34%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  color: var(--text);
  color-scheme: light;
  transition: background 180ms ease, color 180ms ease;
}

body.dark {
  color-scheme: dark;
}

button,
input {
  font: inherit;
}

button {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.title-block {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.04;
  letter-spacing: 0;
}

.topbar p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background 160ms ease, border-color 160ms ease, transform 100ms ease;
}

.theme-toggle:active {
  transform: translateY(1px);
}

.status-pill {
  flex: 0 0 auto;
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.players-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.player-card {
  position: relative;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 100ms ease, background 140ms ease;
}

.player-card:not(:disabled):active {
  transform: translateY(1px);
}

.player-card:disabled {
  cursor: default;
}

.player-card.is-self {
  border-color: color-mix(in srgb, var(--accent), var(--line) 68%);
}

.player-card.current-turn {
  border-color: #2f7df6;
  box-shadow:
    0 0 0 2px rgba(47, 125, 246, 0.24),
    0 0 22px rgba(47, 125, 246, 0.34),
    var(--shadow-soft);
}

.player-card.current-turn .player-name {
  color: #2f7df6;
}

.player-card.current-turn::after {
  content: "";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #2f7df6;
  box-shadow: 0 0 12px rgba(47, 125, 246, 0.9);
}

.player-name {
  min-height: 20px;
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.profile-dot,
.vote-dot,
.exit-dot {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  background: var(--dot, #8b95a5);
  box-shadow: 0 0 0 1px rgba(31, 48, 74, 0.18);
  flex: 0 0 auto;
}

.color-panel,
.stage,
.word-panel,
.history-card,
.setup-panel,
.proposer-panel,
.round-panel,
.custom-word {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

body.dark .color-panel,
body.dark .stage,
body.dark .word-panel,
body.dark .history-card,
body.dark .setup-panel,
body.dark .proposer-panel,
body.dark .round-panel,
body.dark .custom-word {
  background: rgba(21, 29, 42, 0.92);
}

.color-panel {
  margin-bottom: 12px;
  padding: 12px;
}

.panel-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-choice {
  width: 34px;
  height: 34px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--dot);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.5), var(--shadow-soft);
  cursor: pointer;
  transition: transform 100ms ease, box-shadow 120ms ease, opacity 120ms ease;
}

.color-choice.selected {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.72),
    0 0 0 3px color-mix(in srgb, var(--accent), transparent 72%),
    var(--shadow-soft);
}

.color-choice:disabled {
  cursor: default;
  opacity: 0.68;
}

.stage {
  padding: 12px 14px;
}

.hangman-svg {
  display: block;
  width: 100%;
  height: 210px;
}

.gallows,
.body-part {
  fill: none;
  stroke: var(--text);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.body-part {
  opacity: 0.08;
  transform-origin: center;
  transition: opacity 160ms ease, stroke 160ms ease;
}

.body-part.visible {
  opacity: 1;
  stroke: var(--danger);
}

.mistakes {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

#mistakeCount {
  color: var(--miss-text);
  font-weight: 900;
}

.word-panel {
  margin-top: 12px;
  padding: 18px 12px;
}

.word-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
}

.letter-slot {
  width: 34px;
  height: 42px;
  border-bottom: 3px solid var(--text);
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
}

.letter-slot.space-slot {
  width: 18px;
  border-bottom: 0;
  opacity: 0.55;
}

.letter-slot.guessed-slot {
  color: var(--hit-text);
  border-bottom-color: var(--hit-text);
  background: var(--hit);
  border-radius: 8px 8px 4px 4px;
}

.setup-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
}

.proposer-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
}

.proposer-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.proposer-choice {
  min-width: 0;
  min-height: 74px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 100ms ease, opacity 120ms ease;
}

.proposer-choice.selected {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent), var(--surface) 88%);
}

.proposer-choice:disabled {
  cursor: default;
  opacity: 0.76;
}

.proposer-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 900;
}

.proposer-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.proposer-votes {
  grid-row: 1 / span 2;
  grid-column: 2;
}

.round-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
}

.round-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.round-button.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.round-button:disabled {
  opacity: 0.72;
  cursor: default;
}

.continue-button {
  background: #2ca24f;
}

.finish-button {
  background: var(--danger);
}

.round-votes {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.round-votes > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mode-button {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  min-height: 64px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 100ms ease, opacity 120ms ease;
}

.mode-button span:first-child {
  font-size: 16px;
  font-weight: 900;
}

.mode-button small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.mode-button.primary {
  border-color: rgba(23, 125, 220, 0.34);
}

.mode-button.secondary {
  border-color: rgba(123, 97, 255, 0.34);
}

.mode-button.selected {
  outline: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent), var(--surface) 88%);
  border-color: var(--accent);
}

.mode-button:disabled {
  cursor: default;
  opacity: 0.76;
}

.mode-votes {
  grid-row: 1 / span 2;
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  min-width: 38px;
  min-height: 22px;
  padding: 3px 5px;
  border-radius: 999px;
  background: transparent;
}

.mode-votes.has-votes {
  background: color-mix(in srgb, var(--surface), var(--accent) 10%);
}

.mode-hint {
  margin: 0;
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.custom-word {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 12px;
  padding: 12px;
}

.custom-word input {
  min-width: 0;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface-soft);
  color: var(--text);
  text-transform: uppercase;
}

.custom-word button {
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 900;
  cursor: pointer;
}

.keyboard {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 7px;
  margin-top: 14px;
}

.key {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 100ms ease, filter 100ms ease;
}

.key:active {
  transform: scale(0.96);
}

.key.vowel {
  background: var(--vowel);
  color: var(--vowel-text);
}

.key.consonant {
  background: var(--consonant);
  color: var(--consonant-text);
}

.key.hit {
  background: linear-gradient(180deg, var(--hit), color-mix(in srgb, var(--hit), #ffffff 18%));
  color: var(--hit-text);
  border-color: #8fe18e;
  opacity: 0.72;
}

.key.miss {
  background: linear-gradient(180deg, var(--miss), color-mix(in srgb, var(--miss), #ffffff 10%));
  color: var(--miss-text);
  border-color: #f39a94;
  opacity: 0.38;
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.key.miss::after {
  content: "";
  position: absolute;
  left: 16%;
  right: 16%;
  top: 50%;
  border-top: 2px solid currentColor;
  transform: rotate(-14deg);
}

.key:disabled {
  cursor: default;
  filter: saturate(0.72);
}

.key.hit:disabled,
.key.miss:disabled {
  filter: none;
}

.history-card {
  margin-top: 14px;
  padding: 14px;
}

.history-card h2 {
  margin: 0 0 10px;
  font-size: 16px;
  line-height: 1.2;
}

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

.history-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
}

.exit-panel {
  margin-top: 14px;
  padding-bottom: 8px;
  display: grid;
  gap: 10px;
}

.exit-button,
.surrender-button {
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 100ms ease, opacity 120ms ease, filter 120ms ease;
}

.exit-button {
  background: linear-gradient(180deg, #ee5a52, var(--danger));
}

.surrender-button {
  background: linear-gradient(180deg, #9554d8, #7b2cbf);
}

.exit-button:not(:disabled):active,
.surrender-button:not(:disabled):active,
.round-button:not(:disabled):active,
.custom-word button:not(:disabled):active,
.mode-button:not(:disabled):active,
.proposer-choice:not(:disabled):active {
  transform: translateY(1px);
}

.exit-button:disabled,
.surrender-button:disabled {
  opacity: 0.58;
  cursor: default;
}

.exit-votes {
  display: flex;
  justify-content: center;
  gap: 10px;
  min-height: 18px;
}

.exit-dot {
  opacity: 0.28;
  filter: saturate(0.6);
}

.exit-dot.ready {
  opacity: 1;
  filter: none;
}

#exitHint {
  margin: 0;
  min-height: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.error-box {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: 496px;
  margin: 0 auto;
  padding: 12px;
  border-radius: 8px;
  background: #252b35;
  color: white;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.loading-overlay,
.closed-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(238, 243, 248, 0.72);
  backdrop-filter: blur(10px);
}

body.dark .loading-overlay,
body.dark .closed-panel {
  background: rgba(13, 17, 24, 0.74);
}

.loading-card,
.closed-card {
  width: min(100%, 380px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
}

.loading-card {
  min-height: 96px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 18px;
  font-weight: 900;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 3px solid color-mix(in srgb, var(--accent), transparent 76%);
  border-top-color: var(--accent);
  animation: spin 760ms linear infinite;
}

.closed-card {
  display: grid;
  gap: 12px;
  padding: 20px;
  text-align: center;
}

.closed-card h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.closed-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.close-app-button {
  min-height: 48px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.hidden {
  display: none !important;
}

@media (max-width: 420px) {
  .topbar {
    align-items: stretch;
  }

  .top-actions {
    flex-direction: column;
    align-items: flex-end;
  }

  .status-pill,
  .theme-toggle {
    height: 36px;
    min-height: 36px;
  }

  .proposer-choices {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 380px) {
  .keyboard {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
  }

  .key {
    font-size: 16px;
  }

  .letter-slot {
    width: 30px;
    height: 38px;
    font-size: 24px;
  }
}
