/* MarvChat for the web. One column, centered on wide screens like the Mac app. */

:root {
  --bg: #f4f2fa;
  --surface: #ffffff;
  --surface-2: #ece8f6;
  --text: #1d1b24;
  --muted: #6b6878;
  --line: #ddd8ea;
  --accent: #5b3fc4;
  --accent-text: #ffffff;
  --marv-bubble: #ffffff;
  --user-bubble: #5b3fc4;
  --user-text: #ffffff;
  --warning: #b35a00;
  --danger: #c62828;
  --ok: #2e7d32;
  --star: #e0a400;
  --shadow: 0 2px 12px rgba(40, 20, 90, 0.12);
  --radius: 14px;
  --max: 820px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15131c;
    --surface: #211e2b;
    --surface-2: #2c2839;
    --text: #eeeaf7;
    --muted: #a39fb3;
    --line: #3a3549;
    --accent: #9b85ff;
    --accent-text: #15131c;
    --marv-bubble: #2a2637;
    --user-bubble: #6a4fd6;
    --user-text: #ffffff;
    --warning: #ffb15c;
    --danger: #ff6b6b;
    --ok: #7bd389;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: var(--max);
  margin: 0 auto;
  background: var(--bg);
}

@media (min-width: 860px) {
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* MARK: Header */

.top-bar {
  display: grid;
  grid-template-columns: minmax(84px, 1fr) minmax(0, auto) minmax(84px, 1fr);
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.header-side { display: flex; gap: 4px; }
.header-side.right { justify-content: flex-end; }
.header-title { display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 0; }
.avatar { width: 38px; height: 38px; border-radius: 10px; }
.title-text { display: flex; flex-direction: column; min-width: 0; }
.title-main { font-weight: 650; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 340px) {
  .top-bar { grid-template-columns: auto minmax(0, 1fr) auto; padding-left: 4px; padding-right: 4px; }
  .avatar { width: 30px; height: 30px; }
}
.title-sub { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }

.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.icon.filled { fill: currentColor; }

.icon-button {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px;
  border: none; border-radius: 10px;
  background: transparent; color: var(--accent);
  cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); }
.icon-button:disabled { opacity: 0.4; cursor: default; }
.icon-button.danger { color: var(--danger); }
.icon-button.active { color: var(--accent); background: var(--surface-2); }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.loading { margin: auto; color: var(--muted); }

/* MARK: Buttons and fields */

.primary, .secondary, button.danger:not(.icon-button):not(.link) {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  font-weight: 550;
}
.primary { background: var(--accent); color: var(--accent-text); }
.secondary { background: var(--surface-2); color: var(--text); border-color: var(--line); }
button.danger:not(.icon-button):not(.link) { background: transparent; color: var(--danger); border-color: var(--danger); }
.primary:disabled, .secondary:disabled { opacity: 0.5; cursor: default; }
.primary .icon, .secondary .icon { width: 18px; height: 18px; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 4px 6px; font-weight: 550; }
.link.danger { color: var(--danger); }

input[type=text], input[type=password], input[type=url], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

.caption { color: var(--muted); font-size: 0.85rem; margin: 4px 0; line-height: 1.4; }
.warning { color: var(--warning); }

/* MARK: Chat */

.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; --text-scale: 1.2; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 16px 14px 8px; position: relative; overscroll-behavior: contain; }
.messages { display: flex; flex-direction: column; gap: 14px; }

.row { display: flex; flex-direction: column; max-width: 86%; }
.row.assistant { align-self: flex-start; align-items: flex-start; }
.row.user { align-self: flex-end; align-items: flex-end; }

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--marv-bubble);
  box-shadow: var(--shadow);
  font-size: calc(1rem * var(--text-scale));
  line-height: 1.45;
}
.row.user .bubble, .bubble.user { background: var(--user-bubble); color: var(--user-text); }
.bubble-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.full-translation { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid color-mix(in srgb, currentColor 25%, transparent); font-size: 0.8em; opacity: 0.9; white-space: pre-wrap; }

.w { cursor: pointer; border-radius: 4px; }
.w:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.row.user .w:hover { background: rgba(255, 255, 255, 0.2); }
.w.selected { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.row.user .w.selected { color: #fff6a8; background: rgba(255, 255, 255, 0.2); }

.message-actions { display: flex; gap: 0; margin-top: 2px; opacity: 0.75; }
.message-actions .icon-button { width: 34px; height: 34px; color: var(--muted); }
.message-actions .icon { width: 18px; height: 18px; }
.message-actions .icon-button.active { color: var(--accent); background: none; }
.message-actions .icon-button.active .filled { color: var(--star); }
.message-actions .busy { animation: pulse 1s infinite; }
@media (hover: hover) {
  .message-actions { opacity: 0.35; transition: opacity 0.15s; }
  .row:hover .message-actions, .message-actions:focus-within { opacity: 1; }
}

.system-note { align-self: center; font-size: 0.8rem; color: var(--muted); background: var(--surface-2); padding: 4px 10px; border-radius: 999px; }

.live { align-self: flex-end; max-width: 86%; margin-top: 14px; opacity: 0.85; font-size: calc(1rem * var(--text-scale)); }
.live.placeholder { font-style: italic; }
.thinking { display: flex; gap: 5px; padding: 14px 4px; }
.thinking span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: pulse 1.2s infinite; }
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

.empty-chat { text-align: center; padding: 12px 8px 24px; }
.marv-large { width: 132px; height: 132px; border-radius: 30px; box-shadow: var(--shadow); }
.empty-chat h2 { margin: 14px 0 4px; }
.starters { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin: 14px auto; max-width: 600px; }
.starter {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); text-align: left;
}
.starter:hover { border-color: var(--accent); }
.starter-symbol { font-size: 1.2rem; }

.word-popup {
  position: absolute; z-index: 5;
  min-width: 80px; max-width: 260px;
  padding: 10px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  text-align: center;
}
.gloss { font-size: calc(1.05rem * var(--text-scale)); font-weight: 600; }
.popup-actions { display: flex; justify-content: center; gap: 4px; margin-top: 4px; font-size: 0.85rem; }
.spinner { width: 20px; height: 20px; margin: 4px auto; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.selection-bar {
  position: fixed; z-index: 20; max-width: min(92vw, 420px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 4px;
}
.selection-buttons { display: flex; gap: 2px; }
.selection-buttons button { border: none; background: none; color: var(--accent); padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.selection-buttons button:hover { background: var(--surface-2); }
.selection-result { padding: 6px 10px 8px; font-size: 0.95rem; }

/* MARK: Composer */

.composer-area { padding: 6px 10px calc(env(safe-area-inset-bottom) + 8px); border-top: 1px solid var(--line); background: var(--surface); }
.error-banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; padding: 8px 10px; margin-bottom: 6px; border-radius: 10px; background: color-mix(in srgb, var(--warning) 14%, transparent); color: var(--text); font-size: 0.9rem; }
.error-actions { display: flex; gap: 4px; }
.status-line { display: block; width: 100%; border: none; background: none; text-align: center; font-size: 0.75rem; color: var(--muted); padding: 2px 4px 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-line[data-tone=warning] { color: var(--warning); font-weight: 600; }
.composer { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer textarea { flex: 1; resize: none; max-height: 160px; border-radius: 20px; padding: 10px 14px; line-height: 1.35; }
.composer .send { color: var(--accent); }
.mic {
  flex: none; width: 52px; height: 52px; border-radius: 50%; border: none; cursor: pointer;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text);
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.mic .icon { width: 26px; height: 26px; }
.mic.active { background: var(--danger); color: #fff; animation: glow 1.4s infinite; }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 50%, transparent); } 50% { box-shadow: 0 0 0 8px transparent; } }
.mode-hint { text-align: center; font-size: 0.75rem; color: var(--muted); padding-top: 4px; }

/* MARK: Pages (lists, settings) */

.page-scroll { flex: 1; overflow-y: auto; }
.page { padding: 16px 14px calc(env(safe-area-inset-bottom) + 32px); }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.section-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 20px 4px 6px; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 2px; padding: 2px 6px 2px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: none; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 10px 12px; border: none; background: none; cursor: pointer; }
div.row-main { cursor: default; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.row-title .icon { width: 18px; height: 18px; color: var(--accent); }
.row-text { font-size: 1.05rem; overflow-wrap: anywhere; }
.row-subtitle { font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; }
.badge { font-size: 0.7rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 2px 8px; }
.empty-state { text-align: center; padding: 30px 10px; }
.empty-state .icon { color: var(--accent); }

.note-text { font-weight: 650; }
.arrow { color: var(--muted); white-space: pre; }
.note-red { color: #e53935; } .note-orange { color: #f57c00; } .note-green { color: #2e9d48; } .note-teal { color: #00897b; }
.note-blue { color: #1e74e0; } .note-purple { color: #8e44d6; } .note-pink { color: #e0407b; } .note-brown { color: #8d6e63; } .note-black { color: var(--text); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; background: currentColor; cursor: pointer; padding: 0; }
.swatch.chosen { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface) inset; }

/* MARK: Settings */

.settings details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.settings summary { padding: 14px 16px; font-weight: 650; cursor: pointer; list-style-position: inside; }
.section-body { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 550; font-size: 0.92rem; }
.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.button-row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.slider { display: flex; align-items: center; gap: 10px; }
.slider input { flex: 1; accent-color: var(--accent); }
input[type=range] { accent-color: var(--accent); }
.value { min-width: 70px; color: var(--muted); font-size: 0.9rem; }
.system-bar { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; color: #fff; font-weight: 600; font-size: 0.92rem; }
.system-bar .icon { width: 18px; height: 18px; }
.tone-claude { background: #2563c9; }
.tone-other { background: #4b3fb5; }
.tone-warning { background: #c0392b; }
.tone-demo { background: #138a87; }
.tone-onDevice { background: #6a3fb5; }
.free-guide { border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; background: var(--surface-2); }
.free-guide summary { padding: 12px 0; font-weight: 650; cursor: pointer; }
.free-guide[open] { padding-bottom: 14px; }
.free-guide > p:first-of-type { margin-top: 0; }
.free-guide a.secondary { text-decoration: none; }
.caption.strong { font-weight: 650; color: var(--text); margin-top: 10px; }
.others { margin: 0; padding-left: 20px; }
.chrome-ai progress { width: 100%; }
.demo-block .inline-form { display: flex; gap: 6px; }
.demo-block .inline-form input { flex: 1; }
.demo-block p { margin: 4px 0; }
.test-result { margin: 0; font-size: 0.88rem; }
.test-result.ok { color: var(--ok); }
.key-field .inline-form { display: flex; gap: 6px; }
.key-field .inline-form input { flex: 1; }
.key-saved { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: 0.92rem; }
.key-saved .icon { width: 16px; height: 16px; }
.caption-link { font-size: 0.85rem; margin-top: -6px; }
.prompt-editor { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85rem; line-height: 1.4; }
.subhead { margin: 8px 0 0; font-size: 1rem; }
.steps { margin: 0; padding-left: 20px; font-size: 0.9rem; line-height: 1.6; }
.hats { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.hat { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; border-radius: 12px; border: 2px solid transparent; background: none; cursor: pointer; font-size: 0.75rem; }
.hat img { width: 72px; height: 72px; border-radius: 16px; }
.hat.chosen { border-color: var(--accent); background: var(--surface-2); }
.text-sample { margin: 0; font-size: calc(1rem * var(--text-scale)); }

/* MARK: Dialogs and toast */

.dialog {
  border: none; border-radius: 16px; padding: 20px; width: min(92vw, 420px);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(10, 5, 30, 0.45); }
.dialog h2 { margin: 0 0 8px; font-size: 1.15rem; }
.dialog input { margin: 6px 0; }
.dialog-buttons { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.dialog-buttons .link { margin-right: auto; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 110px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 50; max-width: 90vw;
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }

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

.menu {
  position: fixed; z-index: 30; min-width: 200px; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.menu button {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: none; border-radius: 8px;
  background: none; text-align: left; cursor: pointer; font-weight: 500;
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu .icon { width: 18px; height: 18px; color: var(--accent); }
