:root {
    --bg:        #141414;
    --surface:   rgba(255,255,255,0.04);
    --border:    rgba(255,255,255,0.07);
    --border-md: rgba(255,255,255,0.12);
    --text:      rgba(255,255,255,0.87);
    --muted:     rgba(255,255,255,0.45);
    --blue:      rgba(41,158,255,0.85);
    --blue-glow: rgba(41,158,255,0.15);
    --cyan:      rgba(15,255,199,0.85);
    --cyan-dim:  rgba(15,255,199,0.12);
    --red:       rgba(255,80,80,0.85);
    --red-dim:   rgba(255,80,80,0.1);
    --radius:    10px;
    --radius-lg: 14px;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
  html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'Inter', sans-serif; overflow-x: hidden; overflow-y: auto; }
  body { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; min-height: 100svh; }

  /* ── HEADER ── */
  .nn-header {
    position: fixed; top: 0; left: 0; right: 0;
    display: flex; align-items: center; justify-content: center;
    padding: 12px 20px; gap: 8px;
    background: rgba(20,20,20,0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    z-index: 100;
  }
  .nn-title { font-size: .95rem; font-weight: 700; color: var(--text); letter-spacing: .01em; }
  .nn-sub { font-size: .72rem; color: var(--muted); }
  .nn-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--border-md); }

  /* ── LAYOUT ── */
  #app {
    width: 100%;
    max-width: 480px;
    padding: 68px 16px 32px;
    display: flex;
    flex-direction: column;
    min-height: 100svh;
    justify-content: center;
    gap: 0;
  }

  /* Screens gap */
  .screen { display: none; flex-direction: column; gap: 12px; animation: fadeUp .25s ease; width: 100%; }
  .screen.active { display: flex; }
  @keyframes fadeUp { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }

  /* ── CARD ── */
  .card {
    background: linear-gradient(160deg, rgba(20,20,20,.1) 0%, rgba(186,186,186,.06) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(20px);
    box-shadow: 0 4px 40px rgba(0,0,0,.5);
    padding: 20px;
  }

  /* ── SECTION LABEL ── */
  .label { font-size: .72rem; color: var(--blue); text-transform: uppercase; letter-spacing: .1em; margin-bottom: 8px; }

  /* ── HOME ── */
  .home-title { font-size: 1.7rem; font-weight: 700; color: var(--text); }
  .home-sub { font-size: .85rem; color: var(--muted); margin-top: 4px; }

  /* ── INPUT ── */
  input {
    background: rgba(255,255,255,.05);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    outline: none;
    transition: border-color .2s, background .2s;
    width: 100%;
    user-select: text; -webkit-user-select: text;
  }
  input:focus { border-color: rgba(41,158,255,.5); background: rgba(41,158,255,.04); }
  input::placeholder { color: var(--muted); }

  /* ── BUTTONS ── */
  .btn {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: .95rem;
    cursor: pointer;
    transition: all .15s;
    width: 100%;
    color: var(--text);
    background: rgba(255,255,255,.05);
    letter-spacing: .01em;
  }
  .btn:active { transform: scale(.98); opacity: .85; }
  .btn-primary {
    background: rgba(41,158,255,.12);
    border-color: rgba(41,158,255,.3);
    color: var(--blue);
  }
  .btn-primary:hover { background: rgba(41,158,255,.18); border-color: rgba(41,158,255,.5); }
  .btn-ghost { background: transparent; border-color: transparent; color: var(--muted); font-size: .82rem; padding: 8px; }
  .btn-ghost:hover { color: var(--text); }

  /* ── DIVIDER ── */
  .divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .75rem; }
  .divider::before, .divider::after { content:''; flex:1; height:1px; background: var(--border); }

  .error-msg { color: var(--red); font-size: .8rem; min-height: 18px; text-align: center; }

  /* ── LOBBY CODE ── */
  .code-block { text-align: center; padding: 20px 0 8px; }
  .code-big {
    font-size: 2.8rem; font-weight: 700; letter-spacing: .35em;
    color: var(--blue); font-variant-numeric: tabular-nums;
    text-shadow: 0 0 24px rgba(41,158,255,.3);
  }
  .waiting-text { color: var(--muted); font-size: .82rem; margin-top: 8px; }
  .waiting-text::after { content:''; animation: dots 1.5s steps(4,end) infinite; }
  @keyframes dots { 0%{content:''} 25%{content:'.'} 50%{content:'..'} 75%{content:'...'} 100%{content:''} }

  /* ── GAME SCREEN ── */
  #screen-game {
    display: none;
    flex-direction: column;
    position: fixed;
    inset: 0;
    padding: 60px 16px 24px;
    gap: 10px;
    overflow: hidden;
  }
  #screen-game.active { display: flex; }

  /* Score row */
  .score-row { display: flex; gap: 10px; }
  .score-card {
    flex: 1;
    background: linear-gradient(160deg, rgba(20,20,20,.1) 0%, rgba(186,186,186,.06) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(20px);
    padding: 14px 12px;
    text-align: center;
  }
  .score-card.me { border-color: rgba(41,158,255,.25); }
  .score-card .sc-label { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
  .score-card .sc-name { font-size: .85rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 6px; }
  .score-card .sc-score { font-size: 3rem; font-weight: 700; line-height: 1; color: var(--muted); }
  .score-card.me .sc-score { color: var(--blue); }
  .score-card.opp .sc-score { color: var(--cyan); }

  /* Score flash when point scored */
  @keyframes scoreFlash {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.18); }
    100% { transform: scale(1); }
  }
  .score-flash-win { animation: scoreFlash .5s cubic-bezier(.36,.07,.19,.97); }
  .score-flash-win.me  { border-color: rgba(41,158,255,.6) !important; }
  .score-flash-win.opp { border-color: rgba(15,255,199,.6) !important; }

  /* Progress */
  .progress-wrap { background: rgba(255,255,255,.06); border-radius: 99px; height: 3px; overflow: hidden; }
  .progress-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--blue), var(--cyan)); transition: width .4s ease; }

  /* Question area — takes remaining space */
  .question-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, rgba(20,20,20,.1) 0%, rgba(186,186,186,.06) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(20px);
    box-shadow: 0 4px 40px rgba(0,0,0,.5);
    padding: 24px;
  }
  .question-text {
    font-size: clamp(2.4rem, 12vw, 3.6rem);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.01em;
    text-align: center;
  }

  /* Answers */
  .answers-grid { display: flex; gap: 10px; }
  .answer-btn {
    flex: 1;
    background: rgba(255,255,255,.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 8px;
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
    text-align: center;
    min-height: 80px;
  }
  .answer-btn:active:not(.disabled) { transform: scale(.96); }
  .answer-btn:hover:not(.disabled):not(.correct):not(.wrong) {
    background: rgba(41,158,255,.08);
    border-color: rgba(41,158,255,.3);
    color: var(--blue);
  }
  .answer-btn.correct { background: var(--cyan-dim); border-color: rgba(15,255,199,.4); color: var(--cyan); }
  .answer-btn.wrong   { background: var(--red-dim);  border-color: rgba(255,80,80,.3);  color: var(--red); }
  .answer-btn.disabled { pointer-events: none; opacity: .45; }

  /* Status */
  .status-bar {
    text-align: center; font-size: .82rem; color: var(--muted);
    padding: 8px; border-radius: var(--radius); min-height: 36px;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    transition: color .2s;
  }
  .status-bar.correct { color: var(--cyan); }
  .status-bar.wrong   { color: var(--red); }
  .opp-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); animation: pulse 1s ease-in-out infinite; flex-shrink: 0; }
  @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.2} }

  /* ── GAME OVER ── */
  .result-card { text-align: center; padding: 28px 20px; }
  .result-icon { font-size: 3.2rem; margin-bottom: 10px; }
  .result-title { font-size: 1.6rem; font-weight: 700; }
  .result-title.win  { color: var(--blue); }
  .result-title.lose { color: var(--red); }
  .result-title.draw { color: var(--cyan); }
  .result-sub { color: var(--muted); font-size: .82rem; margin-top: 6px; }

  .final-row { display: flex; gap: 10px; }
  .final-card {
    flex: 1;
    background: rgba(255,255,255,.04);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 12px;
    text-align: center;
  }
  .final-card.winner { border-color: rgba(41,158,255,.35); background: rgba(41,158,255,.06); }
  .final-card .fc-name { font-size: .82rem; font-weight: 600; color: var(--muted); }
  .final-card .fc-score { font-size: 2.4rem; font-weight: 700; margin-top: 4px; color: var(--muted); }
  .final-card.winner .fc-score { color: var(--blue); }

  .rematch-hint { color: var(--muted); font-size: .78rem; text-align: center; min-height: 16px; }

  /* ── GOAL INDICATOR ── */
  .goal-bar {
    display: flex; gap: 4px; justify-content: center; align-items: center;
  }
  .goal-pip {
    width: 18px; height: 6px; border-radius: 3px;
    background: rgba(255,255,255,.1); transition: background .3s;
  }
  .goal-pip.filled-me  { background: rgba(41,158,255,.7); }
  .goal-pip.filled-opp { background: rgba(15,255,199,.7); }