:is(#notes,#editor) {
  --paper: var(--bg); --surface: var(--bg2); --surface-2: var(--bg3); --ink: var(--tx);
  --muted: var(--tx2); --line: var(--bdr2); --accent: #2b55c6; --accent-ink: #fff;
  --rule: #6a4cc0; --habit: #1f6fa8; --must: #0a7a67; --dont: #bc2c57;
  --caution: #a55807; --success: #2c7431; --failure: #7a5233;
  --display: 'Zen Kaku Gothic New','Hiragino Sans','Hiragino Kaku Gothic ProN','Yu Gothic',sans-serif;
  --body: 'BIZ UDPGothic','Hiragino Sans','Hiragino Kaku Gothic ProN','Yu Gothic','Meiryo',sans-serif;
  --mono: 'IBM Plex Mono',ui-monospace,'SFMono-Regular',Menlo,Consolas,monospace;
}
:root[data-theme="dark"] :is(#notes,#editor) {
  --muted: var(--tx3); --line: var(--bdr); --accent: #8aa5ff; --accent-ink: #0d1222;
  --rule: #b39bff; --habit: #6cb8f0; --must: #4ccfb2; --dont: #ff7da3;
  --caution: #ffb15a; --success: #7fd388; --failure: #d7a47c;
}
#notes, #editor {
  font: 15px/1.7 var(--body); color: var(--ink); color-scheme: light;
}
:root[data-theme="dark"] :is(#notes,#editor) { color-scheme: dark; }
#notes { max-width: 1160px; margin: auto; padding: 18px max(16px,env(safe-area-inset-right)) 48px max(16px,env(safe-area-inset-left)); }
:is(#notes,#editor) [hidden], #notes[hidden] { display: none !important; }
:is(#notes,#editor) :is(h2,h3) { font-family: var(--display); margin: 0; text-wrap: balance; }
.note-toolbar { display: flex; justify-content: flex-end; margin-bottom: 12px; }
#notes h2, .dialog-layout h2 { font-size: 18px; }
.actions, .filter-bar, .chips, .card-top, .dialog-layout > footer {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
}
:is(#notes,#editor) button { font: 14px/1.4 var(--body); color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 16px; cursor: pointer; }
:is(#notes,#editor) button:disabled { opacity: .55; cursor: default; }
:is(#notes,#editor) :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:is(#notes,#editor) .primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
#notes .small { padding: 4px 10px; font-size: 12.5px; }
#notes .quiet { background: transparent; }
#notes #filters { display: grid; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.cond-grid, .field-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,170px),1fr)); gap: 10px 12px; }
.cond-grid { align-items: end; }
.cond-grid label > span, .filter-bar > .muted { letter-spacing: .04em; }
:is(#notes,#editor) label { display: grid; gap: 4px; min-width: 0; font-size: 12px; color: var(--muted); }
:is(#notes,#editor) :is(select,input,textarea) { width: 100%; min-width: 0; font: 14px/1.6 var(--body); color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
#filters :is(select,input) { line-height: 1.7; }
:is(#notes,#editor) a { color: var(--accent); }
.filter-bar { gap: 8px 14px; }
.chips { gap: 6px; }
.muted, .results, .notebook-foot { font-size: 12px; color: var(--muted); }
#notes .chip { font: 13px/1.5 var(--body); padding: 4px 11px; display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; background: transparent; }
#notes .chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
#steps { display: grid; grid-template-columns: repeat(11,minmax(0,1fr)); gap: 4px; margin: 16px 0 6px; }
#steps button { display: grid; gap: 1px; align-content: start; min-width: 0; text-align: left; font: inherit; padding: 8px 9px; }
#steps .step-name { font-size: 13px; line-height: 1.35; font-weight: 700; overflow-wrap: anywhere; }
#steps .number,#steps .quantity,.chip .quantity { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
#steps button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
#steps button[aria-pressed="true"] :is(.number,.quantity) { color: inherit; opacity: .85; }
#notes .chip .quantity { color: inherit; opacity: .75; }
#kinds { margin-top: 12px; }
[data-kind="rule"] { --kind: var(--rule); } [data-kind="habit"] { --kind: var(--habit); }
[data-kind="must"] { --kind: var(--must); } [data-kind="dont"] { --kind: var(--dont); }
[data-kind="caution"] { --kind: var(--caution); } [data-kind="success"] { --kind: var(--success); }
[data-kind="failure"] { --kind: var(--failure); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--kind); }
.chip .swatch { width: 9px; height: 9px; }
.results { margin-top: 12px; min-height: 1.2em; font-size: 13px; }
#count { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.group { margin-top: 26px; }
#notes .group h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
.group h2 :is(.group-number,.quantity) { font-family: var(--mono); font-size: 13px; color: var(--muted); font-weight: 400; }
.group h2 .group-number { font-weight: 500; }
.group h2 .swatch { width: 12px; height: 12px; border-radius: 3px; }
.group > p { margin: -6px 0 10px; font-size: 13px; color: var(--muted); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(min(100%,470px),1fr)); gap: 12px; align-items: start; }
.note { display: grid; grid-template-columns: minmax(0,1fr); gap: 8px; min-width: 0; overflow-wrap: anywhere; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.note.is-hidden { opacity: .7; }
.note h3 { font-size: 16px; line-height: 1.5; }
.note p { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.note .kind { display: inline-flex; align-items: center; gap: 6px; color: var(--kind); font-weight: 700; }
.card-top,.note .meta,.note details,.generation-spec,.generation-detail { font-size: 12px; color: var(--muted); }
.card-top { gap: 6px 8px; }
.card-top .tag { border: 1px solid var(--line); border-radius: 6px; padding: 0 7px; background: var(--surface-2); color: var(--ink); }
.generation { display: grid; gap: 8px; border-top: 1px dashed var(--line); padding-top: 10px; min-width: 0; }
.generation-spec,.note .meta,.note .media { display: flex; flex-wrap: wrap; gap: 2px 12px; }
.generation b { color: var(--ink); }
.note .media { gap: 10px; }
.note .card-actions { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.prompt { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.prompt .actions { padding: 5px 8px 5px 12px; border-bottom: 1px solid var(--line); font-size: 12px; justify-content: space-between; }
.note pre { margin: 0; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 340px; overflow: auto; font: 12.5px/1.6 var(--mono); }
.note figure { width: min(220px,100%); margin: 0; color: var(--muted); font-size: 12px; }
.note :is(img,video) { max-width: 100%; max-height: 310px; object-fit: contain; border-radius: 6px; display: block; }
.empty { margin-top: 28px; padding: 22px; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface); color: var(--muted); font-size: 14px; }
#pager { justify-content: center; margin-top: 16px; }
.recent { margin-top: 34px; border-top: 1px solid var(--line); padding-top: 16px; }
#notes #recent button { display: block; background: none; border: 0; text-align: left; padding: 2px 0; }
.notebook-foot { display: grid; gap: 8px; margin-top: 28px; }
#editor { width: min(780px,calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
#editor::backdrop { background: rgb(12 16 22 / 60%); }
.dialog-layout { display: grid; grid-template-rows: auto minmax(0,1fr) auto; max-height: calc(100dvh - 26px); }
.dialog-layout > header,.dialog-layout > footer { padding: 12px 18px; }
.dialog-layout > header { border-bottom: 1px solid var(--line); }
.dialog-layout > footer { border-top: 1px solid var(--line); }
.dialog-layout .spacer { flex: 1; }
.dialog-body { padding: 14px 18px; overflow: auto; }
#fields, #kitForm, .field-group { display: grid; gap: 12px; }
#fields fieldset, #fields details { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 0; min-width: 0; }
#fields legend, #fields summary { font-weight: 700; font-size: 14px; }
#fields .field-group { margin: 8px 0; }
#fields select[multiple] { min-height: 85px; }
#fields textarea { resize: vertical; }
#fields textarea[name="prompt"] { font-family: var(--mono); }
#editNotice:empty,#kitNotice:empty { display: none; }
#editor .warn { color: var(--dont); border-color: currentColor; }
:is(#notes,#editor) summary { cursor: pointer; }
@media(max-width:900px) { #steps { grid-template-columns: repeat(4,minmax(0,1fr)); } }
@media(max-width:420px) { #steps { grid-template-columns: repeat(3,minmax(0,1fr)); } }
#fields .radios { display: flex; flex-wrap: wrap; gap: 6px; }
#fields .radios label { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; cursor: pointer; color: var(--ink); }
#fields .radios input { width: auto; accent-color: var(--accent); }
#fields .radios label:has(:checked) { border-color: var(--ink); font-weight: 700; }
#fields .chips button { background: var(--surface-2); padding: 2px 8px; border-radius: 999px; font-size: 12px; }
