:root {
  --bg: #fbfaf7; --panel: #ffffff; --side: #f4f1ec; --line: #e8e3da; --soft: #f3f0ea;
  --ink: #1f1d1a; --ink2: #5c574f; --ink3: #8d877d; --accent: #13836a; --accent-soft: #e3f2ed;
  --rec: #d6453d; --warn: #b7791f; --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; font: 14px/1.5 var(--sans); color: var(--ink); background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }

/* nav */
.nav { width: 220px; flex: none; background: var(--side); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; font: 600 20px var(--serif); padding: 4px 10px 18px; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--ink); color: #f6f3ee; display: grid; place-items: center; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; text-decoration: none; color: var(--ink2); }
.nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
.nav a:hover { background: #ebe6de; }
.nav a.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); font-weight: 600; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.nav .new-note { justify-content: center; background: var(--ink); color: #fff; font-weight: 600; }
.nav .new-note:hover { background: #34312c; }
.ai-status { font-size: 12px; color: var(--ink3); padding: 0 10px; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ink3); }
.dot.ok { background: var(--accent); } .dot.bad { background: var(--warn); }

main { flex: 1; overflow: auto; }
.page { max-width: 1080px; margin: 0 auto; padding: 34px 40px 60px; }
h1 { font: 400 34px/1.2 var(--serif); margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font: 600 15px var(--sans); margin: 28px 0 12px; }
.sub { color: var(--ink3); margin: 0 0 24px; }
.row { display: flex; gap: 12px; align-items: center; }
.grow { flex: 1; }

.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #34312c; }
.btn.danger { color: var(--rec); }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 3px 10px; font-size: 13px; color: var(--ink2); background: var(--panel); }
.chip.dashed { border-style: dashed; }
input.field, textarea.field, select.field { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--panel); outline: none; }
input.field:focus, textarea.field:focus, select.field:focus { border-color: #bdb5a8; }

/* dashboard */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.tile .k { color: var(--ink3); font-size: 12.5px; }
.tile .v { font: 400 32px/1.15 var(--serif); margin-top: 6px; }
.tile .v small { font: 13px var(--sans); color: var(--ink3); margin-left: 4px; }
.tile .n { font-size: 12px; color: var(--ink3); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-top: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card h3 { margin: 0 0 12px; font-size: 14px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 6px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .b span { width: 100%; max-width: 26px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .b.zero span { background: var(--line); }
.bars .b em { font-style: normal; font-size: 10.5px; color: var(--ink3); }
.quick { display: flex; flex-direction: column; gap: 10px; }
.quick .out { min-height: 70px; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; color: var(--ink2); white-space: pre-wrap; }
.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; padding: 12px 4px; border-top: 1px solid var(--line); align-items: flex-start; cursor: pointer; }
.item:first-child { border-top: 0; }
.item:hover { background: var(--bg); }
.item .ic { width: 30px; height: 30px; flex: none; border-radius: 8px; display: grid; place-items: center; background: var(--soft); font-size: 14px; }
.item .ic.note { background: var(--accent-soft); color: var(--accent); }
.item .t { font-weight: 600; }
.item .p { color: var(--ink2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item .w { color: var(--ink3); font-size: 12px; white-space: nowrap; }
.empty { color: var(--ink3); padding: 20px 0; text-align: center; }

/* record view */
.rec-page { height: 100%; display: flex; flex-direction: column; padding: 22px 32px 18px; max-width: 1280px; margin: 0 auto; }
.rec-head { display: flex; align-items: flex-start; gap: 12px; }
.rec-title { font: 400 34px/1.2 var(--serif); border: 0; background: transparent; outline: none; padding: 0; width: 100%; color: var(--ink); }
.rec-title::placeholder { color: #a7a196; }
.rec-meta { display: flex; gap: 8px; margin: 10px 0 14px; }
.rec-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(300px, 0.9fr) 1.1fr; gap: 18px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.live-bar { display: flex; align-items: center; gap: 10px; background: var(--soft); border-radius: 10px; margin: 12px; padding: 9px 12px; font-variant-numeric: tabular-nums; color: var(--ink2); }
.live-bar .clock { font-weight: 600; }
.live-bar .state { margin-left: auto; font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.live-bar .state .dot.rec { background: var(--rec); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.wave { display: flex; gap: 2px; align-items: center; height: 16px; }
.wave i { width: 3px; background: var(--accent); border-radius: 2px; height: 3px; transition: height .12s; }
.live { flex: 1; overflow: auto; padding: 4px 18px 18px; }
.seg { display: flex; gap: 12px; padding: 7px 0; }
.seg.new { animation: fadein .4s; }
.seg .ts { color: var(--ink3); font-size: 12px; font-variant-numeric: tabular-nums; min-width: 38px; padding-top: 2px; }
.seg .tx { flex: 1; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }
.listening { text-align: center; font-style: italic; color: var(--ink2); padding: 22px 0; }
.listening.inline { text-align: left; padding: 6px 0 6px 50px; font-size: 13px; color: var(--ink3); }
.tabs { display: flex; gap: 22px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 14px 0 11px; cursor: pointer; color: var(--ink2); border-bottom: 2px solid transparent; font-weight: 500; }
.tabs button.on { color: var(--ink); border-color: var(--ink); font-weight: 600; }
.tab-body { flex: 1; overflow: auto; padding: 16px 20px; min-height: 0; }
.tab-body textarea { width: 100%; height: 100%; min-height: 200px; border: 0; outline: none; resize: none; background: transparent; line-height: 1.6; }
.md h2 { font: 600 15px var(--sans); margin: 16px 0 6px; }
.md h2:first-child { margin-top: 0; }
.md ul { margin: 4px 0; padding-left: 20px; } .md li { margin: 3px 0; }
.md p { margin: 6px 0; }
.status-line { color: var(--ink3); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.ask { margin-top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.ask-log { max-height: 190px; overflow: auto; padding: 10px 18px 0; }
.ask-log .qa { padding: 8px 0; border-bottom: 1px solid var(--soft); }
.ask-log .q { font-weight: 600; }
.ask-log .a { color: var(--ink2); white-space: pre-wrap; }
.ask-log .a.err { color: var(--warn); }
.ask-hint { text-align: center; color: var(--ink2); padding: 12px 0 2px; }
.ask-row { display: flex; gap: 12px; align-items: center; padding: 12px; }
.recbtn { width: 48px; height: 48px; flex: none; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.recbtn .sq { width: 16px; height: 16px; border-radius: 4px; background: var(--accent); }
.recbtn .cir { width: 18px; height: 18px; border-radius: 50%; background: var(--rec); }
.recbtn:disabled { opacity: .5; cursor: default; }
.ask-input { flex: 1; display: flex; align-items: center; border: 1.5px solid var(--ink); border-radius: 26px; padding: 4px 6px 4px 16px; }
.ask-input input { flex: 1; border: 0; outline: none; background: transparent; padding: 8px 0; }
.ask-input .btn { border-radius: 18px; }
.notice { background: #fff7e6; border: 1px solid #f1dfb8; color: #7a5a17; padding: 8px 12px; border-radius: 10px; margin: 0 0 12px; font-size: 13px; }

/* history */
.hist-head { display: flex; gap: 10px; margin-bottom: 14px; }
.seg-ctl { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.seg-ctl button { border: 0; background: none; padding: 7px 12px; cursor: pointer; color: var(--ink2); }
.seg-ctl button.on { background: var(--ink); color: #fff; }
.hist-item .acts { display: none; gap: 6px; }
.hist-item:hover .acts { display: flex; }
.detail { white-space: pre-wrap; margin-top: 8px; }
.edit-area { min-height: 90px; }

/* dictionary + settings */
.words { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.word { display: inline-flex; align-items: center; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 5px 6px 5px 12px; }
.word button { border: 0; background: none; cursor: pointer; color: var(--ink3); padding: 0 4px; font-size: 15px; }
.word input { border: 0; outline: none; width: auto; min-width: 40px; }
.set { display: flex; align-items: center; gap: 16px; padding: 16px 0; border-top: 1px solid var(--line); }
.set:first-of-type { border-top: 0; }
.set .lbl { flex: 1; } .set .lbl b { display: block; font-weight: 600; } .set .lbl span { color: var(--ink3); font-size: 13px; }
.set select { max-width: 260px; }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d8d2c7; border-radius: 22px; cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.styles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; }
.style-card { border: 1.5px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; background: var(--panel); }
.style-card.on { border-color: var(--ink); }
.style-card b { display: block; } .style-card small { color: var(--ink3); display: block; margin: 4px 0 8px; }
.style-card em { font-size: 12.5px; color: var(--ink2); }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; }
#toast.show { opacity: 1; }

@media (max-width: 900px) {
  .nav { width: 64px; } .nav a { justify-content: center; font-size: 0; } .nav a i { font-size: 16px; } .brand { font-size: 0; } .nav .new-note { font-size: 13px; padding: 8px 4px; } .ai-status { display: none; }
  .tiles { grid-template-columns: repeat(2, 1fr); } .grid2, .rec-body { grid-template-columns: 1fr; } .styles { grid-template-columns: repeat(2, 1fr); }
  .page { padding: 22px 18px; } .rec-page { padding: 16px; height: auto; }
}
