:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: #e3e1dc;
  --accent: #c2643d;
  --accent-text: #ffffff;
  --user-bubble: #ece9e3;
  --error: #b3261e;
  --warning-bg: #fff4d6;
  --code-bg: #f0eee9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1d;
    --panel: #242427;
    --text: #f2f2f4;
    --muted: #a0a0a8;
    --border: #36363b;
    --accent: #e07a50;
    --user-bubble: #303034;
    --error: #ff8a80;
    --warning-bg: #3a3220;
    --code-bg: #2c2c30;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.primary {
  background: var(--accent); color: var(--accent-text);
  border: 0; border-radius: 12px; padding: 14px 22px; font-weight: 600; width: 100%;
}
.ghost { background: none; border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; }
.small { font-size: 14px; }
.error { color: var(--error); min-height: 1.5em; }
.warning { background: var(--warning-bg); border-radius: 10px; padding: 8px 12px; margin: 0 0 8px; font-size: 14px; }

/* Sign-in */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { max-width: 360px; width: 100%; text-align: center; }
.auth-icon { width: 84px; height: 84px; border-radius: 20px; }
.auth h1 { margin: 12px 0 4px; font-size: 26px; }
.auth p { color: var(--muted); }

/* Layout */
.app { height: 100%; display: flex; }
.main {
  flex: 1; min-width: 0; height: 100%;
  display: flex; flex-direction: column;
}
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 6px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.topbar h2 {
  flex: 1; margin: 0; font-size: 17px; font-weight: 600; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon-btn { background: none; border: 0; font-size: 22px; width: 40px; height: 40px; border-radius: 10px; }

/* Drawer */
.drawer {
  position: fixed; inset: 0 auto 0 0; width: min(82vw, 320px); z-index: 20;
  background: var(--panel); border-right: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top) + 12px) 12px calc(env(safe-area-inset-bottom) + 12px);
  display: flex; flex-direction: column; gap: 10px;
  transform: translateX(-100%); transition: transform .2s ease;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .3); z-index: 10; display: none; }
.scrim.open { display: block; }
#chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#chat-list li { display: flex; align-items: center; border-radius: 10px; }
#chat-list li.active { background: var(--user-bubble); }
#chat-list .open-chat {
  flex: 1; text-align: left; background: none; border: 0; padding: 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#chat-list .del { background: none; border: 0; color: var(--muted); padding: 10px; }
@media (min-width: 900px) {
  .drawer { position: static; transform: none; height: 100%; }
  .scrim, #menu { display: none !important; }
}

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; -webkit-overflow-scrolling: touch; }
.empty { color: var(--muted); text-align: center; margin-top: 30vh; }
.msg { max-width: 760px; margin: 0 auto 16px; }
.msg.user .bubble {
  background: var(--user-bubble); border-radius: 18px; padding: 10px 14px;
  margin-left: auto; width: fit-content; max-width: 85%; white-space: pre-wrap; word-wrap: break-word;
}
.msg.assistant .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; letter-spacing: .01em; }
.msg.assistant .body { word-wrap: break-word; }
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.msg .body pre { background: var(--code-bg); padding: 10px 12px; border-radius: 10px; overflow-x: auto; font-size: 14px; }
.msg .body code { background: var(--code-bg); padding: 1px 4px; border-radius: 5px; font-size: .92em; }
.msg .body pre code { background: none; padding: 0; }
.msg .body h1, .msg .body h2, .msg .body h3 { font-size: 1.05em; margin: 1em 0 .4em; }
.msg .body ul, .msg .body ol { padding-left: 1.4em; }
.msg .body a { color: var(--accent); }
.msg .msg-error { color: var(--error); font-size: 14px; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }

/* Composer */
.composer {
  border-top: 1px solid var(--border); background: var(--bg);
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
}
.pickers { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 6px; margin-bottom: 8px; max-width: 760px; margin-inline: auto; }
.pickers label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); min-width: 0; }
.pickers span { padding-left: 4px; }
.pickers select {
  width: 100%; font-size: 16px; padding: 6px 8px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel); -webkit-appearance: none; appearance: none;
}
.input-row { display: flex; gap: 8px; align-items: flex-end; max-width: 760px; margin: 0 auto; }
#input {
  flex: 1; resize: none; max-height: 40vh; font-size: 16px;
  padding: 10px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--panel);
}
.send {
  width: 42px; height: 42px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: var(--accent-text); font-size: 20px; font-weight: 700;
}
.send:disabled { opacity: .4; }
.send.stop { background: var(--text); color: var(--bg); font-size: 14px; }

/* Shared page pieces */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.label { font-size: 12px; color: var(--muted); margin-top: 8px; }
.secondary { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 22px; font-weight: 600; text-align: center; }
.view.page { height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view.page .topbar { position: sticky; top: 0; z-index: 5; }
a.icon-btn { display: grid; place-items: center; color: inherit; text-decoration: none; font-size: 30px; line-height: 1; }
span.icon-btn { display: inline-block; }
.page-body { max-width: 760px; margin: 0 auto; padding: 14px 14px calc(env(safe-area-inset-bottom) + 24px); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 14px; margin-bottom: 14px; }
.text-input {
  width: 100%; font-size: 16px; padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
}
.section-title { font-size: 15px; margin: 22px 0 8px; color: var(--muted); font-weight: 600; }
.row-actions { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 10px; }
.row-actions .primary { width: auto; }

/* Home launcher */
.view.home { min-height: 100%; padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px); max-width: 760px; margin: 0 auto; }
.home-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.home-head h1 { font-size: 28px; margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  display: flex; flex-direction: column; gap: 4px; padding: 16px; min-height: 130px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  color: inherit; text-decoration: none;
}
.tile:active { transform: scale(.98); }
.tile-icon { font-size: 34px; line-height: 1.1; margin-bottom: auto; }
.tile-name { font-weight: 600; font-size: 17px; }
.tile-sub { font-size: 13px; color: var(--muted); }
.tile.soon { opacity: .5; }

/* Net carbs */
.photo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.file-btn { display: block; text-align: center; cursor: pointer; }
.carb-photo { width: 100%; max-height: 320px; object-fit: cover; border-radius: 12px; display: block; margin-bottom: 12px; }
.carb-total { font-size: 15px; color: var(--muted); }
.carb-total .big { font-size: 40px; font-weight: 700; color: var(--accent); margin-right: 4px; }
.carb-title { font-weight: 600; font-size: 18px; margin: 2px 0 10px; }
.carb-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.carb-table th { text-align: right; font-size: 12px; color: var(--muted); font-weight: 500; padding: 4px; }
.carb-table th:first-child { text-align: left; }
.carb-table td { padding: 8px 4px; border-top: 1px solid var(--border); text-align: right; vertical-align: top; }
.carb-table td:first-child { text-align: left; }
.carb-table tfoot td { font-weight: 700; }
.carb-table .net { font-weight: 600; color: var(--accent); }
.item-name { font-weight: 500; }
.num {
  width: 52px; font-size: 16px; text-align: right; padding: 4px 6px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
}
.day-group { margin-bottom: 14px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 0 4px 6px; font-weight: 600; }
.history-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px; margin-bottom: 6px;
}
.history-row.active { border-color: var(--accent); }
.history-row img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; flex: none; }
.h-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.h-val { font-weight: 700; color: var(--accent); }

/* Settings */
.head-actions { display: flex; gap: 8px; }
.head-actions a { color: inherit; text-decoration: none; }
.key-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.ok { color: #2e7d32; }
@media (prefers-color-scheme: dark) { .ok { color: #81c784; } }

/* Journal */
.center { text-align: center; }
.block-link { display: block; text-align: center; text-decoration: none; margin-bottom: 8px; }
.field { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.field .text-input { margin: 0 0 10px; flex: 1; }
.j-note { resize: vertical; min-height: 96px; font: inherit; font-size: 16px; }
.capture-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.capture-buttons .secondary { padding: 12px 8px; font-size: 15px; }
.recording {
  display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 10px 12px;
  border-radius: 12px; background: var(--warning-bg); font-size: 15px;
}
.recording .primary { width: auto; margin-left: auto; padding: 8px 16px; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #e53935; animation: blink 1s steps(2) infinite; }
.attachments { list-style: none; padding: 0; margin: 10px 0 0; }
.attachments li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--border); }
.attachments img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; }
.att-icon { width: 44px; text-align: center; font-size: 24px; }
.att-label { flex: 1; display: flex; flex-direction: column; }
.attachments .del { background: none; border: 0; color: var(--muted); padding: 8px; }
#j-create { margin-top: 4px; }

.journal-row {
  display: flex; gap: 12px; padding: 10px; margin-bottom: 8px; color: inherit; text-decoration: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
}
.journal-row img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; flex: none; }
.j-day { width: 64px; height: 64px; flex: none; border-radius: 10px; background: var(--user-bubble);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.j-day b { font-size: 22px; }
.j-day span { font-size: 12px; color: var(--muted); }
.j-text { min-width: 0; flex: 1; }
.j-title { font-weight: 600; }
.j-summary { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.j-entry { padding: 18px; }
.j-date-line { color: var(--muted); font-size: 14px; }
.j-entry-title { font-size: 26px; line-height: 1.2; margin: 4px 0 10px; font-family: ui-serif, Georgia, serif; }
.j-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--user-bubble); }
.j-highlights { background: var(--bg); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; }
.j-highlights ul { margin: 6px 0 0; padding-left: 1.2em; }
.j-body { font-family: ui-serif, Georgia, serif; font-size: 17px; line-height: 1.65; max-width: none; margin: 0; }
.j-body h3, .j-body h4 { font-family: -apple-system, system-ui, sans-serif; font-size: 15px; margin: 1.2em 0 .3em; }
.j-media-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.j-media audio { width: 100%; }
.j-media video, .j-photo { width: 100%; border-radius: 12px; display: block; }
.j-transcript { white-space: pre-wrap; font-size: 15px; color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); margin: 6px 0; }

/* Live notes */
.n-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; }
.n-status { font-weight: 600; display: flex; align-items: center; gap: 8px; flex: 1; font-variant-numeric: tabular-nums; }
.n-buttons { display: flex; gap: 8px; }
.n-buttons button, #n-resume-session { width: auto; padding: 10px 16px; }
.n-errors { white-space: pre-line; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--user-bubble); border-radius: 10px; padding: 3px; margin-bottom: 10px; }
.segmented button { background: none; border: 0; border-radius: 8px; padding: 7px; font-size: 14px; }
.segmented button.active { background: var(--panel); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .1); }
.notes-split { display: grid; gap: 10px; }
.n-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.notes-split[data-tab="notes"] .n-transcript-panel, .notes-split[data-tab="transcript"] .n-notes-panel { display: none; }
.notes-split[data-tab="both"] .n-panel { height: 38vh; }
.n-transcript-panel { max-height: 65vh; }
.notes-split[data-tab="transcript"] .n-transcript-panel { max-height: none; min-height: 50vh; }
@media (min-width: 760px) {
  #n-tabs { display: none; }
  .notes-split, .notes-split[data-tab] { grid-template-columns: 1fr 1fr; }
  .notes-split[data-tab] .n-panel { display: block; height: 68vh; max-height: none; }
  .view.page .page-body:has(#notes-session-pane:not([hidden])) { max-width: 1200px; }
}
.n-title { font-size: 20px; margin: 0 0 4px; }
.n-overview { margin-top: 4px; }
.n-section { border-left: 4px solid var(--sec); padding: 2px 0 2px 10px; margin: 12px 0; cursor: pointer; }
.n-sec-head { display: flex; align-items: baseline; gap: 6px; }
.n-sec-head .muted { margin-left: auto; }
.n-dot { display: none; }
.n-section ul { margin: 4px 0 0; padding-left: 1.2em; }
.n-seg { border-left: 3px solid var(--sec, var(--border)); padding-left: 10px; margin: 0 0 10px; transition: background .3s; }
.n-seg.flash { background: var(--warning-bg); }
.n-seg.pending { border-color: var(--border); }
.n-time { display: block; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sec-0 { --sec: #c2643d; } .sec-1 { --sec: #3d7cc2; } .sec-2 { --sec: #3da36b; } .sec-3 { --sec: #9b59b6; }
.sec-4 { --sec: #d4a017; } .sec-5 { --sec: #c23d6e; } .sec-6 { --sec: #2aa1a1; } .sec-7 { --sec: #7a8c2a; }

/* Journal: what happened + editor */
.j-what { background: var(--warning-bg); border-radius: 12px; padding: 10px 14px; margin: 0 0 12px; }
.j-what p { margin: 4px 0 0; }
.btn-group { display: flex; gap: 8px; }
.field-col { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field-col .text-input { color: var(--text); font: inherit; font-size: 16px; }
.field-col textarea { resize: vertical; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.j-editor .capture-buttons { margin-top: 8px; }
.rewrite { width: 100%; margin-top: 14px; }

/* Translate */
.toggle { display: flex; align-items: center; gap: 8px; font-size: 15px; margin: 0 4px 10px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
#tr-mode button.active { background: var(--panel); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .1); }
.tr-turns { display: flex; flex-direction: column; gap: 10px; min-height: 40vh; }
.tr-turn { max-width: 88%; padding: 10px 14px; border-radius: 18px; background: var(--panel); border: 1px solid var(--border); }
.tr-turn.from-ko { align-self: flex-start; border-bottom-left-radius: 6px; }
.tr-turn.from-en { align-self: flex-end; border-bottom-right-radius: 6px; background: var(--user-bubble); }
.tr-turn.pending { color: var(--muted); }
.tr-dst { font-size: 20px; line-height: 1.35; }
.tr-rom { font-size: 13px; color: var(--muted); font-style: italic; margin-top: 2px; }
.tr-src { font-size: 14px; color: var(--muted); margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
.tr-row { display: flex; align-items: flex-start; gap: 8px; }
.tr-row .tr-dst { flex: 1; }
.tr-play { background: none; border: 0; font-size: 20px; padding: 0 2px; }
.tr-flag { font-size: 12px; color: var(--muted); }
