* { box-sizing: border-box; }

:root {
  --bg: #0b1020;
  --panel: rgba(17, 24, 39, .86);
  --panel-2: rgba(30, 41, 59, .82);
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: rgba(255,255,255,.10);
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 24px 70px rgba(0,0,0,.38);
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 10% 10%, rgba(139,92,246,.18), transparent 34%),
    radial-gradient(circle at 90% 85%, rgba(34,211,238,.12), transparent 28%),
    linear-gradient(145deg, #090d18 0%, #111827 52%, #0b1020 100%);
}

button, select, input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ambient {
  position: fixed;
  width: 38vw;
  height: 38vw;
  max-width: 520px;
  max-height: 520px;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .16;
  pointer-events: none;
  animation: drift 12s ease-in-out infinite alternate;
}

.ambient-a {
  top: -18vw;
  left: -12vw;
  background: #8b5cf6;
}

.ambient-b {
  right: -16vw;
  bottom: -20vw;
  background: #06b6d4;
  animation-delay: -5s;
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(5vw, 4vh, 0) scale(1.18); }
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 4px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 14px;
  font-weight: 950;
  font-size: 1.4rem;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  box-shadow: 0 10px 30px rgba(139,92,246,.35), inset 0 1px 0 rgba(255,255,255,.28);
  transform: rotate(-5deg);
}

.brand h1 {
  margin: 0;
  letter-spacing: .14em;
  font-size: 1.15rem;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: .78rem;
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 11px;
  border-radius: 999px;
  background: rgba(15,23,42,.68);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .75rem;
  white-space: nowrap;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 12px currentColor;
}

.sync-ok { color: #4ade80; }
.sync-wait { color: #fbbf24; }
.sync-error { color: #fb7185; }

main {
  flex: 1;
  min-height: 0;
  display: flex;
}

.panel,
.game-view {
  width: 100%;
}

.setup-view {
  margin: auto;
  max-width: 820px;
  padding: clamp(18px, 4vw, 38px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(30,41,59,.88), rgba(15,23,42,.82));
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  animation: riseIn .55s cubic-bezier(.2,.8,.2,1);
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(18px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.hero {
  text-align: center;
  margin-bottom: 24px;
}

.eyebrow,
.micro-label {
  color: #c4b5fd;
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .16em;
}

.hero h2 {
  margin: 8px 0 8px;
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  line-height: 1;
}

.hero p {
  max-width: 620px;
  margin: 0 auto;
  color: var(--muted);
  line-height: 1.55;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.setting-card {
  padding: 12px;
  border-radius: 16px;
  background: rgba(15,23,42,.72);
  border: 1px solid var(--line);
}

.setting-card label,
.team-input-wrap label {
  display: block;
  margin-bottom: 7px;
  color: #cbd5e1;
  font-size: .78rem;
  font-weight: 800;
}

select,
.team-input {
  width: 100%;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  padding: 12px;
  outline: none;
  color: var(--text);
  background: #111827;
}

select:focus,
.team-input:focus {
  border-color: rgba(139,92,246,.8);
  box-shadow: 0 0 0 3px rgba(139,92,246,.16);
}

.team-names {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 14px 0 18px;
}

.team-input-wrap {
  padding: 12px;
  border-radius: 16px;
  background: rgba(15,23,42,.58);
  border: 1px solid var(--line);
  animation: fadeScale .25s ease both;
}

@keyframes fadeScale {
  from { opacity: 0; transform: scale(.97); }
  to { opacity: 1; transform: scale(1); }
}

.btn {
  border: 0;
  border-radius: 15px;
  padding: 13px 16px;
  color: white;
  font-weight: 900;
  cursor: pointer;
  transition: transform .12s ease, filter .16s ease, box-shadow .16s ease;
}

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

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

.btn-large {
  width: 100%;
  font-size: 1rem;
  padding: 15px 18px;
}

.btn-primary {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  box-shadow: 0 12px 30px rgba(109,40,217,.28);
}

.btn-primary:hover { filter: brightness(1.08); }

.game-view {
  display: flex;
  flex-direction: column;
  min-height: 0;
  animation: riseIn .4s ease;
}

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

.score-card {
  position: relative;
  overflow: hidden;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(15,23,42,.74);
  min-width: 0;
}

.score-card.active {
  border-color: rgba(167,139,250,.75);
  box-shadow: 0 0 0 2px rgba(139,92,246,.12), 0 10px 28px rgba(109,40,217,.18);
}

.score-card.active::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent);
  transform: translateX(-100%);
  animation: shine 2.4s infinite;
}

@keyframes shine {
  50%,100% { transform: translateX(100%); }
}

.score-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
}

.score-value {
  display: block;
  margin-top: 2px;
  font-size: clamp(1.2rem, 4vw, 1.75rem);
  font-weight: 950;
}

.score-pop {
  animation: scorePop .35s ease;
}

@keyframes scorePop {
  0% { transform: scale(1); }
  45% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.game-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(13px, 2vw, 20px);
  border-radius: 24px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(30,41,59,.82), rgba(15,23,42,.78));
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.round-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

#activeTeamName {
  display: block;
  margin-top: 2px;
  font-size: clamp(1.1rem, 3vw, 1.55rem);
}

.timer-box {
  display: flex;
  align-items: center;
  gap: 7px;
}

.timer-ring {
  --progress: 1turn;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  background: conic-gradient(#22d3ee var(--progress), rgba(255,255,255,.09) 0);
}

.timer-ring::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #111827;
}

.timer-ring span {
  position: relative;
  z-index: 1;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.timer-ring.urgent {
  animation: urgentPulse .7s ease-in-out infinite alternate;
  background: conic-gradient(#fb7185 var(--progress), rgba(255,255,255,.09) 0);
}

@keyframes urgentPulse {
  to { transform: scale(1.08); box-shadow: 0 0 25px rgba(251,113,133,.28); }
}

.timer-caption {
  color: var(--muted);
  font-size: .72rem;
}

.ready-panel {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  padding: 20px;
}

.ready-icon {
  font-size: clamp(3rem, 12vw, 6rem);
  filter: drop-shadow(0 12px 24px rgba(0,0,0,.3));
  animation: floatMic 2.2s ease-in-out infinite;
}

@keyframes floatMic {
  50% { transform: translateY(-8px) rotate(3deg); }
}

.ready-panel h2 {
  margin: 10px 0 4px;
  font-size: clamp(1.5rem, 5vw, 2.4rem);
}

.ready-panel p {
  margin: 0 0 20px;
  color: var(--muted);
}

.play-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.word-card {
  flex: 1;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: clamp(18px, 4vw, 34px);
  border-radius: 23px;
  background:
    radial-gradient(circle at top right, rgba(139,92,246,.22), transparent 36%),
    linear-gradient(160deg, rgba(30,41,59,.96), rgba(15,23,42,.96));
  border: 1px solid rgba(167,139,250,.28);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 14px 40px rgba(0,0,0,.25);
  animation: cardIn .28s cubic-bezier(.2,.9,.2,1);
}

@keyframes cardIn {
  from { opacity: .25; transform: translateY(12px) rotateX(8deg) scale(.985); }
  to { opacity: 1; transform: none; }
}

.word-card::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  right: -80px;
  bottom: -90px;
  background: rgba(34,211,238,.08);
  filter: blur(8px);
}

.card-topline {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #a78bfa;
  font-size: .72rem;
  font-weight: 950;
  letter-spacing: .16em;
}

.main-word {
  margin: clamp(12px, 3vh, 24px) 0;
  text-align: center;
  font-size: clamp(2.1rem, 9vw, 5.6rem);
  font-weight: 1000;
  letter-spacing: .02em;
  line-height: .95;
  overflow-wrap: anywhere;
  text-shadow: 0 8px 28px rgba(0,0,0,.35);
}

.forbidden-title {
  margin-bottom: 9px;
  color: #fca5a5;
  font-size: .75rem;
  font-weight: 950;
  letter-spacing: .11em;
  text-align: center;
}

.forbidden-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 7px;
}

.forbidden-word {
  padding: 9px 10px;
  border-radius: 12px;
  text-align: center;
  background: rgba(239,68,68,.11);
  border: 1px solid rgba(248,113,113,.18);
  color: #fecaca;
  font-weight: 850;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.action-grid .btn {
  min-height: 66px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 8px;
  text-align: left;
}

.action-icon {
  grid-row: 1 / span 2;
  font-size: 1.5rem;
}

.action-grid small {
  opacity: .76;
  font-weight: 700;
  font-size: .68rem;
}

.btn-success {
  background: linear-gradient(135deg, #22c55e, #15803d);
  box-shadow: 0 10px 26px rgba(34,197,94,.18);
}

.btn-error {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  box-shadow: 0 10px 26px rgba(239,68,68,.18);
}

.btn-skip {
  background: linear-gradient(135deg, #64748b, #475569);
}

.btn-ghost {
  margin-top: 9px;
  background: rgba(255,255,255,.055);
  border: 1px solid var(--line);
  color: #cbd5e1;
}

.bottom-actions {
  display: flex;
  justify-content: center;
}

.danger-outline {
  color: #fca5a5;
  padding-inline: 22px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(92vw, 520px);
  transform: translate(-50%, 22px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(15,23,42,.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: white;
  font-weight: 800;
  transition: .24s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hidden { display: none !important; }

@media (max-width: 720px) {
  .brand p { display: none; }

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

  .team-names {
    grid-template-columns: 1fr;
  }

  .scoreboard {
    gap: 5px;
  }

  .score-card {
    padding: 8px;
  }

  .action-grid .btn {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    text-align: center;
    gap: 2px;
    padding: 9px 5px;
  }

  .action-icon {
    grid-row: auto;
    font-size: 1.25rem;
  }

  .forbidden-list {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-height: 680px) and (orientation: landscape) {
  .app-shell { padding-top: 6px; padding-bottom: 6px; }
  .topbar { padding-bottom: 7px; }
  .brand p { display: none; }
  .logo { width: 36px; height: 36px; border-radius: 11px; }
  .game-stage { padding: 10px; }
  .round-header { margin-bottom: 6px; }
  .timer-ring { width: 46px; height: 46px; }
  .word-card { min-height: 150px; padding: 12px 18px; }
  .main-word { margin: 7px 0; font-size: clamp(1.8rem, 7vw, 3.3rem); }
  .forbidden-word { padding: 6px 8px; font-size: .8rem; }
  .action-grid { margin-top: 6px; }
  .action-grid .btn { min-height: 50px; padding: 6px; }
  .btn-ghost { margin-top: 5px; padding: 7px 12px; }
}
