/* ============================================================
   音読 — 夜の読書のためのトークンシステム
   palette: 夜墨 #16161c / 障子 #1f2027 / 淡葱 #35b3b0 / 朱 #d4574e
            和紙 #f4efe3 / 墨字 #2a2620
   type:    Shippori Mincho（本文・見出し） / Zen Kaku Gothic New（UI）
   ============================================================ */
:root {
  --bg: #16161c;
  --surface: #1f2027;
  --surface-2: #262833;
  --border: #2f3140;
  --text: #e9e4d8;
  --muted: #8d8c98;
  --accent: #35b3b0;
  --accent-ink: #062523;
  --stop: #d4574e;
  --paper: #f4efe3;
  --paper-ink: #2a2620;
  --paper-muted: #9b927d;
  --radius: 10px;
  --ui: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", sans-serif;
  --serif: "Shippori Mincho", "Hiragino Mincho ProN", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.6;
  padding-bottom: 96px; /* player 分 */
}
a { color: var(--accent); }
button { font-family: inherit; }
input, textarea, select {
  font-family: inherit; font-size: 15px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px;
}
input:focus-visible, textarea:focus-visible, select:focus-visible,
button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input[type="range"] { padding: 0; accent-color: var(--accent); }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(22,22,28,.92); backdrop-filter: blur(8px);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  font-family: var(--serif); font-weight: 700; font-size: 22px;
  color: var(--accent-ink); background: var(--accent);
  width: 38px; height: 38px; border-radius: 9px;
  display: grid; place-items: center;
}
.brand-name { font-family: var(--serif); font-size: 19px; font-weight: 700; letter-spacing: .04em; }
.brand-name small { font-family: var(--ui); font-size: 11px; color: var(--muted); margin-left: 6px; letter-spacing: .12em; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  background: none; border: none; color: var(--muted);
  font-size: 15px; font-weight: 500; padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--surface-2); }
.tab.active::after { content: ""; display: block; height: 2px; background: var(--accent); border-radius: 2px; margin: 4px 6px -8px; }

/* ---------- layout ---------- */
main { max-width: 860px; margin: 0 auto; padding: 24px 20px; }
.panel { display: none; }
.panel.active { display: block; }
h2 { font-family: var(--serif); font-size: 17px; letter-spacing: .06em; margin: 26px 0 12px; }
h2:first-child { margin-top: 0; }
.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

/* ---------- URL bar / forms ---------- */
.urlbar { display: flex; gap: 10px; margin-bottom: 14px; }
.urlbar input { flex: 1; }
.btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 18px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 18px; height: 18px; }

.freetext { margin-bottom: 18px; border: 1px dashed var(--border); border-radius: var(--radius); }
.freetext summary { padding: 10px 14px; cursor: pointer; color: var(--muted); font-size: 14px; }
.freetext[open] summary { color: var(--text); border-bottom: 1px dashed var(--border); }
.freetext textarea { width: 100%; border: none; background: transparent; resize: vertical; padding: 12px 14px; }
.freetext button { margin: 10px 14px 14px; }

/* ---------- 小説メタ・履歴 ---------- */
.novel-meta { display: flex; gap: 16px; margin: 18px 0; align-items: flex-start; }
.novel-cover { width: 84px; border-radius: 8px; border: 1px solid var(--border); }
.novel-meta h2 { margin: 0 0 4px; font-size: 20px; }
.tags { font-size: 12px; color: var(--accent); }
.tags span { margin-right: 8px; }
.history { margin: 20px 0; }
.history-list { list-style: none; margin: 8px 0 0; padding: 0; }
.history-list li {
  padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; gap: 12px; align-items: baseline;
}
.history-list li:hover { background: var(--surface-2); }
.history-list .t { font-weight: 500; }
.history-list .a { color: var(--muted); font-size: 13px; }

/* ---------- 読書画面（署名要素: 縦書き + 読み上げハイライト） ---------- */
.reader.paper {
  background: var(--paper); color: var(--paper-ink);
  border-radius: var(--radius);
  padding: 34px 30px;
  margin-top: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,.35);
  max-height: 72vh;
  overflow: auto;
  font-family: var(--serif);
}
.reader.yoko { font-size: var(--reader-size, 20px); line-height: 2.05; max-height: none; height: auto; }
.reader.tategaki {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: var(--reader-size, 20px);
  line-height: 2.2;
  height: 72vh;
  max-height: 72vh;
  width: fit-content;
  max-width: 100%;
  overflow: auto;
  padding: 38px 34px;
}
.reader h3.chapter {
  font-size: 1.1em; letter-spacing: .18em; margin: 0 .6em 1.6em;
  color: #6b5f45; border-inline-start: 3px solid #c9b98a; padding-inline-start: .5em;
}
.reader p.chunk { margin: 0; transition: background .25s; border-radius: 2px; }
.reader.tategaki p.chunk { margin: 0 .35em; }
.reader p.chunk.current { background: rgba(53,179,176,.28); box-shadow: 0 0 0 2px rgba(53,179,176,.35); }
.reader .pagebreak {
  display: block; text-align: center; color: var(--paper-muted);
  font-size: 13px; font-family: var(--ui); letter-spacing: .3em;
  margin: 2.2em 0; user-select: none;
}
.reader.tategaki .pagebreak { margin: 1.4em 0; letter-spacing: .1em; }
.reader img { max-width: 100%; }
.reader .imgnote { color: var(--paper-muted); font-size: .8em; }

/* ---------- ポッドキャスト ---------- */
.feed-list, .episode-list { display: flex; flex-direction: column; gap: 8px; }
.feed-item, .episode-item {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.feed-item { cursor: pointer; }
.feed-item:hover, .episode-item:hover { border-color: var(--accent); }
.feed-item img, .episode-item .ep-art {
  width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--surface-2);
  display: grid; place-items: center; font-size: 22px; color: var(--muted);
}
.feed-item .fi-title { font-weight: 700; }
.episode-item .ep-title { font-weight: 500; flex: 1; }
.episode-item .ep-date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.episode-item.playing { border-color: var(--accent); background: rgba(53,179,176,.06); }
.item-remove { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 6px; }
.item-remove:hover { color: var(--stop); }
.ep-desc { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ---------- 設定 ---------- */
.settings-grid { display: flex; flex-direction: column; gap: 16px; max-width: 560px; }
.settings-grid label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.settings-grid input[type="range"] { height: 26px; }
.model-results { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; }
.model-results .mr {
  text-align: left; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; cursor: pointer; color: var(--text); font-size: 14px;
}
.model-results .mr:hover { border-color: var(--accent); }
.model-results .mr small { color: var(--muted); display: block; }

/* ---------- プレイヤー ---------- */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  background: rgba(24,24,31,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
}
.player-info { flex: 1; min-width: 0; }
.player-title { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-progress { font-size: 12px; }
.player-controls { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: none; border: 1px solid var(--border); color: var(--text);
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 13px;
}
.icon-btn:hover { border-color: var(--accent); }
.play-btn {
  width: 52px; height: 52px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-size: 19px; font-weight: 700;
}
.play-btn:hover { filter: brightness(1.08); }
.player-extra { display: flex; align-items: center; gap: 14px; }
.mini { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.mini input { width: 110px; }

/* ---------- empty / toast ---------- */
.empty {
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 44px 24px; text-align: center; margin-top: 18px;
}
.empty p { margin: 4px 0; }
.toast {
  position: fixed; bottom: 108px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 11px 18px; font-size: 14px; max-width: 88vw; z-index: 30;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.toast.error { border-left-color: var(--stop); }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .topbar { flex-direction: column; gap: 8px; padding: 10px 12px; }
  .tabs { margin-left: 0; width: 100%; justify-content: center; }
  main { padding: 16px 14px; }
  .reader.tategaki { height: 64vh; max-height: 64vh; }
  .player { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .player-extra { width: 100%; justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- 検索結果・プレイリスト ---------- */
.search-results { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.search-result {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; cursor: pointer;
}
.search-result:hover { border-color: var(--accent); }
.search-result img { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex-shrink: 0; }
.search-result .sr-title { font-weight: 700; }
.search-result .sr-author { color: var(--muted); font-size: 13px; }
.search-result .sr-desc { color: var(--muted); font-size: 13px; margin-top: 3px; }
.search-result .badge { display: inline-block; font-size: 11px; color: #fff; background: var(--stop); border-radius: 4px; padding: 0 6px; margin-left: 6px; vertical-align: 1px; }
.playlist-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; cursor: pointer;
}
.playlist-item:hover { border-color: var(--accent); }
.playlist-item.current { border-color: var(--accent); background: rgba(53,179,176,.06); }
.playlist-item .pl-idx { color: var(--muted); font-size: 13px; width: 26px; text-align: right; }
.playlist-item .pl-title { font-weight: 500; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.playlist-item .pl-author { color: var(--muted); font-size: 13px; white-space: nowrap; }
