/* ============================================================================
   Doodle Together — cozy theme
   A warm, soft, friendly coat of paint shared across every screen: auth,
   lobby, room/canvas, chat and Pictionary. Vanilla CSS, no build step.
   ========================================================================== */
:root {
  /* Warm cozy palette */
  --bg: #fdf3e7;
  --bg-2: #fff6ea;
  --ink: #463f3a;
  --muted: #8a8178;
  --accent: #ff8a5b;     /* warm peach   */
  --accent-2: #5b8def;   /* friendly blue */
  --accent-3: #ff6f91;   /* playful pink  */
  --good: #5fb86b;
  --gold: #f6b73c;
  --card: #fffdfa;
  --err: #d6455d;
  --line: #efe3d2;

  /* Soft, consistent shape + depth tokens */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;
  --shadow-sm: 0 3px 10px rgba(120, 80, 40, 0.08);
  --shadow-md: 0 8px 24px rgba(120, 80, 40, 0.12);
  --shadow-lg: 0 18px 50px rgba(120, 80, 40, 0.16);
  --ring: 0 0 0 3px rgba(91, 141, 239, 0.25);
  --ease: cubic-bezier(0.34, 1.56, 0.64, 1); /* gentle overshoot */

  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", "Segoe UI",
    system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over component display rules below. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  min-height: 100vh;
  background:
    radial-gradient(900px 600px at 12% -5%, #fff7ec 0%, transparent 55%),
    radial-gradient(800px 600px at 105% 10%, #ffe9dd 0%, transparent 50%),
    radial-gradient(700px 700px at 50% 120%, #ffeede 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* --- Top bar (signed in) --------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1.4rem;
  background: rgba(255, 253, 250, 0.78);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.01em; }

.whoami { display: flex; align-items: center; gap: 0.7rem; }
.hello { color: var(--muted); }
.hello strong { color: var(--ink); }

.icon-btn { padding: 0.5rem 0.65rem; font-size: 1rem; line-height: 1; }
#sound-toggle[aria-pressed="true"] {
  background: #fff0e6;
  box-shadow: inset 0 0 0 2px rgba(255, 138, 91, 0.4);
}

/* --- Stage ----------------------------------------------------------------- */
.stage {
  min-height: calc(100vh - 58px);
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

/* --- Cards: auth + lobby share the cozy card look ------------------------- */
.auth-card,
.lobby {
  background: var(--card);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.7);
  animation: pop-in 0.4s var(--ease) both;
}
.auth-card { width: min(100%, 390px); padding: 2.2rem 1.9rem 1.9rem; text-align: center; }
.lobby { width: min(100%, 580px); padding: 2.2rem 1.9rem; text-align: center; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.logo { font-size: 2rem; margin: 0 0 0.3rem; letter-spacing: -0.02em; }

.tagline { color: var(--muted); margin: 0 0 1.4rem; font-size: 0.98rem; }

.tabs {
  display: flex;
  gap: 0.3rem;
  background: #f5ece0;
  padding: 0.3rem;
  border-radius: 999px;
  margin-bottom: 1.3rem;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.55rem 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.1s;
}
.tab:hover { color: var(--ink); }
.tab.active {
  background: var(--card);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

form { display: grid; gap: 0.9rem; text-align: left; }

label { display: grid; gap: 0.35rem; font-size: 0.82rem; font-weight: 600; color: var(--muted); }

input {
  font: inherit;
  padding: 0.72rem 0.9rem;
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  background: #fffdf9;
  color: var(--ink);
  transition: border-color 0.18s, box-shadow 0.18s;
}
input:focus { outline: none; border-color: var(--accent-2); box-shadow: var(--ring); }
input::placeholder { color: #bcae9c; }

/* --- Buttons --------------------------------------------------------------- */
.btn {
  font: inherit;
  font-weight: 800;
  border: none;
  border-radius: var(--r-md);
  padding: 0.7rem 1.15rem;
  cursor: pointer;
  transition: transform 0.12s var(--ease), box-shadow 0.18s, background 0.18s, filter 0.18s;
}
.btn:active { transform: translateY(1px) scale(0.98); }

.btn.primary {
  margin-top: 0.3rem;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  box-shadow: 0 8px 20px rgba(255, 111, 145, 0.32);
}
.btn.primary:hover { filter: brightness(1.04); box-shadow: 0 10px 26px rgba(255, 111, 145, 0.42); }
.btn.primary:disabled { opacity: 0.6; cursor: progress; filter: none; }

.btn.ghost { background: #f4ebdf; color: var(--ink); }
.btn.ghost:hover { background: #ece0cf; }

/* --- Messages -------------------------------------------------------------- */
.msg { margin: 0.2rem 0 0; min-height: 1.1em; font-size: 0.88rem; }
.msg.err { color: var(--err); font-weight: 600; }

/* --- Lobby ----------------------------------------------------------------- */
.lobby h1 { margin: 0 0 0.3rem; font-size: 1.9rem; letter-spacing: -0.02em; }
.lobby h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.6rem;
}

.room-form { display: flex; gap: 0.6rem; margin-top: 0.4rem; }
.room-form input {
  flex: 1;
  font: inherit;
  padding: 0.72rem 0.9rem;
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  background: #fffdf9;
  color: var(--ink);
}
.room-form input:focus { outline: none; border-color: var(--accent-2); box-shadow: var(--ring); }
.room-form .btn { white-space: nowrap; }

.rooms-list { margin-top: 1.7rem; text-align: left; }
.rooms-list ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.room-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  font: inherit;
  font-weight: 700;
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  background: #fffdf9;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.18s, transform 0.12s var(--ease), box-shadow 0.18s;
}
.room-link::before { content: "🚪"; font-size: 1.05rem; }
.room-link:hover { border-color: var(--accent); transform: translateX(2px); box-shadow: var(--shadow-sm); }
.room-link:active { transform: translateX(2px) scale(0.99); }
.empty { color: var(--muted); font-size: 0.92rem; text-align: center; padding: 0.8rem 0; }

/* Loading skeleton rows for the room list. */
.skeleton {
  height: 44px;
  border-radius: var(--r-md);
  background: linear-gradient(100deg, #f3ebdf 30%, #faf3e8 50%, #f3ebdf 70%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* --- Room / canvas --------------------------------------------------------- */
.room {
  width: min(100%, 1120px);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-self: stretch;
  animation: pop-in 0.35s var(--ease) both;
}
.room-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.room-title { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }

.presence { display: flex; align-items: center; gap: 0.55rem; color: var(--muted); font-size: 0.92rem; }
.avatars { display: inline-flex; }
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 800;
  color: #fff;
  border: 2.5px solid var(--card);
  margin-left: -8px;
  box-shadow: var(--shadow-sm);
  animation: pop-in 0.3s var(--ease) both;
}
.avatar:first-child { margin-left: 0; }
.members-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }

/* --- Toolbar --------------------------------------------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  background: var(--card);
  padding: 0.6rem 0.9rem;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(255, 255, 255, 0.6);
}
.tool { display: flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.tool input[type="color"] {
  width: 36px; height: 36px;
  border: none; background: none; padding: 0; cursor: pointer; border-radius: 10px;
}
.tool input[type="range"] { cursor: pointer; accent-color: var(--accent); }

.swatches { display: flex; gap: 0.35rem; }
.swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s var(--ease), box-shadow 0.15s;
}
.swatch:hover { transform: scale(1.18); }
.swatch.active { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--accent-2); transform: scale(1.1); }

.tool-group { display: inline-flex; background: #f4ebdf; border-radius: 999px; padding: 3px; gap: 2px; }
.tool-btn {
  border: none;
  background: transparent;
  font-size: 1rem;
  line-height: 1;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s var(--ease);
}
.tool-btn:hover { transform: translateY(-1px); }
.tool-btn.active { background: var(--card); box-shadow: var(--shadow-sm); }

.brush-preview {
  display: inline-block;
  border-radius: 50%;
  background: var(--ink);
  min-width: 4px; min-height: 4px;
  transition: width 0.1s, height 0.1s, background 0.1s;
}

.conn { margin-left: auto; font-size: 0.84rem; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 0.4rem; }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.conn.ok { color: var(--good); }
.conn.ok .conn-dot { background: var(--good); box-shadow: 0 0 0 4px rgba(95, 184, 107, 0.18); animation: pulse 2s infinite; }
.conn.off { color: var(--err); }
.conn.off .conn-dot { background: var(--err); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

/* --- Canvas + chat layout -------------------------------------------------- */
.room-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 0.8rem;
  align-items: stretch;
  height: min(64vh, 620px);
}
.canvas-wrap {
  position: relative;
  background:
    linear-gradient(#fffdf9, #fffdf9) padding-box,
    repeating-linear-gradient(0deg, #fbf3e6 0 1px, transparent 1px 26px),
    repeating-linear-gradient(90deg, #fbf3e6 0 1px, transparent 1px 26px),
    #fffdf9;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255, 255, 255, 0.6);
  overflow: hidden;
  height: 100%;
}
#canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; position: relative; z-index: 1; }

/* Hint shown on a fresh, empty canvas; JS hides it once drawing begins. */
.canvas-hint {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 0.5rem 1rem;
  background: rgba(255, 253, 250, 0.85);
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  z-index: 2;
  text-align: center;
  transition: opacity 0.3s;
}

/* Live remote cursors overlay. */
/* Above the draw-lock (z 4) so a guesser can watch the drawer's live cursor. */
.cursors { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.remote-cursor {
  position: absolute;
  transform: translate(-2px, -2px);
  transition: left 0.08s linear, top 0.08s linear;
  will-change: left, top;
}
.remote-cursor .cur-dot {
  width: 14px; height: 14px;
  border-radius: 50% 50% 50% 2px;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
}
.remote-cursor .cur-name {
  position: absolute;
  left: 14px; top: 12px;
  font-size: 0.7rem;
  font-weight: 800;
  color: #fff;
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

/* --- Chat beside the canvas ----------------------------------------------- */
.chat {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255, 255, 255, 0.6);
  overflow: hidden;
  min-height: 0;
}
.chat-title { margin: 0; padding: 0.75rem 1rem; font-size: 1rem; font-weight: 800; border-bottom: 1px solid var(--line); }
.chat-log {
  list-style: none;
  margin: 0;
  padding: 0.75rem 1rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  scroll-behavior: smooth;
}
.chat-msg {
  font-size: 0.9rem;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  background: #f7f0e6;
  padding: 0.4rem 0.65rem;
  border-radius: 12px 12px 12px 4px;
  align-self: flex-start;
  max-width: 92%;
  animation: msg-in 0.22s var(--ease) both;
}
.chat-msg.me {
  align-self: flex-end;
  background: linear-gradient(135deg, #ffe7d9, #ffe0ea);
  border-radius: 12px 12px 4px 12px;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.chat-msg .chat-user { font-weight: 800; color: var(--accent-2); margin-right: 0.35rem; }
.chat-msg.me .chat-user { color: var(--accent); }
.chat-empty { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 1rem; margin: 0; }
.chat-form { display: flex; gap: 0.4rem; padding: 0.6rem; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; border: 2px solid var(--line); border-radius: var(--r-md); padding: 0.55rem 0.7rem; font: inherit; }
.chat-form input:focus { outline: none; border-color: var(--accent-2); box-shadow: var(--ring); }
.chat-form .btn { white-space: nowrap; padding: 0.55rem 0.9rem; }

/* --- Pictionary game panel ------------------------------------------------- */
.game {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.8rem;
  background: linear-gradient(135deg, #fff6ec, #fff0f4);
  padding: 0.7rem 1rem;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(255, 255, 255, 0.6);
}
.game-main { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; min-width: 0; }
.game .btn.primary { margin-top: 0; }
.game-status { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
.game-role { color: var(--muted); font-size: 0.92rem; font-weight: 600; }
.game-word { font-weight: 800; letter-spacing: 0.08em; font-size: 1.15rem; }
.game-word.reveal { color: var(--accent); }
.game-word.hint { color: var(--ink); font-family: ui-monospace, monospace; }
.game-timer { font-variant-numeric: tabular-nums; color: var(--accent-2); font-weight: 800; font-size: 0.92rem; }
.game-result {
  margin: 0;
  font-weight: 800;
  color: var(--good);
  font-size: 0.98rem;
  animation: pop-in 0.4s var(--ease) both;
}

.scoreboard { min-width: 160px; }
.scoreboard h4 {
  margin: 0 0 0.3rem;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.scoreboard ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.2rem; }
.scoreboard li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.18rem 0.45rem;
  border-radius: 8px;
}
.scoreboard li.me { background: #fff2e8; font-weight: 800; }
.score-pts { font-weight: 800; color: var(--accent); }

/* Overlay that blocks (and signals) drawing for non-drawers during a round. */
.draw-lock {
  position: absolute;
  inset: 0;
  z-index: 4;
  cursor: not-allowed;
  display: grid;
  place-items: start center;
  padding-top: 0.7rem;
  background: repeating-linear-gradient(
    45deg,
    rgba(91, 141, 239, 0.04),
    rgba(91, 141, 239, 0.04) 12px,
    rgba(91, 141, 239, 0.08) 12px,
    rgba(91, 141, 239, 0.08) 24px
  );
}
.draw-lock-badge {
  background: var(--accent-2);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

/* --- Toasts (join / leave / events) --------------------------------------- */
.toasts {
  position: fixed;
  top: 70px;
  right: 18px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--line);
  animation: toast-in 0.35s var(--ease) both;
}
.toast.leaving { animation: toast-out 0.3s ease forwards; }
.toast .toast-emoji { font-size: 1.05rem; }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px) scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(30px) scale(0.95); } }

/* The room view wants the full stage width, not centered. */
.stage:has(#room:not([hidden])) { place-items: start center; }

/* --- Responsive / mobile --------------------------------------------------- */
@media (max-width: 760px) {
  .topbar { padding: 0.6rem 1rem; }
  .brand { font-size: 1.05rem; }
  .hello { display: none; }
  .stage { padding: 1rem 0.7rem; }
  .room-body { grid-template-columns: 1fr; height: auto; }
  .canvas-wrap { height: min(52vh, 440px); }
  .chat { height: 300px; }
  .toolbar { gap: 0.6rem; padding: 0.55rem 0.7rem; }
  .conn { margin-left: 0; order: 99; width: 100%; }
  .members-text { max-width: 55vw; }
  .scoreboard { min-width: 130px; }
  .toasts { left: 12px; right: 12px; align-items: center; }
}
