:root {
  --bg: #0b0d12;
  --glass: rgba(16, 18, 26, 0.72);
  --glass-2: rgba(24, 27, 38, 0.86);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f1f2f6;
  --muted: #a3a8b8;
  --accent: #ffd43b;
  --rec: #ff4d4f;
  --live: #3ddc84;
  --font: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --display: "Black Han Sans", "IBM Plex Sans KR", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; cursor: grab; }
#scene.drag { cursor: grabbing; }

.pill {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 14px; white-space: nowrap;
}
button.pill:hover { background: var(--glass-2); }
button.pill:focus-visible, .emotes button:focus-visible, .chatbar button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hud-top { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 16px; right: 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.brand { gap: 12px; }
.brand .mark { display: inline-flex; align-items: center; gap: 6px; font-family: var(--display); font-size: 16px; letter-spacing: .02em; color: var(--accent); }
.brand .count { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; padding-left: 12px; border-left: 1px solid var(--line); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #666; }
.dot.live { background: var(--live); box-shadow: 0 0 0 0 rgba(61, 220, 132, .6); animation: pulse 2s infinite; }
.dot.off { background: #f59f00; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(61, 220, 132, 0); } 100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); } }
.right { display: flex; gap: 8px; }
.swatch { width: 14px; height: 14px; border-radius: 50%; background: #888; border: 2px solid rgba(255,255,255,.6); }
#cookieBtn svg { color: #ffb84d; }

.bottomstack { position: absolute; left: 16px; bottom: calc(14px + var(--safe-b)); width: min(440px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.bottomstack > * { pointer-events: auto; }
.hint { margin: 0; align-self: flex-start; font-size: 12.5px; color: var(--muted); background: var(--glass); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; transition: opacity .6s; }
.hint.gone { opacity: 0; pointer-events: none; }
.toast { margin: 0; align-self: flex-start; font-size: 13.5px; background: var(--glass-2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 12px; }

.chatlog { background: var(--glass); border: 1px solid var(--line); border-radius: 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); overflow: hidden; }
.chatlog-toggle { width: 100%; display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 8px 12px; font-size: 12.5px; color: var(--muted); text-align: left; }
.chatlog-toggle svg { margin-left: auto; width: 16px; height: 16px; transition: transform .2s; }
.chatlog-toggle[aria-expanded="false"] svg { transform: rotate(180deg); }
.chatlog-new { min-width: 8px; height: 8px; border-radius: 4px; background: var(--rec); }
.chatlog-list { list-style: none; margin: 0; padding: 0 12px 10px; max-height: 190px; overflow-y: auto; font-size: 13.5px; line-height: 1.5; -webkit-user-select: text; user-select: text; overscroll-behavior: contain; }
.chatlog-list li { padding: 2px 0; word-break: break-all; }
.chatlog-list .t { color: #6f7586; font-size: 11px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.chatlog-list .n { font-weight: 700; margin-right: 6px; }
.chatlog-list .sys { color: var(--muted); font-size: 12.5px; }
.chatlog-list .ft { color: #ffcf7a; }
.chatlog-list .me .n::after { content: " (나)"; font-weight: 400; color: var(--muted); font-size: 11px; }
.chatlog.closed .chatlog-list { display: none; }

.bottombar { display: flex; gap: 8px; align-items: center; }
.emotes { display: flex; gap: 4px; background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.emotes button { position: relative; width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; }
.emotes button:hover { background: rgba(255,255,255,.08); }
.emotes button span { position: absolute; right: 2px; bottom: 0; font-size: 9px; color: #6f7586; }
.emotes .kk { font-size: 13px; color: var(--accent); }
.emotes [data-emote="heart"] svg { color: #ff7aa8; }
.emotes [data-emote="cut"] svg { color: #9ad0ff; }
.chatbar { flex: 1; min-width: 0; display: flex; align-items: center; background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 4px 4px 4px 14px; }
.chatbar input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--text); font: inherit; font-size: 15px; height: 36px; }
.chatbar input::placeholder { color: #7a8092; }
.chatbar button { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: #111; display: grid; place-items: center; }
.chatbar button:disabled { background: rgba(255,255,255,.1); color: #777; cursor: default; }

.modal { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 6, 10, .45); padding: 16px; }
.modal-card { width: min(420px, 100%); max-height: calc(100% - 16px); overflow-y: auto; background: rgba(17, 19, 27, .94); border: 1px solid var(--line); border-radius: 20px; padding: 24px 22px 20px; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.kicker { margin: 0; font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.modal-card h1 { margin: 4px 0 6px; font-family: var(--display); font-weight: 400; font-size: 34px; color: var(--accent); letter-spacing: .01em; }
.sub { margin: 0 0 18px; color: #c9ccd6; font-size: 14px; line-height: 1.55; }
.field { display: block; border: 0; margin: 0 0 16px; padding: 0; }
.field > span, .field legend { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; padding: 0; }
.field input { width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.05); color: var(--text); font: inherit; font-size: 16px; padding: 0 14px; outline: none; }
.field input:focus { border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { position: relative; }
.chips input, .swatches input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: inline-block; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 13.5px; color: #cfd2db; cursor: pointer; }
.chips input:checked + span { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 700; }
.chips input:focus-visible + span, .swatches input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatches label { position: relative; }
.swatches span { display: block; width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; box-shadow: inset 0 0 0 2px rgba(0,0,0,.25); cursor: pointer; }
.swatches input:checked + span { border-color: #fff; }
.err { color: #ff8787; font-size: 13px; margin: -6px 0 10px; }
.primary { display: block; width: 100%; height: 48px; border: 0; border-radius: 12px; background: var(--accent); color: #111; font-weight: 700; font-size: 16px; }
.primary:hover { filter: brightness(1.05); }
.ghost { height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: transparent; font-size: 13.5px; }
.note { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.note b { color: #cfd2db; }

.card { position: absolute; top: 64px; right: 16px; width: min(320px, calc(100% - 32px)); background: rgba(17, 19, 27, .94); border: 1px solid var(--line); border-radius: 16px; padding: 16px 16px 14px; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.card .x { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border: 0; background: none; font-size: 22px; color: var(--muted); }
.card-kicker { margin: 0; font-size: 12px; color: var(--accent); }
.card-name { margin: 2px 0 4px; font-size: 22px; font-weight: 700; }
.card-meta { margin: 0; font-size: 13.5px; color: #c9ccd6; }
.card-quote { margin: 12px 0 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: rgba(255,255,255,.04); border-radius: 0 10px 10px 0; font-size: 15px; line-height: 1.5; }
.card-note { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.card .ghost { margin-top: 12px; }

.fortune { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 6, 10, .4); padding: 16px; }
.fortune-paper { width: min(380px, 100%); background: #fff8e6; color: #3b2a12; border-radius: 16px; padding: 22px 22px 18px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.5); animation: pop .35s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop { from { transform: scale(.85) rotate(-2deg); opacity: 0; } }
.fortune-title { margin: 0; font-family: var(--display); font-size: 20px; color: #c46a00; }
.fortune-text { margin: 14px 0 8px; font-size: 19px; line-height: 1.55; font-weight: 700; word-break: keep-all; }
.fortune-sub { margin: 0 0 16px; font-size: 12.5px; color: #8a6b3d; }
.fortune .primary { background: #ff9f1c; }

.gate, .fail { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 6, 10, .82); padding: 16px; text-align: center; }
.gate-card { width: min(360px, 100%); background: rgba(17, 19, 27, .96); border: 1px solid var(--line); border-radius: 18px; padding: 22px; }
.gate-title { margin: 0 0 6px; font-size: 20px; font-weight: 700; }
.gate-text { margin: 0 0 16px; color: #c9ccd6; font-size: 14px; line-height: 1.55; }
.fail p { font-size: 15px; line-height: 1.6; color: #e0e2ea; }

@media (max-width: 640px) {
  .hud-top { left: 10px; right: 10px; }
  .pill { height: 36px; padding: 0 11px; font-size: 13px; }
  .brand { gap: 8px; }
  .brand .mark { font-size: 14px; }
  .brand .mark-t { display: none; }
  .brand .count { border-left: 0; padding-left: 0; }
  .brand .count { font-size: 12px; padding-left: 8px; }
  #cookieBtn .lbl { display: none; }
  #meText { max-width: 84px; overflow: hidden; text-overflow: ellipsis; }
  .bottomstack { left: 10px; right: 10px; width: auto; bottom: calc(10px + var(--safe-b)); }
  .chatlog-list { max-height: 120px; }
  .bottombar { flex-direction: column; align-items: stretch; }
  .emotes { align-self: flex-start; }
  .card { top: 56px; right: 10px; }
}
@media (max-width: 380px) {
  .brand .mark span, .brand .mark { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .dot.live { animation: none; }
  .fortune-paper { animation: none; }
}

/* OG 이미지 촬영 모드 */
.og .hud-top, .og .bottomstack { display: none; }
.og-badge { position: absolute; left: 0; top: 0; bottom: 0; width: 52%; padding: 70px 0 0 64px; background: linear-gradient(90deg, rgba(8,9,14,.97) 0%, rgba(8,9,14,.9) 58%, rgba(8,9,14,0) 100%); pointer-events: none; }
.og-k { margin: 0; font-size: 26px; color: #c9ccd6; letter-spacing: .02em; }
.og-t { margin: 10px 0 0; white-space: nowrap; font-family: var(--display); font-size: 76px; line-height: 1.05; color: var(--accent); }
.og-s { display: inline-block; margin: 18px 0 0; font-size: 34px; font-weight: 700; color: #111; background: #fff; padding: 6px 18px; border-radius: 999px; }

/* 테마 전환 */
.fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .35s ease-out; }
.fade.on { opacity: 1; }

/* 미니게임 */
#gameBtn svg { color: #8ce99a; }
.modal-card { position: relative; }
.modal-card .x, .gpanel .x { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border: 0; background: none; font-size: 22px; color: var(--muted); }
.gm-title { margin: 0 0 6px; font-size: 22px; }
.game-list { display: grid; gap: 8px; }
.game-card { text-align: left; border: 1px solid var(--line); background: rgba(255,255,255,.04); border-radius: 14px; padding: 12px 14px; }
.game-card:hover { border-color: var(--accent); }
.game-card b { display: block; font-size: 16px; margin-bottom: 4px; }
.game-card span { display: block; font-size: 13px; color: #c9ccd6; line-height: 1.5; }
.gpanel { position: absolute; top: 64px; right: 16px; width: min(340px, calc(100% - 32px)); max-height: calc(100% - 300px); min-height: 150px; overflow-y: auto; background: rgba(17, 19, 27, .94); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px 14px; }
.gp-head { display: flex; align-items: center; gap: 8px; padding-right: 30px; }
.gpanel .x { top: 6px; right: 6px; }
.gp-title { margin: 0; font-weight: 700; font-size: 15px; flex: 1; }
.gp-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.gp-time.hot { color: #ff6b6b; }
.gp-mini { border: 1px solid var(--line); background: none; border-radius: 8px; font-size: 11.5px; padding: 3px 8px; color: var(--muted); }
.gp-bar { height: 4px; background: rgba(255,255,255,.08); border-radius: 2px; margin: 10px 0; overflow: hidden; }
.gp-bar i { display: block; height: 100%; background: var(--accent); transform-origin: left; }
.gp-body p { margin: 0 0 8px; line-height: 1.5; }
.gp-lead { font-size: 14px; }
.gp-sub { font-size: 12.5px; color: var(--muted); }
.gp-cat { font-size: 12px; color: var(--accent); }
.gp-q { font-size: 17px; font-weight: 700; word-break: keep-all; }
.gp-ans { font-size: 22px; font-weight: 700; color: var(--accent); }
.gp-out { font-size: 13px; color: #ff8787; }
.gp-win { font-size: 22px; font-weight: 700; color: #ffc933; }
.gp-word { font-family: var(--display); font-size: 36px; color: var(--accent); }
.gp-row { display: flex; gap: 8px; margin: 6px 0 10px; }
.gp-row .big { flex: 1; height: 54px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.05); font-size: 20px; font-weight: 700; }
.gp-row .big.on { background: var(--accent); color: #111; border-color: var(--accent); }
.gp-row .ox-o { color: #6ea8ff; } .gp-row .ox-x { color: #ff7b7b; }
.gp-row .ox-o.on, .gp-row .ox-x.on { color: #111; }
.gp-form { display: flex; gap: 6px; margin: 6px 0 10px; }
.gp-form input { flex: 1; min-width: 0; height: 44px; border-radius: 10px; border: 1px solid var(--accent); background: rgba(255,255,255,.05); color: var(--text); font: inherit; font-size: 16px; padding: 0 12px; outline: none; }
.gp-form .primary { width: auto; height: 44px; padding: 0 16px; }
.gp-picks, .gp-players { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.04); }
.chip.out { opacity: .45; text-decoration: line-through; }
.chip.mine { border-color: var(--accent); }
.gp-body .primary, .gp-body .ghost { margin-top: 4px; }

/* 채팅 사진 */
.chatbar .imgbtn { width: 34px; height: 34px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; margin-left: -6px; margin-right: 4px; }
.chatbar .imgbtn:hover { color: var(--text); background: rgba(255,255,255,.06); }
.imgthumb { display: block; margin: 4px 0 2px; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: rgba(255,255,255,.04); max-width: 180px; }
.imgthumb img { display: block; max-width: 180px; max-height: 140px; object-fit: cover; }
.imgthumb.hid { padding: 8px 10px; font-size: 12px; color: var(--muted); }
.lightbox { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 6, 10, .86); padding: 16px; }
.lightbox figure { margin: 0; max-width: 100%; max-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.lightbox img { max-width: min(92vw, 1100px); max-height: 74vh; border-radius: 12px; object-fit: contain; background: #111; }
.lightbox figcaption { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; font-size: 13.5px; color: #d7dae3; }
@media (max-width: 640px) {
  #gameBtn .lbl { display: none; }
  .gpanel { top: 54px; right: 10px; left: 10px; width: auto; max-height: 42vh; }
}

/* 행동: 체력·스킬 */
.actionbox { position: absolute; right: 16px; bottom: calc(14px + var(--safe-b)); width: 300px; background: var(--glass); border: 1px solid var(--line); border-radius: 16px; padding: 10px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.hp-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.hp-bar { flex: 1; height: 10px; border-radius: 5px; background: rgba(255,255,255,.1); overflow: hidden; }
.hp-bar i { display: block; height: 100%; background: #51cf66; transform-origin: left; transition: transform .2s ease-out; }
.hp-bar i.low { background: #ff6b6b; }
.hp-row b { min-width: 28px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.ab-tools { display: flex; gap: 6px; margin: 8px 0; }
.ab-tool { flex: 1; height: 32px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255,255,255,.04); font-size: 12.5px; }
.ab-tool[aria-pressed="true"] { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 700; }
.ab-more { display: none; }
.skillbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.skillbar button { position: relative; overflow: hidden; height: 46px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.05); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.skillbar button:hover { border-color: rgba(255,255,255,.3); }
.skillbar b { font-size: 13px; }
.skillbar span { font-size: 10.5px; color: var(--muted); }
.skillbar i { position: absolute; inset: 0; background: rgba(0,0,0,.55); transform-origin: bottom; transform: scaleY(0); pointer-events: none; }
.down-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(120, 0, 0, .25); pointer-events: none; }
.down-overlay p { margin: 0; text-align: center; font-family: var(--display); font-size: 40px; color: #fff; text-shadow: 0 2px 12px rgba(0,0,0,.6); }
.down-overlay span { font-family: var(--font); font-size: 15px; }
@media (max-width: 1100px) { .bottomstack { width: min(400px, calc(100% - 350px)); } }
@media (max-width: 640px) {
  .bottomstack { width: auto; }
  .actionbox { bottom: calc(318px + var(--safe-b)); right: 10px; width: 196px; padding: 8px; }
  .ab-more { display: block; }
  .skillbar { display: none; }
  .skillbar.open { display: grid; grid-template-columns: repeat(3, 1fr); }
  .skillbar button { height: 42px; }
  .skillbar span { display: none; }
}
