/* styles.css — 로비/HUD/채팅 UI. 부록 C.4 "styles.css 규범" + CLAUDE.md §4.
   색 토큰은 palette.js 와 동일한 값을 CSS 변수로 한 번만 선언한다(중복 정의 금지).
   순수 검정·순백 색상값은 쓰지 않는다 — 짙은 갈색과 크림으로 대체하고 그림자는 DARK 기반 알파다. */

:root {
  --cream: #fdf6e8;
  --dark: #4a3b32;
  --wall: #f3e3d3;

  /* 파스텔 액센트 — character/palette.js FUR 과 같은 값 */
  --peach: #f4b6a0;
  --mint: #a8dcd9;
  --sky: #a9c6ef;
  --sun: #f7d7a8;

  --ink-soft: rgba(74, 59, 50, .62);
  --line: rgba(74, 59, 50, .22);
  --shadow: 0 10px 26px rgba(74, 59, 50, .16);
  --scrim: rgba(74, 59, 50, .26);

  --r-lg: 32px;
  --r-md: 24px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

/* ★ (Phase 2 브라우저 검증) `hidden` 속성이 항상 이기게 한다.
 * UA 기본값 `[hidden]{display:none}` 은 특이도 0-1-0 이라 `.boot-error{display:flex}` 같은
 * 클래스 규칙에 진다. 그래서 `#boot-error` 가 hidden 인데도 computed display:flex 로 남아
 * `position:fixed; inset:0; z-index:50` 전면 투명 레이어가 되어 **[들어가기] 클릭을 전부 삼켰다.**
 * 로비는 `.overlay.is-hidden` 으로 따로 풀었지만 부트 오버레이는 이 규칙에 걸려 있었다.
 * 개별 선택자로 땜질하면 다음에 `hidden` 을 쓰는 요소가 같은 함정을 다시 밟는다. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--wall);
  color: var(--dark);
  font-family: system-ui, -apple-system, 'Segoe UI', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  font-weight: 600;
  -webkit-text-size-adjust: 100%;
}

#app {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;   /* 포인터 제스처를 input.js 가 전담한다 (브라우저 스크롤·핀치 차단) */
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }

/* ── 로비 ────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: calc(20px + var(--safe-t)) calc(20px + var(--safe-r)) calc(20px + var(--safe-b)) calc(20px + var(--safe-l));
  background: linear-gradient(180deg, rgba(243, 227, 211, .10), var(--scrim));
  transition: opacity .4s ease;
}
.overlay.is-hidden { opacity: 0; pointer-events: none; }

.preview {
  flex: 1 1 380px;
  align-self: stretch;
  max-width: 520px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 18px;
  border-radius: var(--r-lg);
  touch-action: none;   /* 프리뷰 드래그 회전 (lobby.js) */
}
.preview-hint {
  margin: 0;
  padding: 8px 18px;
  border-radius: var(--r-md);
  background: rgba(253, 246, 232, .78);
  color: var(--ink-soft);
  font-size: 14px;
}

.card {
  flex: 0 1 400px;
  max-height: 100%;
  overflow-y: auto;
  padding: 26px 26px 22px;
  border-radius: var(--r-lg);
  background: var(--cream);
  border: 4px solid var(--line);
  box-shadow: var(--shadow);
}
.title { margin: 0 0 4px; font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.subtitle { margin: 0 0 18px; font-size: 15px; color: var(--ink-soft); font-weight: 600; }
.field-label { margin: 16px 0 8px; font-size: 14px; color: var(--ink-soft); }
.hint { margin: 6px 2px 0; font-size: 13px; color: var(--ink-soft); font-weight: 600; }

.text-input {
  width: 100%;
  padding: 14px 18px;
  border: 3px solid var(--line);
  border-radius: var(--r-md);
  background: var(--wall);
  color: var(--dark);
  font-size: 18px;
  font-weight: 700;
}
.text-input::placeholder { color: var(--ink-soft); font-weight: 600; }

.grid { display: grid; gap: 10px; }
.grid-species { grid-template-columns: repeat(3, 1fr); }
.grid-color { grid-template-columns: repeat(8, 1fr); }

.species-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 6px;
  border: 3px solid var(--line);
  border-radius: var(--r-md);
  background: var(--wall);
  transition: transform .12s ease, border-color .12s ease;
}
.species-btn:hover { transform: translateY(-2px); }
.species-btn[aria-checked="true"] { border-color: var(--peach); background: var(--cream); }
.sp-name { font-size: 16px; font-weight: 800; }
.sp-motif { font-size: 12px; color: var(--ink-soft); }

.color-btn {
  aspect-ratio: 1 / 1;
  border: 3px solid var(--line);
  border-radius: 50%;
  background: var(--sw, var(--wall));
  transition: transform .12s ease, border-color .12s ease;
}
.color-btn:hover { transform: scale(1.08); }
.color-btn[aria-checked="true"] { border-color: var(--dark); transform: scale(1.12); }
.color-btn[data-color="0"] { --sw: #f4b6a0; }
.color-btn[data-color="1"] { --sw: #f7d7a8; }
.color-btn[data-color="2"] { --sw: #cfe3b2; }
.color-btn[data-color="3"] { --sw: #a8dcd9; }
.color-btn[data-color="4"] { --sw: #a9c6ef; }
.color-btn[data-color="5"] { --sw: #c9b6e4; }
.color-btn[data-color="6"] { --sw: #f2b8cf; }
.color-btn[data-color="7"] { --sw: #d9c3a5; }

.primary-btn {
  width: 100%;
  margin-top: 20px;
  padding: 16px 20px;
  border: 4px solid var(--dark);
  border-radius: var(--r-md);
  background: var(--peach);
  color: var(--dark);
  font-size: 19px;
  font-weight: 800;
  box-shadow: var(--shadow);
  transition: transform .12s ease, opacity .12s ease;
}
.primary-btn:hover { transform: translateY(-2px); }
.primary-btn:disabled { opacity: .55; cursor: default; transform: none; }

.lobby-error {
  margin: 12px 0 0;
  padding: 10px 16px;
  border-radius: var(--r-md);
  background: rgba(244, 182, 160, .35);
  border: 2px solid var(--peach);
  font-size: 14px;
}

/* ── HUD ─────────────────────────────────────────────── */
.hud { position: fixed; inset: 0; pointer-events: none; }
.hud > * { pointer-events: auto; }

.count-badge {
  position: absolute;
  top: calc(16px + var(--safe-t));
  left: calc(16px + var(--safe-l));
  padding: 10px 18px;
  border-radius: var(--r-md);
  background: rgba(253, 246, 232, .88);
  border: 3px solid var(--line);
  font-size: 14px;
  box-shadow: var(--shadow);
}

/* 소리 끄기 (O-02). 문구를 JS 가 아니라 ::after 로 두어 main.js 배선을 한 줄로 줄인다 */
.mute-btn {
  position: absolute;
  top: calc(16px + var(--safe-t));
  right: calc(16px + var(--safe-r));
  padding: 10px 18px;
  border-radius: var(--r-md);
  background: rgba(253, 246, 232, .88);
  border: 3px solid var(--line);
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.mute-btn::after { content: '소리 끄기'; }
.mute-btn[aria-pressed="true"] { background: rgba(244, 182, 160, .55); border-color: var(--peach); }
.mute-btn[aria-pressed="true"]::after { content: '소리 켜기'; }

.toast-area {
  position: absolute;
  top: calc(16px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 20px;
  border-radius: var(--r-md);
  background: var(--cream);
  border: 3px solid var(--dark);
  font-size: 15px;
  box-shadow: var(--shadow);
  animation: toast-in .25s ease;
}
.toast.is-warn { background: rgba(244, 182, 160, .92); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.prompt {
  position: absolute;
  left: 50%;
  bottom: calc(150px + var(--safe-b));
  transform: translateX(-50%);
  padding: 10px 22px;
  border-radius: var(--r-md);
  background: var(--cream);
  border: 3px solid var(--dark);
  font-size: 15px;
  box-shadow: var(--shadow);
}

.chat-panel {
  position: absolute;
  left: calc(16px + var(--safe-l));
  bottom: calc(16px + var(--safe-b));
  width: min(380px, calc(100vw - 32px - var(--safe-l) - var(--safe-r)));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-log {
  max-height: 34vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: rgba(253, 246, 232, .82);
  border: 3px solid var(--line);
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
  word-break: break-word;
  scrollbar-width: thin;
}
.chat-log:empty { display: none; }
.chat-line { margin: 0; line-height: 1.45; }
.chat-nick { font-weight: 800; margin-right: 6px; color: var(--dark); }
/* 내 발화 구분은 새 색 토큰을 만들지 않고 밑줄로 준다 (§4 파스텔·저대비 유지) */
.chat-line.is-me .chat-nick {
  text-decoration: underline;
  text-decoration-color: var(--peach);
  text-decoration-thickness: 3px;
  text-underline-offset: 3px;
}
.chat-line.is-system { color: var(--ink-soft); font-size: 13px; }

.chat-form { display: flex; gap: 8px; }
.chat-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px 18px;
  border: 3px solid var(--line);
  border-radius: var(--r-md);
  background: var(--cream);
  color: var(--dark);
  font-size: 16px;
  font-weight: 600;
}
.chat-input::placeholder { color: var(--ink-soft); }
.chat-send {
  flex: 0 0 auto;
  padding: 12px 18px;
  border: 3px solid var(--dark);
  border-radius: var(--r-md);
  background: var(--mint);
  font-size: 15px;
  font-weight: 800;
}

/* ── 모바일 컨트롤 (P2-7: "동작한다"까지만) ───────────── */
.touch-controls { position: fixed; inset: 0; display: none; pointer-events: none; }
.stick {
  position: absolute;
  left: calc(28px + var(--safe-l));
  bottom: calc(28px + var(--safe-b));
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(253, 246, 232, .40);
  border: 3px solid var(--line);
  pointer-events: none;   /* 스틱 입력은 캔버스 포인터가 처리한다(input.js는 중심 좌표만 읽는다) */
}
.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(253, 246, 232, .85);
  border: 3px solid var(--line);
}
.touch-buttons {
  position: absolute;
  right: calc(24px + var(--safe-r));
  bottom: calc(32px + var(--safe-b));
  display: flex;
  align-items: flex-end;
  gap: 14px;
  pointer-events: auto;
}
.round-btn {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 3px solid var(--dark);
  background: rgba(253, 246, 232, .88);
  font-size: 20px;
  font-weight: 800;
  touch-action: none;
}
/* 이모트 바 (O-07). 터치 컨트롤 안에 있으므로 데스크톱에서는 .touch-controls 규칙이 통째로 숨긴다. */
.emote-bar {
  position: absolute;
  right: calc(24px + var(--safe-r));
  bottom: calc(122px + var(--safe-b));   /* round-btn 74 + 여백 */
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
.emote-btn {
  min-width: 52px;
  padding: 8px 10px;
  border: 3px solid var(--dark);
  border-radius: var(--r-md);
  background: rgba(253, 246, 232, .88);
  font-size: 14px;
  font-weight: 800;
  touch-action: none;
}
@media (hover: none) and (pointer: coarse) {
  .touch-controls:not([hidden]) { display: block; }
  .chat-panel { width: min(320px, calc(100vw - 130px - var(--safe-l) - var(--safe-r))); }
  .chat-log { max-height: 22vh; }
}

/* ── 좁은 화면 로비 ──────────────────────────────────── */
@media (max-width: 760px) {
  .overlay { flex-direction: column; gap: 12px; }
  .preview { flex: 1 1 30%; min-height: 120px; }
  .card { flex: 0 1 auto; width: 100%; max-width: 460px; padding: 20px; }
  .title { font-size: 25px; }
}

/* ── 부트 오류 오버레이 (F-14) ───────────────────────── */
.boot-error {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--wall);
}
.boot-card {
  max-width: 560px;
  padding: 28px 30px;
  border-radius: var(--r-lg);
  background: var(--cream);
  border: 4px solid var(--dark);
  box-shadow: var(--shadow);
}
.boot-title { margin: 0 0 12px; font-size: 24px; font-weight: 800; }
.boot-detail { margin: 0 0 14px; font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
.boot-hint { margin: 0; font-size: 14px; color: var(--ink-soft); }
