:root {
  --primary: #ff6b6b;
  --primary-dark: #ee5253;
  --secondary: #4ecdc4;
  --yellow: #ffd93d;
  --purple: #a29bfe;
  --pink: #ff8fab;
  --bg: #fff6e9;
  --card-bg: #ffffff;
  --text: #2d2d3a;
  --muted: #8888a0;
  --success: #2ecc71;
  --danger: #ff5c5c;
  --ink: #2d2d3a;
  --border-w: 3px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Baloo 2", -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

.connection-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  text-align: center;
  padding: 8px;
  font-weight: 700;
  font-size: 13px;
  background: var(--danger);
  color: white;
  border-bottom: var(--border-w) solid var(--ink);
}
.connection-banner.hidden { display: none; }

.sound-toggle {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 900;
  width: 36px;
  height: 36px;
  font-size: 16px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
}
.leave-room-btn { left: 52px; }
.leave-room-btn.hidden { display: none; }

/* ---------- 卡通背景泡泡 ---------- */
.bg-blobs {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}
.blob {
  position: absolute;
  border-radius: 50%;
  opacity: 0.35;
  filter: blur(2px);
}
.blob-1 { width: 260px; height: 260px; background: var(--secondary); top: -60px; left: -60px; }
.blob-2 { width: 200px; height: 200px; background: var(--yellow); bottom: -50px; right: 5%; }
.blob-3 { width: 160px; height: 160px; background: var(--pink); top: 20%; right: -60px; }
.blob-4 { width: 220px; height: 220px; background: var(--purple); bottom: 10%; left: -70px; }

.screen {
  display: none;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}
.screen.active { display: flex; }
.screen-scroll { align-items: flex-start; overflow-y: auto; padding: 24px 0; }

/* ---------- 廣告位（設定見 client.js 的 ADS_CONFIG）----------
   放在卡片外：寬螢幕在卡片旁邊，窄螢幕換行到卡片下方，都和按鈕保持距離。
   尺寸固定，廣告載入時版面才不會跳動 */
#screen-login, #screen-lobby, #screen-gameover { flex-wrap: wrap; align-content: flex-start; gap: 48px 32px; }
.ad-slot { display: none; flex: none; width: 300px; }
.ad-slot.is-active { display: block; }
.ad-slot:has(ins[data-ad-status="unfilled"]) { display: none; }
.ad-slot::before {
  content: '廣告';
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.ad-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 250px;
  border: 2px dashed var(--muted);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

/* ---------- 登入畫面：標題 + 貓咪吉祥物 + 卡片 ---------- */
.login-hero {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(420px, 92vw);
  padding: 16px 0 32px;
  text-align: center;
}
.login-hero h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
  text-shadow: 2px 2px 0 rgba(255,107,107,0.25);
  position: relative;
  z-index: 2;
}
.login-hero .subtitle {
  position: relative;
  z-index: 2;
  margin: 2px 0 0;
}
.mascot-hero {
  width: 100%;
  max-width: 380px;
  height: auto;
  margin-top: 10px;
  margin-bottom: -14px;
  border-radius: 20px 20px 0 0;
  position: relative;
  z-index: 2;
}
.login-card {
  width: 100%;
  padding-top: 30px;
  position: relative;
  z-index: 1;
}

.how-to-play.card {
  position: relative;
  margin-top: 24px;
  text-align: start;
}
.how-to-play h2 { margin: 0 0 12px; font-size: 1.25rem; }
.how-to-play ol { margin: 0; padding-inline-start: 1.5em; line-height: 1.65; }
.how-to-play li + li { margin-top: 10px; }

.privacy-link, .privacy-page a {
  color: var(--ink);
  text-underline-offset: 0.2em;
}
.privacy-link { margin-top: 16px; padding: 6px 12px; font-size: 14px; }
.privacy-page { height: auto; overflow: auto; padding: 24px 16px 40px; }
.privacy-page .card {
  width: min(100%, 42rem);
  margin: 0 auto;
  padding: clamp(20px, 5vw, 42px);
  text-align: start;
  line-height: 1.8;
}
.privacy-page h1 { margin: 16px 0 0; line-height: 1.3; }
.privacy-page h2 { margin: 24px 0 4px; font-size: 1.2rem; }
.privacy-page p { margin: 0 0 8px; }

.hero-doodle {
  position: absolute;
  font-size: 30px;
  opacity: 0.8;
  pointer-events: none;
  z-index: 0;
}
.doodle-star { top: 6px; left: -6px; font-size: 26px; transform: rotate(-10deg); }
.doodle-heart { top: 70px; right: -10px; font-size: 26px; }
.doodle-bulb { top: 200px; right: -18px; font-size: 26px; }
.doodle-paw-1 { top: 130px; left: -22px; font-size: 30px; transform: rotate(-20deg); opacity: 0.6; }
.doodle-paw-2 { bottom: 40px; right: -20px; font-size: 30px; transform: rotate(15deg); opacity: 0.6; }

@media (max-width: 700px) {
  .hero-doodle { display: none; }
}

@media (max-width: 700px) {
  .category-section { margin: 8px 0; }
  .section-label { margin-bottom: 5px; font-size: 13px; }
  .category-chip { padding: 6px 11px; font-size: 12px; }
  .player-list { margin: 8px 0; }
  input[type="text"] { padding: 10px 12px; margin: 6px 0; }
  button { padding: 10px 14px; margin: 5px 0; }
}

.card {
  background: var(--card-bg);
  border-radius: 28px;
  border: var(--border-w) solid var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
  padding: 32px;
  width: min(420px, 92vw);
  text-align: center;
}
.card-wide { width: min(480px, 92vw); }

.card h2 { font-weight: 700; }
.subtitle { color: var(--muted); font-size: 14px; margin-top: -6px; }

input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  margin: 8px 0;
  border: var(--border-w) solid var(--ink);
  border-radius: 14px;
  font-size: 16px;
  font-family: inherit;
  background: #fffdf8;
}
input[type="text"]:focus { outline: none; border-color: var(--primary); }

.input-icon-wrap { position: relative; }
.input-icon-wrap input[type="text"] { padding-left: 40px; }
.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  font-weight: 800;
  color: var(--muted);
  pointer-events: none;
}

button {
  cursor: pointer;
  border: var(--border-w) solid var(--ink);
  border-radius: 16px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  width: 100%;
  margin: 6px 0;
  background: #fff;
  color: var(--text);
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
button:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
button.primary {
  background: var(--primary);
  color: white;
}
button.primary:hover { background: var(--primary-dark); }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  margin: 12px 0;
  font-size: 13px;
  font-weight: 700;
}
.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 2px;
  background: #e0dcd0;
}

.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-weight: 700; font-size: 13px; min-height: 18px; }
.login-status.hidden { display: none; }

.room-code {
  display: inline-block;
  background: var(--yellow);
  border: var(--border-w) solid var(--ink);
  border-radius: 10px;
  padding: 2px 10px;
  letter-spacing: 2px;
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  text-align: left;
  max-height: 240px;
  overflow-y: auto;
}
.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 12px;
  margin-bottom: 6px;
  background: var(--bg);
  border: 2px solid var(--ink);
  font-size: 14px;
  font-weight: 600;
}
.player-list li.is-drawer { background: var(--yellow); }
.player-list li.guessed { background: #c9f7dc; }
.player-list li .name { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.player-list li .score { color: var(--primary-dark); font-weight: 800; }

/* ---------- 類別選擇 ---------- */
.category-section { margin: 14px 0; text-align: left; }
.section-label { font-weight: 700; margin: 0 0 8px; }
.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.category-chip {
  width: auto;
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  background: #fff;
  box-shadow: 3px 3px 0 var(--ink);
}
.category-chip.selected {
  background: var(--secondary);
  color: white;
}
.category-chip.disabled {
  cursor: default;
  opacity: 0.7;
}
.category-chip.disabled:hover { transform: none; box-shadow: 3px 3px 0 var(--ink); }

/* ---------- 遊戲畫面 ---------- */
#screen-game { flex-direction: column; }
.game-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 20px;
  background: var(--card-bg);
  border-bottom: var(--border-w) solid var(--ink);
  width: 100%;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
/* 左側留位給固定在左上角的音效和離開按鈕 */
.round-info { font-size: 14px; color: var(--muted); font-weight: 700; padding-left: 78px; }
.timer {
  font-size: 24px;
  font-weight: 800;
  color: white;
  background: var(--secondary);
  border: var(--border-w) solid var(--ink);
  border-radius: 50%;
  min-width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.timer.low { background: var(--danger); }
.word-display {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 4px;
  text-align: center;
  min-height: 1.4em;
}
.word-display.is-mine {
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 4px 10px;
}

.game-body {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.player-panel {
  width: 200px;
  padding: 12px;
  background: var(--card-bg);
  overflow-y: auto;
  border-right: var(--border-w) solid var(--ink);
}

.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  gap: 10px;
  min-width: 0;
  container-type: inline-size;
}

/* 畫布尺寸由 client.js 的 fitCanvas 依這個容器計算，永遠維持 4:3。
   預設高度正好是 4:3，高度不夠時才縮小，所以工具列會緊貼在畫布下方 */
.canvas-wrap {
  flex: 0 1 auto;
  height: 60vh; /* 給不支援容器單位的瀏覽器 */
  height: 75cqw;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvas {
  display: block;
  flex: none;
  background: white;
  border: var(--border-w) solid var(--ink);
  border-radius: 20px;
  touch-action: none;
  cursor: crosshair;
  box-shadow: 6px 6px 0 rgba(45,45,58,0.15);
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  background: var(--card-bg);
  padding: 10px 16px;
  border-radius: 16px;
  border: var(--border-w) solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
}
.toolbar.hidden { display: none; }
.toolbar.paused { opacity: 0.45; pointer-events: none; }
.toolbar button {
  width: auto;
  margin: 0;
  padding: 8px 12px;
}
#size-picker { width: 100px; }
#color-picker {
  width: 40px;
  height: 40px;
  border: var(--border-w) solid var(--ink);
  border-radius: 10px;
  padding: 2px;
  background: #fff;
  cursor: pointer;
}

.chat-panel {
  width: 260px;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border-left: var(--border-w) solid var(--ink);
}
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
  font-size: 13px;
}
.chat-log .msg { margin-bottom: 6px; word-break: break-word; }
.chat-log .msg .who { font-weight: 800; }
.chat-log .msg.correct { color: var(--success); font-weight: 800; }
.chat-log .msg.system { color: var(--muted); font-style: italic; }

#chat-form {
  display: flex;
  padding: 10px;
  gap: 6px;
  border-top: var(--border-w) solid var(--ink);
}
#chat-form input {
  flex: 1;
  margin: 0;
  padding: 10px;
}
#chat-form button {
  width: auto;
  margin: 0;
  background: var(--primary);
  color: white;
  padding: 10px 14px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(45,45,58,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: white;
  border-radius: 24px;
  border: var(--border-w) solid var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
  padding: 28px;
  text-align: center;
  width: min(400px, 90vw);
}
.scoreboard {
  text-align: left;
  padding: 0 0 0 24px;
  font-weight: 700;
}
.scoreboard li { margin-bottom: 8px; font-size: 16px; }

/* ---------- 遊戲結束：頒獎台 / 最佳出題者 / 畫廊 ---------- */
.top3-podium {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 16px 0;
  flex-wrap: wrap;
}
.podium-card {
  background: var(--bg);
  border: var(--border-w) solid var(--ink);
  border-radius: 16px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 12px 16px;
  min-width: 90px;
  text-align: center;
}
.podium-card.rank-1 { background: var(--yellow); transform: translateY(-6px); }
.podium-card.rank-2 { background: #e0e0ff; }
.podium-card.rank-3 { background: #ffe0d0; }
.podium-medal { font-size: 28px; }
.podium-name { font-weight: 800; font-size: 14px; margin-top: 2px; }
.podium-score { font-size: 13px; color: var(--primary-dark); font-weight: 700; }

.best-drawer-badge {
  background: var(--secondary);
  color: white;
  font-weight: 700;
  border: var(--border-w) solid var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  display: inline-block;
  margin: 4px 0 12px;
}
.best-drawer-badge.hidden { display: none; }

.gallery-section.hidden { display: none; }
.gallery-section { margin-top: 18px; text-align: left; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.gallery-item {
  background: var(--bg);
  border: 2px solid var(--ink);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 3px 3px 0 var(--ink);
}
.gallery-item img {
  width: 100%;
  height: 90px;
  object-fit: contain;
  background: white;
  display: block;
}
.gallery-caption {
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  padding: 4px 2px;
}

#btn-skip { background: var(--purple); color: white; }
#btn-undo { background: #d7e8ff; }

/* ---------- 搶答模式面板 ---------- */
/* 固定高度：面板內容切換時，畫布才不會跟著跳動 */
.buzz-panel {
  width: 100%;
  min-height: 136px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.buzz-panel.hidden { display: none; }
.buzz-status {
  font-weight: 700;
  text-align: center;
  background: var(--card-bg);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 8px 14px;
}
.buzz-button {
  width: auto;
  padding: 16px 36px;
  font-size: 20px;
  background: var(--danger);
  color: white;
  border-radius: 999px;
  animation: buzz-pulse 1s infinite;
}
@keyframes buzz-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}
.buzz-judge-row { display: flex; gap: 10px; }
.buzz-judge-row button { width: auto; padding: 10px 18px; }
.buzz-correct { background: var(--success); color: white; }
.buzz-wrong { background: var(--danger); color: white; }

@media (max-width: 900px) {
  .card, .card-wide { width: min(440px, 90vw); padding: 24px 20px; }

  /* 遊戲畫面：整頁固定在一個畫面內，不需要上下滑動 —
     畫布維持 4:3，剩下的高度都留給聊天區；空間不夠時先縮畫布 */
  .game-header { padding: 6px 14px; flex-shrink: 0; }
  .game-body { flex-direction: column; overflow: hidden; }

  .player-panel {
    width: 100%;
    flex: 0 0 auto;
    border: none;
    border-top: var(--border-w) solid var(--ink);
    padding: 6px 10px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  #game-player-list {
    display: flex;
    flex-direction: row;
    gap: 6px;
    max-height: none;
    margin: 0;
    padding-bottom: 2px;
  }
  #game-player-list li {
    flex: 0 0 auto;
    margin-bottom: 0;
    padding: 4px 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .canvas-area {
    flex: 0 1 auto;
    min-height: 0;
    padding: 6px;
    gap: 4px;
  }
  .canvas-wrap { height: min(75vw, 48dvh); }
  .toolbar { padding: 4px 8px; gap: 4px; flex-shrink: 0; }
  .toolbar button { padding: 5px 8px; font-size: 13px; }
  #color-picker { width: 30px; height: 30px; }
  #size-picker { width: 70px; }
  .buzz-panel { flex-shrink: 0; min-height: 0; margin-top: 0; gap: 4px; }
  .buzz-button { padding: 8px 20px; font-size: 15px; }
  .buzz-status { padding: 4px 10px; font-size: 12px; }
  .buzz-judge-row button { padding: 6px 12px; font-size: 13px; }

  .chat-panel {
    width: 100%;
    flex: 1 0 130px;
    min-height: 0;
    border: none;
    border-top: var(--border-w) solid var(--ink);
  }
  .chat-log { padding: 6px 10px; font-size: 12px; }
  #chat-form { padding: 6px 10px; }
  #chat-form input { padding: 8px; font-size: 14px; }
  #chat-form button { padding: 8px 12px; font-size: 14px; }

  .word-display { font-size: 20px; letter-spacing: 2px; word-break: break-word; }
  .header-top { flex-wrap: wrap; gap: 6px; }
  .round-info { font-size: 11px; padding-left: 82px; }
  .timer { min-width: 38px; height: 38px; font-size: 16px; }
}

/* 手機橫放：高度放不下直排，改成三欄，畫布放中間吃滿高度。
   min-width 是為了避免直拿手機開鍵盤（視窗變矮）時被誤判成橫放 */
@media (orientation: landscape) and (max-height: 500px) and (min-width: 480px) {
  .sound-toggle { top: 3px; left: 4px; width: 28px; height: 28px; font-size: 13px; box-shadow: 2px 2px 0 var(--ink); }
  .leave-room-btn { left: 36px; }

  /* 標題列壓成一行：回合資訊 | 題目 | 倒數 */
  .game-header { flex-direction: row; align-items: center; gap: 8px; padding: 2px 8px; flex-shrink: 0; }
  .header-top { display: contents; }
  .round-info { font-size: 11px; padding-left: 60px; white-space: nowrap; }
  .word-display { order: 1; flex: 1; min-width: 0; min-height: 0; font-size: 15px; letter-spacing: 2px; }
  .word-display.is-mine { padding: 0 8px; }
  .timer { order: 2; min-width: 28px; height: 28px; font-size: 13px; border-width: 2px; }

  .game-body { flex-direction: row; }

  .player-panel {
    width: 100px;
    flex: none;
    padding: 4px;
    border: none;
    border-right: var(--border-w) solid var(--ink);
    overflow-x: hidden;
    overflow-y: auto;
  }
  #game-player-list { display: flex; flex-direction: column; gap: 3px; max-height: none; margin: 0; padding: 0; }
  #game-player-list li { margin-bottom: 0; padding: 2px 5px; font-size: 11px; white-space: normal; word-break: break-all; }

  .canvas-area { flex: 1 1 0; min-width: 0; min-height: 0; padding: 4px 6px; gap: 3px; }
  .canvas-wrap { flex: 1 1 0; height: auto; }

  .toolbar { flex-wrap: nowrap; flex-shrink: 0; gap: 4px; padding: 2px 6px; box-shadow: 2px 2px 0 var(--ink); }
  .toolbar button { padding: 2px 5px; font-size: 11px; white-space: nowrap; box-shadow: 2px 2px 0 var(--ink); }
  #color-picker { width: 24px; height: 24px; padding: 1px; flex: none; }
  #size-picker { width: 44px; flex: none; }

  .buzz-panel { flex-direction: row; flex-wrap: wrap; flex-shrink: 0; min-height: 0; margin-top: 0; gap: 4px; }
  .buzz-button { padding: 4px 16px; font-size: 13px; margin: 0; }
  .buzz-status { padding: 2px 8px; font-size: 11px; }
  .buzz-judge-row button { padding: 3px 10px; font-size: 12px; margin: 0; }

  .chat-panel { width: clamp(150px, 24vw, 220px); flex: none; min-height: 0; border: none; border-left: var(--border-w) solid var(--ink); }
  .chat-log { padding: 4px 6px; font-size: 11px; }
  #chat-form { padding: 4px; gap: 4px; }
  #chat-form input { min-width: 0; padding: 5px 6px; font-size: 14px; }
  #chat-form button { padding: 5px 8px; font-size: 12px; }
}
