/* 동방홍마향 — docs/touhou.md §7. 영상 영역(.video-wrap) 안에서만 그린다(framework §18.1). 전부 #touhouRoot 안으로 한정. */
.game-touhou { --game-color: 225, 29, 72; }

#touhouRoot {
  position: absolute; inset: 0; width: 100%; height: 100%; box-sizing: border-box;
  z-index: 40; display: none; overflow: hidden;
  color: #f1e7ef; font-family: inherit; font-size: 13px; background: #07040a;
}
#touhouRoot.th-visible { display: block; }
#touhouRoot * { box-sizing: border-box; }
#touhouRoot [hidden] { display: none !important; }
#touhouRoot button { font: inherit; color: inherit; cursor: pointer; }
#touhouRoot button:focus-visible { outline: 3px solid #fda4af; outline-offset: 1px; }
.th-body { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; }

/* CSS 확대만 쓴다. requestFullscreen 계열 금지(framework §18.3). */
#touhouRoot.th-expanded {
  position: fixed; inset: 0; width: 100vw; height: 100dvh; z-index: 10000;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#touhouRoot.th-expanded .th-head { padding-right: 72px; }
#touhouRoot.th-expanded .th-head [data-act="expand"] { display: none; }
.th-collapse { position: absolute; top: 6px; right: 6px; z-index: 50; display: none; padding: 6px 12px; border-radius: 8px;
  border: 1px solid #3f3f46; background: #18181b; color: #f4f4f5; font-weight: 700; font-size: 12px; }
/* 외부 확대 버튼(framework §18.3) — 모바일에서는 app.js 공통 자리가 크기를 줄인다 */
#touhouExpand { display: none; margin: 5px auto; padding: 9px 16px; border-radius: 9px; border: 1px solid #3f3f46; background: none; color: #d4d4d8; font: inherit; cursor: pointer; }
@media (pointer: coarse), (max-width: 900px) { #touhouExpand.th-show { display: block; } }

/* 머리줄: 한 줄, 넓이가 모자라면 client fitHead가 zoom으로 통째로 줄인다(framework §18.6) */
.th-head { display: flex; align-items: center; gap: 8px; padding: 5px 10px; flex: none; white-space: nowrap;
  background: linear-gradient(90deg, rgba(159, 18, 57, .6), rgba(30, 27, 75, .55)); border-bottom: 1px solid #27272a; }
.th-head-info { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }
.th-title { font-size: 14px; }
.th-name { font-weight: 700; color: #fecdd3; }
.th-off { opacity: .5; text-decoration: line-through; }
.th-tag { padding: 1px 8px; border-radius: 999px; background: #27272a; color: #a1a1aa; font-size: 11px; font-weight: 700; }
.th-status { color: #d4d4d8; font-size: 12px; }
.th-head.th-measure { width: max-content; }
#touhouRoot.th-expanded .th-head.th-measure { padding-right: 72px; }
.th-head-btns { display: flex; gap: 6px; flex: none; }
.th-mini { padding: 4px 10px; border-radius: 999px; border: 1px solid #3f3f46; background: #18181b; font-size: 11px; font-weight: 700; }
.th-warn { color: #fda4af; border-color: #881337 !important; }
.th-sound { display: flex; align-items: center; gap: 4px; flex: none; }
.th-sound .th-mini { padding: 4px 7px; line-height: 1; }
.th-vol { width: 64px; height: 14px; margin: 0; accent-color: #fb7185; cursor: pointer; }
.th-vol.th-muted { opacity: .45; }
#touhouRoot.th-narrow .th-head { gap: 5px; padding: 4px 6px; }
/* 좁은 화면 규칙이 확대 모드의 축소 버튼 자리를 덮어쓰지 않게(같은 우선순위라 뒤에 다시 둔다) */
#touhouRoot.th-narrow.th-expanded .th-head { padding-right: 72px; }
#touhouRoot.th-narrow .th-vol { width: 44px; }

/* 화면: 원작 640×480(4:3)을 비율 유지로 맞춘다. 캔버스는 엔진이 그린다(WebGL) */
.th-stage { position: relative; flex: 1 1 auto; min-height: 0; background: #000; }
.th-screen { position: absolute; inset: 0; width: 100% !important; height: 100% !important; object-fit: contain; display: block; }
.th-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 10px; pointer-events: none; z-index: 3; }
.th-overlay > * { pointer-events: auto; }
.th-msg { padding: 8px 14px; border-radius: 10px; background: rgba(0, 0, 0, .72); border: 1px solid #3f3f46; font-weight: 700; text-align: center; }
.th-msg.th-top { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); max-width: 94%; font-size: 12px; }
.th-msg.th-help { font-weight: 600; color: #e4e4e7; opacity: .9; pointer-events: none; }
.th-card { max-width: 92%; padding: 14px 18px; border-radius: 14px; background: rgba(9, 9, 11, .9); border: 1px solid #be123c; text-align: center; }
.th-card h3 { margin: 0 0 6px; font-size: 20px; color: #fecdd3; }
.th-card p { margin: 4px 0; }
.th-load { min-width: min(360px, 90%); }
.th-bar { height: 8px; margin: 8px 0; border-radius: 999px; background: #27272a; overflow: hidden; }
.th-bar i { display: block; height: 100%; background: linear-gradient(90deg, #e11d48, #f472b6); transition: width .2s; }
.th-btn { padding: 7px 16px; border-radius: 9px; border: 1px solid #3f3f46; background: #27272a; color: inherit; font: inherit; font-weight: 700; cursor: pointer; }
.th-btn.th-primary { background: #e11d48; border-color: #e11d48; color: #fff; }

/* 최고기록 창(사용자가 여는 보조 패널 — 목록은 내부 스크롤 허용, framework §18.2) */
.th-records { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 8px; background: rgba(2, 2, 6, .55); }
.th-rec-panel { width: min(640px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 12px;
  background: rgba(14, 10, 16, .96); border: 1px solid #9f1239; }
.th-rec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.th-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.th-tab { padding: 3px 10px; border-radius: 8px; border: 1px solid #3f3f46; background: #18181b; font-size: 12px; font-weight: 700; color: #a1a1aa; }
.th-tab.th-on { background: #9f1239; border-color: #e11d48; color: #fff; }
.th-tab-gap { width: 10px; }
/* 2인 협동: 머리줄 이름 사이 &, 2P 참가 버튼, 기체 고르기 카드 */
.th-amp { color: #a1a1aa; font-weight: 700; }
.th-join { color: #bfdbfe; border-color: #1d4ed8 !important; background: #172554 !important; }
/* 선택 화면의 2P 차례 안내(2P 화면) */
.th-turn { color: #bae6fd; border-color: #0284c7 !important; }
/* 2인 협동 신청 팝업(받는 사람, framework §7.4) */
.th-modal { position: fixed; inset: 0; z-index: 10050; display: flex; align-items: center; justify-content: center; background: rgba(2, 6, 23, .55); }
.th-modal-card { min-width: 260px; max-width: min(420px, 92vw); padding: 16px 18px; border-radius: 14px; border: 1px solid #be123c; background: #0f0f12; color: #e4e4e7; text-align: center; }
.th-modal-card h3 { margin: 0 0 6px; color: #fecdd3; }
.th-modal-card p { margin: 4px 0 8px; }
.th-modal-sub { font-size: 13px; color: #a1a1aa; }
.th-modal-time { margin: 6px 0 10px; color: #fbbf24; font-weight: 700; }
.th-rec-table { width: 100%; border-collapse: collapse; font-size: 12px; display: block; overflow-y: auto; min-height: 0; }
.th-rec-table thead, .th-rec-table tbody { display: table; width: 100%; table-layout: auto; }
.th-rec-table th, .th-rec-table td { padding: 4px 6px; text-align: left; white-space: nowrap; border-bottom: 1px solid #27272a; }
.th-rec-table th { color: #a1a1aa; font-weight: 700; }
.th-rname { max-width: 10em; overflow-wrap: anywhere; white-space: normal !important; font-weight: 700; }
.th-rscore { font-variant-numeric: tabular-nums; color: #fde68a; }
.th-empty { color: #71717a; text-align: center !important; }
.th-rec-note { margin: 0; color: #a1a1aa; font-size: 11px; }

/* 인게임 채팅 입력창(PC 선수만) */
#touhouRoot .th-chat-input { position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%); z-index: 6; width: min(420px, 80%);
  padding: 9px 14px; border: 1px solid rgba(255, 255, 255, .4); border-radius: 18px; background: rgba(11, 19, 26, .9); color: #fff;
  font: inherit; font-size: 14px; outline: none; pointer-events: auto; box-shadow: 0 4px 16px rgba(0, 0, 0, .6); }

/* 모바일 가상패드(framework §18.4): 아래 좌우 구석(4:3 게임 화면 양옆 띠), 가운데는 비운다 */
.th-pad { position: absolute; inset: auto 0 0 0; height: 60%; display: flex; justify-content: space-between; align-items: flex-end; padding: 6px 10px;
  pointer-events: none; touch-action: none; z-index: 4; --s: min(15vmin, 64px); }
.th-dpad { position: relative; width: min(34vmin, 150px); aspect-ratio: 1; border-radius: 50%; pointer-events: auto; touch-action: none;
  background: rgba(255, 255, 255, .08); border: 2px solid rgba(255, 255, 255, .22); }
.th-dpad span { position: absolute; left: 50%; top: 50%; width: 34%; height: 34%; transform: translate(calc(-50% + var(--kx, 0px)), calc(-50% + var(--ky, 0px)));
  border-radius: 50%; background: rgba(255, 255, 255, .18); transition: transform .04s linear, background .08s; }
.th-dpad.th-on { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .45); }
.th-dpad.th-on span { background: rgba(244, 114, 182, .6); }
.th-arrow { position: absolute; width: 0; height: 0; border: 6px solid transparent; opacity: .35; transition: opacity .06s; }
.th-arrow[data-d="u"] { top: 7%; left: 50%; transform: translateX(-50%); border-top-width: 0; border-bottom: 8px solid #fff; }
.th-arrow[data-d="d"] { bottom: 7%; left: 50%; transform: translateX(-50%); border-bottom-width: 0; border-top: 8px solid #fff; }
.th-arrow[data-d="l"] { left: 7%; top: 50%; transform: translateY(-50%); border-left-width: 0; border-right: 8px solid #fff; }
.th-arrow[data-d="r"] { right: 7%; top: 50%; transform: translateY(-50%); border-right-width: 0; border-left: 8px solid #fff; }
.th-dpad.th-u .th-arrow[data-d="u"] { opacity: 1; border-bottom-color: #f472b6; }
.th-dpad.th-d .th-arrow[data-d="d"] { opacity: 1; border-top-color: #f472b6; }
.th-dpad.th-l .th-arrow[data-d="l"] { opacity: 1; border-right-color: #f472b6; }
.th-dpad.th-r .th-arrow[data-d="r"] { opacity: 1; border-left-color: #f472b6; }
#touhouRoot .th-stage, #touhouRoot .th-stage * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.th-btns { display: grid; grid-template-columns: repeat(2, var(--s)); grid-template-rows: repeat(2, var(--s)); gap: calc(var(--s) * .18); pointer-events: none; }
.th-btns button { width: var(--s); height: var(--s); padding: 0; pointer-events: auto; touch-action: none; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .3); background: rgba(225, 29, 72, .3); color: #fff; font-weight: 800; font-size: 15px; line-height: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; }
.th-btns button[data-b="SHOOT"] { grid-column: 2; grid-row: 2; background: rgba(225, 29, 72, .45); }
.th-btns button[data-b="BOMB"] { grid-column: 2; grid-row: 1; }
.th-btns button[data-b="FOCUS"] { grid-column: 1; grid-row: 2; background: rgba(59, 130, 246, .35); }
.th-btns button small { font-size: 9px; font-weight: 600; opacity: .8; }
.th-btns button.th-on { background: rgba(244, 114, 182, .6); }
.th-sys { position: absolute; left: 10px; bottom: calc(min(34vmin, 150px) + 14px); display: flex; gap: 8px; pointer-events: none; }
.th-sys button { pointer-events: auto; touch-action: none; padding: 5px 12px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .35); background: rgba(24, 24, 27, .6); color: #f4f4f5; font-size: 12px; font-weight: 700; }
.th-sys button.th-on { background: rgba(244, 114, 182, .6); }
/* 축소 화면: 작은 패드(게임 화면 양옆 띠) */
#touhouRoot:not(.th-expanded) .th-pad { padding: 4px; --s: min(9vmin, 38px); }
#touhouRoot:not(.th-expanded) .th-dpad { width: min(22vmin, 96px); }
#touhouRoot:not(.th-expanded) .th-btns button { font-size: 12px; }
#touhouRoot:not(.th-expanded) .th-btns button small { display: none; }
#touhouRoot:not(.th-expanded) .th-sys { left: 4px; bottom: calc(min(22vmin, 96px) + 8px); gap: 4px; }
#touhouRoot:not(.th-expanded) .th-sys button { padding: 3px 9px; font-size: 11px; }
