:root {
  --paper: #fff6e0; --paper2: #ffeccc; --ink: #2a2140; --muted: #7a6f8f; --line: #ecdcbc;
  --pink: #ff5d8f; --blue: #3a7bff; --green: #16b37e; --gold: #ffc94a; --card: #fffdf7;
  --shadow: 0 2px 0 #e6d3ad, 0 8px 24px rgba(80, 50, 10, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink); font-family: Nunito, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
  background-image: radial-gradient(rgba(42, 33, 64, .06) 1px, transparent 1px); background-size: 18px 18px;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- shared bits ---------- */
.topbar { display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; }
.topbar .brand { font-family: Fredoka, sans-serif; font-weight: 700; font-size: 20px; text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.topbar .sp { flex: 1; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; }
.icon-btn svg { width: 20px; height: 20px; }
.screen { flex: 1; overflow: auto; display: flex; flex-direction: column; align-items: center; padding: 12px 16px calc(env(safe-area-inset-bottom) + 24px); text-align: center; }
.logo { width: 96px; height: 96px; margin-top: 4vh; }
h1.title { font-family: Fredoka, sans-serif; font-size: 48px; margin: 8px 0 4px; letter-spacing: .5px; }
.tag { color: var(--muted); max-width: 340px; margin: 0 0 22px; line-height: 1.45; }
.btn { border: 0; border-radius: 14px; padding: 13px 22px; font-weight: 800; font-size: 17px; background: var(--pink); color: #fff; box-shadow: 0 3px 0 #d63d70; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #d63d70; }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.link { background: none; border: 0; color: var(--blue); font-weight: 800; padding: 10px; text-decoration: none; }
.row { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.field { border: 2px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 14px; font-size: 17px; outline: none; }
.field:focus { border-color: var(--blue); }
.card { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 16px; width: 100%; max-width: 420px; margin: 14px 0; text-align: left; }
.small { color: var(--muted); font-size: 14px; }
.code { font-family: Fredoka, sans-serif; font-size: 40px; letter-spacing: 6px; margin: 2px 0 10px; }
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px dashed var(--line); }
.plist li:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #d6c9ad; flex: none; }
.dot.on { background: var(--green); }
.you { font-size: 11px; font-weight: 800; background: var(--blue); color: #fff; border-radius: 6px; padding: 2px 6px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none; font-size: 14px; }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.settings label { font-size: 13px; color: var(--muted); font-weight: 700; display: flex; flex-direction: column; gap: 4px; }
.settings select { border: 2px solid var(--line); border-radius: 10px; padding: 8px; background: #fff; }

/* ---------- game ---------- */
.game { flex: 1; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto minmax(84px, 20dvh) auto; padding: 0 10px calc(env(safe-area-inset-bottom) + 8px); gap: 8px; max-width: 760px; width: 100%; margin: 0 auto; }
.status { display: flex; align-items: center; gap: 10px; }
.timer { width: 46px; height: 46px; flex: none; position: relative; display: grid; place-items: center; font-weight: 800; font-family: Fredoka, sans-serif; font-size: 17px; }
.timer svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.timer span { position: relative; }
.timer.low { color: var(--pink); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.word { flex: 1; text-align: center; font-family: Fredoka, sans-serif; font-weight: 600; font-size: 22px; letter-spacing: 3px; line-height: 1.2; min-height: 30px; word-break: break-word; }
.word .hint { font-size: 12px; color: var(--muted); letter-spacing: 0; display: block; font-family: Nunito, sans-serif; font-weight: 700; }
.round { font-size: 13px; font-weight: 800; color: var(--muted); text-align: right; min-width: 46px; }
.stage { position: relative; height: 100%; width: auto; max-width: 100%; min-height: 0; justify-self: center; align-self: center; aspect-ratio: 4 / 3; background: #fff; border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; touch-action: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage.can-draw canvas { cursor: crosshair; }
.overlay { position: absolute; inset: 0; display: flex; align-items: safe center; justify-content: center; overflow: auto; background: rgba(255, 246, 224, .92); text-align: center; padding: 16px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.overlay h2 { font-family: Fredoka, sans-serif; margin: 0 0 6px; font-size: clamp(17px, 4.5vw, 22px); }
.overlay .big { font-family: Fredoka, sans-serif; font-size: clamp(24px, 7vw, 34px); color: var(--pink); margin: 4px 0 12px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 6px; }
.choices .btn { font-size: 18px; padding: 11px 16px; }
.pts { list-style: none; margin: 0 auto; padding: 0; max-width: 260px; text-align: left; }
.pts li { display: flex; justify-content: space-between; gap: 16px; padding: 3px 0; font-weight: 700; }
.pts .plus { color: var(--green); }
.status { grid-row: 1; } .stage { grid-row: 2; } .tools { grid-row: 3; } .players { grid-row: 4; } .chat { grid-row: 5; } .say { grid-row: 6; }
.tools:empty { margin-bottom: -8px; }
.tools { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }
.tools > * { flex: none; }
.sw { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); padding: 0; }
.sw.on { box-shadow: 0 0 0 3px var(--ink); }
.tool { height: 34px; min-width: 34px; border-radius: 10px; border: 0; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; padding: 0 8px; font-weight: 800; font-size: 13px; }
.tool.on { background: var(--ink); color: #fff; }
.tool svg { width: 18px; height: 18px; }
.size-dot { border-radius: 50%; background: currentColor; display: block; }
.players { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.players::-webkit-scrollbar { display: none; }
.pchip { flex: none; display: flex; align-items: center; gap: 6px; background: var(--card); border-radius: 99px; padding: 4px 10px 4px 4px; box-shadow: var(--shadow); font-size: 14px; font-weight: 800; border: 2px solid transparent; }
.pchip.drawer { border-color: var(--gold); }
.pchip.got { background: #dcf7ea; }
.pchip.off { opacity: .5; }
.pchip .sc { color: var(--muted); font-weight: 700; }
.chat { min-height: 90px; overflow-y: auto; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 8px 12px; font-size: 15px; line-height: 1.4; }
.chat p { margin: 3px 0; word-break: break-word; }
.chat .sys { color: var(--muted); font-style: italic; font-weight: 700; }
.chat .good { color: var(--green); font-style: normal; }
.chat .secret { color: #158a63; }
.chat b { margin-right: 4px; }
.say { display: flex; gap: 8px; }
.say input { flex: 1; min-width: 0; }
.say .btn { padding: 12px 16px; }

/* desktop: canvas left, chat right */
@media (min-width: 900px) and (min-height: 560px) {
  .game { max-width: 1240px; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto auto minmax(0, 1fr) auto; column-gap: 16px; }
  .status { grid-column: 1 / -1; }
  .stage { grid-column: 1; grid-row: 2 / 4; width: auto; height: 100%; max-width: 100%; min-height: 0; justify-self: center; align-self: start; }
  .tools { grid-column: 1; grid-row: 4; flex-wrap: wrap; justify-content: center; overflow: visible; }
  .players { grid-column: 2; grid-row: 2; flex-wrap: wrap; overflow: visible; }
  .chat { grid-column: 2; grid-row: 3; }
  .say { grid-column: 2; grid-row: 4; align-self: end; }
  .round { min-width: 90px; }
}

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(42, 33, 64, .45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal[hidden] { display: none; }
.sheet { background: var(--paper); border-radius: 22px; padding: 22px; width: 100%; max-width: 420px; max-height: 88dvh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.sheet h2 { font-family: Fredoka, sans-serif; margin: 0 0 10px; text-align: center; }
.sheet ul { padding-left: 18px; line-height: 1.5; }
.podium { list-style: none; padding: 0 !important; margin: 0 0 14px; }
.podium li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; margin-bottom: 6px; background: var(--card); font-weight: 800; }
.podium li:first-child { background: #fff0c2; font-size: 19px; }
.podium .medal { width: 28px; text-align: center; font-size: 20px; }
.podium .s { margin-left: auto; font-family: Fredoka, sans-serif; }
.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 14px); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 800; z-index: 30; max-width: 90vw; text-align: center; animation: drop .25s; }
.toast.good { background: var(--green); }
.toast[hidden] { display: none; }
@keyframes drop { from { transform: translate(-50%, -12px); opacity: 0; } }
