:root {
  --bg: #f3f1ec; --card: #ffffff; --ink: #222220; --muted: #6d6b66; --line: #e2dfd7;
  --accent: #262624; --soft: #efece5; --ok: #3d7a4a; --warn: #a3622a; --err: #a33a2a;
  --paper: #e2e0d8; --bezel: #34342f;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1d1b; --card: #272724; --ink: #ecebe6; --muted: #a3a19a; --line: #3a3934;
          --accent: #ecebe6; --soft: #2f2e2a; --bezel: #111110; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 -apple-system, "PingFang SC", "Noto Sans SC", sans-serif; }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
h3 { font-size: 13px; margin: 16px 0 8px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); min-height: 1em; margin: 8px 0 0; font-size: 13px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; gap: 12px; }
.gap { gap: 12px; margin-top: 12px; }
.end { justify-content: flex-end; }
.wrap { flex-wrap: wrap; }

button { font: inherit; color: inherit; cursor: pointer; }
button.primary { background: var(--accent); color: var(--bg); border: 0; border-radius: 8px; padding: 8px 16px; }
button.link { background: none; border: 0; color: var(--muted); padding: 8px 4px; }
button.danger { color: var(--err); }
input { font: inherit; font-size: 16px; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0; }
label input { margin-top: 4px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }

.top { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.top .title { font-weight: 600; font-size: 17px; }
.pill { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.online .dot { background: var(--ok); }
.pill.offline .dot { background: var(--warn); }

main { max-width: 640px; margin: 0 auto; padding: 12px 16px 96px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }

.screen { position: relative; background: var(--bezel); border-radius: 10px; padding: 8px; margin-top: 10px; }
.screen::before { content: ""; display: block; aspect-ratio: 800 / 480; }
.screen.portrait::before { aspect-ratio: 480 / 800; }
.screen img { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); border-radius: 2px; background: var(--paper); }
.screen-note { position: absolute; inset: 8px; display: grid; place-items: center; color: #bbb; font-size: 13px; text-align: center; padding: 16px; }
.previews { display: grid; grid-template-columns: 5fr 2fr; gap: 10px; align-items: start; }
.previews .screen { margin-top: 10px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { border: 0; background: var(--card); padding: 8px 16px; font-size: 14px; color: var(--muted); min-height: 40px; }
.seg button.on { background: var(--accent); color: var(--bg); }

.list { list-style: none; margin: 8px 0 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px dashed var(--line); cursor: pointer; }
.list li:last-child { border-bottom: 0; }
.list .t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list .chip { font-size: 12px; color: var(--muted); background: var(--soft); border-radius: 6px; padding: 1px 6px; flex: none; }
.list .done { font-size: 12px; color: var(--ok); flex: none; }
.list .empty { color: var(--muted); cursor: default; }
.add { display: flex; gap: 8px; margin-top: 10px; }
textarea { font: inherit; font-size: 16px; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; resize: vertical; }
.add.note { flex-wrap: wrap; align-items: stretch; }
.add.note textarea { flex-basis: 100%; }
.add.note label { flex: 1; margin: 0; }
.note-text, .note-from, .note-heart { display: block; }
.note-text { white-space: pre-wrap; }
.note-heart { color: var(--muted); }
.past-note { cursor: default !important; }
#noteHistory { margin-top: 12px; }
#noteHistory summary { cursor: pointer; color: var(--muted); font-size: 13px; }
#noteHistoryDate { max-width: 160px; }
.add button { flex: none; min-height: 44px; border: 1px solid var(--line); background: var(--soft); border-radius: 8px; padding: 0 14px; }

.timeline { list-style: none; margin: 10px 0 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 96px 1fr auto; gap: 10px; align-items: center; padding: 9px 2px;
  border-bottom: 1px dashed var(--line); cursor: pointer; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.timeline .now { font-size: 12px; background: var(--accent); color: var(--bg); border-radius: 6px; padding: 1px 6px; }
.timeline li.past { opacity: .55; }

.splits { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.split { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 4px 4px; font-size: 12px; color: var(--muted); text-align: center; }
.split svg { display: block; width: 100%; height: auto; margin-bottom: 3px; }
.split.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); color: var(--ink); }
.area { display: grid; grid-template-columns: 72px 1fr; gap: 6px 10px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.area:last-child { border-bottom: 0; }
.area .name { font-weight: 600; }
.area .cls { font-size: 12px; color: var(--muted); }
.area select, .area .opt { grid-column: 2; }
select { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; width: 100%; }

.status { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); text-align: center; }
.status .ok { color: var(--ok); }
.status .bad { color: var(--err); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chipbtn { border: 1px solid var(--line); background: var(--soft); border-radius: 999px; padding: 6px 14px; min-height: 36px; }
button.primary, button.link { min-height: 44px; }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 16px; width: min(420px, calc(100% - 32px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
dt { color: var(--muted); }
dd { margin: 0; }
