/* kokoro · 어둡고 차분한 테마 · 큰 글씨 (사양 §4) — 터미널 테마(packages/ui-terminal)는 쓰지 않는다: 위기 서비스는 자극 없는 화면이 우선
   테마 4종(프리미엄 선택): night(기본) · dusk · forest · mist — html[data-theme] · 글자 크기: html[data-font] m(기본)·l·xl */
:root {
  --bg: #0e1322; --bg2: #121a2e; --card: #172038; --card2: #1d2744; --line: #2a3657;
  --text: #e8ebf5; --muted: #b3bad2; --dim: #8e97b6;
  --accent: #a7bcff; --accent-ink: #0e1322; --accent-soft: rgba(167, 188, 255, .14);
  --warm: #f3c48f; --warm-ink: #2b1a07; --danger: #ffa3a3; --danger-ink: #2a0b0b; --danger-soft: rgba(255, 163, 163, .12);
  --ok: #9ad8b9; --radius: 16px; --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic UI', 'Noto Sans JP', 'Noto Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color-scheme: dark;
  font-size: 18px;
}
html[data-theme="dusk"] { --bg: #18121c; --bg2: #1f1724; --card: #271d2d; --card2: #2f2337; --line: #44334d; --accent: #f2b8a2; --accent-soft: rgba(242, 184, 162, .14); --accent-ink: #1d1012; }
html[data-theme="forest"] { --bg: #0d1714; --bg2: #11201b; --card: #162822; --card2: #1c322a; --line: #2b4a3e; --accent: #a3dcbf; --accent-soft: rgba(163, 220, 191, .14); --accent-ink: #0b1612; }
html[data-theme="mist"] { --bg: #15181d; --bg2: #1a1e24; --card: #20252d; --card2: #272d36; --line: #3a424f; --accent: #c9d1df; --accent-soft: rgba(201, 209, 223, .14); --accent-ink: #15181d; }
html[data-font="l"] { font-size: 20px; }
html[data-font="xl"] { font-size: 23px; }
html[lang="th"] { --font: 'Noto Sans Thai', 'Leelawadee UI', 'Thonburi', 'Segoe UI', system-ui, sans-serif; }
html[lang="ko"] { --font: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', 'Segoe UI', system-ui, sans-serif; }
html[lang="zh-Hans"] { --font: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', 'Segoe UI', system-ui, sans-serif; }
html[lang="zh-Hant"] { --font: 'PingFang TC', 'Microsoft JhengHei', 'Noto Sans TC', 'Segoe UI', system-ui, sans-serif; }

* { box-sizing: border-box; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: radial-gradient(1200px 600px at 80% -10%, rgba(167, 188, 255, .08), transparent 60%), var(--bg); color: var(--text); font-family: var(--font); line-height: 1.75; letter-spacing: .01em; overflow-x: hidden; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

/* ── 상단 ── */
.top { position: sticky; top: 0; z-index: 30; background: rgba(14, 19, 34, .92); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.05rem; white-space: nowrap; min-width: 0; }
.brand img { width: 30px; height: 30px; flex: none; }
.nav { display: flex; gap: 4px; margin-left: 8px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 10px; font-size: .86rem; white-space: nowrap; }
.nav a:hover { color: var(--text); background: var(--accent-soft); }
.nav a[aria-current="page"] { color: var(--text); background: var(--card); }
.crisis { flex: none; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; border: 0; cursor: pointer; background: var(--warm); color: var(--warm-ink); font-weight: 700; padding: 9px 14px; border-radius: 999px; font-size: .86rem; box-shadow: 0 0 0 4px rgba(243, 196, 143, .16); white-space: nowrap; }
.crisis:hover { filter: brightness(1.06); }
.crisis .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warm-ink); opacity: .75; }
.lang { flex: none; display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.lang select { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; font-size: .8rem; max-width: 7.5rem; }
@media (max-width: 1180px) {
  .top-in { flex-wrap: wrap; row-gap: 6px; }
  .nav { order: 3; flex-basis: 100%; margin: 0 -6px; padding-bottom: 2px; }
  .crisis { margin-left: auto; }
}
@media (max-width: 420px) {
  .brand span.bname { max-width: 7.5rem; overflow: hidden; text-overflow: ellipsis; }
  .crisis { padding: 8px 11px; font-size: .8rem; }
  .lang select { max-width: 5.6rem; }
}

/* ── 본문 ── */
.wrap { max-width: 960px; margin: 0 auto; padding: 28px 16px 40px; }
.narrow { max-width: 760px; }
h1 { font-size: 1.65rem; line-height: 1.4; margin: .2em 0 .5em; letter-spacing: .02em; }
h2 { font-size: 1.25rem; line-height: 1.45; margin: 1.8em 0 .6em; }
h3 { font-size: 1.05rem; margin: 1.4em 0 .4em; }
p { margin: .5em 0 1em; }
.lead { color: var(--muted); font-size: 1.02rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.card h2, .card h3 { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 680px) { .grid { grid-template-columns: minmax(0, 1fr); } h1 { font-size: 1.42rem; } }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--card2); color: var(--text); border-radius: 12px; padding: 10px 18px; cursor: pointer; text-decoration: none; font-weight: 600; min-height: 44px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.warm { background: var(--warm); color: var(--warm-ink); border-color: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: rgba(255, 163, 163, .45); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.pill { display: inline-block; font-size: .72rem; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.pill.warn { background: rgba(243, 196, 143, .14); color: var(--warm); }
.note { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 10px 14px; border-radius: 0 12px 12px 0; color: var(--text); font-size: .9rem; }
.note.warm { border-color: var(--warm); background: rgba(243, 196, 143, .1); }
input[type="text"], input[type="email"], input[type="password"], textarea, select.field { width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; color: var(--text); }
textarea { resize: vertical; min-height: 3.2em; line-height: 1.6; }
label.field { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }

/* 홈 */
.hero { padding: 18px 0 8px; }
.hero .row { margin-top: 18px; }
.cards a.card { display: block; color: var(--text); text-decoration: none; transition: border-color .2s; }
.cards a.card:hover { border-color: var(--accent); }
.cards .card h2 { font-size: 1.05rem; margin: 0 0 .3em; color: var(--accent); }
.cards .card p { margin: 0; color: var(--muted); font-size: .9rem; }
.promise { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.promise li { padding-left: 30px; position: relative; }
.promise li::before { content: ''; position: absolute; left: 6px; top: .62em; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); opacity: .8; }

/* 정적 SEO 본문 */
.seo { max-width: 960px; margin: 10px auto 0; padding: 8px 16px 30px; color: var(--muted); font-size: .92rem; }
.seo h2 { color: var(--text); font-size: 1.12rem; }
.seo h3 { color: var(--text); font-size: 1rem; }
.seo h4 { color: var(--text); font-size: .95rem; margin: 1.1em 0 .2em; }
.seo ol { padding-left: 1.4em; }

/* 푸터 */
.foot { border-top: 1px solid var(--line); margin-top: 20px; }
.foot-in { max-width: 960px; margin: 0 auto; padding: 22px 16px 40px; color: var(--dim); font-size: .8rem; }
.foot nav { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 10px; }
.foot nav a { color: var(--muted); }
.foot p { margin: .4em 0; }

/* ── 창구 시트(dialog) ── */
dialog.sheet { width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 32px); border: 1px solid var(--line); border-radius: 20px; background: var(--bg2); color: var(--text); padding: 0; box-shadow: var(--shadow); }
dialog.sheet::backdrop { background: rgba(4, 6, 12, .7); }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; gap: 10px; padding: 14px 18px; background: var(--bg2); border-bottom: 1px solid var(--line); z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; flex: 1; }
.sheet-body { padding: 14px 18px 22px; }
.x { border: 0; background: var(--card); color: var(--text); width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; line-height: 1; }

/* 긴급 · 창구 카드 */
.em { background: var(--danger-soft); border: 1px solid rgba(255, 163, 163, .4); border-radius: var(--radius); padding: 14px 16px; margin: 6px 0 14px; }
.em h3 { margin: 0 0 4px; color: var(--danger); font-size: 1rem; }
.em p { margin: 0 0 10px; font-size: .9rem; }
.em .btn { background: var(--danger); color: var(--danger-ink); border-color: transparent; }
.lines { display: grid; gap: 10px; }
.line { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-width: 0; }
.line .nm { font-weight: 700; display: block; overflow-wrap: anywhere; }
span[lang|="ja"] { font-family: 'Hiragino Sans', 'Yu Gothic UI', 'Meiryo', 'Noto Sans JP', sans-serif; }
span[lang|="ko"] { font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif; }
span[lang="zh-Hant"] { font-family: 'PingFang TC', 'Microsoft JhengHei', 'Noto Sans TC', sans-serif; }
span[lang="zh-Hans"] { font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif; }
span[lang="th"] { font-family: 'Leelawadee UI', 'Thonburi', 'Noto Sans Thai', sans-serif; }
.line .nat { display: block; color: var(--dim); font-size: .8rem; overflow-wrap: anywhere; }
.line .meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 8px; }
.line .acts { display: flex; flex-wrap: wrap; gap: 8px; }
.line .btn { min-height: 40px; padding: 6px 14px; }
.line .tel { font-variant-numeric: tabular-nums; }
.line .vf { margin: 8px 0 0; font-size: .72rem; color: var(--dim); }
.ctry { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; margin: 4px 0 14px; }
.sec-t { font-size: .95rem; margin: 18px 0 8px; color: var(--muted); }

/* ── 대화 ── */
.chat-wrap { max-width: 820px; margin: 0 auto; padding: 14px 16px 0; display: flex; flex-direction: column; min-height: calc(100vh - 64px); }
.chat-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-head h1 { font-size: 1.15rem; margin: 0; flex: 1; min-width: 0; }
.chat-notice { font-size: .78rem; color: var(--dim); margin: 6px 0 8px; }
.risk-card { border-radius: var(--radius); padding: 14px 16px; margin: 6px 0 10px; border: 1px solid rgba(243, 196, 143, .5); background: var(--bg2); background: color-mix(in srgb, var(--warm) 10%, var(--bg)); position: sticky; top: var(--top-h, 64px); z-index: 5; box-shadow: 0 8px 18px rgba(0, 0, 0, .35); }
.risk-card h2 { margin: 0 0 2px; font-size: 1rem; color: var(--warm); }
.risk-card p { margin: 0 0 8px; font-size: .88rem; }
.risk-card .acts { display: flex; flex-wrap: wrap; gap: 8px; }
.risk-card .em { margin: 0 0 10px; }
.risk-card .foot { margin: 10px 0 0; }
@media (max-width: 1180px) { .risk-card { top: var(--top-h, 104px); } }
/* 모바일도 고정(사양 §2-3) — 화면을 다 덮지 않게 높이 상한 + 카드 안 스크롤 · 긴급 번호(imminent)가 맨 위 */
@media (max-width: 760px) {
  .risk-card { max-height: 40vh; max-height: 40dvh; overflow-y: auto; overscroll-behavior: contain; padding: 10px 12px; margin: 4px 0 8px; }
  .risk-card h2 { font-size: .92rem; }
  .risk-card p { font-size: .8rem; margin-bottom: 6px; line-height: 1.55; }
  .risk-card .em { margin-bottom: 8px; padding: 8px 10px; }
  .risk-card .em h3 { font-size: .9rem; margin-bottom: 2px; }
  .risk-card .em p { margin-bottom: 6px; }
  .risk-card .acts, .risk-card .em .row { gap: 6px; }
  .risk-card .btn { padding: 6px 12px; font-size: .82rem; min-height: 40px; line-height: 1.4; }
  .risk-card .foot { margin-top: 8px; font-size: .7rem; }
}
.msgs { list-style: none; margin: 0; padding: 6px 0 16px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.msg { max-width: 86%; padding: 11px 15px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; }
.msg.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-top-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--accent-soft); border: 1px solid rgba(167, 188, 255, .3); border-top-right-radius: 6px; }
.note-links { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.note > .note-links { justify-content: flex-start; }
.msg.sys { align-self: center; max-width: 100%; background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: .86rem; text-align: center; }
.msg .rep { display: block; margin-top: 6px; background: none; border: 0; color: var(--dim); font-size: .72rem; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.chip { display: inline-flex; align-self: flex-start; gap: 6px; align-items: center; font-size: .82rem; border: 1px solid var(--line); background: transparent; color: var(--accent); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.typing { align-self: flex-start; color: var(--dim); font-size: .85rem; }
.composer { position: sticky; bottom: 0; z-index: 6; background: var(--bg); padding: 10px 0 14px; border-top: 1px solid var(--line); box-shadow: 0 -12px 18px var(--bg); }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 52px; max-height: 40vh; }
.composer .btn { min-height: 52px; }
.limitbar { font-size: .76rem; color: var(--dim); margin: 6px 2px 0; display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.hist { margin: 4px 0 6px; }
.hist summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.hist ul { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.hist li { display: flex; gap: 8px; align-items: center; }
.hist li button.open { flex: 1; min-width: 0; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 진정 도구 ── */
.breath { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 20px; align-items: center; }
@media (max-width: 620px) { .breath { grid-template-columns: minmax(0, 1fr); justify-items: center; text-align: center; } }
.orb-box { width: 200px; height: 200px; display: grid; place-items: center; }
.orb { width: 90px; height: 90px; border-radius: 50%; background: radial-gradient(circle at 38% 35%, #e6ecff, var(--accent) 62%); opacity: .9; transition-property: transform; transition-timing-function: ease-in-out; transform: scale(1); }
.phase { font-size: 1.3rem; font-weight: 700; margin: 0; min-height: 1.6em; }
.phase-sub { color: var(--muted); margin: 0; font-variant-numeric: tabular-nums; }
.gstep { font-size: 1.25rem; font-weight: 700; margin: 6px 0 12px; }
.dots { display: flex; gap: 6px; margin: 4px 0 10px; }
.dots span { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dots span.on { background: var(--accent); }
.memo-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.memo-list li { display: flex; gap: 10px; align-items: flex-start; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.memo-list li span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.memo-list time { color: var(--dim); font-size: .72rem; display: block; }

/* ── 기분 기록 ── */
.faces { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 8px 0 14px; }
.face { border: 1px solid var(--line); background: var(--bg2); border-radius: 14px; padding: 10px 4px; cursor: pointer; text-align: center; min-width: 0; }
.face .e { font-size: 1.6rem; display: block; line-height: 1.2; }
.face .l { font-size: .7rem; color: var(--muted); display: block; overflow-wrap: anywhere; line-height: 1.3; margin-top: 4px; }
.face[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--bg2); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: .82rem; }
.seg button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--dim); font-size: 11px; font-family: var(--font); }
.lock { position: relative; }
.lock .lock-cover { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.pattern li { margin: 4px 0; }

/* ── 프리미엄 ── */
.plans { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .plans { grid-template-columns: minmax(0, 1fr); } }
.plan .price { font-size: 1.4rem; font-weight: 800; margin: 2px 0 6px; }
.plan p { font-size: .85rem; color: var(--muted); }
.cmp { width: 100%; border-collapse: collapse; font-size: .86rem; }
.cmp th, .cmp td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.cmp th { color: var(--muted); font-weight: 600; }
.cmp-wrap { overflow-x: auto; }
@media (max-width: 560px) {
  .cmp thead { display: none; }
  .cmp tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .cmp td { display: block; border: 0; padding: 2px 0; }
  .cmp td::before { content: attr(data-h) ' · '; color: var(--dim); }
  .cmp td:first-child::before { content: ''; }
  .cmp td:first-child { font-weight: 700; }
}
.settings { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .settings { grid-template-columns: minmax(0, 1fr); } }

/* 토스트 */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); background: var(--card2); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; font-size: .88rem; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: calc(100vw - 32px); }
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 404 */
.nf { text-align: center; padding: 60px 16px; }

/* 인쇄(진료용 요약) — 요약 표만 */
#printArea { display: none; }
@media print {
  body { background: #fff; color: #111; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; color: #111; font: 12pt/1.5 sans-serif; padding: 0; }
  #printArea table { width: 100%; border-collapse: collapse; }
  #printArea th, #printArea td { border: 1px solid #999; padding: 4px 6px; text-align: left; vertical-align: top; }
  #printArea h1 { font-size: 16pt; }
}
@media (prefers-reduced-motion: reduce) { .orb { transition: none !important; } .toast { transition: none; } }
@media (max-width: 520px) {
  .brand .bname { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .lang > span { display: none; }
  .lang select { max-width: 5.4rem; }
}
