:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --ink: #2b2620;
  --muted: #7a7064;
  --line: #e4dccd;
  --accent: #8a3b2e;
  --accent-ink: #fff;
  --accent-soft: #f1e1d9;
  --gold: #b88a2e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .05);
  --sans: 'Noto Sans JP', system-ui, -apple-system, 'Hiragino Sans', sans-serif;
  --serif: 'Noto Serif JP', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1a17; --surface: #262320; --ink: #ebe4d8; --muted: #a39887; --line: #3a352f;
    --accent: #d98a74; --accent-ink: #1c1a17; --accent-soft: #3a2a24; --gold: #d6b066;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1a17; --surface: #262320; --ink: #ebe4d8; --muted: #a39887; --line: #3a352f;
  --accent: #d98a74; --accent-ink: #1c1a17; --accent-soft: #3a2a24; --gold: #d6b066;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 15px; line-height: 1.7;
  padding-bottom: env(safe-area-inset-bottom);
}
body.sheet-open { overflow: hidden; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
small { font-size: .8em; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--serif); font-weight: 600; font-size: 18px; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 14px; }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 120px; }

.section-title { font-size: 15px; font-weight: 700; margin: 24px 0 10px; display: flex; align-items: center; gap: 8px; }
.section-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-row .section-title { margin: 24px 0 10px; }
.count { font-size: 12px; background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 8px; min-width: 22px; text-align: center; }
.page-title { font-family: var(--serif); font-size: 22px; margin: 8px 0 16px; }
.page-title small { font-size: 14px; color: var(--muted); margin-left: 4px; }
.meta { color: var(--muted); font-size: 12.5px; margin: 0; }
.center { text-align: center; justify-content: center; }
.empty { color: var(--muted); text-align: center; padding: 16px; margin: 0; }
.back { display: inline-block; text-decoration: none; color: var(--muted); font-size: 14px; padding: 4px 0; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-lg { min-height: 48px; padding: 0 24px; font-size: 16px; width: 100%; }
.link-btn { background: none; border: 0; padding: 6px 8px; color: var(--accent); cursor: pointer; text-decoration: none; font-size: 13px; }
.link-btn.danger { color: var(--muted); }
.chip-btn { background: var(--accent-soft); color: var(--accent); border: 0; border-radius: 99px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.icon-btn { background: var(--surface); border: 1px solid var(--line); border-radius: 99px; min-width: 36px; height: 36px; padding: 0 10px; cursor: pointer; font-size: 13px; }

/* notice */
.notice { background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.notice p { margin: 0; font-size: 14px; flex: 1 1 200px; }

/* cards */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: var(--ink); text-decoration: none; }
.card-unread { border-left: 4px solid var(--accent); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card .title { font-family: var(--serif); font-weight: 600; font-size: 16px; color: var(--ink); text-decoration: none; }
.preview { margin: 4px 0; font-family: var(--serif); font-size: 13.5px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.badge { flex: none; font-size: 11px; background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 1px 8px; }
.progress { height: 4px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 0; }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.card-foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px; margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; }
.actions { display: flex; flex-wrap: wrap; margin-right: -8px; }
.status-paused, .status-finished { opacity: .75; }
.empty-hero { text-align: center; padding: 32px 16px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-hero p { margin: 4px 0; }
.empty-hero .btn { margin-top: 12px; }

/* wizard */
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.step-title { font-size: 16px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.step-no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 13px; }
.field-label { font-size: 13px; font-weight: 700; margin: 18px 0 8px; color: var(--ink); }
.field-label small { font-weight: 400; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 13px; display: inline-flex; gap: 6px; align-items: baseline; }
.chip small { color: var(--muted); font-size: 11px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on small { color: inherit; opacity: .8; }

.author-field { display: flex; align-items: center; gap: 8px; }
.select-btn { flex: 1; display: flex; align-items: baseline; gap: 8px; text-align: left; min-height: 46px; padding: 8px 40px 8px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%237a7064' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 14px center; cursor: pointer; }
.select-btn span { font-weight: 500; }
.select-btn small { color: var(--muted); }
.select-btn .placeholder { color: var(--muted); font-weight: 400; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.segmented button { border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted); }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }
#pick-body { margin-top: 12px; }
.input { width: 100%; min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: inherit; font-size: 16px; }
.input:focus, .select-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#work-count { margin: 6px 2px; }
.work-list { list-style: none; margin: 0 0 8px; padding: 0; max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.work-list li { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; flex-direction: column; }
.work-list li:last-child { border-bottom: 0; }
.work-list li:hover { background: var(--bg); }
.work-list li.selected { background: var(--accent-soft); box-shadow: inset 4px 0 0 var(--accent); }
.work-list .title { font-family: var(--serif); }
.work-list .title small { color: var(--muted); }
.omakase { background: var(--bg); border-radius: 10px; padding: 14px; }
.omakase p { margin: 0 0 4px; }

.stepper { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 8px 0; }
.step-btn { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); font-size: 24px; cursor: pointer; touch-action: manipulation; user-select: none; }
.step-btn:disabled { opacity: .35; }
.stepper-value { min-width: 140px; text-align: center; }
.stepper-value strong { font-family: var(--serif); font-size: 26px; margin-right: 2px; }
#interval-body .chips, #sheet-interval .chips { margin-top: 12px; }

.submit-bar { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 24%); padding: 24px 0 calc(12px + env(safe-area-inset-bottom)); text-align: center; }
.submit-bar .meta { margin-bottom: 8px; }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20, 14, 8, .4); z-index: 50; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-width: 720px; margin: 0 auto;
  max-height: 88vh; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 17px; margin: 0; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* 五十音タブ */
.kana-tabs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.kana-tabs button { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 6px 0 4px; cursor: pointer; font-family: var(--serif); font-size: 17px; line-height: 1.2; display: flex; flex-direction: column; align-items: center; }
.kana-tabs button small { font-family: var(--sans); font-size: 10px; color: var(--muted); min-height: 1em; }
.kana-tabs button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.kana-tabs button.on small { color: inherit; }
.kana-tabs button:disabled { opacity: .3; cursor: default; }
.kana-tabs .pin-tab { color: var(--gold); }
.kana-tabs.dim { opacity: .5; }
.kana-heads { display: flex; gap: 4px; flex-wrap: wrap; }
.kana-heads:empty { display: none; }
.kana-heads button { border: 1px solid var(--line); background: none; border-radius: 99px; min-width: 40px; padding: 2px 10px; cursor: pointer; font-family: var(--serif); }
.kana-heads button:first-child { font-family: var(--sans); font-size: 12px; }
.kana-heads button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.kana-heads button:disabled { opacity: .3; }

.author-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 200px; border-top: 1px solid var(--line); }
.author-list li { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.author-list .list-label { font-size: 11px; color: var(--muted); padding: 10px 4px 4px; border-bottom: 0; font-weight: 700; letter-spacing: .05em; }
.author-item { flex: 1; display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 8px; text-align: left; border: 0; background: none; padding: 10px 4px; cursor: pointer; }
.author-item:hover { background: var(--bg); }
.author-item .name { font-family: var(--serif); font-weight: 600; font-size: 16px; }
.author-item .yomi { color: var(--muted); font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.author-item .works { color: var(--muted); font-size: 12px; }
.star { border: 0; background: none; font-size: 20px; color: var(--line); cursor: pointer; width: 44px; }
.star.on { color: var(--gold); }

/* reader */
.reader { --fs: 18px; }
.reader-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.reader-tools { display: flex; gap: 6px; }
.reader-head { margin: 12px 0 20px; }
.reader-head h1 { font-family: var(--serif); font-size: 24px; margin: 0 0 4px; }
.reader-body { font-family: var(--serif); font-size: var(--fs); line-height: 2; letter-spacing: .02em; }
.reader-body p { margin: 0; text-align: justify; }
.reader-body h3 { font-size: 1.1em; margin: 1.5em 0 .8em; }
.reader-body rt { font-size: .5em; color: var(--muted); }
.reader-body .gaiji { color: var(--muted); cursor: help; }
.reader.vertical .reader-body {
  writing-mode: vertical-rl; width: 100%; height: min(70vh, 640px); overflow-x: auto; overflow-y: hidden;
  padding: 8px 4px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.reader.vertical .reader-body h3 { margin: 0 1em 0 1.5em; }
.fin { text-align: right; font-family: var(--serif); color: var(--muted); }
.reader-nav { display: flex; justify-content: space-between; align-items: center; margin: 32px 0 16px; }
.next-box { text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.next-box p { margin: 0 0 12px; }
.credit { text-align: center; font-size: 12px; color: var(--muted); margin-top: 24px; }

/* history */
.history { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.history li + li { border-top: 1px solid var(--line); }
.history a { display: flex; gap: 14px; padding: 12px 16px; text-decoration: none; color: var(--ink); }
.history a.unread { background: color-mix(in srgb, var(--accent-soft) 50%, transparent); }
.history a.unread .h-no { color: var(--accent); }
.h-no { font-family: var(--serif); font-size: 20px; min-width: 52px; color: var(--muted); }
.h-no small { font-size: 12px; }
.h-body { display: flex; flex-direction: column; min-width: 0; }
.h-body .title { font-family: var(--serif); font-weight: 600; }
.h-body .preview { margin: 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: 14px;
  z-index: 100; max-width: calc(100% - 32px); box-shadow: 0 4px 20px rgba(0, 0, 0, .2);
}
