/* ============================================================================
   분신사바 온라인 — HUD 스타일 「갱지와 빨간 볼펜」
   HUD는 앱 UI가 아니라 1998년 교실 책상 위 물건이다. 두 방은 같은 컴포넌트, 조명(토큰)만 다르다.
   규칙 원본: docs/hud/HUD_DESIGN_GUIDE.md — 그라디언트·블러 그림자·둥근 모서리·이모지 금지.
   ============================================================================ */

/* Galmuri11 (OFL): public/fonts/Galmuri11.woff2 를 넣으면 url(...)을 추가해 자체 호스팅한다. */
@font-face {
  font-family: 'Galmuri11';
  src: local('Galmuri11'), local('Galmuri 11');
  font-display: swap;
}

/* ============================================================================
   0. 토큰
   ============================================================================ */
:root {
  /* 물건에서 뽑은 색 */
  --ink: #1c1915;            /* 연필심·먹 */
  --paper: #e8dec6;          /* 연습장 갱지 */
  --paper-shade: #cfc2a2;    /* 갱지 그늘 */
  --paper-rule: #9fb3c8;     /* 연습장 파란 줄 */
  --chalkboard: #2f4a3c;     /* 칠판 */
  --chalk: #e9eee6;          /* 분필 */
  --monami-red: #c0161f;     /* 모나미 빨간 볼펜 — 의식·금기·화자 전용 */
  --bujeok: #d8b13e;         /* 부적(괴황지) */
  --cinnabar: #a8261a;       /* 경면주사·직인 */
  --candle: #ffb84d;         /* 촛불 */
  --ghost-blue: #8fb4ff;     /* 도깨비불 */
  --nametag: #2b4f8e;        /* 명찰 학년 띠 */
  --highlighter: #f2e35a;    /* 형광펜 */
  --sunset: #e0782f;         /* 노을 (면·강조 전용, 갱지 위 글자 금지) */

  /* 텍스트용 보조 토큰 (대비 4.5:1) */
  --monami-red-text: #e2646b; /* 어두운 바탕 위 빨간 글자 */
  --cinnabar-text: #7a1a10;   /* 부적 위 글자 */
  --ink-dim: #5d554a;         /* 갱지 위 흐린 글자 */
  --ghost-ink-paper: #3f5a78; /* 갱지 위 귀신 글씨 */

  --font-ui: 'Galmuri11', 'DungGeunMo', 'Dotum', '돋움', 'AppleGothic', monospace;
  --font-hand: 'Nanum Pen Script', 'Nanum Brush Script', cursive;

  --gutter: 16px;
  --panel-top: 76px;         /* 상단 바 아래 패널 시작 위치 */
  --bottom-reserve: 76px;    /* 하단 바 높이 + 여백 */
}

/* 평범한 학교 방 — 노을 방과후, 밝은 종이 위 연필 글씨 */
body.theme-normal {
  --bg: #1d2d44;
  --surface: var(--paper);
  --surface-2: var(--paper-shade);
  --surface-3: #bfb08c;
  --on-surface: var(--ink);
  --on-surface-dim: var(--ink-dim);
  --edge: var(--ink);
  --accent: var(--sunset);
  --accent-text: var(--ink);
  --accent-text-bg: var(--highlighter);
  --chip-bg: var(--ink);
  --chip-fg: var(--paper);
  --primary-bg: var(--ink);
  --primary-fg: var(--paper);
  --hud-shadow: 2px 2px 0 rgba(28, 25, 21, 0.55);
  --tag-paper: #f1e9d6;
  --note-rule: rgba(159, 179, 200, 0.75);
  --note-margin: rgba(192, 22, 31, 0.55);
  --story-ink: var(--monami-red);
  --ghost-ink: var(--ghost-ink-paper);
  --me-mark: var(--highlighter);
  --pencil-wood: #b9873f;
  --toast-bg: var(--chalkboard);
  --toast-fg: var(--chalk);
  --toast-edge: var(--ink);
  --focus: var(--nametag);
}

/* 무서운 이야기 방 — 촛불 하나, 달빛에 바랜 종이 */
body.theme-scary {
  --bg: #07070a;
  --surface: #15161d;
  --surface-2: #20222c;
  --surface-3: #2b2e3b;
  --on-surface: #cbc3ad;
  --on-surface-dim: #8c8677;
  --edge: #3a3f52;
  --accent: var(--candle);
  --accent-text: var(--candle);
  --accent-text-bg: transparent;
  --chip-bg: #2b2e3b;
  --chip-fg: #b3ab96;
  --primary-bg: #cfc6ae;
  --primary-fg: var(--ink);
  --hud-shadow: 2px 2px 0 #000;
  --tag-paper: #cfc6ae;
  --note-rule: #23262f;
  --note-margin: #5a1d24;
  --story-ink: var(--monami-red-text);
  --ghost-ink: #9fb3c8;
  --me-mark: var(--candle);
  --pencil-wood: #a9a18c;
  --toast-bg: #101114;
  --toast-fg: #cbc3ad;
  --toast-edge: #3a3f52;
  --focus: var(--candle);
}

/* ============================================================================
   1. 바탕 · 유틸리티
   ============================================================================ */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--on-surface);
  font: 12px/18px var(--font-ui);
  -webkit-font-smoothing: none;
  user-select: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
  margin: 0;
  border-radius: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

input::placeholder {
  color: var(--on-surface-dim);
  opacity: 1;
}

canvas,
.pixel-3d-canvas {
  image-rendering: pixelated;
}

.px-icon {
  display: block;
  fill: currentColor;
  flex: none;
}

.px-hole {
  fill: var(--surface);
}

.hidden {
  display: none !important;
}

body:not(.dev-mode) .dev-only {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================================
   2. 공통 부품 — 판(plate) · 버튼
   ============================================================================ */
.plate {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--on-surface);
  border: 2px solid var(--edge);
  box-shadow: var(--hud-shadow);
}

button.plate:hover {
  background: var(--surface-2);
}

.plate-label {
  color: var(--on-surface-dim);
}

.plate-num {
  font-size: 24px;
  line-height: 24px;
}

.plate-divider {
  width: 2px;
  height: 24px;
  background: var(--edge);
}

.icon-btn {
  width: 44px;
  padding: 0;
  justify-content: center;
}

.btn-sub {
  height: 32px;
  padding: 0 10px;
  background: var(--surface-2);
  color: var(--on-surface);
  border: 2px solid var(--edge);
}

.btn-sub:hover {
  background: var(--surface-3);
}

.accent-text {
  color: var(--accent-text);
  background: var(--accent-text-bg);
  padding: 0 2px;
}

/* 지금 누를 주요 버튼 (화면에 하나) */
.primary-btn {
  height: 44px;
  padding: 0 20px;
  background: var(--primary-bg);
  color: var(--primary-fg);
  border: 2px solid var(--ink);
  box-shadow: var(--hud-shadow);
  font-size: 24px;
  line-height: 24px;
  letter-spacing: 4px;
}

/* 부적 버튼 — 의식 시작·끝 */
.bujeok-btn {
  position: relative;
  height: 44px;
  padding: 0 18px 0 40px;
  background: var(--bujeok);
  color: var(--cinnabar-text);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 #000;
  font-size: 24px;
  line-height: 24px;
  letter-spacing: 2px;
  white-space: nowrap;
}

.bujeok-btn::before {
  content: '';
  position: absolute;
  left: 12px;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  background: var(--cinnabar);
}

/* 종이 위 볼펜으로 그린 테두리 버튼 */
.ink-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 10px;
  background: transparent;
  color: inherit;
  border: 2px solid currentColor;
  text-decoration: none;
  white-space: nowrap;
}

.ink-btn:hover {
  background: rgba(28, 25, 21, 0.1);
}

.ink-btn.ready-next {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* 체크박스처럼 생긴 선택 버튼 (성별 등) */
.check-btn {
  position: relative;
  height: 36px;
  padding: 0 12px 0 32px;
  background: transparent;
  color: var(--ink);
  border: 2px solid var(--ink);
  white-space: nowrap;
}

.check-btn::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  border: 2px solid var(--ink);
}

.check-btn.active::before {
  background: var(--ink);
}

/* 누르면 그림자만큼 내려앉는다 */
.plate:active,
.primary-btn:active,
.bujeok-btn:active,
.react-btn:active,
.react-btn.pressed {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* ============================================================================
   3. 무대 — 3D 픽셀 교실이 화면 전체
   ============================================================================ */
.main-stage {
  position: fixed;
  inset: 0;
}

.viewport-25d {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* ============================================================================
   4. 상단 — 문패 · 촛불 · 쿠폰
   ============================================================================ */
.top-hud {
  position: fixed;
  top: var(--gutter);
  left: var(--gutter);
  right: var(--gutter);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
}

.top-hud > * {
  pointer-events: auto;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-wrap {
  position: relative;
}

/* 교실 문패 */
.room-plate {
  align-items: stretch;
  gap: 0;
  padding: 0;
}

.room-plate-chip {
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: var(--chip-bg);
  color: var(--chip-fg);
}

.room-plate-name {
  display: flex;
  align-items: center;
  padding: 0 8px 0 12px;
  font-size: 24px;
  line-height: 24px;
  letter-spacing: 2px;
}

.room-plate-chevron {
  align-self: center;
  margin-right: 10px;
  color: var(--on-surface-dim);
}

.room-plate[aria-expanded='true'] .room-plate-chevron {
  transform: rotate(180deg);
}

/* 문패·설정에서 펼쳐지는 메뉴 */
.plate-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 232px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  color: var(--on-surface);
  border: 2px solid var(--edge);
  box-shadow: var(--hud-shadow);
  z-index: 40;
}

.settings-menu {
  left: auto;
  right: 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 10px;
  background: transparent;
  border: 0;
  text-align: left;
}

.menu-item:hover {
  background: var(--surface-2);
}

.menu-item.active {
  box-shadow: inset 4px 0 0 var(--accent);
}

.menu-chip {
  padding: 0 6px;
  background: var(--chip-bg);
  color: var(--chip-fg);
}

.menu-sub {
  margin-left: auto;
  color: var(--on-surface-dim);
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 40px;
  padding: 0 10px;
}

.menu-row input[type='range'] {
  width: 110px;
  accent-color: var(--accent);
}

.menu-dev {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-sep {
  margin-top: 4px;
  padding: 6px 10px 2px;
  border-top: 2px solid var(--edge);
  color: var(--on-surface-dim);
}

.menu-mono {
  padding: 4px 10px 6px;
  color: var(--on-surface-dim);
  font-family: monospace;
  word-break: break-all;
}

/* 촛불(공포) · 벽시계(침묵) */
.hud-center {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  gap: 14px;
  padding: 0 14px;
}

.candle .candle-flame {
  fill: var(--candle);
  animation: candleFlicker 0.9s steps(1) infinite;
}

.candle .candle-core {
  fill: #fff3c4;
}

.candle .candle-wick {
  fill: #2a2018;
}

.candle .candle-wax {
  fill: #a9a18c;
}

.candle .candle-shade {
  fill: #8c8677;
}

.candle .candle-drip {
  fill: #cbc3ad;
}

.hud-center[data-tier='2'] .candle-flame {
  animation-duration: 0.36s;
}

.hud-center[data-tier='3'] .candle-flame {
  fill: var(--ghost-blue);
  animation-duration: 0.24s;
}

.fear-segs {
  display: flex;
  gap: 2px;
}

.fear-segs .seg {
  display: block;
  width: 8px;
  height: 16px;
  background: var(--surface-3);
}

.fear-segs .seg.on {
  background: var(--candle);
}

.fear-segs .seg.on.hot {
  background: var(--monami-red);
}

.hud-center[data-tier='3'] .fear-segs .seg.on {
  background: var(--ghost-blue);
}

.fear-num {
  min-width: 28px;
  color: var(--accent);
}

.hud-center[data-tier='3'] .fear-num {
  color: var(--ghost-blue);
}

/* 매점 쿠폰 */
.coupon-plate {
  gap: 10px;
  padding: 0 4px 0 12px;
}

.stamp-mini {
  display: flex;
  gap: 2px;
}

.stamp-mini .stamp {
  position: relative;
  display: block;
  width: 12px;
  height: 12px;
  border: 1px solid var(--edge);
}

.stamp-mini .stamp.on::after {
  content: '';
  position: absolute;
  inset: 1px;
  background: var(--cinnabar);
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
}

.plate-btn {
  padding: 0 16px;
}

/* 소리 */
#btnToggleSound .sound-off,
#btnToggleSound.is-off .sound-on {
  display: none;
}

#btnToggleSound.is-off .sound-off {
  display: block;
}

/* ============================================================================
   5. 교실 위 — 명찰 · 말풍선 · 스티커 · 물건 표시 · 착석 안내
   ============================================================================ */
.avatar-overlay-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.avatar-hud-item {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  z-index: 10;
}

/* 명찰 */
.avatar-name-tag {
  position: relative;
  display: flex;
  align-items: center;
  height: 20px;
  margin-top: 2px;
  padding: 0 6px 0 10px;
  background: var(--tag-paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  line-height: 16px;
  white-space: nowrap;
}

.avatar-name-tag::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--nametag);
}

.avatar-name-tag.is-me::after {
  content: '';
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: -6px;
  height: 2px;
  background: var(--me-mark);
}

.avatar-name-tag.is-speaker {
  border-color: var(--monami-red);
}

.avatar-name-tag.is-speaker::before {
  background: var(--monami-red);
}

/* 귀신: 바래고 금 간 명찰 */
.avatar-name-tag.is-npc {
  background: #3b4050;
  color: #c9cfdc;
  border-color: #23262f;
  transform: rotate(-2deg);
  opacity: 0.9;
}

.avatar-name-tag.is-npc::before {
  background: #23262f;
}

.avatar-name-tag.is-npc.is-speaker {
  border-color: var(--monami-red);
}

/* 말풍선 — 싸이월드식 */
.avatar-speech-bubble {
  position: relative;
  max-width: 240px;
  margin-bottom: 8px;
  padding: 4px 8px;
  background: #fbf7ec;
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
  line-height: 18px;
  text-align: center;
  word-break: keep-all;
}

.avatar-speech-bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 8px;
  height: 6px;
  margin-left: -4px;
  background: var(--ink);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

/* 이야기 줄: 갱지에 빨간 볼펜 */
.avatar-speech-bubble.story-bubble {
  background: #efe6cf;
  color: var(--monami-red);
  border-color: var(--monami-red);
  font-family: var(--font-hand);
  font-size: 20px;
  line-height: 22px;
}

.avatar-speech-bubble.story-bubble::after {
  background: var(--monami-red);
}

/* 귀신: 말풍선 없이 떨리는 글자만 */
.avatar-speech-bubble.npc-bubble {
  background: transparent;
  border: 0;
  box-shadow: none;
  color: #c9d6e6;
  font-family: var(--font-hand);
  font-size: 22px;
  line-height: 24px;
  text-shadow: 1px 1px 0 #000, -1px 0 0 rgba(143, 180, 255, 0.55);
  animation: ghostJitter 0.32s steps(1) infinite;
}

.avatar-speech-bubble.npc-bubble::after {
  display: none;
}

/* 리액션 스티커 */
.avatar-emote-float {
  position: relative;
  height: 24px;
}

.floating-emoji {
  position: absolute;
  bottom: 0;
  left: -16px;
  padding: 2px;
  background: var(--tag-paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  animation: stickerUp 1.6s steps(8) forwards;
}

.floating-emoji .px-hole {
  fill: var(--tag-paper);
}

.floating-emoji .px-flame {
  fill: var(--sunset);
}

/* 괴담과 연결된 교실 물건 표시 */
.prop-floating-badge {
  position: absolute;
  left: 0;
  top: 0;
  padding: 2px 8px;
  background: var(--surface);
  color: var(--on-surface);
  border: 2px solid var(--monami-red);
  box-shadow: var(--hud-shadow);
  white-space: nowrap;
  pointer-events: none;
  z-index: 18;
}

/* 착석 안내 — 책상 아래 화살표 */
.seat-hint {
  position: absolute;
  left: 50%;
  top: calc(50% + 40px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  z-index: 20;
}

.seat-hint-arrow {
  animation: hintBob 0.8s steps(1) infinite;
}

.seat-hint-btn {
  height: 32px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--on-surface);
  border: 2px solid var(--accent);
  box-shadow: var(--hud-shadow);
  white-space: nowrap;
}

/* ============================================================================
   6. 분신사바 — 책상에 펼친 갱지 한 장
   ============================================================================ */
.board-sheet {
  position: absolute;
  left: var(--gutter);
  top: var(--panel-top);
  width: 520px;
  max-width: calc(100vw - 2 * var(--gutter));
  max-height: calc(100vh - var(--panel-top) - var(--bottom-reserve));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: #d9cdb0;
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 #000;
  z-index: 24;
}

.board-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.board-title {
  font-size: 24px;
  line-height: 24px;
  letter-spacing: 4px;
}

.board-gather {
  color: var(--ink-dim);
}

.board-head-btns {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

/* 금기 수칙: 부적 띠 */
.bujeok-strip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bujeok);
  color: var(--cinnabar-text);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 rgba(28, 25, 21, 0.5);
  transform: rotate(-1deg);
}

.bujeok-seal {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  background: var(--cinnabar);
}

.bujeok-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.bujeok-title {
  letter-spacing: 1px;
}

.bujeok-dev {
  color: var(--cinnabar-text);
}

.drawing-canvas-wrap {
  position: relative;
  border: 2px solid var(--ink);
}

#bunshinsabaDrawingCanvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  image-rendering: auto;
}

.chant-overlay-toast {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  padding: 6px 10px;
  background: rgba(21, 22, 29, 0.92);
  color: #e9e4d6;
  border: 2px solid var(--monami-red);
  font-family: var(--font-hand);
  font-size: 20px;
  line-height: 22px;
  text-align: center;
}

/* 괴담집 */
.story-book {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.story-book-label {
  margin-right: 2px;
  color: var(--ink-dim);
}

.paper-select {
  flex: 1;
  min-width: 160px;
  height: 32px;
  padding: 0 8px;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
}

.story-meta {
  margin: 0;
  color: var(--ink-dim);
}

.board-actions {
  display: flex;
  gap: 8px;
}

.board-actions .bujeok-btn {
  flex: 1;
}

/* ============================================================================
   7. 쪽지장 — 연습장 갱지
   ============================================================================ */
.note-panel {
  position: absolute;
  top: var(--panel-top);
  right: var(--gutter);
  width: 304px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--on-surface);
  border: 2px solid var(--edge);
  box-shadow: var(--hud-shadow);
  z-index: 20;
}

.note-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 32px;
  padding: 0 2px 0 12px;
  border-bottom: 2px solid var(--edge);
}

.note-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--on-surface-dim);
}

.note-panel.collapsed .note-head {
  border-bottom: 0;
}

.note-panel.collapsed .chat-log-list {
  display: none;
}

.note-panel.collapsed .note-toggle .px-icon {
  transform: rotate(180deg);
}

.chat-log-list {
  height: 264px;
  overflow-y: auto;
  padding: 4px 0 8px;
  user-select: text;
}

.chat-item {
  position: relative;
  min-height: 24px;
  padding: 3px 10px 2px 36px;
  border-bottom: 1px solid var(--note-rule);
  word-break: break-word;
}

/* 연습장 빨간 여백선 */
.chat-item::before {
  content: '';
  position: absolute;
  left: 28px;
  top: 0;
  bottom: -1px;
  width: 1px;
  background: var(--note-margin);
}

.chat-name {
  margin-right: 6px;
  color: var(--on-surface-dim);
  font-family: var(--font-ui);
  font-size: 12px;
}

body.theme-normal .chat-name.is-me {
  color: var(--ink);
  background: var(--highlighter);
}

body.theme-scary .chat-name.is-me {
  color: var(--on-surface);
  box-shadow: inset 0 -2px 0 var(--candle);
}

.chat-item.story-item {
  color: var(--story-ink);
  font-family: var(--font-hand);
  font-size: 18px;
  line-height: 20px;
}

.chat-item.npc-item {
  color: var(--ghost-ink);
  font-family: var(--font-hand);
  font-size: 18px;
  line-height: 20px;
}

.chat-item.notice-item {
  color: var(--on-surface-dim);
}

/* ============================================================================
   8. 자막 — 하단 중앙, 영화 자막처럼
   ============================================================================ */
.subtitle {
  position: absolute;
  left: 50%;
  bottom: var(--bottom-reserve);
  width: min(880px, calc(100vw - 2 * var(--gutter)));
  transform: translateX(-50%);
  padding: 10px 16px 8px;
  background: rgba(0, 0, 0, 0.66);
  color: #e9e4d6;
  z-index: 25;
}

body.board-open .subtitle {
  left: calc(var(--gutter) + 536px);
  right: var(--gutter);
  width: auto;
  transform: none;
}

.subtitle-top-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

/* 말하는 동안 움직이는 픽셀 파형 */
.subtitle-wave {
  display: block;
  width: 2px;
  height: 8px;
  margin-right: 12px;
  background: #e9e4d6;
  box-shadow: 4px -2px 0 #e9e4d6, 8px 2px 0 #e9e4d6, 12px 0 0 #e9e4d6;
  animation: voiceWave 0.5s steps(1) infinite;
}

.subtitle-wave.finished {
  animation: none;
  opacity: 0.4;
}

.subtitle-speaker {
  color: var(--monami-red-text);
}

.subtitle-speaker .subtitle-meta {
  margin-left: 8px;
  color: #a8a296;
}

.subtitle-text {
  font-size: 24px;
  line-height: 32px;
  word-break: keep-all;
}

.subtitle-progress {
  height: 2px;
  margin-top: 8px;
  background: rgba(233, 228, 214, 0.2);
}

.subtitle-progress-fill {
  height: 100%;
  background: #e9e4d6;
}

.subtitle-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 6px;
}

.subtitle-dev {
  margin-right: auto;
  color: #8c8677;
}

.subtitle-btn {
  height: 28px;
  padding: 0 10px;
  background: transparent;
  color: #cbc3ad;
  border: 2px solid #4a4f63;
}

.subtitle-btn[aria-pressed='false'] {
  color: #8c8677;
}

.subtitle-btn.ready-next {
  background: var(--candle);
  color: var(--ink);
  border-color: var(--candle);
}

/* ============================================================================
   9. 하단 — 상황 버튼 · 쪽지 쓰기 · 스티커
   ============================================================================ */
.bottom-bar {
  position: fixed;
  left: var(--gutter);
  right: var(--gutter);
  bottom: var(--gutter);
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 30;
  pointer-events: none;
}

.bottom-bar > * {
  pointer-events: auto;
}

.action-controls {
  display: flex;
  gap: 8px;
}

.chat-form {
  flex: 1;
  min-width: 0;
  gap: 10px;
  padding: 0 4px 0 12px;
}

.chat-form:focus-within {
  border-color: var(--accent);
}

.chat-form input {
  flex: 1;
  min-width: 0;
  height: 36px;
  background: transparent;
  border: 0;
  outline: none;
}

.chat-pencil .pencil-tip {
  fill: var(--on-surface);
}

.chat-pencil .pencil-wood {
  fill: var(--pencil-wood);
}

.chat-pencil .pencil-eraser {
  fill: #c77d8b;
}

.listener-lock {
  flex: 1;
  min-width: 0;
  gap: 10px;
  color: var(--on-surface-dim);
}

.reaction-controls {
  display: flex;
  gap: 6px;
}

.react-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: var(--surface);
  color: var(--on-surface);
  border: 2px solid var(--edge);
  box-shadow: var(--hud-shadow);
}

.react-btn:hover {
  background: var(--surface-2);
}

.react-btn .px-flame {
  fill: var(--accent);
}

body.theme-scary .react-normal,
body.theme-normal .react-scary {
  display: none;
}

/* ============================================================================
   10. 교내 방송 (토스트)
   ============================================================================ */
.toast-container {
  position: fixed;
  top: var(--panel-top);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 200;
  pointer-events: none;
}

.toast-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(640px, calc(100vw - 2 * var(--gutter)));
  padding: 6px 12px 6px 6px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  border: 2px solid var(--toast-edge);
  box-shadow: var(--hud-shadow);
  animation: toastIn 0.24s steps(3);
}

.toast-msg::before {
  content: '방송';
  flex: none;
  padding: 0 6px;
  background: var(--toast-fg);
  color: var(--toast-bg);
}

/* ============================================================================
   11. 모달 — 종이 서류
   ============================================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
  background: rgba(10, 9, 8, 0.66);
  overflow: auto;
  z-index: 100;
}

.modal-card {
  max-width: 100%;
  max-height: calc(100vh - 2 * var(--gutter));
  overflow: auto;
}

.paper-doc {
  padding: 20px 24px;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.6);
  user-select: text;
}

.paper-doc .primary-btn {
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  letter-spacing: 1px;
}

.close-modal-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  color: var(--ink);
  border: 2px solid var(--ink);
}

/* 입학: 전학 서류 */
.entry-doc {
  width: 680px;
  transform: rotate(-0.5deg);
}

.doc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--ink);
}

.doc-title {
  margin: 0;
  font-size: 24px;
  font-weight: normal;
  line-height: 24px;
  letter-spacing: 8px;
}

.doc-sub {
  display: block;
  margin-top: 6px;
  color: var(--ink-dim);
}

.doc-seal-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px dashed var(--cinnabar);
  color: rgba(168, 38, 26, 0.45);
  font-size: 24px;
}

.doc-body {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 16px;
}

.doc-photo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#entryPreviewCanvas,
#bmPreviewCanvas {
  width: 144px;
  height: 192px;
  background: var(--paper-shade);
  border: 2px solid var(--ink);
}

.doc-caption {
  color: var(--ink-dim);
}

.doc-fields {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--ink);
}

.doc-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  min-height: 52px;
  border-bottom: 1px solid var(--ink);
}

.doc-label {
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: rgba(207, 194, 162, 0.55);
  border-right: 1px solid var(--ink);
}

.doc-value {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
}

.hand-input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 8px;
  background: transparent;
  color: #1f2f5c;
  border: 0;
  border-bottom: 2px solid var(--ink);
  outline: none;
  font-family: var(--font-hand);
  font-size: 24px;
}

.swatch-row {
  gap: 6px;
}

.skin-swatch-btn {
  width: 32px;
  height: 32px;
  padding: 2px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.skin-swatch-btn:hover {
  border-color: var(--ink-dim);
}

.skin-swatch-btn.active {
  border-color: var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}

.room-pick-group {
  gap: 12px;
}

.door-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 150px;
  padding: 6px 12px;
  cursor: pointer;
}

.door-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.door-card:has(input:focus-visible) {
  outline: 2px solid var(--nametag);
  outline-offset: 2px;
}

.door-text b {
  display: block;
  font-weight: normal;
}

.door-text small {
  display: block;
  color: var(--ink-dim);
  font-size: 12px;
}

/* 고른 교실에 빨간 볼펜으로 동그라미 */
.pen-circle {
  position: absolute;
  left: -6px;
  top: -4px;
  width: calc(100% + 12px);
  height: calc(100% + 8px);
  display: none;
  fill: none;
  stroke: var(--monami-red);
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.door-card input:checked ~ .pen-circle {
  display: block;
}

.doc-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-top: 16px;
}

.doc-hint {
  color: var(--ink-dim);
}

/* 직인 */
.seal-btn {
  width: 88px;
  height: 88px;
  background: var(--cinnabar);
  color: var(--paper);
  border: 2px solid #5a120b;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
  font-size: 24px;
  letter-spacing: 4px;
  transform: rotate(4deg);
}

.seal-btn:active {
  transform: rotate(4deg) translate(2px, 2px);
  box-shadow: none;
}

/* 문방구 */
.shop-doc {
  width: 1040px;
}

.shop-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.shop-sign {
  margin: 0;
  padding: 6px 16px;
  background: var(--nametag);
  color: var(--paper);
  border: 2px solid var(--ink);
  font-size: 24px;
  font-weight: normal;
  line-height: 24px;
  letter-spacing: 6px;
}

.shop-chip {
  padding: 2px 8px;
  border: 2px solid var(--ink);
}

.shop-dev {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.shop-head > .close-modal-btn {
  margin-left: auto;
}

.shop-dev + .close-modal-btn {
  margin-left: 0;
}

.coupon-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--paper-shade);
  border: 2px dashed var(--ink);
}

.coupon-info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.coupon-label {
  letter-spacing: 2px;
}

.coupon-amount b {
  font-size: 24px;
  font-weight: normal;
}

.ad-stamp-track {
  display: flex;
  gap: 4px;
}

.ad-stamp-slot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--paper);
  color: var(--ink-dim);
  border: 2px solid var(--ink);
}

.ad-stamp-slot.filled {
  color: transparent;
}

.ad-stamp-slot.filled::after {
  content: '';
  position: absolute;
  inset: 3px;
  background: var(--cinnabar);
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
}

.coupon-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.coupon-hint {
  color: var(--ink-dim);
}

.admob-unit-status-line {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--ink-dim);
}

.admob-unit-status-line code,
.admob-meta-strip code {
  font-family: monospace;
}

.admob-config-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px;
  background: var(--paper-shade);
  border: 2px solid var(--ink);
}

.admob-config-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.admob-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admob-field input,
.admob-field select {
  height: 32px;
  padding: 0 8px;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  font-family: monospace;
}

.admob-config-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: var(--ink-dim);
}

.admob-config-btns {
  display: flex;
  gap: 6px;
}

.bm-layout {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 16px;
}

.bm-preview-pane {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#bmPreviewCanvas {
  align-self: center;
}

.bm-gender-switch {
  display: flex;
  gap: 6px;
}

.bm-gender-switch .check-btn {
  flex: 1;
  padding-left: 28px;
}

/* 공책 색인 탭 */
.bm-cat-tabs {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: -2px;
}

.bm-cat-btn {
  position: relative;
  height: 36px;
  margin-right: -2px;
  padding: 0 12px;
  background: var(--paper-shade);
  color: var(--ink);
  border: 2px solid var(--ink);
}

.bm-cat-btn.active {
  z-index: 1;
  background: var(--paper);
  border-bottom-color: var(--paper);
}

.bm-item-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-height: 320px;
  overflow-y: auto;
  padding: 14px;
  background: var(--paper);
  border: 2px solid var(--ink);
}

/* 가격표 */
.bm-item-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 10px 10px 28px;
  background: #f3ecdb;
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 rgba(28, 25, 21, 0.4);
}

.bm-item-card .tag-hole {
  position: absolute;
  left: 8px;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  background: var(--paper);
  border: 2px solid var(--ink);
}

.bm-item-card.equipped {
  background: var(--highlighter);
}

.bm-item-desc {
  flex: 1;
  color: var(--ink-dim);
}

.bm-item-card.equipped .bm-item-desc {
  color: var(--ink);
}

.bm-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

/* 광고 — 광고답게 정직하게 */
.ad-frame {
  width: 520px;
  padding: 16px;
  background: #101114;
  color: #e9e4d6;
  border: 2px solid #3a3f52;
  box-shadow: 4px 4px 0 #000;
}

.ad-frame-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.ad-tag {
  padding: 2px 6px;
  background: #e9e4d6;
  color: #101114;
}

.ad-title {
  flex: 1;
  margin: 0;
  font-size: 12px;
  font-weight: normal;
}

.ad-count {
  font-size: 24px;
  line-height: 24px;
  color: var(--candle);
}

.admob-meta-strip {
  margin-bottom: 8px;
  color: #8c8677;
}

.ad-screen-box {
  padding: 24px;
  background: #1a1b22;
  border: 2px solid #3a3f52;
  text-align: center;
}

.ad-advertiser-badge {
  display: inline-block;
  margin-bottom: 12px;
  padding: 2px 8px;
  color: #b3ab96;
  border: 2px solid #3a3f52;
}

.ad-pixel-art {
  display: none;
}

.ad-screen-box h3 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: normal;
  line-height: 30px;
}

.ad-screen-box p {
  margin: 0 0 16px;
  color: #b3ab96;
}

.ad-progress-outer {
  height: 8px;
  background: #2b2e3b;
}

.ad-progress-inner {
  height: 100%;
  background: var(--candle);
}

.ad-frame .modal-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.ad-frame .primary-btn {
  background: #cfc6ae;
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 1px;
}

/* 개발자 도구 서류 (금지어 · 보이스 스튜디오) */
.tool-doc {
  width: 560px;
}

.tool-doc-wide {
  width: 860px;
}

.tool-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.tool-head > .close-modal-btn {
  margin-left: auto;
}

.tool-title {
  margin: 0;
  font-size: 24px;
  font-weight: normal;
  line-height: 24px;
}

.tool-chip {
  padding: 2px 8px;
  border: 2px solid var(--ink);
  font-family: monospace;
}

.tool-desc {
  margin: 0 0 12px;
  color: var(--ink-dim);
}

.tool-form {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.tool-form input {
  flex: 1;
  height: 32px;
  padding: 0 8px;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
}

.banned-tags-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
  border: 2px dashed var(--ink);
}

.banned-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 2px 2px 8px;
  border: 2px solid var(--ink);
}

.banned-tag button {
  width: 24px;
  height: 24px;
  padding: 0;
  background: none;
  color: var(--ink);
  border: 0;
}

.varco-prop-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  padding: 8px;
  border: 2px dashed var(--ink);
}

.varco-prop-bar-label {
  color: var(--ink-dim);
}

.voice-script-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 360px;
  overflow-y: auto;
}

.voice-line-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #f3ecdb;
  border: 2px solid var(--ink);
}

.voice-line-meta {
  margin-bottom: 2px;
  color: var(--ghost-ink-paper);
}

.voice-line-actions {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
}

/* ============================================================================
   12. 금기 위반 — 카드 없이 화면 전체
   ============================================================================ */
.jumpscare-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(60, 0, 8, 0.8);
  z-index: 999;
  animation: jumpscareShake 0.09s steps(1) infinite;
}

.jumpscare-scan {
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='4' height='4'><rect width='4' height='2' fill='rgba(0,0,0,0.35)'/></svg>");
  pointer-events: none;
}

.jumpscare-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 2 * var(--gutter));
  text-align: center;
}

.jumpscare-rule-tag {
  padding: 2px 10px;
  background: var(--bujeok);
  color: var(--cinnabar-text);
}

#jumpscareCanvas {
  width: 640px;
  max-width: 100%;
  height: auto;
}

.jumpscare-title {
  margin: 0;
  color: #e9e4d6;
  font-size: 48px;
  font-weight: normal;
  line-height: 56px;
  text-shadow: 4px 4px 0 var(--monami-red);
}

.jumpscare-desc {
  max-width: 560px;
  margin: 0;
  color: #e9e4d6;
}

.jumpscare-violator {
  color: #cbc3ad;
}

/* ============================================================================
   13. 모션 — steps()로만, 부드러운 글로우 펄스 없음
   ============================================================================ */
@keyframes candleFlicker {
  0% { transform: translate(0, 0); }
  33% { transform: translate(0, -1px); }
  66% { transform: translate(1px, 0); }
}

@keyframes hintBob {
  0% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes ghostJitter {
  0% { transform: translate(0, 0); }
  50% { transform: translate(1px, -1px); }
}

@keyframes stickerUp {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}

@keyframes voiceWave {
  0% { box-shadow: 4px -2px 0 #e9e4d6, 8px 2px 0 #e9e4d6, 12px 0 0 #e9e4d6; }
  50% { box-shadow: 4px 2px 0 #e9e4d6, 8px -2px 0 #e9e4d6, 12px 2px 0 #e9e4d6; }
}

@keyframes toastIn {
  0% { transform: translateY(-8px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes jumpscareShake {
  0% { transform: translate(-6px, 4px); }
  50% { transform: translate(6px, -4px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ============================================================================
   14. 반응형 — 1280×720 · 1920×1080 · 390×844
   ============================================================================ */
@media (max-width: 1120px) {
  :root {
    --panel-top: 128px;
  }

  .top-hud {
    flex-wrap: wrap;
  }

  .hud-center {
    position: static;
    order: 3;
    margin: 0 auto;
    transform: none;
  }
}

@media (max-width: 760px) {
  :root {
    --gutter: 8px;
    --panel-top: 172px;
    --bottom-reserve: 172px;
  }

  .top-hud {
    row-gap: 8px;
  }

  .hud-right {
    flex-wrap: wrap;
  }

  .attend-plate .plate-label,
  .coupon-plate .plate-label,
  .hud-center .plate-label {
    display: none;
  }

  .note-panel {
    top: auto;
    left: var(--gutter);
    right: var(--gutter);
    bottom: var(--bottom-reserve);
    width: auto;
  }

  .chat-log-list {
    height: 160px;
  }

  .board-sheet {
    right: var(--gutter);
    width: auto;
  }

  body.board-open .subtitle {
    left: 50%;
    right: auto;
    width: calc(100vw - 2 * var(--gutter));
    transform: translateX(-50%);
  }

  .bottom-bar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .action-controls {
    order: 1;
    width: 100%;
  }

  .action-controls > * {
    flex: 1;
  }

  .chat-form,
  .listener-lock {
    order: 2;
    flex-basis: 100%;
  }

  .reaction-controls {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }

  .doc-body,
  .bm-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .bm-item-grid,
  .admob-config-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .coupon-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .ad-stamp-slot {
    width: 24px;
    height: 24px;
  }

  .entry-doc {
    transform: none;
  }

  .jumpscare-title {
    font-size: 24px;
    line-height: 32px;
  }
}
