:root {
  --bg: #07060b;
  --surface: #110f18;
  --surface-2: #181523;
  --border: #262036;
  --border-strong: #3a3050;
  --ink: #ece9f3;
  --muted: #8d86a0;
  --violet: #8b5cf6;
  --violet-bright: #a78bfa;
  --violet-deep: #6d28d9;
  --violet-glow: rgba(139, 92, 246, 0.35);
  --win: #a78bfa;
  --loss: #f0506e;
  --draw: #8d86a0;
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(109, 40, 217, 0.28), transparent 70%),
    radial-gradient(ellipse 60% 40% at 50% 110%, rgba(109, 40, 217, 0.12), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  justify-content: center;
}

.screen-game { justify-content: flex-start; }

.enter .card, .enter .hero { animation: fade-up 0.35s ease-out both; }
.enter .card { animation-delay: 0.04s; }

.card {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
}

.center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }

h1, h2 { margin: 0; line-height: 1.15; }
h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.icon { display: inline-flex; color: var(--ink); }
.icon svg { width: 100%; height: 100%; }

/* ---------- hero ---------- */

.hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.hero-icons { display: flex; gap: 18px; }
.hero-icon { width: 34px; height: 34px; color: var(--violet-bright); opacity: 0.9; }

.title {
  font-size: clamp(1.5rem, 7vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.subtitle {
  font-size: 0.8rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--violet-bright);
}

.name-tag {
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.95rem;
}

/* ---------- buttons ---------- */

button { font: inherit; color: inherit; cursor: pointer; border: none; }
button:disabled { cursor: default; opacity: 0.5; }
button:focus-visible { outline: 2px solid var(--violet-bright); outline-offset: 3px; }

.big-button {
  width: 100%;
  max-width: 340px;
  min-height: 60px;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(180deg, var(--violet), var(--violet-deep));
  border: 1px solid rgba(167, 139, 250, 0.5);
  border-radius: 10px;
  box-shadow: 0 0 0 0 var(--violet-glow), 0 8px 24px rgba(109, 40, 217, 0.3);
  transition: box-shadow 0.2s ease, transform 0.08s ease, filter 0.2s ease;
}
.big-button:not(:disabled):hover { filter: brightness(1.12); box-shadow: 0 0 0 4px var(--violet-glow), 0 8px 28px rgba(109, 40, 217, 0.45); }
.big-button:not(:disabled):active { transform: translateY(1px); filter: brightness(0.95); }

.link-button {
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
}
.link-button:not(:disabled):hover { color: var(--ink); border-color: var(--border-strong); }

/* ---------- loading / waiting ---------- */

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--violet-bright);
  animation: spin 0.9s linear infinite;
  margin: 0 auto;
}
.screen-loading { align-items: center; gap: 14px; }

.searching { display: flex; gap: 20px; margin: 6px 0; }
.search-icon { width: 40px; height: 40px; color: var(--violet-bright); animation: pulse 1.8s ease-in-out infinite; }
.search-icon-1 { animation-delay: 0.3s; }
.search-icon-2 { animation-delay: 0.6s; }

.status { font-size: 1.05rem; font-weight: 500; }
.status::after, .ellipsis::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.4s steps(4, end) infinite; }

/* ---------- game ---------- */

.topbar { display: flex; justify-content: space-between; align-items: center; }
.round-pill {
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--violet-bright);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 5px 10px;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
}
.side { min-width: 0; }
.side.right { text-align: right; }
.side-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.18em; color: var(--muted); margin-bottom: 4px; }
.side-name { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score { text-align: center; font-family: var(--mono); font-weight: 700; line-height: 1; }
.score-num { font-size: 2.4rem; }
.score-num.win { color: var(--ink); }
.score-num.loss { color: var(--muted); }
.score-sep { font-size: 1.8rem; margin: 0 8px; color: var(--violet); }
.draws { font-size: 0.7rem; color: var(--muted); font-weight: 500; margin-top: 6px; letter-spacing: 0.1em; text-transform: uppercase; }

.moves {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}
.move-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 4px 14px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.move-button:not(:disabled):hover {
  border-color: var(--violet);
  background: rgba(139, 92, 246, 0.08);
  box-shadow: 0 0 0 3px var(--violet-glow);
}
.move-button:not(:disabled):hover .move-icon { color: var(--violet-bright); }
.move-button:not(:disabled):active { background: rgba(139, 92, 246, 0.16); }
.move-icon { width: clamp(44px, 14vw, 56px); height: clamp(44px, 14vw, 56px); transition: color 0.15s ease; }
.move-label { font-weight: 500; font-size: 0.8rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }

.opponent-status { color: var(--muted); font-size: 0.9rem; display: inline-flex; align-items: center; gap: 8px; }
.opponent-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
  animation: pulse 1.6s ease-in-out infinite;
}
.opponent-status.ready { color: var(--ink); }
.opponent-status.ready::before { background: var(--violet-bright); box-shadow: 0 0 8px var(--violet); animation: none; }

.picked { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.picked-icon { width: 88px; height: 88px; color: var(--violet-bright); }
.enter .pop { animation: scale-in 0.35s ease-out both; }

.left-mark { font-size: 2rem; color: var(--muted); }

/* ---------- result ---------- */

.versus { display: flex; align-items: center; justify-content: center; gap: 16px; width: 100%; }
.versus-side { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; overflow: hidden; }
.versus-side .muted { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.versus-icon { width: clamp(64px, 20vw, 84px); height: clamp(64px, 20vw, 84px); }
.versus-vs { font-family: var(--mono); color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.1em; }
.enter .slide-left { animation: from-left 0.4s ease-out both; }
.enter .slide-right { animation: from-right 0.4s ease-out both; }
.enter .headline { animation: fade-up 0.35s 0.25s ease-out both; }

.headline { font-size: 1.9rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; }
.result-win .headline { color: var(--violet-bright); text-shadow: 0 0 24px var(--violet-glow); }
.result-loss .headline { color: var(--loss); }
.result-draw .headline { color: var(--ink); }
.result-win { border-color: rgba(139, 92, 246, 0.6); box-shadow: 0 0 40px rgba(109, 40, 217, 0.25); }
.result-win .versus-side:first-child .versus-icon { color: var(--violet-bright); }
.result-loss .versus-side:last-child .versus-icon { color: var(--loss); }
.result-loss { border-color: rgba(240, 80, 110, 0.4); }

/* ---------- toasts ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  font-size: 0.9rem;
  animation: fade-up 0.25s ease-out both;
}
.toast-error { border-color: var(--loss); color: #ffd4dc; cursor: pointer; }
.toast-offline { color: var(--muted); }

/* ---------- animations ---------- */

@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes scale-in { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: none; } }
@keyframes from-left { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
@keyframes from-right { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
