:root {
  --bg: #0b0f14;
  --surface: #151b24;
  --surface2: #1c2430;
  --border: #2a3444;
  --text: #eef3fa;
  --muted: #7d8da3;
  --accent: #3dd68c;
  --accent-dim: #2fa66a;
  --warn: #e8b84a;
  --danger: #f07178;
  --letter: #6cb6ff;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.35;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: calc(0.55rem + var(--safe-t)) 0.75rem 0.55rem;
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.chip {
  margin-left: auto;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--accent);
  cursor: pointer;
}

.icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.main {
  flex: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0.75rem 0.75rem calc(1rem + var(--safe-b));
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.hidden {
  display: none !important;
}

.tagline {
  margin: 0.25rem 0 0.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.85rem;
}

.card-tight {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 0.8rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

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

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.btn {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 0.8rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 44px;
}

.btn-primary {
  background: var(--accent);
  color: #052012;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #1a0506;
}

.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-wide {
  width: 100%;
}

.btn.is-ready {
  background: #132219;
  color: var(--accent);
  border: 1px solid #2a5c40;
}

.status-pill,
.turn-banner {
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.45rem 0.65rem;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  align-self: center;
}

.turn-banner.is-mine {
  color: var(--accent);
  border-color: #2a5c40;
  background: #132219;
}

.turn-banner.is-wait {
  color: var(--warn);
}

.turn-banner.is-out {
  color: var(--danger);
  border-color: #4a2830;
  background: #1a1014;
}

.out-banner {
  text-align: center;
  font-weight: 800;
  font-size: 1rem;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  background: #2a1418;
  border: 1px solid #5a3038;
  color: var(--danger);
}

.screen.is-spectator .letter-pad,
.screen.is-spectator .sticky-actions,
.screen.is-spectator #reveal-results {
  display: none !important;
}

.screen.is-spectator .guess-row {
  display: none !important;
}

.micro {
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.winner-line {
  margin: 0.5rem 0;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
}

.player-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
}

.player-chips li {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.6rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}

.player-chips .is-me {
  border-color: #2a5c40;
}

.badge {
  font-size: 0.68rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
}

.badge.ready {
  background: #1a3d2c;
  color: var(--accent);
}

.badge.out {
  background: #3a1e22;
  color: var(--danger);
}

.badge.turn {
  background: #2a3548;
  color: var(--letter);
}

.len-picker {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 0.5rem;
  align-items: center;
}

.len-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
}

.len-picker input {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
}

.letter-pad {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 0.3rem;
}

.letter-pad button {
  aspect-ratio: 1;
  min-height: 36px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}

.letter-pad button:active {
  background: var(--accent);
  color: #052012;
}

.reveal-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
}

.reveal-title {
  font-size: 0.82rem;
  color: var(--warn);
  font-weight: 700;
  margin-bottom: 0.45rem;
}

.reveal-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.35rem 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.reveal-row:last-child {
  border-bottom: none;
}

.reveal-yes {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.reveal-no {
  color: var(--muted);
}

.reveal-foot {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.section-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 0.25rem;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.7rem;
}

.note-card.is-out {
  opacity: 0.55;
}

.note-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.45rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.note-len {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

.slot-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.slot {
  width: 1.65rem;
  height: 1.85rem;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--letter);
}

.slot.filled {
  border-color: #2a4a68;
  background: #121c28;
}

.guess-row {
  display: grid;
  grid-template-columns: 1fr 64px;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.guess-row input {
  padding: 0.55rem 0.65rem;
  font-size: 0.9rem;
}

.guess-row .btn {
  padding: 0.55rem;
  min-height: auto;
}

.activity {
  margin-top: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.activity summary {
  padding: 0.55rem 0.7rem;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}

.activity summary::-webkit-details-marker {
  display: none;
}

.log {
  max-height: 120px;
  overflow-y: auto;
  padding: 0 0.7rem 0.55rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.log p {
  margin: 0.2rem 0;
}

.sticky-actions {
  position: sticky;
  bottom: calc(0.5rem + var(--safe-b));
  padding-top: 0.5rem;
  background: linear-gradient(transparent, var(--bg) 30%);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.75rem 0.75rem calc(0.85rem + var(--safe-b));
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + var(--safe-b));
  transform: translateX(-50%);
  max-width: calc(100% - 2rem);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
  font-size: 0.85rem;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.toast.is-ok {
  border-color: #2a5c40;
}

@media (min-width: 520px) {
  .letter-pad {
    grid-template-columns: repeat(13, 1fr);
  }

  .main {
    padding-top: 1rem;
  }
}
