/* 공통 토큰과 기본 컴포넌트. 모든 화면이 맨 먼저 불러온다.
   소유: 메인(사람). 화면별 스타일은 tv.css / kid.css / viz.css에 둔다.
   디자인 기준: 우리반운동회(class-sports-day) — 물마루 한 글꼴, 종이·벽돌·칠판·나무 색, 둥근 모서리 없는 계단식 픽셀 외곽선. */

/* 물마루(Mulmaru, OFL 1.1, /assets/fonts/OFL.txt). 굵기가 하나라 400~700에 같은 파일을 써서 가짜 굵게를 막는다. 12px 격자 글꼴.
   swap: 느린 와이파이에서 약 100KB 파일을 기다리는 동안 글자 없는 화면이 되지 않게 기본 글꼴로 먼저 보인다. 캔버스는 document.fonts.load 뒤에 그린다. */
@font-face { font-family: Mulmaru; src: url(/assets/fonts/Mulmaru.woff2) format("woff2"); font-weight: 400 700; font-display: swap; }

:root {
  /* 운동회 팔레트 */
  --paper: #efe3c8;     /* 바탕 종이 */
  --paper-2: #e2d2ad;   /* 한 단계 어두운 종이(눌림·구역) */
  --paper-3: #fbf4e2;   /* 밝은 종이(카드 안쪽·입력칸) */
  --brick: #a4483a;  --brick-d: #7a3027;  --brick-l: #c9705c;
  --board: #2f4a3c;  --board-d: #233a2f;  --board-l: #3d5d4c;   /* 칠판 */
  --chalk: #f1ece0;  --chalk-y: #f2d983;  --chalk-b: #a9cdf2;  --chalk-r: #f0a58f;
  --wood: #a9743f;   --wood-d: #7c5128;   --wood-l: #cc985f;  --wood-dd: #5e3c1d;
  --cheong: #2f6cc0; --cheong-d: #1f4a8a; --cheong-l: #8fb8ea;
  --navy: #2a2a3a;   /* 위 띠·어두운 바탕 */

  /* 의미색(예전 이름 유지: 다른 파일이 쓴다) */
  --ink: #3a3a50;       /* 글자·외곽선 */
  --ink-2: #2a2a3a;
  --muted: #5f5748;     /* 종이 위 보조 글자(paper 5.6 · paper-2 4.8 · paper-3 6.5 : 1) */
  --line: #cdbb94;      /* 종이 위 얇은 구분선 */
  --card: var(--paper-3);
  --o: var(--cheong);   --o-d: var(--cheong-d);  --o-soft: #d6e4f6;
  --x: var(--brick);    --x-d: var(--brick-d);   --x-soft: #f3d9cf;
  --sim: #2f7a55;       --sim-soft: #d3eadc;     /* 비슷함(초록) */
  --sim-d: #286848;     /* 종이 위 초록 글자(paper 5.2 : 1). --sim은 4.1 : 1이라 글자에 쓰지 않는다 */
  --navy-d: #15151f;    /* 남색 바탕 위 외곽선 */
  --gold: var(--chalk-y); --gold-soft: #f8edc4;  /* 강조 노랑 */
  --danger: var(--brick);
  --ok: #2f7a55;

  /* 글꼴: 물마루 하나. 크기는 12px 격자(12·18·24·30·36·48·60·72) */
  --title: Mulmaru, sans-serif;
  --body: Mulmaru, sans-serif;
  --fs-xs: 12px;
  --fs-sm: 18px;
  --fs-md: 24px;
  --fs-lg: 30px;
  --fs-xl: 36px;
  --fs-2xl: 48px;
  --fs-3xl: 72px;

  /* 간격: 3px 도트의 배수 */
  --s1: 3px;
  --s2: 6px;
  --s3: 12px;
  --s4: 18px;
  --s5: 24px;
  --s6: 36px;
  --s7: 48px;

  /* 모양: 둥근 모서리 없음. 외곽선은 box-shadow 계단(아래 .pn 계열)으로 그린다. */
  --border: 3px solid var(--ink);
  --border-thin: 3px solid var(--line);
  --r-sm: 0; --r-md: 0; --r-lg: 0; --r-xl: 0; --r-pill: 0;
  --shadow-hard: 0 6px 0 var(--ink);
  --shadow-hard-lg: 0 9px 0 var(--ink);
  --shadow-soft: 0 9px 0 rgba(58, 58, 80, .25);
  --step3: -3px 0 0 var(--ink), 3px 0 0 var(--ink), 0 -3px 0 var(--ink), 0 3px 0 var(--ink);

  --ease: steps(3, end);  /* 픽셀 게임처럼 계단식 움직임 */
  --ease-smooth: cubic-bezier(.2, .8, .2, 1);
  --dur: 150ms;
  --z-overlay: 20;
  --z-modal: 30;
  --z-toast: 40;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--body); font-size: var(--fs-sm); line-height: 1.5;
  overflow-x: hidden; word-break: keep-all; overflow-wrap: anywhere;
  -webkit-font-smoothing: none; -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; image-rendering: pixelated; }
h1, h2, h3, h4 { font-family: var(--title); font-weight: 400; margin: 0; line-height: 1.25; }
p { margin: 0; }
.px { image-rendering: pixelated; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-xs); }
.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; }
:focus-visible { outline: 3px solid var(--cheong); outline-offset: 3px; }

/* ---------- 표면 ---------- */
/* 3px 계단 패널(운동회 .pn): 위는 밝게, 아래는 어둡게 한 줄씩 */
.pn, .card {
  background: var(--paper-3); border: 0; border-radius: 0;
  box-shadow: var(--step3), inset 0 3px 0 rgba(255, 255, 255, .55), inset 0 -3px 0 rgba(58, 58, 80, .14);
}
.card.raised, .pn.raised { box-shadow: var(--step3), 0 9px 0 var(--ink), inset 0 3px 0 rgba(255, 255, 255, .55), inset 0 -3px 0 rgba(58, 58, 80, .14); }
/* 6px 쪽지(운동회 .pn2): 모서리를 한 칸 깎은 두꺼운 테두리 */
.pn2 {
  background: var(--paper-3);
  box-shadow: -6px 0 0 var(--ink), 6px 0 0 var(--ink), 0 -6px 0 var(--ink), 0 6px 0 var(--ink),
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink);
}
/* 나무 테두리 칠판(운동회 .chalk): 어두운 초록 위 분필 글자. 테두리가 바깥으로 12px 나가므로 둘레에 그만큼 여백을 둔다. */
.chalk {
  position: relative; color: var(--chalk); background: var(--board);
  box-shadow: -9px 0 0 var(--wood), 9px 0 0 var(--wood), 0 -9px 0 var(--wood), 0 9px 0 var(--wood),
    -6px -6px 0 var(--wood), 6px -6px 0 var(--wood), -6px 6px 0 var(--wood), 6px 6px 0 var(--wood),
    -12px 0 0 var(--ink), 12px 0 0 var(--ink), 0 -12px 0 var(--ink), 0 12px 0 var(--ink),
    -9px -9px 0 var(--ink), 9px -9px 0 var(--ink), -9px 9px 0 var(--ink), 9px 9px 0 var(--ink);
}
.chalk .muted { color: #c9d3c9; }
/* 패널 머리 띠: 벽돌(기본)·나무·청·칠판 */
.band { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); background: var(--brick); color: #fff7e6; text-shadow: 3px 3px 0 var(--brick-d); font-size: var(--fs-md); line-height: 1.2; box-shadow: inset 0 -3px 0 var(--brick-d); }
.band.wood { background: var(--wood); text-shadow: 3px 3px 0 var(--wood-dd); box-shadow: inset 0 -3px 0 var(--wood-d); }
.band.blue { background: var(--cheong); text-shadow: 3px 3px 0 var(--cheong-d); box-shadow: inset 0 -3px 0 var(--cheong-d); }
.band.board { background: var(--board); color: var(--chalk); text-shadow: none; box-shadow: inset 0 -3px 0 var(--board-d); }
/* 만국기 줄(삼각 깃발 장식, 운동회 입장 화면). 높이 24px, 장식이라 aria-hidden 요소에 쓴다 */
.bunting { height: 24px; background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='96' height='24' shape-rendering='crispEdges'><rect width='96' height='3' fill='%233a3a50'/><path d='M3 3h18l-9 15z' fill='%23a4483a'/><path d='M27 3h18l-9 15z' fill='%23f2d983'/><path d='M51 3h18l-9 15z' fill='%232f6cc0'/><path d='M75 3h18l-9 15z' fill='%232f7a55'/></svg>") 0 0 / 96px 24px repeat-x; image-rendering: pixelated; }

/* ---------- 버튼: 운동회 나무 버튼(.wb) ---------- */
.btn {
  position: relative; isolation: isolate; display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 48px; padding: 6px 18px; border: 0; border-radius: 0;
  font-size: var(--fs-sm); line-height: 1.15; text-align: center; user-select: none;
  color: #fff7e6; background: var(--wood); text-shadow: 3px 3px 0 var(--wood-dd);
  box-shadow: var(--step3), 0 9px 0 var(--ink), inset 0 3px 0 var(--wood-l), inset 0 -6px 0 var(--wood-d);
  margin-bottom: 9px; /* 아래 9px 그림자가 다음 요소에 닿지 않게 */
}
.btn::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 3px; background: var(--wood-d); opacity: .45; z-index: -1; }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(6px); box-shadow: var(--step3), 0 3px 0 var(--ink), inset 0 3px 0 var(--wood-l), inset 0 -6px 0 var(--wood-d); }
/* 링은 아래 그림자(9px) 밖에 그린다. 그림자 위에 놓이면 남색 위 청이라 대비가 2.1 : 1이다 */
.btn:focus-visible { outline: 3px solid var(--cheong); outline-offset: 9px; }
.btn.light:focus-visible, .btn.ghost:focus-visible { outline-offset: 6px; }
.btn.primary, .btn.red, .btn.x { background: var(--brick); text-shadow: 3px 3px 0 var(--brick-d); box-shadow: var(--step3), 0 9px 0 var(--ink), inset 0 3px 0 var(--brick-l), inset 0 -6px 0 var(--brick-d); }
.btn.primary::before, .btn.red::before, .btn.x::before { background: var(--brick-d); }
.btn.primary:active, .btn.red:active, .btn.x:active { box-shadow: var(--step3), 0 3px 0 var(--ink), inset 0 3px 0 var(--brick-l), inset 0 -6px 0 var(--brick-d); }
.btn.o, .btn.blue { background: var(--cheong); text-shadow: 3px 3px 0 var(--cheong-d); box-shadow: var(--step3), 0 9px 0 var(--ink), inset 0 3px 0 var(--cheong-l), inset 0 -6px 0 var(--cheong-d); }
.btn.o::before, .btn.blue::before { background: var(--cheong-d); }
.btn.o:active, .btn.blue:active { box-shadow: var(--step3), 0 3px 0 var(--ink), inset 0 3px 0 var(--cheong-l), inset 0 -6px 0 var(--cheong-d); }
/* 종이 버튼(덜 중요한 동작) */
.btn.light { color: var(--ink); background: var(--paper-3); text-shadow: none; box-shadow: var(--step3), 0 6px 0 var(--ink), inset 0 -3px 0 var(--paper-2); margin-bottom: 6px; }
.btn.light::before { display: none; }
.btn.light:active { transform: translateY(3px); box-shadow: var(--step3), 0 3px 0 var(--ink), inset 0 -3px 0 var(--paper-2); }
/* 글자 버튼 */
.btn.ghost { color: var(--ink); background: transparent; text-shadow: none; box-shadow: none; min-height: 48px; margin-bottom: 0; text-decoration: underline 3px; text-underline-offset: 6px; }
.btn.ghost::before { display: none; }
.btn.ghost:hover { background: var(--paper-2); filter: none; }
.btn.ghost:active { transform: none; box-shadow: none; }
.btn.lg { min-height: 72px; font-size: var(--fs-md); padding: 9px 24px; }
.btn.block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] {
  color: var(--ink-2); background: #a79d88; text-shadow: none; cursor: not-allowed; filter: none; transform: none;
  box-shadow: var(--step3), 0 3px 0 var(--ink), inset 0 3px 0 #bdb49f, inset 0 -3px 0 #8d8470;
}
.btn:disabled::before { display: none; }
.btn .icon { width: 24px; height: 24px; flex: none; }
.iconbtn {
  display: inline-grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 0; border-radius: 0;
  color: var(--ink); background: var(--paper-3); box-shadow: var(--step3), 0 6px 0 var(--ink), inset 0 -3px 0 var(--paper-2);
}
.iconbtn:hover { background: #fff; }
.iconbtn:active { transform: translateY(3px); box-shadow: var(--step3), 0 3px 0 var(--ink); }
.iconbtn svg { width: 24px; height: 24px; }

/* ---------- 작은 것들 ---------- */
.chip { display: inline-flex; align-items: center; gap: var(--s2); padding: 3px 9px; border: 0; border-radius: 0; background: var(--paper-3); color: var(--ink); font-size: var(--fs-sm); line-height: 1.3; box-shadow: var(--step3); }
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 0 6px; border-radius: 0; font-size: var(--fs-xs); line-height: 18px; background: var(--ink); color: var(--paper-3); }
.field-label { font-size: var(--fs-sm); color: var(--ink); }
.input {
  width: 100%; min-height: 54px; padding: 6px 12px; border: 0; border-radius: 0; background: #fff; color: var(--ink); font-size: var(--fs-md);
  box-shadow: var(--step3), inset 0 3px 0 var(--paper-2);
}
.input:focus { outline: 3px solid var(--cheong); outline-offset: 3px; }
.input::placeholder { color: #8a826f; }
select.input { appearance: none; padding-right: 36px; background: #fff linear-gradient(45deg, transparent 50%, var(--ink) 50%) calc(100% - 21px) 50% / 9px 9px no-repeat; }

/* 얼굴(캐릭터 얼굴 data URL): 네모 픽셀 액자 */
.face { display: inline-block; border: 0; border-radius: 0; background: var(--paper-3); image-rendering: pixelated; object-fit: cover; flex: none; box-shadow: var(--step3); }

/* 토스트 · 연결 상태 */
/* 토스트: 종이 쪽지(.pn2와 같은 외곽선)라 남색 위 띠와 구분된다. TV 위 띠(최대 84px)의 방 번호판을 가리지 않게 그 아래(96px)에 띄운다. */
.toast {
  position: fixed; left: 50%; top: 96px; transform: translateX(-50%); z-index: var(--z-toast); background: var(--paper-3); color: var(--ink); padding: 12px 18px; font-size: var(--fs-sm); max-width: min(90vw, 720px); text-align: center;
  box-shadow: -6px 0 0 var(--ink), 6px 0 0 var(--ink), 0 -6px 0 var(--ink), 0 6px 0 var(--ink),
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink), 0 15px 0 rgba(42, 42, 58, .35);
  animation: toast-in 240ms var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -12px); } }
.conn { display: inline-flex; align-items: center; gap: 9px; font-size: var(--fs-xs); color: inherit; }
.conn::before { content: ""; width: 9px; height: 9px; background: #49b07a; box-shadow: 0 0 0 3px var(--ink); }
.conn.off::before { background: var(--brick-l); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
