:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #0f172a;
  --muted: #5b6475;
  --line: #dde2ec;
  --primary: #3b5bfd;
  --primary-ink: #ffffff;
  --danger: #d92d43;
  --ok: #138a52;
  --warn-bg: #fff6e5;
  --warn-line: #f2c36b;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --c-blue: #3b6cf6;
  --c-green: #16a36a;
  --c-purple: #8b5cf6;
  --c-orange: #f08a24;
  --c-red: #e5484d;
  --c-gray: #6b7280;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --surface: #141b2e;
    --surface-2: #1c2540;
    --text: #e8ecf6;
    --muted: #98a2b8;
    --line: #26304b;
    --primary: #6d86ff;
    --primary-ink: #0b1020;
    --danger: #ff6b7d;
    --ok: #3ccf8e;
    --warn-bg: #2a2212;
    --warn-line: #7a5b1d;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #141b2e;
  --surface-2: #1c2540;
  --text: #e8ecf6;
  --muted: #98a2b8;
  --line: #26304b;
  --primary: #6d86ff;
  --primary-ink: #0b1020;
  --danger: #ff6b7d;
  --ok: #3ccf8e;
  --warn-bg: #2a2212;
  --warn-line: #7a5b1d;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; word-break: keep-all; }
p { margin: 0 0 .6em; word-break: keep-all; }
ul, ol { margin: 0 0 .6em; padding-left: 1.2em; }
li { margin: .2em 0; word-break: keep-all; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 60%, transparent); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: .92rem; }
.error:empty { min-height: 0; }
.pre { white-space: pre-wrap; margin: 0; }
.ok-note { color: var(--ok); font-weight: 600; margin: 0; }
.danger-text { color: var(--danger) !important; }

/* 버튼 */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: .65em 1.05em; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4em; text-decoration: none;
  min-height: 44px; transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: .9em 1em; font-size: 1.05rem; min-height: 52px; }
.btn.small { padding: .35em .75em; font-size: .88rem; min-height: 36px; border-radius: 10px; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--text); font-size: 1.2rem;
  width: 44px; height: 44px; border-radius: 12px; cursor: pointer; display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); }
.link { appearance: none; border: 0; background: none; color: var(--primary); font: inherit; cursor: pointer; padding: .4em 0; text-decoration: underline; text-underline-offset: 3px; }
.link.small { font-size: .88rem; }
.link.back { text-decoration: none; margin-bottom: .8rem; display: inline-block; }

/* 입력 */
input[type="text"], input[type="password"], input[type="search"], input[type="url"], input:not([type]), select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: .7em .85em; min-height: 46px;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
.pw-field { position: relative; flex: 1; min-width: 0; }
.pw-field input { padding-right: 48px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pw-field .eye { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); opacity: .55; font-size: 1rem; }
.pw-field .eye.on { opacity: 1; }
.field { display: flex; flex-direction: column; gap: .3em; }
.field-label { font-size: .88rem; font-weight: 600; color: var(--muted); }
.field-hint { font-size: .8rem; color: var(--muted); }
.check { display: flex; gap: .6em; align-items: flex-start; cursor: pointer; font-size: .95rem; }
.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--primary); }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.row { display: flex; gap: .5rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.switch { width: 46px; height: 26px; accent-color: var(--primary); }

/* 강도 표시 */
.meter { display: flex; align-items: center; gap: .6em; margin-top: -.4rem; }
.meter-track { flex: 1; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter-bar { height: 100%; width: 0; background: var(--danger); transition: width .2s ease; }
.meter-bar[data-score="2"] { background: var(--c-orange); }
.meter-bar[data-score="3"], .meter-bar[data-score="4"] { background: var(--ok); }
.meter-label { font-size: .8rem; color: var(--muted); min-width: 4.5em; text-align: right; }

/* 첫 화면 */
.landing { max-width: 960px; margin: 0 auto; padding: calc(28px + var(--safe-top)) 16px calc(40px + var(--safe-bottom)); }
.hero { text-align: center; padding: 28px 0 20px; }
.logo { font-size: 3.4rem; line-height: 1; margin-bottom: .3em; }
.hero h1 { font-size: clamp(2rem, 7vw, 2.8rem); letter-spacing: -.02em; margin-bottom: .3em; }
.tagline { font-size: clamp(1.05rem, 4vw, 1.25rem); color: var(--muted); white-space: pre-line; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 18px 0; }
.feature { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.feature h3 { font-size: 1.05rem; margin: .4em 0 .3em; }
.feature p { color: var(--muted); font-size: .93rem; margin: 0; }
.f-icon { font-size: 1.6rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 12px 0; box-shadow: var(--shadow); }
.card.warn { background: var(--warn-bg); border-color: var(--warn-line); box-shadow: none; }
.card.warn h3 { font-size: 1rem; }
.card.warn li { font-size: .93rem; }
.install { display: flex; flex-direction: column; gap: 12px; }
.install-guide { font-size: .92rem; color: var(--muted); }
.install-guide strong { color: var(--text); display: block; margin-bottom: .3em; }
.install-guide ol { margin: 0; }
.cta { max-width: 420px; margin: 20px auto; }
.foot { text-align: center; color: var(--muted); font-size: .88rem; margin-top: 24px; }

/* 오터데이 스튜디오 놀이터 배지 */
.studio-badge {
  display: flex; align-items: center; justify-content: center; gap: .5em; width: fit-content; max-width: 100%; margin: 0 auto;
  padding: .5em 1em; border-radius: 99px; background: #f5e6e2; color: #7d3b45; border: 1px solid #e9ddd0;
  font-size: .9rem; font-weight: 600; text-decoration: none; text-align: center;
}
.studio-badge:hover { background: #efd9d3; }

/* 좁은 화면 (설정/잠금) */
.narrow { max-width: 440px; margin: 0 auto; padding: calc(36px + var(--safe-top)) 16px calc(32px + var(--safe-bottom)); }
.narrow h1 { font-size: 1.55rem; }
.lock { text-align: center; padding-top: calc(12vh + var(--safe-top)); }
.lock .stack { text-align: left; margin-top: 1.2rem; }
.lock-foot { margin-top: 2rem; display: flex; flex-direction: column; align-items: center; gap: .4rem; }
.rec-note { color: var(--danger); font-weight: 600; }

/* 메인 */
.shell { max-width: 820px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(96px + var(--safe-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 8px 8px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { font-size: 1.15rem; margin: 0; }
.top-actions { display: flex; gap: 2px; }
.rec-dot { color: var(--danger); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.spaces { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 10px; scrollbar-width: none; }
.spaces::-webkit-scrollbar { display: none; }
.space-tab {
  flex: none; appearance: none; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text); border-radius: 99px; padding: .5em 1em; min-height: 42px;
  --c: var(--c-gray);
}
.space-tab.active { background: var(--c); border-color: var(--c); color: #fff; }
.space-tab.add { color: var(--muted); }
.c-blue { --c: var(--c-blue); } .c-green { --c: var(--c-green); } .c-purple { --c: var(--c-purple); }
.c-orange { --c: var(--c-orange); } .c-red { --c: var(--c-red); } .c-gray { --c: var(--c-gray); }
.banner {
  display: block; width: calc(100% - 32px); margin: 0 16px 10px; text-align: left; font: inherit; font-size: .9rem; cursor: pointer;
  background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--text); border-radius: 12px; padding: .7em .9em;
}
.content { padding: 0 16px; }
.toolbar { margin-bottom: 10px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chip {
  flex: none; appearance: none; font: inherit; font-size: .9rem; cursor: pointer; border: 1px solid var(--line);
  background: transparent; color: var(--muted); border-radius: 99px; padding: .35em .85em; min-height: 36px;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .count { margin-left: .4em; opacity: .7; font-size: .8em; }
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.items li { margin: 0; }
.item, .menu-btn {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; font: inherit; color: var(--text); cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 12px 12px 14px; min-height: 62px;
}
.item:active, .menu-btn:active { background: var(--surface-2); }
.item-icon { font-size: 1.4rem; flex: none; width: 36px; height: 36px; display: grid; place-items: center; background: var(--surface-2); border-radius: 10px; }
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.items.compact .item { min-height: 48px; padding: 8px 12px; }
.quick { font-size: 1.1rem; color: var(--muted); }
.empty { text-align: center; padding: 48px 16px; }
.locked-space { text-align: center; padding: 60px 16px; }
.fab {
  position: fixed; right: max(20px, calc(50% - 390px)); bottom: calc(22px + var(--safe-bottom)); width: 62px; height: 62px; border-radius: 20px;
  border: 0; background: var(--primary); color: var(--primary-ink); font-size: 2rem; box-shadow: 0 10px 30px color-mix(in srgb, var(--primary) 45%, transparent);
  cursor: pointer; z-index: 6;
}
.menu { display: flex; flex-direction: column; gap: 8px; }

/* 시트 */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 92dvh;
  background: var(--surface); color: var(--text); border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
}
dialog.sheet.wide { max-width: 720px; }
dialog.sheet::backdrop { background: rgba(5, 8, 20, .55); }
@media (min-width: 640px) {
  dialog.sheet { margin: auto; border-radius: 22px; }
}
.sheet-inner { display: flex; flex-direction: column; max-height: 92dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 8px 6px 18px; }
.sheet-head h2 { font-size: 1.12rem; margin: 0; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { padding: 6px 18px 12px; overflow-y: auto; overscroll-behavior: contain; }
.sheet-actions {
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  padding: 10px 18px calc(14px + var(--safe-bottom)); border-top: 1px solid var(--line);
}
.sheet-body .sheet-actions { border-top: 0; padding: 8px 0 0; }

.kv-list { display: flex; flex-direction: column; gap: 14px; }
.kv { display: flex; flex-direction: column; gap: 4px; }
.kv-label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.kv-val { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.secret { font-size: 1rem; word-break: break-all; flex: 1; min-width: 0; background: var(--surface-2); padding: .45em .65em; border-radius: 10px; }
.secret.masked { letter-spacing: .12em; }
.otp { display: flex; align-items: center; gap: 10px; }
.otp-code { font-size: 1.6rem; font-weight: 700; letter-spacing: .06em; }
.otp-remain { color: var(--muted); font-size: .85rem; min-width: 3em; }
.history summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.gen-out { display: block; font-size: 1.2rem; word-break: break-all; background: var(--surface-2); padding: .8em; border-radius: 12px; text-align: center; }
.pick { appearance: none; border: 2px solid transparent; background: var(--surface-2); border-radius: 12px; width: 44px; height: 44px; font-size: 1.3rem; cursor: pointer; }
.pick.active { border-color: var(--primary); }
.swatch { background: var(--c); }
.note-body { min-height: 40dvh; }
.score strong { font-size: 2rem; }

/* 녹음 */
.rec { text-align: center; }
.rec-timer { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.rec-level { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.rec-level-bar { height: 100%; width: 0; background: var(--danger); transition: width .08s linear; }
.rec-status { color: var(--muted); font-weight: 600; }
.rec-status.on { color: var(--danger); }
.rec-live { min-height: 1.4em; font-style: italic; }
.rec .field { text-align: left; }
.stt { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; }
.player-box { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.player { width: 100%; }

/* 설정 */
.settings { display: flex; flex-direction: column; gap: 14px; }
.set-group { border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; scroll-margin-top: 10px; }
.set-group h3 { font-size: 1rem; margin: 0; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.set-row > span:first-child { flex: 1; min-width: 0; }
.set-row select { width: auto; min-width: 7.5em; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.doc h3 { margin-top: .6em; font-size: 1rem; }
.doc li { font-size: .93rem; }

/* 알림 */
#toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-bottom)); transform: translate(-50%, 20px); z-index: 1000;
  background: var(--text); color: var(--bg); padding: .7em 1.1em; border-radius: 12px; font-size: .92rem; max-width: calc(100vw - 32px);
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.update-bar {
  position: fixed; left: 16px; right: 16px; top: calc(10px + var(--safe-top)); z-index: 999; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); max-width: 560px; margin: 0 auto;
}

/* 앱 전환 시 내용 가림 */
.privacy-cover { display: none; }
body.privacy .privacy-cover {
  display: grid; place-items: center; position: fixed; inset: 0; z-index: 2000; background: var(--bg); font-size: 4rem;
}
body.privacy #app, body.privacy dialog { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
