:root {
  --bg0: #1a1410;
  --bg1: #2a1f18;
  --ink: #f3ebe2;
  --muted: #b09a88;
  --line: rgba(243, 235, 226, 0.14);
  --amber: #e8a04a;
  --danger: #d94b3d;
  --calm: #6f9e7a;
  --hero: #3aa0ff;
  --panel: rgba(20, 14, 10, 0.72);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  font-synthesis: none;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  color: var(--ink);
  font-family: "Source Sans 3", system-ui, sans-serif;
  background: var(--bg0);
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 70% 50% at 20% 0%, rgba(232, 160, 74, 0.18), transparent 55%),
    radial-gradient(ellipse 55% 45% at 90% 80%, rgba(58, 160, 255, 0.12), transparent 50%),
    linear-gradient(165deg, #241a14 0%, #15100d 48%, #0f0c0a 100%);
}

.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
  opacity: 0.35;
  pointer-events: none;
}

.top {
  max-width: 520px;
  margin: 0 auto;
  padding: 14px 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-mini {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 1.05rem;
}

.scoreboard {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.score em {
  font-style: normal;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 4px;
}

.score strong {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.35rem;
}

.score.you strong { color: var(--hero); }
.score.ai strong { color: var(--amber); }
.score-sep, .score-goal { color: var(--muted); font-size: 0.9rem; }

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 16px 28px;
}

.screen.hidden { display: none; }

.title-stage, .end-card {
  text-align: center;
  padding: 18px 8px 8px;
  animation: rise 0.7s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero-art {
  position: relative;
  width: 120px;
  height: 88px;
  margin: 0 auto 18px;
}

.mini-crosswalk {
  position: absolute;
  inset: 28px 8px;
  background:
    repeating-linear-gradient(
      90deg,
      #f3ebe2 0 10px,
      transparent 10px 18px
    );
  opacity: 0.35;
  border-radius: 4px;
}

.mini-ball {
  position: absolute;
  left: 52px;
  top: 18px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 16px rgba(232, 160, 74, 0.55);
  animation: bounce 1.4s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(36px); }
}

.eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--amber);
  font-weight: 700;
  margin-bottom: 8px;
}

h1, h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  font-size: clamp(2.2rem, 8vw, 3rem);
  line-height: 1.05;
  margin-bottom: 12px;
}

.lead {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
  margin-bottom: 18px;
  max-width: 36em;
  margin-left: auto;
  margin-right: auto;
}

.rules {
  list-style: none;
  text-align: left;
  max-width: 360px;
  margin: 0 auto 22px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.rules li {
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--ink);
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.rules li:last-child { border-bottom: 0; }

kbd {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  font-family: inherit;
  font-size: 0.85em;
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  padding: 14px 28px;
  border-radius: 999px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn.primary {
  background: linear-gradient(180deg, #f0b86a, var(--amber));
  color: #1a120c;
  box-shadow: 0 10px 28px rgba(232, 160, 74, 0.28);
}

.btn.primary:hover {
  transform: translateY(-2px);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.secondary:hover {
  border-color: var(--amber);
}

.btn.linkish {
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  padding: 10px 12px;
  font-weight: 600;
}

.btn.linkish:hover { color: var(--ink); }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 4px;
}

.nick-form {
  display: grid;
  gap: 12px;
  max-width: 320px;
  margin: 0 auto 12px;
}

.nick-form input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(20, 14, 10, 0.8);
  color: var(--ink);
  font-family: inherit;
  font-size: 1.05rem;
}

.nick-form input:focus {
  outline: none;
  border-color: var(--amber);
}

.error {
  color: var(--danger);
  margin-bottom: 10px;
}

.lobby {
  text-align: left;
  animation: rise 0.7s ease both;
}

.lobby-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.lobby h2 {
  font-size: 1.8rem;
  margin-bottom: 0;
}

.lead.tight {
  margin-bottom: 14px;
  text-align: left;
}

.you-chip {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.you-chip strong { color: var(--amber); }

.player-list {
  list-style: none;
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.player-list li button {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.player-list li button:hover {
  border-color: var(--amber);
  transform: translateY(-1px);
}

.player-list li button:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.lobby-empty, .lobby-status {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 6, 4, 0.72);
}

.modal.hidden { display: none; }

.modal-card {
  width: min(380px, 100%);
  padding: 22px 20px;
  border-radius: var(--radius);
  background: #1c1510;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
}

.modal-card h3 {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.45rem;
  margin-bottom: 8px;
}

.modal-card p {
  color: var(--muted);
  margin-bottom: 18px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(20, 14, 10, 0.92);
  border: 1px solid var(--amber);
  color: var(--ink);
  font-weight: 600;
  max-width: min(420px, calc(100% - 32px));
  text-align: center;
}

.toast.hidden { display: none; }

.back {
  display: inline-block;
  margin-top: 16px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.back:hover { color: var(--ink); }

#screen-play {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#screen-play.hidden { display: none; }

#game {
  width: min(100%, 480px);
  height: auto;
  aspect-ratio: 480 / 720;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #0c0a08;
  box-shadow: var(--shadow);
  touch-action: none;
  display: block;
}

.hud-hint {
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.fx-banner {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(20, 14, 10, 0.88);
  border: 1px solid var(--amber);
  color: var(--amber);
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  pointer-events: none;
  z-index: 2;
  animation: pop 0.35s ease;
}

.fx-banner.fire { border-color: var(--danger); color: #ff8a6a; }
.fx-banner.fast { border-color: var(--hero); color: #9fd0ff; }
.fx-banner.wobble { border-color: #c07ae8; color: #e0b8ff; }
.fx-banner.ghost { border-color: #aaa; color: #ddd; }

@keyframes pop {
  from { opacity: 0; transform: translate(-50%, -40%) scale(0.9); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.end-score {
  font-family: "Fraunces", Georgia, serif;
  font-size: 2rem;
  margin: 12px 0 20px;
  color: var(--amber);
}

#end-text {
  color: var(--muted);
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  .mini-ball, .title-stage, .end-card, .fx-banner { animation: none; }
}
