:root {
  --bg: #0f1a24;
  --panel: #1a2a3a;
  --text: #f0f6fc;
  --muted: #9bb0c4;
  --accent: #7dd3fc;
  --good: #6ee7b7;
  --warn: #fbbf24;
  --touch: 72px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  min-height: 100dvh;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background:
    radial-gradient(ellipse at 15% 0%, #4c1d95 0%, transparent 50%),
    radial-gradient(ellipse at 85% 100%, #0e7490 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  padding:
    max(0.45rem, var(--safe-t))
    max(0.55rem, var(--safe-r))
    max(0.45rem, var(--safe-b))
    max(0.55rem, var(--safe-l));
  user-select: none;
  touch-action: none;
}
button { font: inherit; border: none; cursor: pointer; color: inherit; touch-action: manipulation; }
button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { opacity: 0.45; }
.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: calc(100dvh - 0.9rem);
  display: flex;
  flex-direction: column;
}
.screen { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; min-height: 0; }
.hidden { display: none !important; }
.top { text-align: center; }
.top h1 {
  font-size: clamp(1.05rem, 3.5vw, 1.4rem);
  color: #e9d5ff;
  font-weight: 900;
}
.gentle { color: var(--muted); font-weight: 600; margin-top: 0.3rem; }
.panel {
  flex: 1;
  background: var(--panel);
  border-radius: 16px;
  padding: 0.9rem;
  border: 1px solid rgba(167, 139, 250, 0.25);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.label { color: var(--warn); font-weight: 800; margin: 0.4rem 0 0.45rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.chips button {
  min-height: var(--touch);
  min-width: 5.4rem;
  padding: 0.55rem 0.95rem;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.34);
  border: 3px solid rgba(182, 199, 216, 0.4);
  font-weight: 900;
  font-size: 1.05rem;
}
.chips button.active {
  border-color: var(--warn);
  background: rgba(251, 191, 36, 0.28);
  color: #fde68a;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.35);
}
.current { margin: 0.5rem 0; font-weight: 800; }
.current span { color: var(--warn); }
.hint { color: var(--muted); font-weight: 600; line-height: 1.5; margin-top: 0.75rem; font-size: 0.95rem; }
.btn-start, .btn.primary {
  min-height: 68px;
  width: 100%;
  border-radius: 16px;
  font-size: 1.15rem;
  font-weight: 900;
  background: linear-gradient(180deg, #c4b5fd, #7c3aed);
  color: #fff;
  margin-top: 0.35rem;
}
.btn.ghost {
  min-height: 52px;
  width: 100%;
  margin-top: 0.4rem;
  border-radius: 14px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.08);
}
.btn { min-height: 56px; border-radius: 14px; font-weight: 900; padding: 0 0.8rem; background: rgba(255,255,255,.1); }
.room-list { display: flex; flex-direction: column; gap: 0.45rem; margin-top: 0.55rem; }
.room-card {
  text-align: left;
  min-height: 64px;
  padding: 0.75rem 0.9rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid rgba(167, 139, 250, 0.4);
  font-weight: 800;
}
.room-card .sub { color: var(--muted); font-size: 0.88rem; margin-top: 0.2rem; }
.empty { color: var(--muted); font-weight: 700; text-align: center; padding: 0.75rem; }

.game-head {
  background: var(--panel);
  border-radius: 14px;
  padding: 0.55rem 0.75rem;
  border: 1px solid rgba(167, 139, 250, 0.3);
  flex-shrink: 0;
}
.row-between { display: flex; justify-content: space-between; align-items: center; font-weight: 900; gap: 0.5rem; }
#room-label { color: var(--warn); font-size: 0.95rem; }
.status { margin-top: 0.3rem; font-weight: 800; color: var(--good); text-align: center; }
.scores {
  display: flex; flex-wrap: wrap; gap: 0.35rem; justify-content: center; margin-top: 0.4rem;
}
.score-chip {
  background: rgba(0,0,0,.28);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-weight: 800;
  font-size: 0.85rem;
  border: 1px solid rgba(255,255,255,.1);
}
.score-chip.me { border-color: var(--warn); color: var(--warn); }
.role-banner {
  text-align: center;
  font-weight: 900;
  font-size: 1.05rem;
  padding: 0.45rem;
  border-radius: 12px;
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: var(--warn);
  flex-shrink: 0;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 240px;
  background: #f8fafc;
  border-radius: 16px;
  overflow: hidden;
  border: 4px solid #fbbf24;
  box-shadow: 0 10px 28px rgba(0,0,0,.4), inset 0 0 0 2px #0f172a;
}
#canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
  background: #f8fafc;
}
.word-secret {
  position: absolute;
  top: 0.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  color: #fde68a;
  font-weight: 900;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 2px solid #fbbf24;
  z-index: 2;
  white-space: nowrap;
}

.draw-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex-shrink: 0;
}
.tool {
  min-height: 56px;
  min-width: 3.8rem;
  border-radius: 14px;
  font-weight: 900;
  font-size: 1.02rem;
  background: rgba(255,255,255,.14);
  border: 3px solid rgba(255,255,255,.18);
}
.tool.active { border-color: var(--warn); background: rgba(251,191,36,.28); color: #fde68a; box-shadow: 0 0 0 2px rgba(251,191,36,.3); }
.tool.wide { flex: 1; min-width: 6rem; }

.guess-area { flex-shrink: 0; }
.guess-title { text-align: center; font-weight: 900; margin-bottom: 0.45rem; color: var(--accent); }
.guess-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.guess-opts button {
  min-height: 80px;
  border-radius: 18px;
  font-size: 1.28rem;
  font-weight: 900;
  background: linear-gradient(180deg, rgba(255,255,255,.16), rgba(0,0,0,.28));
  border: 4px solid rgba(167,139,250,.55);
  color: #f8fafc;
}
.guess-opts button.correct { border-color: var(--good); background: rgba(110,231,183,.25); }
.guess-opts button.wrong { opacity: 0.55; border-color: #f87171; }

.reveal {
  text-align: center;
  padding: 0.65rem;
  background: rgba(110, 231, 183, 0.12);
  border: 1px solid rgba(110, 231, 183, 0.35);
  border-radius: 14px;
  flex-shrink: 0;
}
.reveal-title { font-weight: 800; color: var(--good); }
.reveal-word { font-size: 1.6rem; font-weight: 900; color: var(--warn); margin-top: 0.25rem; }

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex-shrink: 0;
}

@media (max-width: 420px) {
  .guess-opts { grid-template-columns: 1fr; }
}
