/* =====================================================================
   StudyPaws stylesheet
   1. Tokens          5. Lobby           9. History
   2. Base            6. Study room     10. Admin
   3. Layout & nav    7. Tasks          11. Login
   4. Components      8. Shop           12. Small screens & motion
   ===================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  --paper: #f6f4fb;
  --surface: #ffffff;
  --ink: #2b2540;
  --ink-soft: #5f5777;
  --line: #e2dcef;
  --lav: #c3b1e1;
  --lav-deep: #6d58a8;
  --lav-wash: #ece5f6;
  --lamp: #ffcf5c;
  --lamp-wash: #fff4d6;
  --mint: #1d6a4c; /* dark enough for 4.5:1 text on --mint-wash */
  --mint-wash: #ddf2e8;
  --coral: #b93f3f;
  --coral-wash: #fbe4e4;

  --font-display: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --radius-panel: 18px;
  --radius-control: 10px;
  --shadow-panel: 0 1px 0 rgba(43, 37, 64, 0.04), 0 8px 24px -12px rgba(43, 37, 64, 0.18);
  --page-width: 1120px;
}

/* ---------- 2. Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  margin: 0 0 0.4em;
}

h1 { font-size: clamp(1.7rem, 3.5vw, 2.3rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

p { margin: 0 0 1em; }

a { color: var(--lav-deep); }

img, svg { max-width: 100%; }

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--lav-deep);
  outline-offset: 2px;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted { color: var(--ink-soft); }
.small { font-size: 0.875rem; }

/* ---------- 3. Layout & nav ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(246, 244, 251, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--ink);
  text-decoration: none;
}

.brand img { width: 40px; height: 40px; display: block; }

.nav {
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav a {
  display: block;
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
}

.nav a:hover { color: var(--ink); background: var(--lav-wash); }
.nav a[aria-current='page'] { color: var(--ink); background: var(--lav); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.points-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 8px;
  border-radius: 999px;
  background: var(--lamp-wash);
  border: 1px solid #f2dd9c;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.points-pill svg { width: 18px; height: 18px; }

.topbar .nav-toggle { display: none; }

.page {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 22px;
}

.page-head p { margin: 0; color: var(--ink-soft); max-width: 60ch; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
  padding: 20px;
}

.panel + .panel { margin-top: 18px; }

.panel-head {
  flex-wrap: wrap;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 { margin: 0; }

/* ---------- 4. Components ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--lav-wash);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn:hover { background: var(--lav); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--lav-deep); color: #fff; }
.btn-primary:hover { background: #5a4691; }

.btn-lamp { background: var(--lamp); color: var(--ink); }
.btn-lamp:hover { background: #f5c13d; }

.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--lav-wash); }

.btn-danger { background: var(--coral-wash); color: var(--coral); }
.btn-danger:hover { background: #f6cccc; }

.btn-small { padding: 5px 12px; font-size: 0.875rem; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.chip[aria-pressed='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 700;
  font-size: 0.9rem;
}

.field input,
.field select,
.field textarea {
  padding: 10px 12px;
  border-radius: var(--radius-control);
  border: 1px solid #cfc6e2;
  background: #fff;
  font-weight: 400;
  font-size: 1rem;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--lav-deep);
}

.field .hint { font-weight: 400; color: var(--ink-soft); font-size: 0.82rem; }

.form-error {
  min-height: 1.4em;
  margin: 8px 0 0;
  color: var(--coral);
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--lav-wash);
  color: var(--lav-deep);
}

.badge-quiet { background: #e4eef7; color: #2f5c85; }
.badge-discussion { background: var(--lamp-wash); color: #7a5a00; }
.badge-closed { background: var(--coral-wash); color: var(--coral); }
.badge-ok { background: var(--mint-wash); color: var(--mint); }

.empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--ink-soft);
}

/* Toasts: short confirmations in the corner. */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.2s ease-out;
}

.toast.error { background: var(--coral); }
.toast.reward { background: var(--lamp); color: var(--ink); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

dialog {
  border: none;
  border-radius: var(--radius-panel);
  padding: 24px;
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 30px 80px -20px rgba(43, 37, 64, 0.5);
  color: var(--ink);
}

dialog::backdrop { background: rgba(43, 37, 64, 0.45); }

dialog .actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

table.data th,
table.data td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.data th { color: var(--ink-soft); font-size: 0.85rem; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* position: relative keeps hidden screen-reader labels inside the scrolling box, so the page itself never scrolls sideways */
.table-wrap { overflow-x: auto; position: relative; }

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  vertical-align: -2px;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.connection-bar {
  position: fixed;
  top: 0;
  left: 50%;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  margin-top: 10px;
  padding: 10px 18px;
  border-radius: 999px;
  background: #fff4d6;
  border: 1px solid #f2dd9c;
  color: #6b4d00;
  font-weight: 700;
  font-size: 0.9rem;
  transform: translateX(-50%);
  box-shadow: 0 10px 30px -12px rgba(43, 37, 64, 0.4);
}

.connection-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e8a917;
  animation: pulse-dot 1.2s ease-in-out infinite;
}

@keyframes pulse-dot { 50% { opacity: 0.3; } }

/* ---------- 5. Lobby ---------- */
.seat-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--radius-panel);
  background: var(--lamp-wash);
  border: 1px solid #f2dd9c;
  margin-bottom: 20px;
}

.seat-banner p { margin: 0; font-weight: 700; }

.room-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
  margin-top: 16px;
  padding: 0;
  list-style: none;
}

.room-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  overflow: hidden;
}

.room-card .scene-thumb { height: 108px; }

.room-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px 16px;
  flex: 1;
}

.room-card-body h2 { margin: 0; font-size: 1.15rem; }

.seat-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.seat-dots span {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: var(--mint-wash);
  border: 1px solid #b7e0cd;
}

.seat-dots span.taken { background: var(--lav-deep); border-color: var(--lav-deep); }

.room-card .btn { margin-top: auto; align-self: flex-start; }

/* ---------- Room themes (used by thumbnails and the study room) ---------- */
.theme-library {
  background:
    repeating-linear-gradient(90deg, transparent 0 34px, rgba(0, 0, 0, 0.18) 34px 36px),
    repeating-linear-gradient(180deg, #7b4a2e 0 6px, transparent 6px 54px),
    linear-gradient(90deg, #b5523b 0 12%, #2f6b5a 12% 22%, #d8a643 22% 30%, #3b4f8a 30% 41%, #8a3b5c 41% 50%,
      #c27a3c 50% 58%, #2f6b5a 58% 69%, #d8a643 69% 77%, #3b4f8a 77% 88%, #b5523b 88%);
  background-color: #5b3a26;
}

.theme-cafe {
  background:
    radial-gradient(circle at 78% 30%, rgba(255, 230, 170, 0.9) 0 7%, transparent 8%),
    linear-gradient(180deg, transparent 0 18%, #f7e3c4 18% 52%, transparent 52%),
    linear-gradient(90deg, transparent 0 58%, #9cc9e0 58% 92%, transparent 92%),
    linear-gradient(180deg, #e7b98b 0 70%, #a9714a 70%);
}

.theme-beach {
  background:
    radial-gradient(circle at 82% 26%, #fff3b0 0 9%, transparent 10%),
    linear-gradient(180deg, #a8dcf0 0 52%, #4fb1cf 52% 64%, #f3dfae 64%);
}

/* ---------- 6. Study room ---------- */
/* Desktop: the room on the left with its chat right under it, timer and sounds on the right.
   Phone: room, then timer, then chat (set in section 12). */
.room-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    'scene side'
    'chat  side';
  gap: 20px;
  align-items: start;
}

.room-layout > .scene { grid-area: scene; }
.room-layout > .side { grid-area: side; }
.room-layout > #chat-panel { grid-area: chat; margin-top: 0; }

.room-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.room-title h1 { margin: 0; }

.scene {
  position: relative;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-panel);
}

.scene-backdrop { height: 160px; }
.scene-backdrop svg, .scene-thumb svg { display: block; width: 100%; height: 100%; }

.scene-floor {
  padding: 18px;
  background: #efe6d6;
}

/* Floors: wooden parquet, café floor tiles, sand. */
.scene.theme-wrap-library .scene-floor {
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.12) 0 2px, transparent 2px 64px),
    repeating-linear-gradient(0deg, #7d5236 0 24px, #8a5c3d 24px 48px);
}
.scene.theme-wrap-cafe .scene-floor {
  background: conic-gradient(#efe6d8 25%, #d6c3a8 0 50%, #efe6d8 0 75%, #d6c3a8 0) 0 0 / 56px 56px;
}
.scene.theme-wrap-beach .scene-floor {
  background:
    radial-gradient(circle, #dcbc80 1.3px, transparent 1.8px) 0 0 / 18px 18px,
    radial-gradient(circle, #e7cc96 1px, transparent 1.6px) 9px 9px / 18px 18px,
    #f3e1b5;
}

.seat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.seat {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 8px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
  border: 2px solid transparent;
  text-align: center;
  min-height: 100%;
}

.seat svg { width: 100%; max-width: 128px; height: auto; display: block; }

.seat.mine { border-color: var(--lav-deep); background: #fff; }
.seat.focus { box-shadow: 0 0 0 4px rgba(255, 207, 92, 0.55) inset; }

/* "What I'm doing" bubble above the character. */
.seat-bubble {
  position: relative;
  max-width: 100%;
  margin-bottom: 4px;
  padding: 4px 10px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.seat-bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 10px;
  height: 10px;
  background: #fff;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: translateX(-50%) rotate(45deg);
}

.seat-bubble.quiet { color: var(--ink-soft); font-weight: 400; font-style: italic; }
.seat.focus .seat-bubble:not(.quiet) { background: var(--lamp-wash); }
.seat.focus .seat-bubble:not(.quiet)::after { background: var(--lamp-wash); }

/* ---- Top three students: medal, glowing animated border, twinkling sparkles ---- */
@property --spin {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

.seat.top {
  --medal: #f5c542;
  --medal-dark: #b8860b;
  border: 3px solid transparent;
  background:
    linear-gradient(#fffdf6, #fffdf6) padding-box,
    conic-gradient(from var(--spin), var(--medal), #fff6d0, var(--medal), var(--medal-dark), var(--medal)) border-box;
  box-shadow: 0 0 18px 2px color-mix(in srgb, var(--medal) 55%, transparent);
  animation: medal-spin 4s linear infinite;
}

.seat.top-2 { --medal: #b9c4d3; --medal-dark: #7b8796; }
.seat.top-3 { --medal: #d9915f; --medal-dark: #9a5a2e; }
.seat.top.mine { outline: 2px solid var(--lav-deep); outline-offset: 2px; }

@keyframes medal-spin { to { --spin: 360deg; } }

.medal {
  position: absolute;
  top: -14px;
  left: 50%;
  z-index: 2;
  width: 28px;
  height: 33px;
  transform: translateX(-50%);
}

.seat.top { padding-top: 22px; }

.sparkle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--medal);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  opacity: 0;
  animation: twinkle 2.4s ease-in-out infinite;
  pointer-events: none;
}

.sparkle.s1 { top: 18%; right: 10%; }
.sparkle.s2 { top: 48%; left: 8%; width: 9px; height: 9px; animation-delay: 0.8s; }
.sparkle.s3 { bottom: 30%; right: 16%; width: 8px; height: 8px; animation-delay: 1.6s; }

@keyframes twinkle {
  0%, 100% { opacity: 0; transform: scale(0.4) rotate(0deg); }
  50% { opacity: 1; transform: scale(1) rotate(45deg); }
}

.seat-name {
  font-weight: 700;
  font-size: 0.9rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-status { font-size: 0.8rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.seat-empty-btn {
  width: 100%;
  border: 2px dashed #cdbfa6;
  background: transparent;
  border-radius: 16px;
  padding: 8px;
  cursor: pointer;
  color: #6b5a3d;
  font-weight: 700;
}

.seat-empty-btn:hover,
.seat-empty-btn:focus-visible { background: rgba(255, 255, 255, 0.7); border-color: var(--lav-deep); color: var(--lav-deep); }

.seat-empty-btn:disabled { cursor: default; opacity: 0.6; }
.seat-empty-btn:disabled:hover { background: transparent; border-color: #cdbfa6; color: #6b5a3d; }

.side { display: flex; flex-direction: column; gap: 18px; }
.side .panel + .panel { margin-top: 0; }

/* The timer: one ring, one number. Same stroke-dashoffset trick as Lab 3. */
.timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.timer-ring {
  position: relative;
  width: 200px;
  height: 200px;
}

.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-ring .track { fill: none; stroke: var(--lav-wash); stroke-width: 10; }

.timer-ring .arc {
  fill: none;
  stroke: var(--lav-deep);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 100 100;
  transition: stroke-dashoffset 0.25s linear, stroke 0.3s ease;
}

.timer[data-phase='focus'] .arc { stroke: #e8a917; }
.timer[data-phase='break'] .arc { stroke: var(--mint); }
.timer[data-phase='reminder'] .arc { stroke: var(--coral); }

.timer-readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.timer-digits {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timer-label { color: var(--ink-soft); font-weight: 700; margin-top: 6px; }

.timer-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.preset-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; justify-content: center; }
.preset-row .label { font-weight: 700; font-size: 0.9rem; min-width: 46px; text-align: left; }
.preset-row input { width: 64px; padding: 5px 8px; border-radius: 8px; border: 1px solid #cfc6e2; }

.sound-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  align-items: center;
  gap: 10px 12px;
}

.sound-row input[type='range'] { width: 100%; accent-color: var(--lav-deep); }

/* Chat */
.chat-log {
  height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 12px;
  padding: 4px 4px 4px 0;
  list-style: none;
}

.chat-msg { display: flex; flex-direction: column; gap: 2px; }
.chat-meta { font-size: 0.8rem; color: var(--ink-soft); }
.chat-meta strong { color: var(--ink); }

.chat-body {
  align-self: flex-start;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 4px 14px 14px 14px;
  background: var(--lav-wash);
  overflow-wrap: anywhere;
}

.chat-msg.mine { align-items: flex-end; }
.chat-msg.mine .chat-body { align-self: flex-end; background: var(--lav-deep); color: #fff; border-radius: 14px 4px 14px 14px; }

.chat-tools { display: flex; gap: 4px; }
.chat-tools button { background: none; border: none; min-height: 24px; padding: 2px 6px; color: var(--ink-soft); cursor: pointer; font-size: 0.8rem; text-decoration: underline; }

.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 999px; border: 1px solid #cfc6e2; }

/* Room jukebox (discussion rooms). YouTube asks for a visible player of at least 200 x 200 px,
   so the screen keeps a 16:9 shape but never gets shorter than 200px. */
.jukebox-intro { margin: -4px 0 12px; }
.jukebox-screen {
  position: relative;
  width: 100%; /* a fixed width, so the 200px minimum only makes it taller, never wider */
  aspect-ratio: 16 / 9;
  min-height: 200px;
  border-radius: 12px;
  overflow: hidden;
  background: #1f1a2e;
}
.jukebox-screen > iframe,
.jukebox-screen > #jukebox-player { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.jukebox-idle {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  text-align: center;
  color: #ece5f6;
  font-size: 0.92rem;
  background: radial-gradient(circle at 30% 20%, #3b3157, #1f1a2e 70%);
}
.jukebox-now {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0 6px;
}
.jukebox-now:empty { display: none; }
.jukebox-now-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.jukebox-label { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--lav-deep); }
.jukebox-title { overflow-wrap: anywhere; line-height: 1.3; }
.jukebox-now .btn { flex-shrink: 0; }
.jukebox-volume { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; margin: 6px 0 12px; }
.jukebox-volume input { width: 100%; accent-color: var(--lav-deep); }
.jukebox-queue-title { margin: 16px 0 8px; font-size: 1rem; }
.jukebox-queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.jukebox-item { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.jukebox-item img { width: 64px; height: 36px; object-fit: cover; border-radius: 6px; background: var(--lav-wash); }
.jukebox-item-text { display: flex; flex-direction: column; min-width: 0; }
.jukebox-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; }

/* Danmaku: new chat messages drift across the room, right to left.
   The layer covers the whole scene but never catches clicks. */
.danmaku {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  pointer-events: none;
}

.danmaku-item {
  position: absolute;
  left: 0;
  top: 0;
  white-space: nowrap;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(43, 37, 64, 0.62);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  will-change: transform;
}

.danmaku-item .who { opacity: 0.75; font-weight: 400; margin-right: 6px; }
.danmaku-item.mine { box-shadow: 0 0 0 2px var(--lamp); }

.note-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 16px;
  text-align: left;
}

.note-form label { font-weight: 700; font-size: 0.9rem; }
.note-row { display: flex; gap: 6px; }
.note-row input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 1px solid #cfc6e2; }

.sound-row select {
  min-width: 0;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #cfc6e2;
  background: #fff;
}

.check-row {
  display: flex;
  align-items: center;
  min-height: 28px; /* the whole label is the click target */
  gap: 8px;
  margin-top: 14px;
  color: var(--ink-soft);
}

.check-row input { accent-color: var(--lav-deep); width: 16px; height: 16px; }

/* ---------- 7. Tasks ---------- */
.task-form {
  display: grid;
  grid-template-columns: 1fr 150px auto;
  gap: 12px;
  align-items: end;
}

.task-list { list-style: none; margin: 0; padding: 0; }

.task-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}

.task-row input[type='checkbox'] { width: 24px; height: 24px; accent-color: var(--lav-deep); }
.task-title { font-weight: 700; overflow-wrap: anywhere; }
.task-row.done .task-title { text-decoration: line-through; color: var(--ink-soft); }

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--lav-wash);
  overflow: hidden;
  margin-top: 6px;
  max-width: 280px;
}

.progress span { display: block; height: 100%; background: var(--lav-deep); border-radius: inherit; }
.task-actions { display: flex; gap: 6px; }
.task-edit { display: flex; flex-wrap: wrap; gap: 8px; }
.task-edit input { padding: 6px 10px; border-radius: 8px; border: 1px solid #cfc6e2; }

/* ---------- 8. Shop ---------- */
.shop-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.wardrobe { position: sticky; top: 76px; }

.wardrobe-stage {
  border-radius: 16px;
  background: linear-gradient(180deg, var(--lav-wash), #fff);
  padding: 10px 24px 0;
  margin-bottom: 14px;
}

.wardrobe-stage svg { display: block; width: 100%; height: auto; }

.species-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.species-pick .chip { padding: 5px 11px; font-size: 0.85rem; }

.fur-swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; padding: 0; border: 0; }
.fur-swatches legend { font-weight: 700; font-size: 0.9rem; padding: 0; margin-bottom: 6px; }

.fur-swatches label {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
}

.fur-swatches input { position: absolute; opacity: 0; pointer-events: none; }
.fur-swatches label:has(input:checked) { box-shadow: 0 0 0 3px var(--lav-deep); }
.fur-swatches label:has(input:focus-visible) { outline: 3px solid var(--lav-deep); outline-offset: 3px; }

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.item-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.item-card.equipped { border-color: var(--lav-deep); box-shadow: 0 0 0 1px var(--lav-deep); }

.item-icon {
  display: grid;
  place-items: center;
  height: 86px;
  border-radius: 12px;
  background: var(--paper);
}

.item-icon svg { width: 72px; height: 72px; }
.item-name { font-weight: 700; }
.item-price { display: flex; align-items: center; gap: 4px; font-weight: 700; font-variant-numeric: tabular-nums; }
.item-price svg { width: 16px; height: 16px; }

.wardrobe-places { margin: -4px 0 14px; }
.wardrobe-places .chip { padding: 4px 10px; font-size: 0.8rem; }
.preview-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--lamp-wash);
  font-weight: 700;
  font-size: 0.9rem;
}
.item-actions { display: flex; gap: 6px; margin-top: auto; }
.item-actions .btn { flex: 1; margin-top: 0; padding: 6px 8px; white-space: nowrap; }
.item-card.previewing { border-color: #e8a917; box-shadow: 0 0 0 1px #e8a917; }

/* ---------- 9. History ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  padding: 16px 18px;
  border-radius: var(--radius-panel);
  background: var(--surface);
  border: 1px solid var(--line);
}

.stat dt { color: var(--ink-soft); font-weight: 700; font-size: 0.9rem; }
.stat dd { margin: 4px 0 0; font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.history-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.week-chart svg { width: 100%; height: auto; display: block; }
.week-chart .bar { fill: var(--lav); }
.week-chart .bar.today { fill: var(--lav-deep); }
.week-chart text { font-family: var(--font-body); font-size: 12px; fill: var(--ink-soft); }
.week-chart .value { fill: var(--ink); font-weight: 700; }

.leaderboard { list-style: none; margin: 0; padding: 0; }

.leaderboard li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.leaderboard li.me { font-weight: 700; color: var(--lav-deep); }
.leaderboard .rank { font-family: var(--font-display); font-weight: 600; color: var(--ink-soft); }

/* Streak: a flame, the number of days, and a 14-day strip shaded by how much was done. */
.streak-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px 28px;
  margin-bottom: 18px;
}

.streak-main { display: flex; align-items: center; gap: 16px; }
.streak-main h2 { margin: 0; font-size: 1rem; color: var(--ink-soft); }
.streak-flame svg { width: 64px; height: 64px; display: block; }
.streak-number { margin: 0; font-family: var(--font-display); font-size: 2rem; font-weight: 600; line-height: 1.1; }
.streak-main .small { margin: 4px 0 0; max-width: 46ch; }
.streak-cal-label { margin: 0 0 6px; }

.streak-calendar {
  display: grid;
  grid-template-columns: repeat(14, 26px);
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cal-day {
  display: grid;
  place-items: center;
  height: 26px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  background: var(--lav-wash);
  color: var(--ink-soft);
}

.cal-day.level-1 { background: #ffd9b8; color: #7a3e12; }
.cal-day.level-2 { background: #ffb27a; color: #5c2a06; }
.cal-day.level-3 { background: #f2873f; color: #fff; }
.cal-day.level-4 { background: #d9621f; color: #fff; }
.cal-day.today { outline: 2px solid var(--ink); outline-offset: 1px; }

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.badge-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 10px;
  border-radius: 16px;
  border: 1px dashed #d5cde6;
  text-align: center;
}

.badge-card.earned { border-style: solid; border-color: var(--line); background: #fffdf6; }
.badge-icon svg { width: 56px; height: 56px; display: block; }
.badge-card:not(.earned) .badge-icon { filter: saturate(0.3); }
.badge-name { font-weight: 700; }
.badge-progress { display: flex; align-items: center; gap: 8px; width: 100%; margin-top: auto; }
.badge-progress .progress { flex: 1; margin-top: 0; }
.badge-card .badge { margin-top: auto; }

/* Pomodoro rounds: four dots under the timer. */
.rounds {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}

.round-dots { display: flex; gap: 8px; }
.round-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #e2a62a; }
.round-dots span.done { background: #e2a62a; }
.round-dots span.now { background: var(--lamp-wash); box-shadow: 0 0 0 3px rgba(255, 207, 92, 0.45); }
.rounds-label { font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); }
.long-break-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; font-size: 0.88rem; }
.long-break-row select { padding: 4px 6px; border-radius: 8px; border: 1px solid #cfc6e2; }
.long-break-hint { margin: 0; font-size: 0.85rem; font-weight: 700; color: #8a5a00; background: var(--lamp-wash); padding: 6px 10px; border-radius: 10px; }

/* ---------- 10. Admin ---------- */
.overview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  margin: 0 0 18px;
  padding: 14px 18px;
  border-radius: var(--radius-panel);
  background: var(--surface);
  border: 1px solid var(--line);
}

.overview div { display: flex; gap: 6px; align-items: baseline; }
.overview dt { color: var(--ink-soft); }
.overview dd { margin: 0; font-weight: 700; font-family: var(--font-display); font-size: 1.2rem; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

/* ---------- 11. Login ---------- */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}

.login-art {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
  padding: 48px clamp(24px, 6vw, 80px);
  background: var(--ink);
  color: #fff;
}

/* The logo sits on a warm paper plate so its dark outlines read well on the dark panel. */
.login-logo {
  margin: 0;
  width: min(300px, 70vw);
  padding: 14px 22px 6px;
  border-radius: 32px;
  background: #fbf7ef;
  box-shadow: 0 20px 50px -24px rgba(0, 0, 0, 0.6);
}

.login-logo img { display: block; width: 100%; height: auto; }

.login-art p { font-size: 1.15rem; max-width: 34ch; color: #d9d2ec; margin: 0; }

.login-desks {
  display: flex;
  gap: 8px;
  max-width: 420px;
  padding: 16px 16px 0;
  border-radius: 22px 22px 0 0;
  background: #3a3254;
  box-shadow: inset 0 -10px 0 #4a4068;
}

.login-desks svg { flex: 1; height: auto; }

.login-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.login-card { width: min(400px, 100%); }
.login-card .tabs { margin-bottom: 20px; }

.species-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; border: 0; padding: 0; margin: 0; }
.species-cards legend { font-weight: 700; font-size: 0.9rem; margin-bottom: 6px; padding: 0; }

.species-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 8px 10px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: #fff;
  cursor: pointer;
  font-weight: 700;
}

.species-card svg { width: 92px; height: 82px; }
.species-card { font-size: 0.85rem; text-align: center; }
.species-card input { position: absolute; opacity: 0; pointer-events: none; }
.species-card:has(input:checked) { border-color: var(--lav-deep); background: var(--lav-wash); }
.species-card:has(input:focus-visible) { outline: 3px solid var(--lav-deep); outline-offset: 2px; }

.demo-accounts { margin-top: 18px; font-size: 0.9rem; color: var(--ink-soft); }
.demo-accounts code { background: var(--lav-wash); padding: 1px 6px; border-radius: 6px; }

/* ---------- 12. Small screens & motion ---------- */
@media (max-width: 960px) {
  .room-layout,
  .shop-layout,
  .history-layout { grid-template-columns: minmax(0, 1fr); }
  .room-layout {
    grid-template-rows: auto;
    grid-template-areas: 'scene' 'side' 'chat';
  }
  .wardrobe { position: static; }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .streak-panel { grid-template-columns: minmax(0, 1fr); }
  .streak-calendar { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; padding: 10px 16px; }
  .topbar .nav-toggle { display: inline-flex; margin-left: auto; }
  .topbar-right { order: 4; width: 100%; margin-left: 0; justify-content: space-between; }
  .nav { order: 3; display: none; flex-direction: column; width: 100%; padding-bottom: 6px; }
  .nav.open { display: flex; }
  .page { padding: 20px 16px 48px; }
  .login-page { grid-template-columns: 1fr; }
  .login-art { padding: 32px 20px; gap: 18px; align-items: center; text-align: center; }
  .login-logo { width: min(220px, 60vw); }
  .login-desks { width: 100%; max-width: 320px; }
  .task-form { grid-template-columns: 1fr; }
  .task-row { grid-template-columns: auto 1fr; }
  .task-actions { grid-column: 2; }
  .seat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .scene-floor { padding: 12px; }
  .scene-backdrop { height: 96px; }
  .points-pill .label-long { display: none; }
}

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