:root {
  color-scheme: light;
  --app-height: 100dvh;
  --bg: #f4f1eb;
  --surface: #ffffff;
  --surface-muted: #f7f7f5;
  --ink: #202326;
  --muted: #74787c;
  --line: rgba(30, 33, 36, 0.10);
  --mine: #f7cf39;
  --accent: #f2c72f;
  --composer-height: 68px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Noto Sans KR", sans-serif;
}
button, textarea, input { font: inherit; }
button { color: inherit; -webkit-tap-highlight-color: transparent; }

main {
  width: min(100%, 760px);
  height: var(--app-height);
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--bg);
}

header {
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-bottom: 1px solid var(--line);
}
.identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.identity > div { display: grid; min-width: 0; }
.identity b { font-size: 16px; line-height: 1.25; }
.identity small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 13px;
  background: var(--ink);
  color: #fff;
  font-weight: 750;
}
.header-actions { display: flex; align-items: center; gap: 4px; }
.header-actions button, .sheet-title button {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  font-size: 23px;
}
.header-actions .text-action { font-size: 13px; color: #b14b3f; }

#chat {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 14px 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-padding-bottom: calc(var(--composer-height) + 16px);
}
.empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}
article {
  width: fit-content;
  max-width: min(86%, 620px);
  display: grid;
  gap: 3px;
}
article.mine { align-self: end; justify-items: end; }
article small, article time { color: var(--muted); font-size: 11px; }
article div {
  padding: 9px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface);
  border: 1px solid rgba(30, 33, 36, 0.04);
  border-radius: 5px 17px 17px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.mine div { background: var(--mine); border-radius: 17px 5px 17px 17px; }
.card {
  width: min(100%, 620px);
  padding: 12px;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line));
  border-radius: 14px;
}
.card p { margin: 7px 0 10px; }
.card button {
  min-height: 42px;
  margin: 3px 6px 0 0;
  padding: 8px 12px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
}

#composer {
  z-index: 5;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  min-height: var(--composer-height);
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
#text {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  max-height: 116px;
  resize: none;
  overflow-y: auto;
  padding: 12px 14px;
  color: inherit;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 18px;
  outline: none;
}
#text:focus { border-color: color-mix(in srgb, var(--accent) 70%, #6f5d12); }
#composer button {
  flex: 0 0 auto;
  min-width: 46px;
  min-height: 46px;
  padding: 0 12px;
  border: 0;
  border-radius: 15px;
  background: var(--accent);
  font-weight: 700;
}
#voice { padding: 0; }
#voice[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
#send:disabled { opacity: 0.45; }

#new {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: calc(var(--composer-height) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  min-height: 40px;
  padding: 8px 13px;
  border: 0;
  border-radius: 18px;
  background: var(--ink);
  color: var(--surface);
}

#settings-panel {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  align-items: end;
  padding: 16px;
  background: rgba(0, 0, 0, 0.38);
}
.sheet {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 22px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
}
.sheet-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet-title b { font-size: 18px; }
.sheet-title button { font-size: 14px; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 10px 4px;
  border-top: 1px solid var(--line);
}
.setting-row span { display: grid; gap: 2px; }
.setting-row small, #voice-help, #app-version { color: var(--muted); font-size: 12px; }
.setting-row input { width: 48px; height: 28px; }
.setting-button {
  width: 100%;
  min-height: 46px;
  margin: 8px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-muted);
}

.dark {
  color-scheme: dark;
  --bg: #17191c;
  --surface: #24282d;
  --surface-muted: #1c1f22;
  --ink: #f4f4f2;
  --muted: #a9adb1;
  --line: rgba(255, 255, 255, 0.10);
  --mine: #9e7f18;
  --accent: #cba82e;
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
