:root {
  color-scheme: dark;
  --bg: #0b0616;
  --bg-soft: #150d2a;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f5f3ff;
  --muted: #a9a3c2;
  --violet: #a855f7;
  --cyan: #22d3ee;
  --pink: #f472b6;
  --green: #34d399;
  --amber: #fbbf24;
  --danger: #fb7185;
  --radius: 22px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

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

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

body {
  background:
    radial-gradient(120% 80% at 10% -10%, rgba(168, 85, 247, 0.32), transparent 60%),
    radial-gradient(110% 80% at 100% 0%, rgba(34, 211, 238, 0.18), transparent 55%),
    radial-gradient(90% 70% at 50% 110%, rgba(244, 114, 182, 0.16), transparent 60%),
    var(--bg);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(10px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(12px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 10px;
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  letter-spacing: 0.2px;
  font-size: 17px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--violet), var(--cyan));
  box-shadow: 0 0 16px rgba(168, 85, 247, 0.8);
}

.conn {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.conn--on {
  color: var(--green);
  background: rgba(52, 211, 153, 0.08);
  border-color: rgba(52, 211, 153, 0.3);
}

.conn--off {
  color: var(--amber);
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.3);
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  min-height: 0;
  animation: rise 0.28s ease both;
}

.view--center {
  justify-content: center;
  align-items: center;
  text-align: center;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 7vw, 34px);
  line-height: 1.15;
  letter-spacing: -0.5px;
}

.section-title {
  font-size: 22px;
  letter-spacing: -0.3px;
}

.small-title {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}

.eyebrow {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted);
}

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

.small {
  font-size: 13px;
}

.center {
  text-align: center;
}

.hero {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
}

.landing-title {
  font-size: clamp(30px, 9vw, 42px);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.landing-form {
  margin-top: 10px;
  max-width: 360px;
}

.input {
  width: 100%;
  min-height: 58px;
  padding: 0 18px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input::placeholder {
  color: rgba(169, 163, 194, 0.65);
}

.input:focus {
  border-color: rgba(168, 85, 247, 0.7);
  box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.18);
}

.input--code {
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 10px;
  text-transform: uppercase;
}

.btn {
  min-height: 58px;
  padding: 0 20px;
  border-radius: 16px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease, opacity 0.2s ease;
  user-select: none;
}

.btn:active {
  transform: scale(0.975);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn--primary {
  background: linear-gradient(135deg, var(--violet), #6366f1 55%, var(--cyan));
  color: #0b0616;
  box-shadow: 0 14px 34px rgba(124, 58, 237, 0.35);
}

.btn--ghost {
  background: var(--panel);
  border-color: var(--border);
  color: var(--text);
}

.btn--success {
  background: linear-gradient(135deg, var(--green), #0ea5e9);
  color: #052e22;
}

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

.code {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 7px;
  line-height: 1;
  background: linear-gradient(135deg, #ffffff, #c4b5fd);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.code-inline {
  color: var(--cyan);
  font-weight: 900;
  letter-spacing: 2px;
}

.players-count {
  text-align: right;
  font-weight: 800;
  font-size: 20px;
}

.players-count .muted {
  font-size: 12px;
  font-weight: 600;
}

.players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 4px;
}

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  min-width: 0;
}

.player--offline {
  opacity: 0.5;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 16px;
  color: #0b0616;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  flex: 0 0 auto;
}

.player-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.player-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-status {
  font-size: 11px;
  color: var(--muted);
}

.player-status--ready {
  color: var(--green);
}

.spacer {
  flex: 1 1 auto;
  min-height: 8px;
}

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--violet);
  animation: spin 0.9s linear infinite;
  margin-bottom: 8px;
}

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

.secret-card {
  padding: 18px;
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, rgba(168, 85, 247, 0.22), rgba(34, 211, 238, 0.08)),
    var(--panel);
  border: 1px solid rgba(168, 85, 247, 0.35);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  text-align: center;
}

.secret-card .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  font-weight: 800;
}

.secret {
  font-size: 58px;
  font-weight: 900;
  letter-spacing: 6px;
  line-height: 1;
  background: linear-gradient(135deg, #ffffff, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.75;
    transform: scale(0.97);
  }
}

.words {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
}

.word {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.word-name {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.word-value {
  font-weight: 800;
  font-size: 17px;
  text-align: right;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  font-size: 22px;
  padding: 8px 14px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  min-width: 84px;
  text-align: center;
}

.timer--low {
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.4);
}

.score-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.score-line strong {
  font-size: 24px;
}

.scores {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
}

.score {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.score--first {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.18), rgba(168, 85, 247, 0.16));
  border-color: rgba(251, 191, 36, 0.4);
}

.score-rank {
  width: 28px;
  font-weight: 900;
  color: var(--muted);
  text-align: center;
}

.score-name {
  flex: 1 1 auto;
  font-weight: 800;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-value {
  font-weight: 900;
  font-size: 20px;
}

.error {
  color: var(--danger);
  font-size: 14px;
  text-align: center;
}

.error-mark {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 42px;
  font-weight: 900;
  color: var(--amber);
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.35);
}

.logo {
  margin-bottom: 6px;
  filter: drop-shadow(0 18px 40px rgba(124, 58, 237, 0.45));
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(20, 12, 38, 0.96);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 20;
  animation: rise 0.2s ease both;
}

@media (max-height: 680px) {
  .app {
    gap: 0;
  }

  .secret {
    font-size: 46px;
  }

  .secret-card {
    padding: 12px;
  }

  .btn {
    min-height: 52px;
  }
}

@media (min-width: 480px) {
  .players {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.loto-remaining {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-weight: 900;
  font-size: 20px;
  line-height: 1.1;
}

.loto-remaining .small {
  font-size: 11px;
  font-weight: 600;
}

.loto-last {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 14px;
  border-radius: 20px;
  background:
    linear-gradient(160deg, rgba(34, 211, 238, 0.16), rgba(168, 85, 247, 0.1)),
    var(--panel);
  border: 1px solid rgba(34, 211, 238, 0.3);
}

.loto-last .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  font-weight: 800;
}

.loto-barrel {
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
  color: var(--text);
  text-shadow: 0 0 26px rgba(34, 211, 238, 0.45);
  font-variant-numeric: tabular-nums;
}

.loto-window {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.loto-window--low {
  color: var(--danger);
}

.loto-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
}

.loto-card {
  padding: 8px 10px 10px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.loto-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.loto-card-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.loto-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 3px;
}

.loto-cell {
  aspect-ratio: 1 / 1;
  min-width: 0;
  padding: 0;
  border-radius: 6px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font: inherit;
  font-size: clamp(10px, 3vw, 14px);
  font-weight: 700;
  display: grid;
  place-items: center;
  user-select: none;
}

.loto-cell--blank {
  background: transparent;
}

.loto-cell--drawn {
  background: rgba(34, 211, 238, 0.16);
  border-color: rgba(34, 211, 238, 0.4);
  color: var(--text);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.15);
}

.loto-cell--marked {
  background: linear-gradient(135deg, var(--green), #0ea5e9);
  border-color: transparent;
  color: #0b0616;
}

.loto-cell--expired {
  opacity: 0.3;
}

.loto-cell:disabled {
  cursor: default;
}

@media (max-height: 680px) {
  .loto-barrel {
    font-size: 44px;
  }

  .loto-last {
    padding: 8px 12px;
  }

  .loto-card {
    padding: 6px 8px 8px;
  }
}
