/* ============================================================
   Doodle — modern UI
   ============================================================ */
:root {
  --bg-1: #1e1b4b;
  --bg-2: #4338ca;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #6366f1;
  --primary-600: #4f46e5;
  --accent: #8b5cf6;
  --success: #22c55e;
  --success-bg: #dcfce7;
  --warn-bg: #fef9c3;
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .08);
  --shadow: 0 4px 14px rgba(15, 23, 42, .10);
  --shadow-lg: 0 18px 50px rgba(15, 23, 42, .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2));
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; }
input { font-family: inherit; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 15px; font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease, opacity .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.big { padding: 15px; font-size: 18px; width: 100%; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; border: none;
  box-shadow: 0 6px 18px rgba(99, 102, 241, .45);
}
.btn-primary:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--primary), var(--accent)); }
.btn[disabled] { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }

/* ---------- Landing ---------- */
.landing { display: grid; place-items: center; padding: 20px; min-height: 100dvh; }
.card {
  background: var(--surface);
  width: min(460px, 100%);
  border-radius: 24px;
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
.logo { font-size: 40px; font-weight: 800; margin: 0; text-align: center; letter-spacing: -.5px; }
.tagline { text-align: center; color: var(--muted); margin: 8px 0 26px; font-size: 16px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.field input {
  width: 100%; padding: 13px 14px; font-size: 16px;
  border: 1px solid var(--surface-3); border-radius: var(--radius-sm);
  background: var(--surface-2); transition: border .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.18); background: #fff; }
.field.row { display: flex; gap: 8px; }
.field.row input { flex: 1; }
.divider { text-align: center; color: var(--muted); margin: 22px 0; position: relative; font-size: 14px; }
.divider::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--border); }
.divider span { background: var(--surface); padding: 0 12px; position: relative; }
.error { color: var(--danger); text-align: center; font-size: 14px; }
.how { color: var(--muted); font-size: 14px; line-height: 1.6; margin-top: 26px; padding-left: 18px; }
.how li { margin-bottom: 4px; }

/* ============================================================
   Room — mobile-first flex column
   ============================================================ */
.room { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

/* Top bar */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
  z-index: 5;
}
.timer {
  flex: 0 0 auto;
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: grid; place-items: center;
  font-size: 20px; font-weight: 800;
  box-shadow: 0 4px 12px rgba(99,102,241,.4);
}
.topbar .center { flex: 1; min-width: 0; text-align: center; }
.round { font-size: 13px; color: var(--muted); font-weight: 600; }
.word {
  font-size: 22px; min-height: 28px; font-weight: 700;
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; align-items: flex-end;
}
.word .w { display: inline-flex; gap: 5px; }
.word .l {
  border-bottom: 3px solid var(--text); min-width: 15px; text-align: center;
  line-height: 1.1; text-transform: uppercase;
}
.word .l.revealed { border-color: var(--primary); color: var(--primary); }
.word .count { font-size: 12px; font-weight: 600; color: var(--muted); width: 100%; }

/* Main area */
.game { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* Players strip */
.players {
  flex: 0 0 auto; order: 1;
  display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden;
  padding: 8px 10px; scrollbar-width: thin;
}
.pcard {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: 12px; padding: 6px 10px 6px 6px;
  box-shadow: var(--shadow-sm); position: relative; min-width: 120px;
}
.pcard.you { box-shadow: 0 0 0 2px var(--primary), var(--shadow-sm); }
.pcard.drawer { background: var(--warn-bg); }
.pcard.guessed { background: var(--success-bg); }
.pcard.offline { opacity: .45; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
}
.pinfo { min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.pname { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.pscore { font-size: 12px; color: var(--muted); }
.pbadge { position: absolute; top: -6px; right: -4px; font-size: 14px; }

/* Stage (canvas + tools) */
.stage { order: 2; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 0 10px; }
.canvas-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: grid; place-items: center; overflow: hidden; padding: 6px 0; }
#canvas {
  /* Display size is set in JS (fitCanvas) so it always fits the wrapper. */
  display: block;
  background: #fff; border-radius: 14px; touch-action: none;
  box-shadow: var(--shadow);
  cursor: crosshair;
}

/* Overlay (modal) */
.overlay {
  position: absolute; inset: 6px; border-radius: 14px;
  background: rgba(15, 16, 38, .82); backdrop-filter: blur(4px); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; text-align: center; padding: 22px; z-index: 3; overflow: auto;
}
.overlay[hidden] { display: none; }
.overlay h2 { font-size: 24px; margin: 0; font-weight: 800; }
.overlay p { font-size: 15px; margin: 0; color: #cbd5e1; }
.overlay .choices { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.overlay .choices .btn { font-size: 17px; padding: 14px 18px; }
.overlay .scoreboard { width: min(360px, 92%); display: flex; flex-direction: column; gap: 2px; }
.overlay .scorerow { display: flex; justify-content: space-between; font-size: 16px; padding: 8px 4px; border-bottom: 1px solid rgba(255,255,255,.14); }
.overlay .invite-link {
  background: rgba(255,255,255,.12); color: #fff; padding: 11px 14px; border-radius: 10px;
  font-size: 14px; word-break: break-all; width: min(420px, 94%); border: 1px solid rgba(255,255,255,.18);
}

/* Tools */
.tools {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 8px; margin-bottom: 6px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-sm);
  overflow-x: auto; scrollbar-width: thin;
}
.tools[hidden] { display: none; }
.swatches { display: flex; gap: 5px; flex: 0 0 auto; }
.swatch { width: 26px; height: 26px; border-radius: 7px; flex: 0 0 auto; border: 1px solid rgba(15,23,42,.15); cursor: pointer; transition: transform .08s; }
.swatch:hover { transform: scale(1.1); }
.swatch.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--primary); }
.sizes { display: flex; gap: 8px; align-items: center; flex: 0 0 auto; padding: 0 4px; }
.sizedot { background: var(--text); border-radius: 50%; cursor: pointer; border: 2px solid transparent; flex: 0 0 auto; }
.sizedot.sel { border-color: var(--primary); }
.tools .btn { flex: 0 0 auto; }

/* Chat */
.chat {
  order: 3; flex: 0 0 auto;
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 14px rgba(15,23,42,.12); margin-top: 6px; overflow: hidden;
}
.chat-toggle {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2); color: var(--muted);
  font-size: 13px; font-weight: 700; padding: 7px 12px;
  border-bottom: 1px solid var(--border);
}
.chat-toggle .chev { transition: transform .2s ease; }
.chat.collapsed .chev { transform: rotate(-90deg); }
.chat.collapsed .messages { display: none; }
.messages {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  /* Bounded on mobile/tablet so the chat never grows over the canvas. */
  max-height: 22dvh;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 5px; font-size: 14px;
  -webkit-overflow-scrolling: touch;
}
.msg { line-height: 1.35; word-wrap: break-word; }
.msg .who { font-weight: 700; }
.msg.system { color: var(--muted); }
.msg.system.correct { color: #16a34a; font-weight: 700; }
.msg.system.info { color: var(--primary-600); }
.msg.system.join { color: var(--primary); }
.msg.system.leave { color: var(--danger); }
.msg.system.close { color: var(--danger); font-weight: 700; }
.msg.insider { background: var(--warn-bg); border-radius: 8px; padding: 2px 6px; align-self: flex-start; }
.guessform { flex: 0 0 auto; border-top: 1px solid var(--border); padding: 10px; display: flex; gap: 8px; background: var(--surface); }
.guessform input { flex: 1; min-width: 0; padding: 12px 14px; font-size: 15px; border: 1px solid var(--surface-3); border-radius: 12px; background: var(--surface-2); }
.guessform input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.18); background: #fff; }
.guessform input:disabled { background: var(--surface-2); color: var(--muted); }
.guessform #sendbtn { padding: 12px 18px; }
.guessform #sendbtn:not([disabled]) { background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; }

/* Name gate (shown to link-joiners before connecting) */
.namegate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 20px;
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2));
}
.namecard {
  background: var(--surface); width: min(380px, 100%);
  border-radius: 20px; padding: 28px; text-align: center;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 14px;
}
.namecard h2 { margin: 0; font-size: 24px; font-weight: 800; }
.namecard p { margin: 0; color: var(--muted); font-size: 15px; }
.namecard input {
  padding: 13px 14px; font-size: 17px; text-align: center;
  border: 1px solid var(--surface-3); border-radius: 12px; background: var(--surface-2);
}
.namecard input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.18); background: #fff; }

/* ============================================================
   Desktop — three columns
   ============================================================ */
@media (min-width: 860px) {
  .game {
    flex-direction: row;
    display: grid;
    grid-template-columns: 230px 1fr 320px;
    gap: 12px; padding: 12px;
  }
  .players {
    order: 0; flex-direction: column; overflow-x: hidden; overflow-y: auto;
    padding: 0; gap: 8px; background: transparent;
  }
  .pcard { min-width: 0; width: 100%; }
  .pname { max-width: 150px; }
  .stage { order: 0; padding: 0; }
  .chat {
    order: 0; height: auto; border-radius: 16px;
    box-shadow: var(--shadow); margin-top: 0;
  }
  .chat-toggle { display: none; }       /* always expanded on desktop */
  .chat.collapsed .messages { display: flex; }
  .messages { max-height: none; }       /* fill the column on desktop */
  .word { font-size: 26px; }
  .word .l { min-width: 17px; }
}

@media (min-width: 860px) {
  .topbar { padding: 12px 18px; }
}
