:root {
  --bg: #f4f2ee; --panel: #ffffff; --line: #dcd8d0; --ink: #1f2328; --muted: #6b6f76;
  --accent: #c8643b; --accent-ink: #fff; --soft: #f7e6dc; --ok: #2f7d4f;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overflow: hidden; }
[hidden] { display: none !important; }
button {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: #b9b3a8; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; }
button.danger { color: #b3261e; }
button.big { padding: 12px 20px; font-size: 17px; width: 100%; }
button.icon { padding: 4px 9px; }
input, textarea { font: inherit; color: var(--ink); }
input { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; min-width: 0; }
code { font-family: ui-monospace, Consolas, monospace; background: #f1efe9; padding: 2px 6px; border-radius: 5px; word-break: break-all; }
pre { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: #f1efe9; padding: 10px; border-radius: 8px; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: #b3261e; min-height: 1.2em; }
.row { display: flex; gap: 8px; align-items: center; }
.row > code, .row > input { flex: 1; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.grow { flex: 1; }

/* 登录 */
#login { height: 100%; overflow-y: auto; display: flex; padding: 20px; }
#login .card { margin: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; max-width: 440px; width: 100%; }
.card h1 { margin: 0 0 8px; font-size: 26px; }
.lead { color: var(--muted); line-height: 1.6; margin: 0 0 20px; }
.or { text-align: center; color: var(--muted); margin: 18px 0 10px; font-size: 14px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { flex: 1; background: transparent; border-color: transparent; color: var(--muted); font-weight: 600; }
.tabs button.on { background: #f1ede6; border-color: var(--line); color: var(--ink); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack input { padding: 10px 12px; font-size: 16px; }
.hint { margin: 0; line-height: 1.5; }
.keyEntry { margin-top: 14px; font-size: 14px; }
.keyEntry summary { cursor: pointer; color: var(--muted); }
.keyEntry .row, .keyEntry > button { margin-top: 10px; }
.acctLine { margin: 0 0 12px !important; padding: 8px 12px; background: #f1ede6; border-radius: 8px; }

/* 主界面 */
#app { height: 100%; display: flex; flex-direction: column; }
header {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding-top: max(8px, env(safe-area-inset-top));
}
.brand { font-size: 15px; }
.title { width: 260px; border-color: transparent; background: transparent; font-weight: 600; }
.title:hover, .title:focus { border-color: var(--line); background: #fff; }
.request {
  display: flex; gap: 10px; align-items: baseline; padding: 9px 14px;
  background: var(--soft); border-bottom: 1px solid #ecd2c3; line-height: 1.55; font-size: 14.5px;
}
.request .tag { flex: none; font-size: 12px; font-weight: 600; color: var(--accent); }
.request #requestText { white-space: pre-wrap; }
.body { flex: 1; display: flex; min-height: 0; }
aside {
  width: 230px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 10px 10px 44px;
}
.new { width: 100%; margin-bottom: 10px; }
.sheet {
  display: block; width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
  padding: 8px 9px; margin-bottom: 4px; border-radius: 8px; white-space: normal;
}
.sheet:hover { background: #f6f4f0; border-color: transparent; }
.sheet.on { background: #f1ede6; border-color: var(--line); }
.sheet .t { font-weight: 600; font-size: 14px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet .s { font-size: 12px; color: var(--muted); }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; margin-right: 4px; }
.badge.pending { background: var(--accent); color: #fff; }
.badge.drawing { background: #e8e4dc; color: #555; }
.badge.done { background: #dcefe2; color: var(--ok); }

main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tools {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.tools button { padding: 5px 9px; font-size: 14px; }
.tools button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
.colors, .widths { display: flex; gap: 5px; align-items: center; }
.sw { width: 22px; height: 22px; border-radius: 50%; padding: 0; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.sw.on { box-shadow: 0 0 0 2px var(--ink); }
.wd { width: 30px; height: 28px; padding: 0; display: grid; place-items: center; }
.wd i { display: block; background: var(--ink); border-radius: 4px; width: 16px; }
.tools .wd.on { box-shadow: 0 0 0 2px var(--ink); background: var(--panel); border-color: var(--line); }

.stage { flex: 1; position: relative; min-height: 0; display: grid; place-items: center; padding: 14px; overflow: hidden; }
canvas { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); border-radius: 4px; touch-action: none; cursor: crosshair; display: block; }
#textEdit {
  position: absolute; border: 1px dashed var(--accent); background: rgba(255,255,255,.9); outline: none;
  resize: none; padding: 0; margin: 0; line-height: 1.2; overflow: hidden; min-width: 60px; font-family: sans-serif;
}

/* 说明栏：打字 + 语音 */
.composer {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: 40px; /* 左下角留给 happydavid.cc 的小圆点菜单 */
}
.noteWrap { flex: 1; min-width: 0; }
#inNote {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; resize: vertical;
  min-height: 44px; max-height: 40vh; line-height: 1.5; font-size: 15px; background: #fff; display: block;
}
#inNote:focus { outline: none; border-color: #b9b3a8; }
.interim { color: var(--muted); font-size: 13.5px; padding: 4px 2px 0; }
.mic { width: 44px; height: 44px; border-radius: 50%; font-size: 19px; padding: 0; flex: none; }
.mic.on { background: #d1352b; border-color: #d1352b; color: #fff; animation: pulse 1.2s infinite; }
.mic:disabled { opacity: .4; cursor: not-allowed; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(209,53,43,.45); } 50% { box-shadow: 0 0 0 7px rgba(209,53,43,0); } }

dialog { border: 1px solid var(--line); border-radius: 14px; max-width: 560px; width: calc(100% - 24px); padding: 22px; }
dialog::backdrop { background: rgba(20,20,20,.35); }
dialog h2 { margin: 0 0 8px; }
dialog h3 { margin: 18px 0 6px; font-size: 15px; }
dialog p { margin: 6px 0; line-height: 1.55; color: #3d4147; font-size: 14px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 10;
  max-width: calc(100% - 32px);
}

/* 手机：侧栏变抽屉，工具栏横向滚动 */
@media (max-width: 760px) {
  .brand, #saveState { display: none; }
  .title { width: auto; flex: 1; }
  .grow { display: none; }
  aside { position: absolute; z-index: 5; top: 0; bottom: 0; left: 0; box-shadow: 2px 0 12px rgba(0,0,0,.15); }
  .body { position: relative; }
  aside.closed { display: none; }
  .tools { flex-wrap: nowrap; overflow-x: auto; }
  .tools button { padding: 6px 8px; }
  .stage { padding: 6px; }
}
@media (min-width: 761px) { aside.closed { display: none; } }
