/* ══════════════════════════════════════════════════════════
   RESET & BASE
══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f1a;
  --surface:   #1a1a2e;
  --surface2:  #16213e;
  --border:    #2a2a4a;
  --accent:    #e94560;
  --accent2:   #0f3460;
  --text:      #e8e8f0;
  --text-dim:  #8888aa;
  --green:     #4ade80;
  --yellow:    #facc15;
  --blue:      #60a5fa;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,0.5);
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* ══════════════════════════════════════════════════════════
   SCREENS
══════════════════════════════════════════════════════════ */
.screen { width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; }
.screen.hidden { display: none !important; }
.hidden { display: none !important; }

/* ══════════════════════════════════════════════════════════
   LOBBY
══════════════════════════════════════════════════════════ */
.lobby-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 480px;
  max-width: 95vw;
  box-shadow: var(--shadow);
}

.logo {
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  text-align: center;
  color: var(--text);
}
.logo-o { color: var(--accent); }
.tagline { text-align: center; color: var(--text-dim); margin-bottom: 1.5rem; font-size: 0.9rem; }

.input-group { margin-bottom: 1rem; }
.input-group label, .setting label { display: block; font-size: 0.8rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); margin-bottom: 0.4rem; }
.hint { font-weight: 400; text-transform: none; letter-spacing: 0; }

input[type="text"], input[type="color"], select, textarea {
  width: 100%; padding: 0.6rem 0.8rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 0.95rem;
  outline: none; transition: border-color 0.2s;
}
input[type="text"]:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; font-family: inherit; }

.lobby-switch {
  text-align: center; margin-top: 0.75rem; font-size: 0.82rem; color: var(--text-dim);
}
.direct-join-msg {
  font-size: 0.95rem; color: var(--text-dim); margin-bottom: 1.25rem; text-align: center;
}
.invite-copied {
  font-size: 0.78rem; color: var(--green); text-align: center; margin-top: 0.3rem;
}
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: inherit; padding: 0; text-decoration: underline;
}
.link-btn:hover { color: #c73652; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.75rem; margin-bottom: 0.75rem; }
.setting { margin-bottom: 0.75rem; }
.custom-words-section label { margin-bottom: 0.4rem; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; text-transform: none; letter-spacing: 0; font-size: 0.9rem; color: var(--text); }

.error-msg { background: rgba(233,69,96,0.15); border: 1px solid var(--accent);
  border-radius: 6px; padding: 0.5rem 0.75rem; color: var(--accent); font-size: 0.85rem; margin-top: 0.75rem; }

/* ══════════════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.65rem 1.4rem; border: none; border-radius: 8px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all 0.15s;
  width: 100%; margin-top: 0.5rem;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #c73652; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-ghost:hover { border-color: var(--text-dim); color: var(--text); }
.btn-sm { padding: 0.4rem 0.9rem; font-size: 0.85rem; width: auto; margin-top: 0; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.75rem; width: auto; margin-top: 0; }

/* ══════════════════════════════════════════════════════════
   WAITING ROOM
══════════════════════════════════════════════════════════ */
.waiting-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 2rem; width: 440px; max-width: 95vw; box-shadow: var(--shadow);
}
.waiting-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.waiting-header h2 { font-size: 1.4rem; }

.room-code-display {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.75rem 1rem; display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem;
}
.room-code-label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.room-code-value { font-size: 1.6rem; font-weight: 900; letter-spacing: 0.15em; color: var(--accent); flex: 1; }

.waiting-info { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.75rem; }

.waiting-player-list { list-style: none; margin-bottom: 1.25rem; display: flex; flex-direction: column; gap: 0.4rem; }
.waiting-player-list li {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem;
  background: var(--bg); border-radius: 6px; font-size: 0.9rem;
}
.waiting-player-list .crown { font-size: 0.8rem; }

.waiting-status { font-size: 0.85rem; color: var(--text-dim); text-align: center; margin-top: 0.5rem; }

/* ══════════════════════════════════════════════════════════
   GAME SCREEN — TOP BAR
══════════════════════════════════════════════════════════ */
#game-screen {
  display: flex; flex-direction: column; align-items: stretch;
  height: 100vh; overflow: hidden; padding: 0;
}
#game-screen.hidden { display: none !important; }

#game-topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem; height: 52px; flex-shrink: 0; gap: 1rem;
}
#topbar-round { font-size: 0.85rem; color: var(--text-dim); white-space: nowrap; min-width: 90px; }
#topbar-word { flex: 1; text-align: center; }

.word-display {
  font-size: 1.35rem; font-weight: 700; letter-spacing: 0.12em;
  color: var(--text); font-family: 'Courier New', monospace;
}

#topbar-timer { display: flex; align-items: center; gap: 0.5rem; min-width: 70px; justify-content: flex-end; }

.timer-ring { width: 36px; height: 36px; transform: rotate(-90deg); }
.timer-bg  { fill: none; stroke: var(--border); stroke-width: 3; }
.timer-arc { fill: none; stroke: var(--accent); stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.9s linear, stroke 0.3s;
}
.timer-arc.low { stroke: var(--accent); }
.timer-arc.critical { stroke: #ff4444; }
.timer-number { font-size: 1rem; font-weight: 700; min-width: 24px; text-align: right; }

/* ══════════════════════════════════════════════════════════
   GAME SCREEN — 3-COLUMN LAYOUT
══════════════════════════════════════════════════════════ */
#game-layout {
  display: grid;
  grid-template-columns: 180px 1fr 260px;
  flex: 1; min-height: 0; overflow: hidden;
}

/* ── Player Panel ── */
#player-panel {
  background: var(--surface2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-title {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim); padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#player-list { list-style: none; overflow-y: auto; flex: 1; padding: 0.4rem 0; }
#player-list li {
  display: flex; align-items: center; gap: 0.4rem; padding: 0.45rem 0.75rem;
  font-size: 0.85rem; border-bottom: 1px solid rgba(255,255,255,0.04); position: relative;
}
#player-list li.is-drawer { background: rgba(233,69,96,0.08); }
#player-list li.has-guessed { color: var(--green); }
.player-rank { font-size: 0.7rem; color: var(--text-dim); min-width: 16px; }
.player-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-score { font-size: 0.8rem; font-weight: 700; color: var(--text-dim); }
.player-icon { font-size: 0.75rem; }
.player-drawing-badge {
  font-size: 0.65rem; background: var(--accent); color: #fff;
  border-radius: 3px; padding: 1px 4px; flex-shrink: 0;
}
.player-guessed-badge {
  font-size: 0.7rem; color: var(--green); flex-shrink: 0;
}

/* ── Canvas Panel ── */
#canvas-panel {
  display: flex; flex-direction: column; align-items: center;
  padding: 0.5rem; gap: 0.5rem; overflow: hidden; background: var(--bg);
}
#canvas-wrapper {
  position: relative; flex: 1; width: 100%; min-height: 0;
  display: flex; align-items: center; justify-content: center;
}
#game-canvas {
  background: #fff; border-radius: 4px;
  max-width: 100%; max-height: 100%;
  cursor: crosshair;
  box-shadow: 0 2px 16px rgba(0,0,0,0.4);
  touch-action: none;
}
#game-canvas.not-drawing { cursor: default; }

.canvas-overlay-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(15,15,26,0.7); border-radius: 4px;
  font-size: 1.5rem; font-weight: 700; color: var(--text); text-align: center; padding: 1rem;
}

/* ── Toolbar ── */
.toolbar {
  display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.4rem 0.6rem; width: 100%;
}
.tool-divider { width: 1px; height: 28px; background: var(--border); margin: 0 0.2rem; }

#tool-buttons { display: flex; gap: 0.3rem; }
.tool-btn {
  width: 34px; height: 34px; border: 1px solid transparent;
  border-radius: 6px; background: transparent; color: var(--text);
  cursor: pointer; font-size: 1rem; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.tool-btn:hover { background: var(--border); }
.tool-btn.active { background: var(--accent2); border-color: var(--accent); }

.color-palette { display: flex; gap: 0.25rem; flex-wrap: wrap; max-width: 200px; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; transition: transform 0.1s, border-color 0.1s;
  flex-shrink: 0;
}
.swatch:hover { transform: scale(1.2); }
.swatch.active { border-color: #fff; transform: scale(1.15); }

#color-picker { width: 34px; height: 34px; padding: 2px; border-radius: 6px; cursor: pointer; flex-shrink: 0; }

#size-buttons { display: flex; gap: 0.3rem; align-items: center; }
.size-btn {
  width: 34px; height: 34px; border: 1px solid transparent; border-radius: 6px;
  background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.size-btn:hover { background: var(--border); }
.size-btn.active { background: var(--accent2); border-color: var(--accent); }
.size-btn span { background: #e8e8f0; border-radius: 50%; display: block; }

/* ── Chat Panel ── */
#chat-panel {
  background: var(--surface2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 0.5rem 0.6rem;
  display: flex; flex-direction: column; gap: 0.2rem;
}
.chat-msg {
  padding: 0.25rem 0.4rem; border-radius: 4px; font-size: 0.82rem; line-height: 1.4;
  word-break: break-word;
}
.chat-msg .msg-name { font-weight: 700; margin-right: 0.3rem; }
.chat-msg.type-system { color: var(--text-dim); font-style: italic; font-size: 0.78rem; }
.chat-msg.type-correct { background: rgba(74,222,128,0.12); color: var(--green); font-weight: 600; }
.chat-msg.type-close   { background: rgba(250,204,21,0.1);  color: var(--yellow); }
.chat-msg.type-guess   { color: var(--text); }
.chat-msg.type-chat    { color: var(--text); }

/* Reaction bar */
.reaction-bar {
  display: flex; gap: 0.3rem; justify-content: center;
  padding: 0.35rem 0.5rem; border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.reaction-btn {
  font-size: 1.35rem; background: transparent;
  border: 1px solid transparent; border-radius: 8px;
  padding: 0.2rem 0.35rem; cursor: pointer; line-height: 1;
  transition: transform 0.1s, background 0.12s;
}
.reaction-btn:hover  { background: var(--surface); transform: scale(1.2); }
.reaction-btn:active { transform: scale(0.88); }

/* Floating reaction animation */
.floating-reaction {
  position: fixed; font-size: 2.2rem;
  pointer-events: none; z-index: 500;
  animation: floatUp 2s ease-out forwards;
}
@keyframes floatUp {
  0%   { opacity: 1; transform: translateY(0)     scale(1);   }
  40%  { opacity: 1; transform: translateY(-70px)  scale(1.4); }
  100% { opacity: 0; transform: translateY(-150px) scale(0.7); }
}

.chat-input-row {
  display: flex; gap: 0.4rem; padding: 0.5rem 0.5rem;
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.chat-input-row input { flex: 1; }
.chat-input-row .btn { width: auto; margin-top: 0; }

/* ══════════════════════════════════════════════════════════
   OVERLAYS
══════════════════════════════════════════════════════════ */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(4px);
}
.overlay.hidden { display: none !important; }

.overlay-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem 2.5rem;
  min-width: 340px; max-width: 500px; text-align: center;
  box-shadow: var(--shadow);
}
.overlay-card h2 { font-size: 1.6rem; margin-bottom: 0.5rem; }
.overlay-sub { color: var(--text-dim); margin-bottom: 1rem; }

.word-choice-buttons { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1rem; }
.word-choice-btn {
  padding: 0.8rem 1.5rem; background: var(--accent2); border: 1px solid var(--accent);
  border-radius: 8px; color: var(--text); font-size: 1.1rem; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
}
.word-choice-btn:hover { background: var(--accent); }

.revealed-word {
  font-size: 2rem; font-weight: 900; letter-spacing: 0.1em; color: var(--accent);
  margin: 0.5rem 0 1.25rem; font-family: 'Courier New', monospace;
}

.score-list {
  list-style: none; margin: 1rem 0; display: flex; flex-direction: column; gap: 0.4rem;
  text-align: left;
}
.score-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.45rem 0.75rem; background: var(--bg); border-radius: 6px; font-size: 0.9rem;
}
.score-list li.first  { border-left: 3px solid var(--yellow); }
.score-list li.second { border-left: 3px solid #aaa; }
.score-list li.third  { border-left: 3px solid #cd7f32; }
.score-rank { font-size: 0.8rem; color: var(--text-dim); min-width: 24px; }
.score-name { flex: 1; }
.score-pts  { font-weight: 700; color: var(--accent); }

.winner-banner {
  background: linear-gradient(135deg, #f59e0b, #e94560);
  border-radius: 8px; padding: 0.75rem 1.25rem;
  font-size: 1.15rem; font-weight: 700; margin-bottom: 1rem;
}

/* ══════════════════════════════════════════════════════════
   SHAPES DROPDOWN
══════════════════════════════════════════════════════════ */
.shapes-dropdown {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem;
  box-shadow: 0 -4px 28px rgba(0,0,0,0.6);
  z-index: 300;
}
/* small downward caret */
.shapes-dropdown::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: var(--border);
  pointer-events: none;
}
.shapes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.3rem;
}
.shape-opt {
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface2);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
}
.shape-opt:hover { background: var(--accent2); border-color: var(--accent); }
.shape-opt.active { background: var(--accent2); border-color: var(--accent); color: #fff; }

/* ══════════════════════════════════════════════════════════
   WAITING ROOM — CATEGORY PICKER
══════════════════════════════════════════════════════════ */

.cat-picker {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
}

.cat-picker-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.5rem;
}

.cat-picker-label {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--text-dim);
}

.cat-winner-badge {
  font-size: 0.78rem; font-weight: 700; color: var(--accent);
  background: rgba(233,69,96,0.12); border: 1px solid rgba(233,69,96,0.3);
  border-radius: 4px; padding: 0.15rem 0.5rem;
}

.cat-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
}

.cat-btn {
  padding: 0.35rem 0.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-dim);
  font-size: 0.7rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  line-height: 1.3;
  position: relative;
}

.cat-btn:hover { border-color: var(--text-dim); color: var(--text); }

.cat-btn.my-vote {
  background: var(--accent2);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 700;
}

.cat-btn.leading {
  border-color: var(--green);
  color: var(--green);
}

.cat-btn.my-vote.leading {
  background: rgba(74,222,128,0.15);
  border-color: var(--green);
  color: var(--green);
}

.cat-vote-pill {
  display: inline-block;
  background: rgba(255,255,255,0.12);
  border-radius: 3px;
  padding: 0 3px;
  font-size: 0.6rem;
  font-weight: 700;
  margin-left: 2px;
  vertical-align: middle;
}

.cat-btn.my-vote .cat-vote-pill { background: rgba(233,69,96,0.3); }
.cat-btn.leading .cat-vote-pill  { background: rgba(74,222,128,0.25); color: var(--green); }

/* ══════════════════════════════════════════════════════════
   SCROLLBAR STYLING
══════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
