/* ひとくち読書 見た目 */
:root {
  --bg: #f7f1e3;
  --fg: #3b3326;
  --sub: #7a6f5c;
  --card: #fffaf0;
  --line: #e3d8c0;
  --accent: #5f8a6b;
  --accent-fg: #ffffff;
  --mark: rgba(232, 168, 92, 0.35);
  --shadow: 0 2px 6px rgba(60, 45, 20, 0.18);
  --font-ui: -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  --font-read: var(--font-ui);
  --read-size: 26px;
  --read-lh: 1.9;
  --read-ls: 0.04em;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 18px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#view {
  min-height: 100vh;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 96px);
}
body.no-tabs #view { padding-bottom: var(--safe-bottom); }
body.no-tabs #tabbar, body.no-tabs #continue-bar { display: none !important; }

/* ===== タブ ===== */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 20;
}
.tab {
  flex: 1; border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 13px; color: var(--sub);
}
.tab svg { width: 28px; height: 28px; }
.tab.on { color: var(--accent); font-weight: 700; }

/* ===== 続きを読むバー ===== */
#continue-bar {
  position: fixed; left: 10px; right: 10px;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 8px);
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px 8px 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 19;
  min-height: 72px;
}
#continue-bar img { width: 40px; height: 60px; object-fit: cover; border-radius: 4px; flex: none; }
#continue-bar .cb-text { flex: 1; min-width: 0; }
#continue-bar .cb-label { font-size: 13px; color: var(--sub); }
#continue-bar .cb-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#continue-bar .cb-bar { height: 5px; background: var(--line); border-radius: 3px; margin-top: 4px; overflow: hidden; }
#continue-bar .cb-bar i { display: block; height: 100%; background: var(--accent); }
#continue-bar .cb-pct { font-weight: 700; color: var(--accent); flex: none; }

/* ===== 見出し ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  margin-top: calc(-1 * var(--safe-top));
  background: var(--bg);
}
.topbar h1 { flex: 1; margin: 0; font-size: 28px; font-weight: 800; letter-spacing: 0.04em; }
.topbar h1.small { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 48px; height: 48px; flex: none;
  border: 0; border-radius: 14px;
  background: var(--card);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--fg);
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.icon-btn.accent { background: var(--accent); color: var(--accent-fg); }
.icon-btn svg { width: 26px; height: 26px; }
.back-btn {
  height: 48px; padding: 0 12px 0 6px; border: 0; background: none;
  font-size: 18px; color: var(--accent); font-weight: 700; flex: none;
  display: inline-flex; align-items: center;
}

/* ===== 本棚 ===== */
.notice {
  margin: 4px 12px 12px; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  font-size: 15px; line-height: 1.6;
}
.notice b { color: var(--accent); }
.notice .row { display: flex; justify-content: flex-end; margin-top: 6px; }
.notice .row button { border: 0; background: none; color: var(--sub); font-size: 14px; padding: 6px; }

.shelf {
  display: grid; gap: 18px 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 6px 12px 12px;
}
.shelf.cols3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px 14px; }
.item { border: 0; padding: 0; background: none; text-align: left; min-width: 0; }
.cover {
  position: relative; width: 100%; aspect-ratio: 2 / 3;
  border-radius: 4px 6px 6px 4px;
  box-shadow: var(--shadow);
  background: var(--line);
}
.cover img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.cover.stack::before, .cover.stack::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: var(--card); border: 1px solid var(--line);
  z-index: -1;
}
.cover.stack::before { transform: translate(3px, -4px); }
.cover.stack::after { transform: translate(6px, -8px); opacity: .7; z-index: -2; }
.shelf .cover { margin-top: 8px; }
.item { position: relative; z-index: 0; }
.badge {
  position: absolute; right: -6px; bottom: -6px;
  min-width: 28px; height: 28px; padding: 0 6px;
  border-radius: 14px; background: var(--accent); color: var(--accent-fg);
  font-size: 14px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
}
.done-band {
  position: absolute; left: 0; right: 0; top: 10%;
  background: rgba(95, 138, 107, 0.92); color: #fff;
  font-size: 12px; font-weight: 800; text-align: center;
  padding: 2px 0; letter-spacing: 0.1em;
}
.cols3 .done-band { font-size: 14px; }
.check {
  position: absolute; left: 4px; bottom: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 900; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.item-title {
  margin-top: 6px; font-size: 12px; line-height: 1.35; color: var(--fg);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cols3 .item-title { font-size: 14px; }
.item-sub { font-size: 11px; color: var(--sub); }
.cols3 .item-sub { font-size: 13px; }
.empty {
  margin: 40px 24px; text-align: center; color: var(--sub); line-height: 1.9;
}
.empty .big-btn { margin-top: 18px; }

/* ===== ボタン・入力 ===== */
.big-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 56px; padding: 12px 18px;
  border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-fg);
  font-size: 19px; font-weight: 800;
}
.big-btn.sub { background: var(--card); color: var(--fg); border: 1px solid var(--line); font-weight: 700; }
.big-btn.danger { background: #b5544a; color: #fff; }
.big-btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > * { flex: 1 1 140px; }
.small-btn {
  min-height: 44px; padding: 8px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
  font-size: 15px; font-weight: 700;
}

.form { padding: 4px 16px 40px; }
.field { margin: 18px 0; }
.field > label, .field > .label { display: block; font-weight: 800; margin-bottom: 6px; }
.field .hint { font-size: 14px; color: var(--sub); margin: 4px 0 8px; line-height: 1.6; }
.input, .textarea {
  width: 100%; padding: 12px 14px; font-size: 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--fg);
  -webkit-appearance: none; appearance: none;
}
.textarea { min-height: 260px; line-height: 1.7; resize: vertical; font-size: 16px; }
.count { font-size: 14px; color: var(--sub); text-align: right; margin-top: 4px; }
.cover-pick { display: flex; gap: 14px; align-items: flex-start; }
.cover-pick .cover { width: 104px; flex: none; }
.cover-pick .btns { flex: 1; display: flex; flex-direction: column; gap: 10px; }

/* ===== 設定 ===== */
.group { margin: 10px 12px 22px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 4px 16px; }
.group h2 { font-size: 15px; color: var(--sub); margin: 16px 4px 4px; font-weight: 700; }
.set-row { padding: 14px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row .label { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 8px; }
.set-row .label span { color: var(--accent); }
input[type=range] { width: 100%; height: 40px; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 46px; padding: 8px 14px; border-radius: 23px;
  border: 2px solid var(--line); background: var(--bg); font-size: 16px; font-weight: 700;
}
.chip.on { border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
.swatch { width: 54px; height: 54px; border-radius: 50%; border: 3px solid var(--line); font-size: 13px; font-weight: 800; }
.swatch.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.swatch-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--sub); }
.preview {
  margin: 8px 0 4px; padding: 16px; border-radius: 12px; border: 1px dashed var(--line);
  font-family: var(--font-read); font-size: var(--read-size); line-height: var(--read-lh); letter-spacing: var(--read-ls);
}
select.input { background-image: none; }
.storage { font-size: 15px; color: var(--sub); line-height: 1.7; }

/* ===== 読む画面 ===== */
.reader { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.reader .rtop {
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-top) + 6px) 10px 6px;
}
.reader .rtitle { flex: 1; min-width: 0; font-size: 15px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.reader .stage {
  flex: 1; position: relative; overflow-y: auto;
  display: flex; align-items: center;
  padding: 12px 22px;
  -webkit-user-select: none; user-select: none;
}
.reader .text {
  width: 100%;
  font-family: var(--font-read);
  font-size: var(--read-size); line-height: var(--read-lh); letter-spacing: var(--read-ls);
  word-break: normal; overflow-wrap: anywhere; line-break: strict;
  margin: auto 0;
}
.reader .text .u { border-radius: 6px; transition: background .2s, opacity .2s; padding: 0.05em 0; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.reader .text.speaking .u { opacity: .45; }
.reader .text.speaking .u.now { opacity: 1; background: var(--mark); }
.reader .text .para { display: block; height: 0.6em; }
.reader .hint-overlay {
  position: absolute; inset: 0; display: flex; pointer-events: none;
  font-size: 16px; font-weight: 700; color: var(--sub);
}
.reader .hint-overlay div { display: flex; align-items: center; justify-content: center; border: 2px dashed var(--line); margin: 8px; border-radius: 12px; background: color-mix(in srgb, var(--bg) 70%, transparent); }
.reader .hint-overlay .l { flex: 3; }
.reader .hint-overlay .r { flex: 7; }
.reader .rbottom {
  padding: 6px 12px calc(var(--safe-bottom) + 10px);
}
.progress-line { display: flex; align-items: center; gap: 10px; margin: 2px 4px 10px; border: 0; background: none; width: calc(100% - 8px); padding: 6px 0; }
.progress-line .bar { flex: 1; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress-line .bar i { display: block; height: 100%; background: var(--accent); }
.progress-line .pct { font-weight: 800; color: var(--accent); min-width: 3.5em; text-align: right; font-size: 17px; }
.controls { display: flex; gap: 10px; }
.controls button {
  height: 64px; border: 0; border-radius: 18px; font-size: 18px; font-weight: 800;
  background: var(--card); color: var(--fg); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.controls .prev { flex: 2; }
.controls .play { flex: 3; background: var(--accent); color: var(--accent-fg); border: 0; }
.controls .next { flex: 3; }
.controls svg { width: 26px; height: 26px; }
.end-box { text-align: center; width: 100%; }
.end-box .big { font-size: 28px; font-weight: 800; margin-bottom: 18px; }
.end-box .big-btn { margin: 10px 0; }

/* ===== 下から出る小窓 ===== */
#sheet-layer {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.35);
  display: flex; align-items: flex-end;
}
.sheet {
  width: 100%; max-height: 88vh; overflow-y: auto;
  background: var(--bg); color: var(--fg);
  border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(var(--safe-bottom) + 16px);
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet .grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 4px 4px 12px; font-size: 20px; }
.sheet p { margin: 4px 4px 14px; line-height: 1.7; }
.sheet .big-btn { margin-top: 10px; }
.menu-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 56px; padding: 0 16px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  font-size: 18px; font-weight: 700; text-align: left;
}
.menu-btn.on { border: 2px solid var(--accent); color: var(--accent); }
.menu-btn.danger { color: #b5544a; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 100px);
  background: rgba(40, 35, 25, .9); color: #fff;
  padding: 12px 20px; border-radius: 24px; font-weight: 700; z-index: 60;
  max-width: 90vw; text-align: center;
}
