:root {
  color-scheme: light;
  --ink: #1e281f;
  --muted: #667064;
  --forest: #263b29;
  --forest-deep: #172519;
  --frog: #78984a;
  --frog-light: #b8ce78;
  --chestnut: #914f33;
  --cream: #f6f0e3;
  --paper: #fffdf7;
  --gold: #d9b76c;
  --line: rgba(38, 59, 41, 0.13);
  font-family: "SF Pro Rounded", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { min-width: 320px; min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(184, 206, 120, 0.18), transparent 34rem),
    radial-gradient(circle at 95% 100%, rgba(145, 79, 51, 0.13), transparent 32rem),
    #e9ecdf;
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -2;
  content: "";
  background: linear-gradient(135deg, #18271b 0 36%, #213925 36% 52%, transparent 52%);
  clip-path: polygon(0 0, 100% 0, 78% 24%, 0 47%);
}

.page-texture {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.12;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.72' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E");
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(120, 152, 74, 0.52); outline-offset: 3px; }

.app-shell { min-height: 100vh; min-height: 100dvh; }
[hidden] { display: none !important; }

.home-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(26px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
}

.home-card {
  position: relative;
  width: min(100%, 1040px);
  min-height: 650px;
  display: grid;
  grid-template-columns: 1.12fr 0.88fr;
  align-items: center;
  gap: clamp(28px, 6vw, 76px);
  padding: clamp(28px, 5vw, 64px);
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 34px;
  background: rgba(250, 248, 239, 0.9);
  box-shadow: 0 42px 110px rgba(25, 39, 27, 0.28), inset 0 1px 0 white;
  backdrop-filter: blur(18px);
}

.brand-lockup { text-align: center; }
.home-mascots { width: min(100%, 440px); margin: -40px auto -22px; display: block; filter: drop-shadow(0 24px 25px rgba(42, 50, 31, 0.22)); }
.edition-mark { display: inline-flex; padding: 7px 12px; border: 1px solid rgba(38, 59, 41, 0.2); border-radius: 999px; color: var(--forest); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.12em; }
.brand-lockup h1 { margin: 18px 0 10px; font-size: clamp(2.6rem, 7vw, 4.8rem); line-height: 0.95; letter-spacing: -0.075em; color: var(--forest-deep); }
.brand-lockup > p { max-width: 440px; margin: 0 auto; color: var(--muted); font-size: 1rem; line-height: 1.8; }

.entry-panel { padding: clamp(22px, 4vw, 36px); border: 1px solid var(--line); border-radius: 26px; background: rgba(255, 253, 247, 0.75); box-shadow: 0 18px 50px rgba(38, 59, 41, 0.1); }
.entry-panel label { display: block; margin-bottom: 10px; font-size: 0.92rem; font-weight: 800; }
.entry-panel input, .guess-form input { width: 100%; min-height: 51px; padding: 0 16px; border: 1px solid rgba(38, 59, 41, 0.16); border-radius: 15px; color: var(--ink); background: rgba(255,255,255,.8); box-shadow: inset 0 1px 4px rgba(38,59,41,.05); }
.entry-panel > input { margin-bottom: 13px; }

.button { min-height: 46px; border: 0; border-radius: 15px; cursor: pointer; font-weight: 850; transition: transform .15s ease, filter .15s ease, box-shadow .15s ease; }
.button:hover { filter: brightness(1.04); box-shadow: 0 10px 24px rgba(38,59,41,.16); }
.button:active { transform: scale(.98); }
.button-primary { padding: 0 18px; color: #fffef7; background: linear-gradient(135deg, #58723b, #263b29); box-shadow: 0 8px 20px rgba(38,59,41,.18), inset 0 1px 0 rgba(255,255,255,.15); }
.button-secondary { padding: 0 18px; color: var(--forest); border: 1px solid rgba(38,59,41,.18); background: #edf0e3; }
.button-large { width: 100%; min-height: 64px; display: flex; align-items: center; justify-content: space-between; text-align: left; }
.button-large span { font-size: 1rem; }
.button-large small { opacity: .7; font-size: .75rem; font-weight: 650; }
.divider { margin: 20px 0; display: flex; align-items: center; gap: 12px; color: #8a9186; font-size: .77rem; }
.divider::before, .divider::after { height: 1px; flex: 1; content: ""; background: var(--line); }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
#room-code { text-transform: uppercase; font-weight: 850; letter-spacing: .12em; }
.entry-status { min-height: 1.25em; margin: 10px 2px 0; color: #a34d3f; font-size: .8rem; }
.home-note { position: absolute; align-self: end; justify-self: center; margin: 0 0 19px; color: #798076; font-size: .76rem; }

.game-view { width: min(100%, 1500px); min-height: 100vh; min-height: 100dvh; margin: auto; padding: max(14px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; }
.topbar { min-height: 74px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px; padding: 8px 16px; border: 1px solid rgba(255,255,255,.1); border-radius: 22px; color: white; background: rgba(20,33,22,.94); box-shadow: 0 15px 35px rgba(23,37,25,.18); }
.mini-brand { min-width: 0; display: flex; align-items: center; gap: 10px; }
.mini-brand img { width: 66px; height: 52px; object-fit: cover; object-position: center; border-radius: 14px; }
.mini-brand strong, .mini-brand span { display: block; }
.mini-brand strong { font-size: .96rem; }
.mini-brand span { margin-top: 2px; color: #9daa9c; font-size: .68rem; }
.round-status { text-align: center; }
.round-status span { display: block; margin-bottom: 3px; color: #aab4aa; font-size: .72rem; }
.round-status strong { font-size: 1.22rem; letter-spacing: .1em; }
.room-actions { justify-self: end; display: flex; align-items: center; gap: 10px; }
.room-code { min-height: 43px; padding: 0 14px; border: 1px solid rgba(255,255,255,.13); border-radius: 13px; color: #bec8bc; background: rgba(255,255,255,.07); cursor: pointer; font-size: .76rem; }
.room-code strong { margin-left: 5px; color: white; letter-spacing: .08em; }
.timer { position: relative; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--frog-light) var(--timer-progress, 100%), rgba(255,255,255,.12) 0); }
.timer::after { position: absolute; inset: 4px; border-radius: 50%; content: ""; background: var(--forest-deep); }
.timer strong { z-index: 1; font-size: .85rem; }

.game-layout { min-height: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 370px); gap: 14px; margin-top: 14px; }
.play-stage { min-width: 0; display: flex; flex-direction: column; gap: 11px; }
.player-ribbon { min-height: 60px; display: flex; gap: 8px; overflow-x: auto; padding: 3px 1px 5px; scrollbar-width: none; }
.player-ribbon::-webkit-scrollbar { display: none; }
.player-chip { position: relative; min-width: 118px; display: grid; grid-template-columns: 35px 1fr; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid rgba(255,255,255,.64); border-radius: 16px; background: rgba(255,253,247,.83); box-shadow: 0 6px 18px rgba(38,59,41,.07); }
.player-chip.drawer { border-color: rgba(120,152,74,.52); background: #eff3df; }
.player-chip.guessed::after { position: absolute; top: -4px; right: -3px; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--frog); content: "✓"; font-size: .68rem; font-weight: 900; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; color: white; background: linear-gradient(145deg, var(--frog), var(--forest)); font-weight: 900; }
.player-chip:nth-child(2n) .avatar { background: linear-gradient(145deg, #bd7652, var(--chestnut)); }
.player-meta { min-width: 0; }
.player-meta strong, .player-meta span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-meta strong { font-size: .81rem; }
.player-meta span { margin-top: 2px; color: #7a8278; font-size: .67rem; }
.player-chip.offline { opacity: .48; }

.canvas-frame { position: relative; min-height: 0; flex: 1; overflow: hidden; border: 1px solid rgba(38,59,41,.14); border-radius: 24px; background: var(--paper); box-shadow: 0 20px 52px rgba(38,59,41,.13); }
#drawing-canvas { width: 100%; height: 100%; min-height: 420px; display: block; touch-action: none; background: #fffdf8; cursor: default; }
#drawing-canvas.can-draw { cursor: crosshair; }
.canvas-placeholder { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; padding: 28px; text-align: center; background: radial-gradient(circle at 50% 38%, #fff 0, #f8f4e8 66%); }
.canvas-placeholder img { width: min(310px, 64%); margin: -55px 0 -25px; filter: drop-shadow(0 16px 20px rgba(38,59,41,.16)); }
.overline { margin: 0 0 8px; color: var(--chestnut); font-size: .7rem; font-weight: 900; letter-spacing: .16em; }
.canvas-placeholder h2 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.8rem); letter-spacing: -.05em; }
.canvas-placeholder > p:not(.overline) { margin: 9px 0 20px; color: var(--muted); font-size: .9rem; }
.round-card { position: absolute; inset: 0; z-index: 4; display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; background: rgba(247,243,231,.91); backdrop-filter: blur(9px); }
.round-card p { margin: 0 0 8px; color: var(--chestnut); font-size: .78rem; font-weight: 900; letter-spacing: .13em; }
.round-card > strong { font-size: clamp(2.4rem, 7vw, 5.2rem); letter-spacing: -.06em; }
.round-card > span { margin-top: 10px; color: var(--muted); font-size: .86rem; }
.final-card ol { width: min(360px, 80vw); margin: 18px 0; padding: 0; list-style: none; }
.final-card li { display: grid; grid-template-columns: 35px 1fr auto; padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.final-card li b:last-child { color: var(--chestnut); }

.drawing-toolbar { min-height: 58px; display: flex; align-items: center; gap: 15px; padding: 8px 12px; border: 1px solid rgba(255,255,255,.58); border-radius: 18px; background: rgba(255,253,247,.85); box-shadow: 0 8px 24px rgba(38,59,41,.08); }
.colors, .brush-sizes { display: flex; align-items: center; gap: 7px; }
.color { width: 30px; height: 30px; padding: 0; border: 3px solid transparent; border-radius: 50%; background: var(--swatch); background-clip: padding-box; cursor: pointer; }
.color.active { border-color: var(--paper); box-shadow: 0 0 0 2px var(--swatch); }
.brush { width: 30px; height: 30px; display: grid; place-items: center; padding: 0; border: 1px solid transparent; border-radius: 9px; background: transparent; cursor: pointer; }
.brush i { width: calc(var(--brush-size, 5) * 1px); height: calc(var(--brush-size, 5) * 1px); max-width: 18px; max-height: 18px; border-radius: 50%; background: var(--ink); }
.brush:nth-child(1) i { width: 5px; height: 5px; }.brush:nth-child(2) i { width: 10px; height: 10px; }.brush:nth-child(3) i { width: 17px; height: 17px; }
.brush.active { border-color: var(--line); background: #edf0e5; }
.clear-button { min-height: 36px; margin-left: auto; padding: 0 12px; border: 1px solid var(--line); border-radius: 11px; color: var(--chestnut); background: transparent; cursor: pointer; font-weight: 800; }
.toolbar-hint { color: #858c82; font-size: .72rem; }
.drawing-toolbar.disabled .colors, .drawing-toolbar.disabled .brush-sizes, .drawing-toolbar.disabled .clear-button { opacity: .34; pointer-events: none; }

.chat-panel { min-height: 0; display: flex; flex-direction: column; overflow: hidden; border: 1px solid rgba(255,255,255,.64); border-radius: 24px; background: rgba(255,253,247,.9); box-shadow: 0 20px 52px rgba(38,59,41,.12); }
.chat-heading { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.chat-heading span { color: var(--chestnut); font-size: .66rem; font-weight: 850; letter-spacing: .12em; }
.chat-heading h2 { margin: 2px 0 0; font-size: 1.25rem; }
.online-count { padding: 6px 9px; border-radius: 999px; background: #edf1e5; letter-spacing: 0 !important; color: var(--forest) !important; }
.messages { min-height: 200px; flex: 1; overflow-y: auto; padding: 15px; }
.message { margin-bottom: 12px; display: grid; grid-template-columns: 32px 1fr; gap: 9px; }
.message-avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 10px; color: white; background: var(--forest); font-size: .72rem; font-weight: 850; }
.message-copy { min-width: 0; }
.message-copy b { display: block; margin-bottom: 3px; color: #70786d; font-size: .68rem; }
.message-copy p { width: fit-content; max-width: 100%; margin: 0; padding: 8px 11px; overflow-wrap: anywhere; border-radius: 4px 13px 13px 13px; background: #eff1e9; font-size: .88rem; line-height: 1.45; }
.message.correct .message-copy p { color: #3f5a2b; border: 1px solid rgba(120,152,74,.22); background: #e9f0d4; font-weight: 850; }
.message.system { display: block; margin: 9px 0; text-align: center; }
.message.system p { display: inline-block; margin: 0; padding: 5px 9px; border-radius: 999px; color: #788076; background: #eceee7; font-size: .7rem; }
.guess-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px 14px 6px; border-top: 1px solid var(--line); }
.guess-form input { min-height: 46px; }
.guess-hint { margin: 0; padding: 3px 16px 13px; color: #8b9288; font-size: .7rem; line-height: 1.45; }

.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 20; max-width: calc(100% - 30px); padding: 11px 17px; border-radius: 13px; color: white; background: rgba(24,37,26,.94); box-shadow: 0 12px 32px rgba(23,37,25,.25); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: .22s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  body::before { clip-path: polygon(0 0, 100% 0, 100% 18%, 0 33%); }
  .home-card { min-height: auto; grid-template-columns: 1fr; gap: 22px; }
  .home-mascots { width: min(100%, 360px); margin-bottom: -25px; }
  .home-note { position: static; grid-column: 1; }
  .game-view { overflow: visible; }
  .topbar { grid-template-columns: 1fr auto; }
  .round-status { grid-row: 2; grid-column: 1 / -1; padding: 4px 0 8px; }
  .game-layout { grid-template-columns: 1fr; }
  .canvas-frame { min-height: min(72vw, 620px); }
  .chat-panel { min-height: 440px; }
}

@media (max-width: 600px) {
  .home-view { padding-inline: 10px; }
  .home-card { padding: 22px 15px; border-radius: 25px; }
  .brand-lockup h1 { font-size: 3rem; }
  .entry-panel { padding: 20px 15px; }
  .game-view { padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .topbar { gap: 8px; padding: 7px 9px; border-radius: 17px; }
  .mini-brand img { width: 49px; height: 42px; }
  .mini-brand span { display: none; }
  .room-code { padding-inline: 9px; }
  .game-layout { margin-top: 8px; }
  .canvas-frame { min-height: min(92vw, 510px); border-radius: 18px; }
  #drawing-canvas { min-height: min(92vw, 510px); }
  .drawing-toolbar { flex-wrap: wrap; gap: 10px; padding: 9px; }
  .toolbar-hint { width: 100%; text-align: center; }
  .clear-button { margin-left: auto; }
  .chat-panel { min-height: 410px; border-radius: 18px; }
  .join-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
