:root {
  --accent: #803131;
  --accent-soft: #c4a4a4;
  --text: #282828;
  --muted: #8a8a8a;
  --line: #e6e6ea;
  --blue: #0a84ff;
  --danger: #d0342c;
  --grouped: #f2f2f7;
  --shadow: 0 4px 18px rgba(0, 0, 0, .09);
  --sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  --column: 720px;
  --bar-height: calc(74px + env(safe-area-inset-top));
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--sans); color: var(--text); background: #fff; line-height: 1.7; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
.symbols { display: none; }
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

.round {
  width: 50px; height: 50px; border-radius: 50%; border: 0; background: #fff;
  box-shadow: var(--shadow); display: inline-grid; place-items: center; padding: 0;
}
.round:disabled { opacity: .35; cursor: default; }
.round:focus-visible, .pill:focus-visible, .text-button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* Header */
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  max-width: var(--column); margin: 0 auto; padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: #fff;
}
.bar-title { display: flex; flex-direction: column; align-items: center; line-height: 1.2; color: inherit; text-decoration: none; border-radius: 10px; padding: 2px 6px; }
.bar-title:hover .app-name { text-decoration: underline; }
.bar-title:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.app-name { font-weight: 700; font-size: 19px; }
.trial-mark { font-size: 11px; color: var(--accent); letter-spacing: .08em; margin-top: 3px; }

html, body { height: 100%; overflow: hidden; }
/* The reader frame plays the app's web view: the app's own pages, between the bars. */
.frame-holder { position: fixed; left: 0; right: 0; bottom: 0; top: var(--bar-height); }
.frame { display: block; width: 100%; height: 100%; border: 0; }
.main { position: fixed; inset: var(--bar-height) 0 0; z-index: 3; overflow-y: auto; background: #fff; padding: 8px 20px calc(110px + env(safe-area-inset-bottom)); outline: none; }

/* Bottom toolbar */
.toolbar {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 5; width: 100%; max-width: var(--column);
  display: flex; justify-content: space-between; padding: 14px 24px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(255, 255, 255, 0), #fff 40%);
}
.toolbar .round { width: 54px; height: 54px; }

.empty { text-align: center; padding: 36px 8px; }
.empty h1 { font-size: 22px; margin: 18px 0 10px; }
.empty p { color: #555; margin: 0 auto 12px; max-width: 30em; }
.empty .notes { font-size: 13px; color: var(--muted); margin-top: 22px; }
.button-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 24px; }
.pill {
  border: 1.5px solid var(--blue); color: var(--blue); background: #fff; border-radius: 999px;
  padding: 9px 20px; font-size: 16px; display: inline-flex; align-items: center; gap: 6px;
}
.pill.filled { background: var(--blue); color: #fff; }
.pill.danger { border-color: var(--danger); color: var(--danger); }

.section-label { font-size: 14px; font-weight: 600; color: var(--muted); margin: 0 0 10px; }

/* Sheets */
.sheet-layer { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .25); display: flex; justify-content: center; align-items: flex-end; }
.sheet {
  width: 100%; max-width: var(--column); height: calc(100% - 28px - env(safe-area-inset-top)); background: #fff;
  border-radius: 24px 24px 0 0; display: flex; flex-direction: column; overflow: hidden;
}
.sheet.entering { animation: rise .22s ease-out; }
.sheet.grouped { background: var(--grouped); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet.entering { animation: none; } }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 18px 16px 12px; }
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 700; text-align: center; }
.sheet-head .left { justify-self: start; display: flex; gap: 10px; }
.sheet-head .right { justify-self: end; display: flex; gap: 10px; }
.sheet-head .round { width: 46px; height: 46px; }
.text-button { white-space: nowrap; height: 46px; min-width: 46px; padding: 0 18px; border-radius: 23px; border: 0; background: #fff; box-shadow: var(--shadow); font-size: 16px; }
.text-button.primary { color: var(--blue); font-weight: 600; }
.sheet-body { flex: 1; overflow-y: auto; padding: 8px 20px 24px; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px calc(14px + env(safe-area-inset-bottom)); }
.sheet-foot .round { width: 54px; height: 54px; }
.foot-note { width: 54px; font-size: 11px; line-height: 1.4; color: var(--muted); text-align: center; }
.round.active { color: var(--blue); }
.round.active .icon { fill: var(--blue); }
.round.danger { color: var(--danger); }

/* Editor: the app's editor page in a frame, with the toolbar under it */
.editor-sheet .sheet-body { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.editor-frame { flex: 1; width: 100%; height: 100%; border: 0; display: block; }
.editor-foot { position: relative; padding-top: 8px; border-top: 1px solid var(--line); }
.insert-holder { position: relative; }
.insert-menu {
  position: absolute; left: 0; bottom: calc(100% + 10px); z-index: 2; min-width: 250px; max-height: 60vh; overflow-y: auto;
  padding: 6px 0; border-radius: 14px; background: rgba(250, 250, 250, .98); box-shadow: 0 8px 30px rgba(0, 0, 0, .2);
}
.insert-item { display: flex; align-items: center; gap: 6px; width: 100%; min-height: 46px; padding: 0 16px 0 8px; border: 0; background: none; text-align: left; font-size: 16px; }
.insert-item:hover, .insert-item:focus-visible { background: rgba(0, 0, 0, .05); outline: none; }
.insert-item + .insert-item { border-top: 1px solid var(--line); }
.insert-check { width: 20px; flex: none; text-align: center; color: var(--blue); font-weight: 700; }
.insert-label { flex: 1; }
.insert-glyph { flex: none; min-width: 26px; text-align: center; font-weight: 600; color: #555; }
.insert-item .icon { width: 18px; height: 18px; color: #999; }
.insert-back { color: var(--blue); font-weight: 600; }
.insert-back .icon { color: var(--blue); }

/* Editing lists: UITableView in edit mode, inset grouped */
.list-header { margin: 14px 20px 6px; font-size: 13px; color: #6d6d72; }
.list-footer { margin: 6px 20px 22px; font-size: 13px; line-height: 1.45; color: #6d6d72; white-space: pre-line; }
.group.edit-list { margin-bottom: 0; border-radius: 22px; }
.group.edit-list + .list-footer:empty { display: none; }
.edit-list .edit-row { position: relative; gap: 14px; padding: 0 0 0 16px; min-height: 52px; overflow: hidden; background: #fff; transition: transform .18s; }
.edit-list .edit-row.dragging { z-index: 2; transition: none; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
.edit-control { position: relative; flex: none; width: 23px; height: 23px; border-radius: 50%; border: 0; padding: 0; display: inline-block; }
.edit-control::before { content: ""; position: absolute; left: 5px; right: 5px; top: 10px; height: 3px; border-radius: 1.5px; background: #fff; }
.edit-control.minus { background: #ff3b30; transition: transform .2s; }
.edit-control.plus { background: #34c759; }
.edit-control.plus::after { content: ""; position: absolute; top: 5px; bottom: 5px; left: 10px; width: 3px; border-radius: 1.5px; background: #fff; }
.edit-row.confirming .edit-control.minus { transform: rotate(-90deg); }
.edit-control-space { flex: none; width: 23px; }
.edit-label { flex: 1; min-width: 0; padding: 13px 0; overflow-wrap: anywhere; font-size: 17px; line-height: 1.4; }
.edit-grip { flex: none; align-self: stretch; width: 52px; cursor: grab; touch-action: none; position: relative;
  background: linear-gradient(#c7c7cc, #c7c7cc) center calc(50% - 5px) / 20px 1.5px no-repeat,
              linear-gradient(#c7c7cc, #c7c7cc) center 50% / 20px 1.5px no-repeat,
              linear-gradient(#c7c7cc, #c7c7cc) center calc(50% + 5px) / 20px 1.5px no-repeat; }
.edit-grip:focus-visible { outline: 2px solid var(--blue); outline-offset: -4px; }
.edit-confirm { position: absolute; top: 0; bottom: 0; right: 0; border: 0; padding: 0 20px; background: #ff3b30; color: #fff; font-size: 17px;
  transform: translateX(100%); transition: transform .2s; }
.edit-row.confirming .edit-confirm { transform: none; }
.edit-row:not(:last-child)::after { content: ""; position: absolute; left: 53px; right: 0; bottom: 0; height: 1px; background: var(--line); }
.edit-list li.edit-row { border-top: 0; }
.edit-action { flex: 1; display: flex; align-items: center; gap: 14px; min-height: 52px; border: 0; background: none; padding: 0; text-align: left; color: var(--blue); }
.action-row.disabled .edit-action { color: #c4c4c7; cursor: default; }

/* Knowledge picker */
.picker-head { display: flex; align-items: center; gap: 10px; padding: 20px 16px 6px; }
.picker-field { flex: 1; display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 14px; border-radius: 23px; background: #fff; }
.picker-field .icon { width: 20px; height: 20px; color: var(--muted); }
.picker-field-input { flex: 1; min-width: 0; border: 0; outline: none; background: none; font-size: 17px; }
.picker-head .round { width: 46px; height: 46px; box-shadow: none; }
.picker .sheet-body { padding-top: 10px; }
.results .result-row { gap: 12px; }
.result-icon { color: var(--blue); display: inline-grid; }
.result-icon .icon { width: 22px; height: 22px; }
.results .result-title mark { background: none; color: var(--blue); font-weight: 700; }
.edit-action:focus-visible, .edit-confirm:focus-visible { outline: none; background-color: rgba(0, 0, 0, .04); }
.edit-confirm:focus-visible { background-color: #e0352b; }
.row-sub.excerpt { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.picker-empty { text-align: center; color: var(--muted); margin-top: 40px; }

/* Grouped lists (collections, tree, keywords, search) */
.group { list-style: none; margin: 0 0 22px; padding: 0; background: #fff; border-radius: 16px; overflow: hidden; }
.group li { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 16px; border-top: 1px solid var(--line); }
.group li:first-child { border-top: 0; }
.group .row-button { flex: 1; display: flex; align-items: center; gap: 14px; min-height: 52px; border: 0; background: none; padding: 0; text-align: left; }
.group .row-main { flex: 1; min-width: 0; padding: 10px 0; overflow-wrap: anywhere; }
.group .row-sub { display: block; font-size: 13px; color: var(--muted); }
.group .row-count { color: var(--muted); }
.group .row-icon { color: var(--blue); }
.group .chevron { color: #c4c4c7; width: 18px; height: 18px; }
.group .mini { border: 0; background: none; padding: 6px; color: var(--muted); display: inline-grid; }
.group .mini:disabled { opacity: .3; }
.group .mini.remove { color: var(--danger); }
.group .note { color: var(--muted); font-size: 15px; }
.group .action { color: var(--blue); }
.group .action .icon { width: 20px; height: 20px; }
.group mark { background: #fff2a8; color: inherit; border-radius: 2px; }
.danger-text { color: var(--danger); }
.group .row-button:disabled { opacity: .4; cursor: default; }
a.row-button { text-decoration: none; }
.check { width: 22px; height: 22px; accent-color: var(--blue); flex: none; }
.hint { font-size: 13px; color: var(--muted); margin: -12px 4px 22px; }
.search-field { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 12px; padding: 0 12px; margin: 4px 0 18px; }
.search-field .icon { color: var(--muted); width: 20px; height: 20px; }
.search-field input { flex: 1; border: 0; outline: none; background: none; font-size: 17px; padding: 11px 0; min-width: 0; }
.prose { background: #fff; border-radius: 16px; padding: 18px 20px; margin-bottom: 22px; font-size: 15px; }
.prose p { margin: 0 0 10px; }
.prose p:last-child { margin: 0; }
.prose table { width: 100%; border-collapse: collapse; font-size: 14px; }
.prose td { padding: 7px 0; border-top: 1px solid var(--line); vertical-align: top; }
.prose tr:first-child td { border-top: 0; }
.prose td:last-child { text-align: right; color: #555; padding-left: 12px; }
.meter { height: 6px; border-radius: 3px; background: #e5e5ea; overflow: hidden; margin: 8px 0 4px; }
.meter span { display: block; height: 100%; background: var(--accent-soft); }

/* Dialog */
.dialog { border: 0; border-radius: 18px; padding: 0; width: min(340px, calc(100% - 40px)); box-shadow: 0 12px 40px rgba(0, 0, 0, .2); }
.dialog::backdrop { background: rgba(0, 0, 0, .3); }
.dialog form { padding: 22px 20px 16px; }
.dialog h2 { font-size: 17px; margin: 0 0 8px; text-align: center; }
#dialog-message { font-size: 14px; color: #444; text-align: center; }
#dialog-message p { margin: 0 0 8px; }
#dialog-message { white-space: pre-line; }
.dialog-field { display: block; width: 100%; margin-top: 10px; border: 1px solid #c8c8cc; border-radius: 10px; padding: 9px 12px; font-size: 16px; outline: none; }
.dialog-field.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; }
.dialog-field:focus { border-color: var(--blue); }
.dialog-buttons.stacked { flex-direction: column; }
.dialog-error { color: var(--danger); font-size: 13px; margin: 8px 0 0; text-align: center; }
.dialog-buttons { display: flex; gap: 10px; margin-top: 18px; }
.dialog-buttons button { flex: 1; border: 0; border-radius: 12px; padding: 11px 8px; background: #f0f0f3; font-size: 16px; }
.dialog-buttons .primary { background: var(--blue); color: #fff; font-weight: 600; }
.dialog-buttons .destructive { background: var(--danger); color: #fff; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px); z-index: 40;
  max-width: calc(100% - 40px); margin: 0; padding: 10px 18px; border-radius: 12px; background: rgba(40, 40, 40, .92); color: #fff;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.shown { opacity: 1; transform: translate(-50%, 0); }
.noscript { text-align: center; padding: 40px 20px; }

@media (max-width: 420px) {
  .toolbar { padding-left: 14px; padding-right: 14px; }
  .knowledge-list a { gap: 18px; padding: 12px 6px; }
  .reader-title { font-size: 22px; }
}
