:root {
  color-scheme: dark;
  --bg: #0E1828;        /* 밤 남색 */
  --surface: #172338;
  --raised: #22324F;
  --line: #2A3A58;
  --text: #EDF0F6;
  --muted: #8F9BB3;
  --lamp: #F2C14E;      /* 기본·말하는 중 */
  --listen: #5BD0BF;    /* 듣는 중 */
  --alert: #F28B7A;
  --ink: #1B1405;       /* 밝은 버튼 위 글자 */
  --sans: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --serif: "Gowun Batang", "AppleMyungjo", "Batang", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--lamp); outline-offset: 3px; }

/* 좌측 상단 고정 브랜드 로고 (수리 SURI) */
.brand-fixed {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top, 0px));
  left: 18px;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  background: rgba(23, 35, 56, 0.85);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}
.brand-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lamp);
  box-shadow: 0 0 8px var(--lamp);
}
.brand-ko {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}
.brand-en {
  font-size: .75rem;
  font-weight: 500;
  color: var(--lamp);
  letter-spacing: 0.06em;
}

/* 레이아웃 */
.app {
  height: 100%;
  max-width: 640px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-top: env(safe-area-inset-top, 0px);
}
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--line);
}
@media (max-width: 860px) {
  .top { padding-top: 52px; }
}
.top h1 { margin: 0; font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.notice { margin: 2px 0 0; font-size: .8125rem; color: var(--muted); }
.actions { display: flex; gap: 6px; flex: none; }

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: .875rem;
}
.ghost:hover { background: var(--surface); }
.primary {
  background: var(--lamp);
  color: var(--ink);
  border: 0;
  border-radius: 999px;
  padding: 12px 26px;
  font-weight: 600;
}
.primary:disabled { opacity: .5; }

/* 대화 영역: 나레이션은 명조, 대사는 고딕 */
.scroll { overflow-y: auto; padding: 24px 20px 32px; overscroll-behavior: contain; }
.scene {
  font-family: var(--serif);
  color: var(--muted);
  font-size: 1.0625rem;
  line-height: 1.85;
  margin: 0 0 28px;
  padding-bottom: 20px;
  border-bottom: 1px dashed var(--line);
}
.log { display: flex; flex-direction: column; gap: 14px; }
.line { max-width: 85%; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; }
.line.ai {
  align-self: flex-start;
  font-size: 1.0625rem;
  padding-left: 14px;
  border-left: 2px solid var(--emo, var(--lamp));
}
.line.ai .emo { display: block; font-size: .75rem; line-height: 1.4; color: var(--muted); margin-bottom: 2px; }
.line.ai .emo span { color: var(--emo); }
/* 감정 색. 대사 왼쪽 선은 첫 문장의 감정, 라벨은 문장마다의 감정 */
[data-emotion="기본"] { --emo: var(--muted); }
[data-emotion="기쁨"] { --emo: #F2C14E; }
[data-emotion="설렘"] { --emo: #F59AC0; }
[data-emotion="슬픔"] { --emo: #7FA7E8; }
[data-emotion="화남"] { --emo: #F28B7A; }
[data-emotion="놀람"] { --emo: #B79CF2; }
[data-emotion="걱정"] { --emo: #8FC9A9; }
[data-emotion="장난"] { --emo: #F2A65A; }
.line.user { align-self: flex-end; background: var(--raised); padding: 10px 14px; border-radius: 18px 18px 4px 18px; }
.line .text { margin: 0; }
.line .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 4px; }
.line.user .meta { justify-content: flex-end; }
.play {
  background: none;
  border: 0;
  padding: 2px 0;
  font-size: .75rem;
  color: var(--muted);
}
.play:hover { color: var(--text); }
.voice { font-size: .75rem; color: var(--muted); }

/* 확인·수정 중인 내 말 */
.line.user.editing {
  width: 85%;
  background: var(--surface);
  border: 1px dashed var(--lamp);
}
.edit-input {
  display: block;
  width: 100%;
  min-height: 1.6em;
  padding: 0;
  border: 0;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.6;
}
.edit-input:focus { outline: none; }
.line.user.editing:focus-within { border-style: solid; }
.edit-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.mini { padding: 5px 14px; font-size: .8125rem; border-radius: 999px; }
.mini.primary { padding: 5px 16px; }
.voice[data-state="가라앉음"] { color: #7FA7E8; }
.voice[data-state="들뜸"] { color: #F2C14E; }
.voice[data-state="격앙"] { color: #F28B7A; }
.voice[data-state="평온"] { color: var(--text); opacity: .7; }
.voice[data-state="rejected"], .voice[data-state="off"] { opacity: .8; }
.line.error { align-self: center; max-width: 100%; color: var(--alert); font-size: .875rem; text-align: center; }

/* 하단 마이크 */
.dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 16px 20px calc(22px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
}
.status { margin: 0; min-height: 1.6em; max-width: 36ch; font-size: .9375rem; color: var(--muted); text-align: center; }
.status.error { color: var(--alert); }

.mic-wrap { --level: 0; position: relative; width: 84px; height: 84px; }
.halo {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  opacity: 0;
  transition: transform .08s linear, opacity .2s;
}
.mic {
  position: relative;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 50%;
  background: var(--lamp);
  color: var(--ink);
  display: grid;
  place-items: center;
  transition: background-color .2s;
}
.mic svg { width: 32px; height: 32px; fill: currentColor; grid-area: 1 / 1; }
.mic .icon-send { display: none; }
.mic:disabled { background: var(--raised); color: var(--muted); }

body[data-phase="listening"] .mic { background: var(--listen); }
body[data-phase="listening"] .mic .icon-mic { display: none; }
body[data-phase="listening"] .mic .icon-send { display: block; }
body[data-phase="listening"] .halo {
  background: var(--listen);
  opacity: .3;
  transform: scale(calc(1.08 + var(--level) * .9));
}
body[data-phase="transcribing"] .halo,
body[data-phase="thinking"] .halo {
  inset: -9px;
  border: 2px dashed var(--muted);
  opacity: 1;
  animation: spin 2s linear infinite;
}
body[data-phase="speaking"] .halo {
  background: var(--lamp);
  opacity: .28;
  animation: breathe 1.6s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { transform: scale(1.35); opacity: .12; } }

/* 시작 화면 */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(9, 15, 26, .86);
  backdrop-filter: blur(6px);
}
.overlay[hidden] { display: none; }
.start { max-width: 420px; width: 100%; }
.start-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.char-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: .8125rem;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover {
  color: var(--text);
  border-color: var(--muted);
}
.chip[aria-pressed="true"] {
  background: rgba(242, 193, 78, 0.16);
  border-color: var(--lamp);
  color: var(--lamp);
  font-weight: 600;
}
.small-ghost {
  padding: 5px 12px;
  font-size: .8125rem;
  flex: none;
}
.start-scene { font-family: var(--serif); color: var(--muted); line-height: 1.85; margin: 0 0 20px; }
.start h2 { font-family: var(--serif); font-size: 2.5rem; font-weight: 700; line-height: 1.2; margin: 0 0 28px; }
.hint { color: var(--muted); font-size: .875rem; margin: 14px 0 0; }

/* 프로필 */
dialog {
  width: min(92vw, 440px);
  padding: 24px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
}
dialog::backdrop { background: rgba(9, 15, 26, .7); }
dialog { max-height: 90vh; overflow-y: auto; }
dialog h2 { margin: 0 0 8px; font-size: 1.125rem; }
dialog fieldset { border: 0; border-top: 1px solid var(--line); margin: 16px 0 0; padding: 4px 0 0; min-width: 0; }
dialog legend { padding: 0 8px 0 0; font-size: .8125rem; color: var(--muted); }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.char-actions { display: flex; gap: 16px; margin-top: 6px; }
.memory-info { margin: 8px 0 6px; font-size: .875rem; color: var(--muted); }
.memory-list { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 8px; }
.memory-list li { padding: 8px 10px; background: var(--bg); border-radius: 8px; font-size: .875rem; line-height: 1.5; }
.memory-date { display: block; font-size: .75rem; color: var(--muted); }
.link.danger, .ghost.danger { color: var(--alert); }
.push-left { margin-right: auto; }
.start-memory { margin: -16px 0 24px; color: var(--lamp); font-size: .9375rem; }
.link { background: none; border: 0; padding: 4px 0; font-size: .8125rem; color: var(--lamp); text-decoration: underline; text-underline-offset: 3px; }
dialog label { display: block; margin: 14px 0 6px; font-weight: 500; }
dialog label span { color: var(--muted); font-weight: 400; font-size: .8125rem; margin-left: 6px; }
dialog input, dialog textarea, dialog select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
}
dialog textarea { resize: vertical; }

.count { margin: 4px 0 0; text-align: right; font-size: .8125rem; color: var(--muted); }
.note { margin: 12px 0 0; font-size: .8125rem; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

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

dialog .check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
dialog .check input { width: auto; margin: 0; accent-color: var(--lamp); }
.link { white-space: nowrap; flex: none; }

/* 글로 쓰기 · 소리 켜기/끄기 (마이크 양옆) */
.dock-row { display: flex; align-items: center; justify-content: center; gap: 28px; }
.side {
  width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  display: grid; place-items: center; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.side:hover:not(:disabled) { background: var(--surface); color: var(--text); }
.side:disabled { opacity: .35; cursor: default; }
.side svg { width: 22px; height: 22px; fill: currentColor; grid-area: 1 / 1; }
.sound .icon-sound-off { display: none; }
.sound[aria-pressed="false"] { color: var(--alert); border-color: var(--alert); }
.sound[aria-pressed="false"] .icon-sound-on { display: none; }
.sound[aria-pressed="false"] .icon-sound-off { display: block; }
.voice[data-state="typed"] { opacity: .8; }
.edit-input::placeholder { color: var(--muted); }
/* 내 말풍선 속 괄호 상태 설명 (대사가 아님) */
.line.user .stage { color: var(--muted); font-style: italic; }