:root {
  --cream: #f7f3ea;
  --paper: #fffdf8;
  --ink: #263238;
  --muted: #7b7a75;
  --coral: #ff6b5e;
  --blue: #4d7cfe;
  --yellow: #f7c948;
  --mint: #69d2b0;
  --line: #e8e1d5;
  --shadow: 5px 6px 0 var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--cream);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { color: inherit; }
button:not(:disabled) { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(77,124,254,.28); outline-offset: 3px; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.background-doodles { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.doodle { position: absolute; opacity: .7; }
.doodle-star { top: 12%; left: 6%; font-size: 54px; color: var(--yellow); transform: rotate(-15deg); }
.doodle-circle { right: 7%; top: 16%; width: 42px; height: 42px; border: 7px solid var(--mint); border-radius: 50%; }
.doodle-squiggle { left: 4%; bottom: 10%; color: var(--blue); font-size: 76px; font-weight: 900; transform: rotate(25deg); }
.doodle-plus { right: 5%; bottom: 12%; color: var(--coral); font-size: 52px; font-weight: 800; transform: rotate(16deg); }

.home-screen { position: relative; z-index: 1; min-height: 100vh; display: grid; place-content: center; padding: 44px 24px 24px; }
.home-card { width: min(1060px, 100%); display: grid; grid-template-columns: 1.08fr .92fr; background: var(--paper); border: 2px solid var(--ink); border-radius: 30px; overflow: hidden; box-shadow: 9px 10px 0 var(--ink); }
.hero-side { position: relative; padding: 44px 48px; background: #fff7e8; border-right: 2px solid var(--ink); overflow: hidden; }
.hero-side::after { content: ""; position: absolute; width: 180px; height: 180px; border-radius: 50%; background: var(--yellow); right: -95px; bottom: -105px; opacity: .6; }
.brand { display: flex; align-items: center; gap: 11px; font-size: 21px; font-weight: 900; letter-spacing: -.5px; }
.brand-large { font-size: 24px; margin-bottom: 38px; }
.brand-mark { width: 43px; height: 43px; display: grid; place-items: center; background: var(--coral); border: 2px solid var(--ink); border-radius: 13px; box-shadow: 3px 3px 0 var(--ink); transform: rotate(-4deg); }
.brand-mark svg { width: 29px; height: 29px; stroke-width: 2.4; }
.party-tag { display: flex; align-items: center; gap: 9px; color: #7d6349; font-size: 12px; font-weight: 700; margin-bottom: 13px; }
.party-tag i { width: 4px; height: 4px; border-radius: 50%; background: var(--coral); }
h1 { font-size: clamp(42px, 4.3vw, 58px); line-height: 1.18; letter-spacing: -3px; margin: 0 0 18px; font-weight: 950; }
h1 span { position: relative; display: inline-block; color: var(--blue); transform: rotate(-2deg); margin-left: 8px; }
h1 span::after { content: ""; position: absolute; height: 8px; left: 0; right: 0; bottom: -4px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='8' viewBox='0 0 180 8'%3E%3Cpath d='M2 6c45-7 104 2 176-4' stroke='%23ff6b5e' stroke-width='4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") center/100% 100% no-repeat; }
.hero-copy { color: #766e64; line-height: 1.9; font-size: 15px; }
.mini-steps { display: flex; gap: 22px; margin-top: 34px; }
.mini-steps div { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; }
.mini-steps b { color: var(--coral); font-size: 13px; }
.join-side { padding: 48px 44px 38px; align-self: center; }
.join-heading { margin-bottom: 28px; }
.eyebrow { display: block; color: var(--blue); font-size: 11px; font-weight: 900; letter-spacing: 2px; margin-bottom: 8px; }
.join-heading h2 { margin: 0 0 8px; font-size: 26px; letter-spacing: -.8px; }
.join-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.field-label { display: block; font-size: 13px; font-weight: 800; margin: 0 0 8px; }
.text-input { width: 100%; height: 50px; padding: 0 16px; border: 2px solid var(--ink); border-radius: 12px; background: white; color: var(--ink); transition: box-shadow .15s, transform .15s; }
.text-input::placeholder { color: #aaa69f; }
.text-input:focus { box-shadow: 3px 3px 0 var(--yellow); outline: none; }
.button { min-height: 48px; padding: 0 22px; border: 2px solid var(--ink); border-radius: 12px; font-weight: 900; display: inline-flex; align-items: center; justify-content: center; gap: 10px; transition: transform .12s, box-shadow .12s; }
.button svg { width: 20px; }
.button:not(:disabled):hover { transform: translateY(-2px); }
.button:not(:disabled):active { transform: translate(2px,2px); box-shadow: none; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-primary { color: white; background: var(--coral); box-shadow: 4px 4px 0 var(--ink); }
.button-secondary { background: var(--yellow); box-shadow: 3px 3px 0 var(--ink); white-space: nowrap; }
.button-full { width: 100%; margin-top: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: #a29c91; font-size: 11px; margin: 24px 0 16px; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.join-row { display: flex; gap: 10px; }
.code-input { text-transform: uppercase; letter-spacing: 4px; font-weight: 900; text-align: center; }
.form-error { min-height: 18px; margin: 10px 0 0; color: #d84236; font-size: 12px; }
.privacy-note { color: #9a958d; font-size: 11px; display: flex; align-items: center; justify-content: center; gap: 6px; margin: 14px 0 0; }
.privacy-note span { width: 6px; height: 6px; background: var(--mint); border-radius: 50%; }
.home-footnote { text-align: center; color: #8f887e; font-size: 12px; margin: 25px 0 0; }

.game-screen { position: relative; z-index: 1; width: min(1380px, calc(100% - 40px)); margin: 0 auto; padding: 22px 0 30px; }
.game-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 19px; }
.header-actions { display: flex; gap: 10px; }
.room-pill { height: 45px; padding: 0 14px; display: flex; align-items: center; gap: 9px; border: 2px solid var(--ink); border-radius: 12px; background: var(--paper); box-shadow: 3px 3px 0 var(--ink); }
.room-pill > span { color: var(--muted); font-size: 11px; }
.room-pill strong { color: var(--blue); letter-spacing: 3px; font-size: 17px; }
.room-pill svg { width: 17px; height: 17px; color: var(--muted); }
.icon-button { width: 45px; height: 45px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 12px; background: var(--paper); }
.icon-button svg { width: 20px; }
.score-strip { display: grid; grid-template-columns: 1fr 150px 1fr; align-items: center; gap: 20px; margin-bottom: 18px; }
.player-card { display: flex; align-items: center; gap: 13px; min-height: 82px; padding: 12px 17px; background: var(--paper); border: 2px solid var(--ink); border-radius: 18px; transition: transform .2s, background .2s; }
.player-card.is-drawer { background: #fff2c8; box-shadow: 3px 4px 0 var(--yellow); transform: translateY(-2px); }
.player-card.is-guesser { background: #edf2ff; }
.avatar { position: relative; flex: 0 0 auto; width: 52px; height: 52px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 16px; background: var(--avatar, var(--mint)); font-size: 23px; font-weight: 900; transform: rotate(-3deg); }
.turn-dot { display: none; position: absolute; width: 13px; height: 13px; right: -5px; top: -5px; border: 2px solid var(--paper); background: var(--coral); border-radius: 50%; }
.is-drawer .turn-dot { display: block; animation: pulse 1.2s infinite; }
.player-info { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 900; }
.player-role { font-size: 11px; color: var(--muted); }
.player-score { margin-left: auto; display: flex; align-items: baseline; gap: 3px; white-space: nowrap; }
.player-score strong { font-size: 28px; line-height: 1; color: var(--blue); }
.player-score span { font-size: 11px; color: var(--muted); }
.empty-player { opacity: .55; }
.round-center { text-align: center; }
.round-center > span { display: block; font-size: 12px; font-weight: 900; margin-bottom: 5px; }
.timer { display: inline-flex; align-items: center; gap: 3px; color: var(--ink); }
.timer svg { width: 19px; height: 19px; margin-right: 3px; }
.timer strong { font-size: 27px; font-variant-numeric: tabular-nums; }
.timer span { font-size: 12px; color: var(--muted); }
.timer.danger { color: #e3483c; animation: timerPulse .8s infinite; }

.play-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: stretch; }
.board-column { min-width: 0; }
.prompt-bar { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 18px; background: var(--paper); border: 2px solid var(--ink); border-bottom: 0; border-radius: 18px 18px 0 0; }
.prompt-label { font-size: 13px; font-weight: 900; }
.prompt-bar p { margin: 4px 0 0; font-size: 11px; color: var(--muted); }
.word-display { display: flex; align-items: center; justify-content: flex-end; gap: 8px; color: var(--blue); font-size: 24px; font-weight: 950; letter-spacing: 2px; text-align: right; }
.word-blank { width: 31px; height: 36px; display: grid; place-items: center; border-bottom: 3px solid var(--ink); color: var(--muted); font-size: 15px; }
.canvas-shell { position: relative; border: 2px solid var(--ink); background: var(--paper); overflow: hidden; }
#drawingCanvas { position: relative; z-index: 2; display: block; width: 100%; height: auto; aspect-ratio: 20 / 13; background: #fffdf9; touch-action: none; cursor: not-allowed; }
#drawingCanvas.drawing-enabled { cursor: crosshair; }
.canvas-grid { position: absolute; z-index: 1; inset: 0; opacity: .35; background-image: radial-gradient(#ddd6ca 1px, transparent 1px); background-size: 24px 24px; pointer-events: none; }
.board-overlay { position: absolute; z-index: 5; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(255,253,248,.88); backdrop-filter: blur(4px); }
.overlay-card { text-align: center; max-width: 430px; }
.overlay-illustration { width: 85px; height: 85px; margin: 0 auto 10px; }
.overlay-illustration svg { width: 100%; height: 100%; }
.overlay-illustration .blob { fill: #e9efff; stroke: var(--ink); }
.overlay-illustration .pencil { fill: var(--coral); stroke: var(--ink); }
.overlay-card h2 { margin: 8px 0; font-size: 25px; }
.overlay-card p { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.overlay-card .button { min-width: 170px; }
.result-overlay { background: rgba(255,250,232,.9); }
.result-badge { display: inline-block; padding: 5px 13px; color: var(--ink); background: var(--yellow); border: 2px solid var(--ink); border-radius: 30px; font-size: 12px; font-weight: 900; transform: rotate(-3deg); }
.answer-reveal { margin: 16px 0 10px; font-size: 14px; }
.answer-reveal strong { color: var(--blue); font-size: 25px; margin-left: 5px; }
.next-tip { color: var(--muted); font-size: 11px; }

.drawing-tools { min-width: 0; margin: 0; padding: 11px 14px; display: flex; align-items: center; gap: 13px; border: 2px solid var(--ink); border-top: 0; border-radius: 0 0 18px 18px; background: var(--paper); }
.drawing-tools:disabled { opacity: .48; }
.tool-group { display: flex; align-items: center; gap: 7px; }
.tool-divider { width: 1px; height: 28px; background: var(--line); }
.color-swatch { width: 25px; height: 25px; padding: 0; border: 2px solid var(--paper); outline: 1px solid transparent; border-radius: 50%; background: var(--swatch); transition: transform .12s; }
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { outline: 2px solid var(--ink); transform: scale(1.12); }
.brush-group svg { width: 18px; }
.brush-group input { width: 80px; accent-color: var(--coral); }
.brush-preview { width: 26px; height: 26px; display: grid; place-items: center; }
.brush-preview::after { content: ""; display: block; width: var(--brush, 8px); height: var(--brush, 8px); max-width: 24px; max-height: 24px; border-radius: 50%; background: var(--ink); }
.tool-button { height: 35px; padding: 0 9px; display: flex; align-items: center; gap: 4px; border: 1px solid transparent; border-radius: 8px; background: transparent; font-size: 11px; font-weight: 800; }
.tool-button svg { width: 17px; height: 17px; }
.tool-button.active { background: #e9efff; border-color: #b9c9ff; color: var(--blue); }
.clear-tool { color: #d45146; }

.chat-panel { min-height: 0; display: flex; flex-direction: column; background: var(--paper); border: 2px solid var(--ink); border-radius: 18px; overflow: hidden; box-shadow: 4px 5px 0 #e4dccf; }
.chat-heading { min-height: 62px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.chat-heading > div { display: flex; align-items: center; gap: 7px; font-size: 14px; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #51cf66; box-shadow: 0 0 0 3px #dcf7e7; }
.chat-heading > span { color: var(--muted); font-size: 10px; }
.chat-log { height: 450px; flex: 1; min-height: 250px; overflow-y: auto; padding: 16px; scroll-behavior: smooth; }
.chat-log::-webkit-scrollbar { width: 5px; }
.chat-log::-webkit-scrollbar-thumb { background: #ddd5c8; border-radius: 5px; }
.chat-welcome { margin: 12px 0 22px; padding: 15px; text-align: center; color: #8b857c; background: #faf7f0; border: 1px dashed #d9d0c2; border-radius: 13px; }
.chat-welcome span { display: inline-block; padding: 2px 8px; border-radius: 5px; background: #eee7db; font-size: 10px; font-weight: 900; }
.chat-welcome p { font-size: 11px; line-height: 1.8; margin: 8px 0 0; }
.chat-message { margin-bottom: 13px; }
.chat-meta { margin: 0 0 4px 3px; color: #999187; font-size: 10px; }
.chat-bubble { display: inline-block; max-width: 95%; padding: 8px 11px; background: #f1eee8; border-radius: 4px 12px 12px 12px; font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; }
.chat-message.own { text-align: right; }
.chat-message.own .chat-bubble { color: white; background: var(--blue); border-radius: 12px 4px 12px 12px; text-align: left; }
.chat-message.own .chat-meta { margin-right: 3px; }
.system-message { display: flex; align-items: center; gap: 8px; margin: 13px 0; color: #928b81; font-size: 10px; text-align: center; }
.system-message::before, .system-message::after { content: ""; flex: 1; height: 1px; background: #eee8de; }
.chat-form { display: flex; gap: 8px; padding: 12px 12px 8px; border-top: 1px solid var(--line); }
.chat-form input { min-width: 0; flex: 1; height: 42px; padding: 0 12px; border: 1.5px solid #dcd5ca; border-radius: 10px; background: #faf8f4; font-size: 12px; }
.chat-form input:focus { border-color: var(--blue); background: white; outline: none; }
.chat-form button { width: 42px; height: 42px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 10px; color: white; background: var(--coral); box-shadow: 2px 2px 0 var(--ink); }
.chat-form button:active { transform: translate(2px,2px); box-shadow: none; }
.chat-form button svg { width: 19px; }
.chat-footnote { margin: 0 0 9px; color: #aaa39a; font-size: 9px; text-align: center; }

.modal-backdrop { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(38,50,56,.45); backdrop-filter: blur(7px); }
.modal-card { width: min(440px,100%); padding: 28px 32px 30px; text-align: center; background: var(--paper); border: 2px solid var(--ink); border-radius: 25px; box-shadow: 8px 9px 0 var(--ink); animation: popIn .35s cubic-bezier(.2,.9,.3,1.3); }
.trophy { width: 90px; height: 90px; display: grid; place-items: center; margin: -68px auto 17px; border: 2px solid var(--ink); border-radius: 50%; background: var(--yellow); box-shadow: 3px 4px 0 var(--ink); }
.trophy svg { width: 63px; height: 63px; }
.modal-card h2 { margin: 4px 0 8px; font-size: 27px; }
.modal-card > p { color: var(--muted); font-size: 13px; }
.final-scores { display: flex; gap: 10px; margin: 22px 0 10px; }
.final-player { flex: 1; padding: 14px 8px; background: #f7f2e9; border: 1px solid var(--line); border-radius: 13px; }
.final-player.winner { background: #fff2c8; border: 2px solid var(--yellow); }
.final-player span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 800; }
.final-player strong { display: block; color: var(--blue); font-size: 30px; margin-top: 4px; }
.final-player small { color: var(--muted); font-size: 10px; }
.again-hint { min-height: 15px; margin: 13px 0 0 !important; font-size: 11px !important; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 30px; transform: translateX(-50%); max-width: calc(100% - 30px); padding: 11px 18px; color: white; background: var(--ink); border-radius: 10px; box-shadow: 0 5px 20px rgba(0,0,0,.18); font-size: 13px; animation: toastIn .2s ease-out; }
.confetti-container { position: fixed; z-index: 80; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-piece { position: absolute; top: -20px; left: var(--left); width: 10px; height: 16px; background: var(--color); border: 1px solid rgba(38,50,56,.25); border-radius: 2px; animation: confettiFall var(--duration) var(--delay) cubic-bezier(.2,.6,.4,1) forwards; }

@keyframes pulse { 50% { transform: scale(1.25); } }
@keyframes timerPulse { 50% { transform: scale(1.08); } }
@keyframes popIn { from { opacity: 0; transform: translateY(20px) scale(.92); } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%,10px); } }
@keyframes confettiFall { to { transform: translate(var(--drift), 105vh) rotate(var(--rotate)); } }

@media (max-width: 1050px) {
  .play-layout { grid-template-columns: minmax(0,1fr) 275px; gap: 14px; }
  .drawing-tools { flex-wrap: wrap; gap: 8px; }
  .tool-divider { display: none; }
  .colors { width: 100%; justify-content: center; }
  .action-tools { margin-left: auto; }
  .chat-log { height: 420px; }
}
@media (max-width: 800px) {
  .home-card { grid-template-columns: 1fr; max-width: 540px; }
  .hero-side { border-right: 0; border-bottom: 2px solid var(--ink); padding: 32px; }
  .brand-large { margin-bottom: 24px; }
  .join-side { padding: 32px; }
  .mini-steps { margin-top: 24px; }
  .play-layout { grid-template-columns: 1fr; }
  .chat-panel { min-height: 340px; }
  .chat-log { height: 260px; min-height: 180px; }
  .score-strip { grid-template-columns: 1fr 75px 1fr; gap: 8px; }
  .player-card { gap: 8px; padding: 10px; }
  .avatar { width: 43px; height: 43px; border-radius: 13px; font-size: 18px; }
  .player-score strong { font-size: 23px; }
}
@media (max-width: 520px) {
  .home-screen { padding: 20px 14px; }
  .hero-side, .join-side { padding: 26px 23px; }
  h1 { font-size: 40px; }
  .hero-copy br { display: none; }
  .mini-steps { gap: 12px; }
  .mini-steps div { flex-direction: column; align-items: flex-start; gap: 2px; }
  .join-row { flex-direction: column; }
  .game-screen { width: calc(100% - 20px); padding-top: 12px; }
  .game-header .brand > span:last-child { display: none; }
  .room-pill > span { display: none; }
  .score-strip { grid-template-columns: 1fr 55px 1fr; }
  .player-card { min-height: 71px; flex-wrap: wrap; gap: 6px; }
  .avatar { width: 36px; height: 36px; border-radius: 11px; font-size: 15px; }
  .player-name { max-width: 75px; font-size: 12px; }
  .player-role { font-size: 9px; }
  .player-score { margin-left: 0; width: 100%; justify-content: flex-end; margin-top: -23px; }
  .player-score strong { font-size: 20px; }
  .round-center > span { font-size: 10px; }
  .timer strong { font-size: 23px; }
  .timer svg { display: none; }
  .prompt-bar { align-items: flex-start; padding: 10px 12px; }
  .word-display { font-size: 19px; }
  .word-blank { width: 23px; height: 28px; }
  .drawing-tools { padding: 9px; }
  .color-swatch { width: 23px; height: 23px; }
  .brush-group input { width: 65px; }
  .tool-button span { display: none; }
  .tool-button { padding: 0 7px; }
  .background-doodles { display: none; }
}
