:root {
  --bg-dark: #090d16;
  --bg-gradient: radial-gradient(circle at top right, #1e1b4b 0%, #0f172a 45%, #090d16 100%);
  --bg-card: rgba(30, 41, 59, 0.94);
  --bg-panel: #0b1120;
  --accent: #38bdf8;
  --purple: #a855f7;
  --gold: #fbbf24;
  --silver: #cbd5e1;
  --bronze: #d97706;
  --success: #10b981;
  --danger: #f43f5e;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.22);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: var(--bg-gradient);
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

body.pseudo-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  overflow-y: auto;
  width: 100vw;
  height: 100dvh;
  background: var(--bg-gradient);
  background-color: var(--bg-dark);
}

header {
  background: rgba(11, 17, 32, 0.96);
  border-bottom: 1px solid rgba(56, 189, 248, 0.25);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
  font-size: 1.12rem;
  color: #38bdf8;
}

.brand-pill {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #0f172a;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 800;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge-status {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--gold);
}
.dot.online { background: var(--success); box-shadow: 0 0 10px var(--success); }
.dot.error { background: var(--danger); }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-weight: 700;
  font-size: 0.95rem;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, #38bdf8, #0284c7); color: #fff; }
.btn-success { background: linear-gradient(135deg, #10b981, #059669); color: #fff; box-shadow: 0 4px 16px rgba(16, 185, 129, 0.35); }
.btn-gold { background: linear-gradient(135deg, #fbbf24, #d97706); color: #0f172a; }
.btn-purple { background: linear-gradient(135deg, #a855f7, #7e22ce); color: #fff; }
.btn-danger { background: linear-gradient(135deg, #f43f5e, #be123c); color: #fff; }
.btn-ghost { background: rgba(30, 41, 59, 0.6); border: 1px solid var(--border); color: var(--text-main); }
.btn-sm { padding: 7px 13px; font-size: 0.85rem; }
.btn-xs { padding: 4px 8px; font-size: 0.72rem; border-radius: 7px; }

.container {
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
  padding: 18px;
  flex: 1;
}

.hidden { display: none !important; }

.hero-intro {
  text-align: center;
  max-width: 780px;
  margin: 6px auto 22px auto;
}

.hero-intro h1 {
  font-size: clamp(1.5rem, 3.4vw, 2.1rem);
  font-weight: 900;
  margin-bottom: 6px;
  color: #f8fafc;
}

.hero-intro p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.lobby-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 22px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.card-student { border-top: 4px solid var(--accent); }
.card-teacher { border-top: 4px solid var(--gold); }
.card-ranking { border-top: 4px solid var(--success); margin-top: 22px; }

.card h2 {
  font-size: 1.25rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
  line-height: 1.5;
}

.form-group { margin-bottom: 13px; }
.form-group label {
  display: block;
  font-size: 0.84rem;
  font-weight: 700;
  margin-bottom: 5px;
  color: #e2e8f0;
}

input, textarea, select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: #fff;
  font-size: 0.95rem;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.45;
}

input:focus, textarea:focus, select:focus { border-color: var(--accent); }

.admin-story-box {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.mod-list-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.mod-chip {
  background: var(--bg-panel);
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.76rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #fef3c7;
}

.mod-chip button {
  padding: 0 4px;
  font-size: 0.75rem;
  background: transparent;
  color: #fda4af;
}

.mod-actions-cell {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.filtered-words-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 8px;
  margin-top: 10px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

.filter-word-item {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.filter-word-item label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  cursor: pointer;
  font-weight: 700;
}

.filter-word-item input[type="checkbox"] {
  width: auto;
  padding: 0;
  margin: 0;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
  background: var(--bg-panel);
  padding: 5px;
  border-radius: 10px;
}

.auth-tab {
  padding: 8px;
  font-size: 0.85rem;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
}

.auth-tab.active {
  background: var(--gold);
  color: #0f172a;
  font-weight: 800;
}

.plan-banner {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.45);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.plan-banner.expired {
  background: rgba(244, 63, 94, 0.14);
  border-color: var(--danger);
  color: #fda4af;
}

.admin-control-box {
  background: rgba(168, 85, 247, 0.12);
  border: 1px solid rgba(168, 85, 247, 0.45);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.saved-rooms-box {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.saved-rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.saved-room-row {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.legend-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.legend-pill {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  color: #090d16;
}

.room-banner {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.98) 100%);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 16px;
  padding: 16px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 18px;
}

.pin-display {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 7px;
  color: var(--gold);
  background: var(--bg-panel);
  padding: 6px 20px;
  border-radius: 12px;
  border: 2px dashed rgba(251, 191, 36, 0.65);
}

.waiting-lobby-box {
  max-width: 620px;
  margin: 30px auto;
  text-align: center;
  padding: 38px 24px;
  border: 2px solid rgba(56, 189, 248, 0.45);
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.95) 0%, rgba(11, 17, 32, 0.98) 100%);
}

.pulse-ring {
  width: 68px;
  height: 68px;
  margin: 0 auto 18px auto;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.15);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  animation: pulseGlow 1.8s infinite ease-in-out;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.45); }
  50% { transform: scale(1.06); box-shadow: 0 0 0 14px rgba(56, 189, 248, 0); }
}

.waiting-players-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.player-pill-tag {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
  color: #e2e8f0;
}

.player-pill-tag.me { border-color: var(--gold); color: var(--gold); }

.teacher-layout {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
}

@media (max-width: 920px) {
  .teacher-layout { grid-template-columns: 1fr; }
}

.podium {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.podium-item {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}

.podium-item.rank-1 { border-color: var(--gold); background: rgba(251, 191, 36, 0.16); }
.podium-item.rank-2 { border-color: var(--silver); background: rgba(203, 213, 225, 0.08); }
.podium-item.rank-3 { border-color: var(--bronze); background: rgba(217, 119, 6, 0.1); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

th, td {
  padding: 9px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--accent);
  font-size: 0.74rem;
  text-transform: uppercase;
}

.status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
}
.st-waiting { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; border: 1px solid #38bdf8; }
.st-active { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid #10b981; }
.st-repechage { background: rgba(251, 191, 36, 0.2); color: #fbbf24; border: 1px solid #f59e0b; }
.st-eliminated { background: rgba(244, 63, 94, 0.2); color: #fda4af; border: 1px solid #f43f5e; }

.live-scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.score-tile {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.score-tile.is-human {
  border-color: var(--gold);
  background: rgba(251, 191, 36, 0.12);
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 1024px) {
  .game-layout { grid-template-columns: 1fr; }
}

.story-box {
  background: #0b1120;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-left: 5px solid var(--accent);
  line-height: 2.0;
  font-size: 1rem;
  margin-bottom: 14px;
}

.word-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.45);
  font-weight: 700;
  color: #f8fafc;
}

.word-tag.solved {
  color: #090d16 !important;
  border-color: transparent !important;
  font-weight: 800;
}

.word-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: #e2e8f0;
}

.chip.claimed {
  color: #090d16;
  border-color: transparent;
  font-weight: 800;
}

.math-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(168, 85, 247, 0.18);
  border: 1px solid rgba(168, 85, 247, 0.45);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.84rem;
  font-weight: 700;
  color: #e9d5ff;
}

.grid-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 6px;
}

.grid-wrapper {
  display: flex;
  justify-content: center;
  width: 100%;
  touch-action: none;
}

.ws-grid {
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  gap: 4px;
  background: var(--bg-panel);
  padding: 10px;
  border-radius: 14px;
  border: 2px solid rgba(56, 189, 248, 0.3);
  width: 100%;
  max-width: min(86vw, 720px);
  aspect-ratio: 1 / 1;
  touch-action: none;
  transition: box-shadow 0.35s ease, border-color 0.35s ease;
}

.ws-grid.celebration-mode {
  border-color: var(--gold) !important;
  box-shadow: 0 0 28px rgba(251, 191, 36, 0.55), inset 0 0 18px rgba(251, 191, 36, 0.2);
}

.cell {
  background: #1e293b;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(0.95rem, 2.2vw, 1.45rem);
  color: #f1f5f9;
  cursor: pointer;
  touch-action: none;
}

@media (max-width: 600px) {
  .container { padding: 10px; }
  .card { padding: 14px; border-radius: 14px; }
  .ws-grid {
    max-width: 100%;
    gap: 2px;
    padding: 6px;
    border-radius: 10px;
  }
  .cell {
    border-radius: 4px;
    font-size: clamp(0.95rem, 4.4vw, 1.3rem);
  }
}

.cell.selected {
  background: linear-gradient(135deg, #38bdf8, #818cf8) !important;
  color: #090d16 !important;
  transform: scale(1.06);
}

.cell.found {
  color: #090d16 !important;
  font-weight: 900;
}

.cell.celebrate-pop {
  animation: celebrateCellPop 0.7s ease;
}

@keyframes celebrateCellPop {
  0% { transform: scale(1); filter: brightness(1); }
  45% { transform: scale(1.14); filter: brightness(1.35); }
  100% { transform: scale(1); filter: brightness(1); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 17, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10000;
}

.modal-card {
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border: 2px solid var(--accent);
  border-radius: 18px;
  max-width: 560px;
  width: 100%;
  padding: 22px;
  position: relative;
  overflow: hidden;
}

.modal-card.winner-showcase {
  border: 3px solid var(--gold);
  background: radial-gradient(circle at top, rgba(251, 191, 36, 0.24) 0%, #1e293b 48%, #090d16 100%);
  box-shadow: 0 0 45px rgba(251, 191, 36, 0.45);
}

.winner-banner-badge {
  display: inline-block;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #090d16;
  font-weight: 900;
  font-size: 0.78rem;
  letter-spacing: 1.5px;
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10001;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -16px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

.modal-card.math-lock { border-color: var(--purple); }
.modal-card.repechage-lock { border-color: var(--gold); }
.modal-card.eliminated-lock { border-color: var(--danger); }

.class-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.class-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: #f8fafc;
  padding: 11px 14px;
  justify-content: flex-start;
  font-size: 0.9rem;
  border-radius: 10px;
}

.math-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 14px;
}

.math-btn {
  background: var(--bg-panel);
  border: 1px solid rgba(168, 85, 247, 0.45);
  color: #f8fafc;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 800;
  border-radius: 12px;
}

.repechage-btn {
  background: var(--bg-panel);
  border: 1px solid rgba(251, 191, 36, 0.55);
  color: #f8fafc;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 800;
  border-radius: 12px;
}

.attempts-pill {
  display: inline-block;
  background: rgba(244, 63, 94, 0.18);
  border: 1px solid rgba(244, 63, 94, 0.55);
  color: #fda4af;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.recomp-choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0;
}

.recomp-countdown-box {
  background: var(--bg-panel);
  border: 2px dashed var(--gold);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  margin-top: 10px;
}

.recomp-timer-num {
  font-size: 2.4rem;
  font-weight: 900;
  color: var(--gold);
  margin: 4px 0;
}

.color-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.site-footer {
  text-align: center;
  padding: 14px 18px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: rgba(11, 17, 32, 0.85);
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.site-footer a:hover {
  text-decoration: underline;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-panel);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-left: 5px solid var(--accent);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  z-index: 11000;
  font-weight: 700;
}