/* 웹소설 AI 챗 게임 v0.2.14 */
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #090910;
  --surface: #14141f;
  --surface2: #1b1b2b;
  --input-bg: #1e1e2e;
  --border: #2a2a3d;
  --line: rgba(255,255,255,.08);
  --glass: rgba(16,16,28,.62);
  --glass-border: rgba(255,255,255,.12);
  --text: #ececf4;
  --text2: #a9a9c0;
  --text3: #6b6b86;
  --accent: #8b6cff;
  --accent-hover: #a48dff;
  --accent-dim: rgba(139,108,255,.16);
  --accent2: #e879f9;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #ff5a6a;
  --overlay: rgba(3,3,8,.65);
  --font: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Noto Sans KR', system-ui, sans-serif;
  --ease: cubic-bezier(.32,.72,0,1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

html, body {
  height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
body {
  overscroll-behavior: none;
  background: radial-gradient(120% 70% at 50% 0%, #1a1432 0%, #0b0b15 55%, #07070d 100%);
}
button { font-family: inherit; color: inherit; cursor: pointer; -webkit-appearance: none; appearance: none; }
input, textarea, select { font-family: inherit; }
.ic { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mt6 { margin-top: 6px; }
@media (pointer: coarse) { input, textarea, select { font-size: 16px !important; } }

.app {
  position: relative; display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; max-width: 640px; margin: 0 auto;
  background: var(--bg); overflow: hidden; isolation: isolate;
}
@media (min-width: 641px) {
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); box-shadow: 0 0 80px rgba(0,0,0,.6); }
}

.ambient {
  position: absolute; inset: -8%; width: 116%; height: 116%; object-fit: cover; z-index: 0;
  filter: blur(34px) saturate(1.4) brightness(.45); opacity: 0; transition: opacity .5s; pointer-events: none;
}
.ambient.on { opacity: 1; }

.gen-bar { position: absolute; top: 0; left: 0; right: 0; height: 3px; z-index: 40; overflow: hidden; opacity: 0; transition: opacity .2s; pointer-events: none; }
.gen-bar::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: -40%; width: 40%;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent2), transparent);
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { from { left: -40%; } to { left: 100%; } }
.app.busy .gen-bar { opacity: 1; }

.stage { position: relative; flex: 1 1 auto; min-height: 0; z-index: 1; overflow: hidden; }
.main-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transition: opacity .3s; }
.placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 12px; padding: 32px; color: var(--text2);
}
.ph-orb {
  position: absolute; width: 340px; height: 340px; border-radius: 50%; top: 50%; left: 50%; transform: translate(-50%, -55%);
  background: radial-gradient(closest-side, rgba(139,108,255,.28), rgba(232,121,249,.1) 50%, transparent 100%);
  pointer-events: none;
}
.placeholder-icon {
  position: relative; width: 72px; height: 72px; border-radius: 22px; display: grid; place-items: center;
  background: var(--glass); border: 1px solid var(--glass-border); color: var(--accent-hover); font-size: 1.9rem;
}
.placeholder-text { position: relative; font-size: 1.05rem; font-weight: 700; color: var(--text); word-break: keep-all; }
.ph-actions { position: relative; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.ph-cta {
  padding: 9px 15px; border-radius: 999px; border: 1px solid rgba(139,108,255,.55);
  background: var(--accent-dim); color: #d4c9ff; font-size: .82rem; font-weight: 600;
}
.ph-cta.secondary { background: rgba(255,255,255,.06); border-color: var(--glass-border); color: var(--text2); }

.stage-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20; pointer-events: none;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 0;
}
.stage-top button { pointer-events: auto; }
.stage-top-right { display: flex; align-items: center; gap: 6px; padding-top: 6px; flex-wrap: wrap; justify-content: flex-end; }
.glass-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--glass-border); background: rgba(10,10,20,.58); color: var(--text2); font-size: .72rem;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.glass-chip .ic { width: 13px; height: 13px; }
.glass-chip b { color: var(--text); font-weight: 600; }
.model-chip { border-color: rgba(139,108,255,.45); background: rgba(139,108,255,.16); }
.auto-chip.on { border-color: rgba(52,211,153,.55); background: rgba(52,211,153,.16); color: #6ee7b7; }
.auto-chip.on b { color: #a7f3d0; }

.menu-dropdown { position: relative; }
.menu-toggle {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--glass-border);
  background: rgba(10,10,20,.58); color: #fff; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.menu-toggle .ic { width: 20px; height: 20px; fill: currentColor; }
.menu-items {
  position: absolute; top: calc(100% + 8px); left: 0; min-width: 230px; padding: 6px;
  background: rgba(18,18,30,.92); border: 1px solid var(--glass-border); border-radius: 16px;
  backdrop-filter: blur(20px); box-shadow: 0 14px 40px rgba(0,0,0,.55);
  opacity: 0; visibility: hidden; pointer-events: none; transform: translateY(-8px) scale(.96);
  transition: opacity .18s, transform .22s var(--ease), visibility 0s .22s;
}
.menu-dropdown.open .menu-items { opacity: 1; visibility: visible; pointer-events: auto; transform: none; transition: opacity .18s, transform .22s var(--ease), visibility 0s; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 42px; padding: 0 12px;
  border: none; background: none; border-radius: 10px; color: var(--text); font-size: .86rem; text-align: left;
}
.menu-item:active { background: rgba(255,255,255,.1); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu-scrim { position: fixed; inset: 0; z-index: 19; }

/* ===== Dock ===== */
.dock {
  position: relative; flex: none; z-index: 5;
  padding: 8px 12px calc(10px + var(--safe-b));
  background: rgba(10,10,18,.96); border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
}
.vn-panel {
  background: rgba(20,20,34,.8); border: 1px solid var(--line); border-radius: 14px;
  padding: 9px 12px; max-height: 36vh; overflow-y: auto;
}
.vn-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.vn-meta { font-size: .72rem; color: var(--accent-hover); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vn-tools { display: flex; gap: 4px; flex: none; }
.vn-tool-btn {
  width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(255,255,255,.05); color: var(--text2); display: inline-flex; align-items: center; justify-content: center;
}
.vn-tool-btn .ic { width: 13px; height: 13px; }
.vn-tool-btn:active { background: var(--accent-dim); color: #fff; }

.vn-narration { font-size: .88rem; color: var(--text); line-height: 1.6; word-break: keep-all; margin-bottom: 6px; }
.vn-dialogue {
  margin-top: 6px; padding: 7px 10px; border-radius: 10px; background: rgba(255,255,255,.04);
  border-left: 3px solid var(--accent-hover); font-size: .88rem; line-height: 1.5; word-break: keep-all;
}
.vn-dialogue[data-emo="happy"] { border-left-color: #fbbf24; }
.vn-dialogue[data-emo="embarrassed"] { border-left-color: #f472b6; }
.vn-dialogue[data-emo="angry"] { border-left-color: #fb7185; }
.vn-dialogue[data-emo="sad"] { border-left-color: #60a5fa; }
.vn-dialogue[data-emo="surprised"] { border-left-color: #34d399; }
.vn-speaker { font-size: .76rem; font-weight: 700; color: #d4c9ff; margin-bottom: 2px; }

.vn-thoughts { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: .78rem; color: var(--text2); }
.vn-thoughts summary { cursor: pointer; color: #f0abfc; font-weight: 600; font-size: .74rem; }
.thought-item { margin-top: 4px; padding: 4px 8px; border-radius: 8px; background: rgba(232,121,249,.08); }

.choice-list { display: flex; flex-wrap: wrap; gap: 6px; }
.choice-chip {
  flex: 1 1 auto; min-width: 44%; padding: 7px 10px; border-radius: 12px; text-align: left;
  border: 1px solid rgba(139,108,255,.45); background: var(--accent-dim); color: var(--text);
  font-size: .78rem; font-weight: 500; line-height: 1.35;
}
.choice-chip:active { background: rgba(139,108,255,.32); }

.input-bar {
  display: flex; align-items: center; gap: 8px; padding: 5px 5px 5px 14px; border-radius: 26px;
  background: var(--input-bg); border: 1px solid var(--glass-border);
}
.input-bar:focus-within { border-color: var(--accent-hover); }
.input-bar input { flex: 1; min-width: 0; height: 38px; border: none; background: transparent; color: var(--text); font-size: .92rem; outline: none; }
.input-bar input::placeholder { color: var(--text3); }
.btn-send {
  width: 38px; height: 38px; border-radius: 50%; border: none; color: #fff;
  background: linear-gradient(135deg, #8b6cff, #c46bff); display: flex; align-items: center; justify-content: center;
}
.btn-send:disabled { opacity: .5; }

/* ===== Bottom Sheets ===== */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 100; background: var(--overlay); backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sheet-overlay.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 640px; z-index: 101;
  display: flex; flex-direction: column; max-height: 88dvh;
  background: var(--surface); border: 1px solid var(--glass-border); border-bottom: none; border-radius: 22px 22px 0 0;
  transform: translateY(105%); visibility: hidden; transition: transform .32s var(--ease), visibility 0s .32s;
}
.sheet.open { transform: translateY(0); visibility: visible; transition: transform .32s var(--ease), visibility 0s; }
.sheet-handle { display: flex; justify-content: center; padding: 10px 0 6px; }
.sheet-handle::before { content: ''; width: 40px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.22); }
.sheet-header { display: flex; justify-content: space-between; align-items: center; padding: 2px 14px 10px 20px; }
.sheet-header h2 { font-size: 1.05rem; font-weight: 700; }
.sh-title { display: flex; align-items: baseline; gap: 8px; }
.sh-sub { font-size: .74rem; color: var(--text3); font-weight: 500; }
.sheet-close { width: 34px; height: 34px; border-radius: 50%; border: none; background: rgba(255,255,255,.08); color: var(--text2); display: grid; place-items: center; }
.sheet-body { padding: 0 16px calc(22px + var(--safe-b)); overflow-y: auto; overscroll-behavior: contain; }

.set-card { background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.set-title { font-size: .74rem; font-weight: 700; letter-spacing: .04em; color: var(--accent-hover); margin-bottom: 10px; }
.setting-group { margin-bottom: 12px; }
.setting-group:last-child { margin-bottom: 0; }
.setting-group label { display: block; font-size: .78rem; color: var(--text2); margin-bottom: 5px; font-weight: 600; }
.setting-group input[type="text"], .setting-group input[type="password"], .setting-group input[type="number"],
.setting-group select, .setting-group textarea {
  width: 100%; background: var(--input-bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; font-size: .86rem; outline: none;
}
.setting-group input:focus, .setting-group select:focus, .setting-group textarea:focus { border-color: var(--accent); }
.setting-row { display: flex; gap: 10px; }
.setting-row > .setting-group { flex: 1; min-width: 0; }
.seed-row { display: flex; gap: 6px; }
.seed-row input { flex: 1; min-width: 0; }
.chk-row { display: flex !important; align-items: center; gap: 8px; cursor: pointer; }
.chk-row input { width: 16px; height: 16px; accent-color: var(--accent); }

.ghost-sm {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px; height: 34px; padding: 0 11px;
  border-radius: 10px; background: var(--accent-dim); color: var(--text); border: 1px solid rgba(139,108,255,.5);
  font-size: .78rem; font-weight: 600; white-space: nowrap;
}
.ghost-sm.on { background: rgba(52,211,153,.2); border-color: rgba(52,211,153,.6); color: #6ee7b7; }
.ghost-sm.danger { background: rgba(255,90,106,.14); border-color: rgba(255,90,106,.5); color: #ffb3bd; }
.btn-block {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 42px;
  border-radius: 12px; margin-top: 8px; background: linear-gradient(135deg, #6366f1, #8b6cff);
  color: #fff; border: none; font-size: .88rem; font-weight: 700;
}
.btn-block:disabled { opacity: .55; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }

.item-list { display: flex; flex-direction: column; gap: 8px; }
.list-card {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 12px; background: var(--surface2); border: 1px solid var(--border);
}
.list-card-main { min-width: 0; flex: 1; }
.list-card-title { font-size: .88rem; font-weight: 700; color: var(--text); }
.list-card-sub { font-size: .74rem; color: var(--text3); line-height: 1.45; }
.list-card-btns { display: flex; gap: 5px; flex: none; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; font-size: .8rem; }
.stat-box { padding: 8px 10px; border-radius: 10px; background: var(--surface2); border: 1px solid var(--border); }
.stat-box small { display: block; font-size: .68rem; color: var(--text3); }

.ref-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ref-thumb { width: 44px; height: 58px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: #000; }

.proxy-test-result { margin-top: 8px; font-size: .76rem; font-family: ui-monospace, monospace; white-space: pre-wrap; color: var(--text2); }
.proxy-test-result.pass { color: var(--ok); }
.proxy-test-result.fail { color: var(--danger); }

.toast {
  position: fixed; left: 50%; top: calc(56px + var(--safe-t)); z-index: 900; max-width: 90vw;
  padding: 8px 16px; border-radius: 999px; background: rgba(22,22,36,.95); color: var(--text);
  border: 1px solid var(--glass-border); font-size: .8rem; font-weight: 500;
  opacity: 0; transform: translate(-50%, -10px); pointer-events: none; transition: opacity .22s, transform .25s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { color: #6ee7b7; border-color: rgba(52,211,153,.5); }
.toast.error { color: #ff9aa6; border-color: rgba(255,90,106,.55); }
.toast.warn { color: #fcd34d; border-color: rgba(251,191,36,.5); }


/* ===== 전수조사 기반 레이아웃 이탈(Overflow) 방지 보강 ===== */
.app, .sheet, .sheet-body, .set-card, .setting-group, .item-list, .list-card, .list-card-main, .stat-grid, .stat-box, .vn-panel, .vn-content, .vn-narration, .vn-dialogue, .choice-list, .choice-chip, .proxy-test-result, .toast {
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

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

.stat-box {
  min-width: 0;
  overflow: hidden;
}

.stat-box b {
  display: block;
  overflow-wrap: anywhere;
  word-break: break-word;
}

#statInvFlags {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-all;
  max-height: 180px;
  overflow-y: auto;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .72rem;
  line-height: 1.45;
}

.list-card-sub {
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.choice-chip {
  flex: 1 1 100%;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.proxy-test-result {
  overflow-wrap: anywhere;
  word-break: break-word;
}


/* ===== 단일 링크 개인용 PIN 잠금 게이트 ===== */
.pin-gate {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(9, 9, 16, 0.94);
  backdrop-filter: blur(12px);
}
.pin-gate[hidden] { display: none; }
.pin-card {
  width: 100%;
  max-width: 360px;
  padding: 22px 20px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.pin-badge {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--accent-hover);
}
.pin-card h2 { font-size: 1.05rem; margin: 0; }
.pin-card p { font-size: .8rem; color: var(--text2); line-height: 1.45; margin: 0; }
.pin-card input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: .92rem;
}
.pin-error { font-size: .76rem; color: #f87171; }
