/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg:       #0f1117;
  --surface:  #1a1d2e;
  --surface2: #232640;
  --border:   #2e3255;
  --text:     #e8eaf6;
  --muted:    #7b80a8;
  --accent:   #8b5cf6;
  --accent2:  #a78bfa;
  --red:    #cc2222;
  --green:  #3dc87a;
  --yellow: #f5c518;
  --blue:   #3a7bd5;
  --uno-red:    #e84040;
  --uno-yellow: #f5c518;
  --uno-green:  #2ecc71;
  --uno-blue:   #3a7bd5;
}
body.light {
  --bg:       #eef0f7;
  --surface:  #ffffff;
  --surface2: #f0f2fb;
  --border:   #dde0ef;
  --text:     #1a1b2e;
  --muted:    #6b6d8e;
  --accent:   #6d28d9;
  --accent2:  #7c3aed;
  --red:    #bb1111;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(139,92,246,0.06) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(167,139,250,0.04) 0%, transparent 50%);
  transition: background 0.3s, color 0.3s;
}
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input  { font-family: inherit; outline: none; }

/* ── Screens ─────────────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* ── Top bar ─────────────────────────────────────────────────────────────────── */
#top-bar {
  position: fixed; top: 0; right: 0;
  display: flex; gap: 8px; align-items: center;
  padding: 10px 16px; z-index: 100;
}
#theme-toggle {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 16px;
  color: var(--text); cursor: pointer;
}

/* ── Lobby ─────────────────────────────────────────────────────────────────── */
#screen-lobby { min-height: 100vh; justify-content: center; padding: 80px 16px 40px; }
.lobby-inner { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.lobby-title { text-align: center; margin-bottom: 8px; }
.lobby-title h1 { font-size: 2rem; font-weight: 700; }
.lobby-title p  { color: var(--muted); margin-top: 4px; }
.lobby-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.lobby-card h3 { font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.name-input, .room-code-input {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; color: var(--text); font-size: 1rem; width: 100%;
}
.name-input:focus, .room-code-input:focus { border-color: var(--accent2); }
.btn-primary {
  background: var(--accent); color: #fff;
  border-radius: 8px; padding: 11px 20px; font-size: 0.95rem; font-weight: 600; transition: opacity .15s;
}
.btn-primary:hover { opacity: .85; }
.btn-secondary {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 20px; font-size: 0.95rem; font-weight: 500; transition: background .15s;
}
.btn-secondary:hover { background: var(--border); }
.btn-join {
  background: var(--accent2); color: #fff;
  border-radius: 8px; padding: 10px 18px; font-size: 0.95rem; font-weight: 600;
  white-space: nowrap; transition: opacity .15s;
}
.btn-join:hover { opacity: .85; }
.room-code-row { display: flex; gap: 8px; }
.room-code-input { text-transform: uppercase; letter-spacing: 0.15em; font-weight: 700; }
#lobby-error { color: var(--red); font-size: 0.9rem; text-align: center; min-height: 1.2em; }

/* ── Waiting ─────────────────────────────────────────────────────────────────── */
#screen-waiting { min-height: 100vh; justify-content: center; }
.waiting-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 48px 40px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  max-width: 380px; width: 100%;
}
.spinner {
  width: 48px; height: 48px; border: 4px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.waiting-box h2 { font-size: 1.3rem; font-weight: 700; }
.waiting-box p  { color: var(--muted); font-size: 0.95rem; }
.room-code-display {
  font-size: 2rem; font-weight: 800; letter-spacing: 0.25em;
  color: var(--accent2); background: var(--surface2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 24px; text-align: center;
}
.room-share-hint { color: var(--muted); font-size: 0.85rem; }

/* ── Game layout ─────────────────────────────────────────────────────────────── */
#screen-game {
  min-height: 100vh; flex-direction: row; align-items: flex-start;
  justify-content: center; padding: 56px 16px 16px; gap: 20px;
}
.table-area { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 0 0 auto; }

/* ── Opponents ─────────────────────────────────────────────────────────────── */
.opp-area { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.opp-name { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.opp-name.active-turn { color: var(--accent2); }
.opp-info {
  font-size: 0.72rem; color: var(--muted); padding: 1px 7px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 5px;
}
.opp-info.uno-alert { color: #e84040; border-color: #e84040; font-weight: 700; }
.middle-row { display: flex; flex-direction: row; align-items: center; gap: 16px; }
.opp-side { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 72px; }

/* ── Face-down fan ─────────────────────────────────────────────────────────── */
.fan-hand { display: flex; position: relative; }
.fan-hand .uno-card { margin-left: -28px; }
.fan-hand .uno-card:first-child { margin-left: 0; }

/* ── Center zone ─────────────────────────────────────────────────────────────── */
.center-zone {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: rgba(139,92,246,0.05); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 20px; min-width: 180px;
}
.piles-row { display: flex; flex-direction: row; align-items: center; gap: 20px; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pile-label { font-size: 0.72rem; color: var(--muted); font-weight: 600; }
.discard-wrap { position: relative; }
.wild-color-ring {
  position: absolute; inset: -4px; border-radius: 13px;
  border: 4px solid transparent; pointer-events: none; z-index: 1;
}
.wild-color-ring.c0 { border-color: var(--uno-red); }
.wild-color-ring.c1 { border-color: var(--uno-yellow); }
.wild-color-ring.c2 { border-color: var(--uno-green); }
.wild-color-ring.c3 { border-color: var(--uno-blue); }
.direction-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
#deck-pile { cursor: pointer; transition: opacity .15s; }
#deck-pile.drawable:hover { opacity: .8; }
#deck-pile.drawable { cursor: pointer; }

/* ── My area ─────────────────────────────────────────────────────────────────── */
.my-area { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 4px; }
.my-name { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.my-name.active-turn { color: var(--accent2); }
#my-hand {
  display: flex; flex-wrap: wrap; gap: 4px; justify-content: center;
  max-width: 700px; min-height: 90px; padding: 4px 0;
}

/* ── Action row ─────────────────────────────────────────────────────────────── */
#action-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  justify-content: center; min-height: 44px; padding: 4px 0;
}
#btn-draw-card {
  background: var(--accent); color: #fff;
  border-radius: 8px; padding: 9px 22px; font-size: 0.95rem; font-weight: 600; transition: opacity .15s;
}
#btn-draw-card:hover { opacity: .85; }
#btn-pass-turn {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 22px; font-size: 0.95rem; font-weight: 600; transition: background .15s;
}
#btn-pass-turn:hover { background: var(--border); }
.color-pick-label { font-size: 0.85rem; color: var(--muted); }
#color-picker { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.color-btn {
  border-radius: 8px; padding: 8px 14px; font-size: 0.85rem; font-weight: 700;
  color: #fff; transition: transform .1s; border: 2px solid transparent;
}
.color-btn:hover { transform: scale(1.1); }
.cbtn-red    { background: var(--uno-red); }
.cbtn-yellow { background: var(--uno-yellow); color: #1a1a1a; }
.cbtn-green  { background: var(--uno-green); }
.cbtn-blue   { background: var(--uno-blue); }

/* ── UNO card ─────────────────────────────────────────────────────────────────── */
.uno-card {
  width: 58px; height: 88px; border-radius: 9px;
  position: relative; display: flex; align-items: center; justify-content: center;
  user-select: none; flex-shrink: 0; cursor: default;
  border: 2px solid rgba(255,255,255,0.25);
  transition: transform .15s, box-shadow .15s;
  font-weight: 900;
}
.uno-card.back {
  background: repeating-linear-gradient(135deg,#2a1060,#2a1060 4px,#3a1880 4px,#3a1880 8px);
  border-color: var(--accent2);
}
.uno-card.back::after { content: 'UNO'; font-size: 10px; font-weight: 900; color: var(--accent2); }
.uno-card.c0 { background: var(--uno-red);    color: #fff; }
.uno-card.c1 { background: var(--uno-yellow); color: #1a1a1a; }
.uno-card.c2 { background: var(--uno-green);  color: #fff; }
.uno-card.c3 { background: var(--uno-blue);   color: #fff; }
.uno-card.cwild {
  background: conic-gradient(var(--uno-red) 25%, var(--uno-yellow) 25% 50%, var(--uno-green) 50% 75%, var(--uno-blue) 75%);
  color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.uno-card .u-tl {
  position: absolute; top: 4px; left: 5px;
  font-size: 11px; font-weight: 900; line-height: 1;
}
.uno-card .u-br {
  position: absolute; bottom: 4px; right: 5px;
  font-size: 11px; font-weight: 900; line-height: 1;
  transform: rotate(180deg);
}
.uno-card .u-mid { font-size: 24px; font-weight: 900; }
.uno-card.valid { cursor: pointer; }
.uno-card.valid:hover { transform: translateY(-12px); box-shadow: 0 6px 16px rgba(139,92,246,.5); border-color: var(--accent2); }
.uno-card.dimmed { opacity: .35; }

/* ── Side panel ─────────────────────────────────────────────────────────────── */
.side-panel {
  display: flex; flex-direction: column; gap: 12px;
  width: 220px; flex-shrink: 0;
}
.panel-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.panel-card h4 {
  font-size: 0.75rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px;
}
#score-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
#score-table th { color: var(--muted); font-weight: 600; text-align: left; padding: 2px 4px; font-size: 0.75rem; }
#score-table td { padding: 3px 4px; border-top: 1px solid var(--border); }
#score-table tr.me td { color: var(--accent2); font-weight: 700; }
#status-text { font-size: 0.9rem; color: var(--text); min-height: 1.4em; line-height: 1.4; }
#last-action-text { font-size: 0.82rem; color: var(--muted); min-height: 1.2em; line-height: 1.4; }
.ctrl-btn {
  width: 100%; border-radius: 8px; padding: 9px 14px;
  font-size: 0.88rem; font-weight: 600; transition: opacity .15s;
}
.ctrl-btn.danger {
  background: rgba(232,64,64,0.15); color: var(--red); border: 1px solid rgba(232,64,64,0.3);
}
.ctrl-btn.danger:hover { background: rgba(232,64,64,0.25); }

/* ── Result overlay ─────────────────────────────────────────────────────────── */
#uno-result {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.72); z-index: 200;
  align-items: center; justify-content: center;
}
#uno-result.visible { display: flex; }
.result-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px 48px;
  display: flex; flex-direction: column; align-items: center; gap: 20px; min-width: 320px;
}
.result-title { font-size: 1.8rem; font-weight: 800; }
.result-scores { width: 100%; }
.result-scores table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.result-scores th { color: var(--muted); padding: 4px 8px; text-align: left; font-size: 0.8rem; }
.result-scores td { padding: 5px 8px; border-top: 1px solid var(--border); }
.result-scores tr.winner td { color: var(--green); font-weight: 700; }
.result-scores tr.me td { color: var(--accent2); }
.result-btns { display: flex; gap: 12px; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  #screen-game { flex-direction: column; align-items: center; }
  .side-panel { width: 100%; max-width: 520px; flex-direction: row; flex-wrap: wrap; }
  .panel-card { flex: 1 1 160px; }
}
