/* ============ テーマトークン ============ */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;      /* series-1 */
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --seq-300: #6da7ec;
  --seq-450: #2a78d6;
  --danger: #d03b3b;
  --good-text: #006300;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --seq-300: #2a78d6;
    --seq-450: #3987e5;
    --danger: #e66767;
    --good-text: #0ca30c;
    --shadow: 0 2px 12px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

/* ============ ヘッダー / タブ ============ */
.app-header {
  display: flex; align-items: baseline; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
}
.app-header h1 { font-size: 19px; font-weight: 700; }
.header-count { font-size: 12px; color: var(--muted); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; padding: 7px 0 6px; border: none; background: none;
  font-size: 10.5px; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: inherit;
}
.tab .tab-icon { font-size: 20px; line-height: 1.1; filter: grayscale(1) opacity(.55); }
.tab.active { color: var(--accent); font-weight: 700; }
.tab.active .tab-icon { filter: none; }

/* ============ 共通 ============ */
.view { padding: 4px 16px 24px; max-width: 640px; margin: 0 auto; }
.hidden { display: none !important; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin-bottom: 8px; }
.desc { font-size: 12.5px; color: var(--ink-2); line-height: 1.6; margin-bottom: 8px; }

.primary-btn {
  display: block; width: 100%; padding: 13px; border: none; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit;
}
.primary-btn:disabled { opacity: .4; }
.primary-btn.small { width: auto; padding: 9px 16px; font-size: 13px; }
.ghost-btn {
  display: block; width: 100%; padding: 11px; margin-top: 10px;
  border: 1px solid var(--border); border-radius: 12px;
  background: none; color: var(--ink-2); font-size: 13px; cursor: pointer; font-family: inherit;
}
.ghost-btn.small { width: auto; padding: 9px 16px; margin-top: 0; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.icon-btn {
  border: none; background: var(--surface-2); color: var(--ink-2);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; flex-shrink: 0;
  font-size: 13px;
}
.linklike { border: none; background: none; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }

.banner {
  margin: 4px 16px 10px; padding: 10px 14px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--ink-2); line-height: 1.5;
  max-width: 640px;
}
.banner .linklike { font-size: 12.5px; }

.hint-card {
  background: var(--surface-2); border-radius: 12px; padding: 12px 14px;
  font-size: 12.5px; color: var(--ink-2); line-height: 1.6; margin-bottom: 14px;
}

/* ============ 記録画面 ============ */
.search-wrap { position: relative; margin-bottom: 14px; }
input[type="search"], input[type="text"], input[type="password"], input[type="date"], textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--ink); font-size: 16px; font-family: inherit;
  -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.search-status {
  padding: 8px 4px; font-size: 12px; color: var(--muted);
}
.search-results {
  list-style: none; position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 15;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); max-height: 55vh; overflow-y: auto;
}
.search-results li {
  display: flex; gap: 10px; align-items: center; padding: 9px 12px;
  border-bottom: 1px solid var(--grid); cursor: pointer;
}
.search-results li:last-child { border-bottom: none; }
.search-results img, .search-results .noposter {
  width: 40px; height: 60px; border-radius: 6px; object-fit: cover; flex-shrink: 0;
  background: var(--surface-2);
}
.noposter { display: flex; align-items: center; justify-content: center; font-size: 18px; color: var(--muted); }
.sr-title { font-size: 14px; font-weight: 600; line-height: 1.35; }
.sr-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.badge {
  display: inline-block; font-size: 10px; font-weight: 700; padding: 2px 7px;
  border-radius: 99px; line-height: 1.4;
}
.badge.anime { background: color-mix(in srgb, var(--series-2) 16%, transparent); color: var(--series-2); }
.badge.live  { background: color-mix(in srgb, var(--series-1) 16%, transparent); color: var(--series-1); }
.badge.count { background: var(--surface-2); color: var(--ink-2); }
.badge.review { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.selected-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; margin-bottom: 14px;
}
.selected-head { display: flex; gap: 12px; align-items: flex-start; }
.poster { width: 64px; height: 96px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex-shrink: 0; }
.selected-info { flex: 1; min-width: 0; }
.sel-title { font-size: 16px; font-weight: 700; line-height: 1.35; }
.sel-year { font-size: 12px; color: var(--muted); margin: 3px 0 6px; }
.genre-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.genre-chips span {
  font-size: 10.5px; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--ink-2);
}
.notice {
  margin-top: 11px; padding: 10px 12px; border-radius: 10px;
  font-size: 12.5px; line-height: 1.55; background: var(--surface-2); color: var(--ink-2);
}
.notice b { color: var(--ink); }
.notice ul { list-style: none; margin-top: 6px; }
.notice li { padding: 3px 0; display: flex; gap: 6px; align-items: baseline; }
.notice .seen { color: var(--muted); }
.notice .unseen { font-weight: 600; color: var(--ink); }

.record-form .field { margin-bottom: 13px; }
.field label { display: block; font-size: 11.5px; font-weight: 700; color: var(--ink-2); margin-bottom: 5px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }
.field-row input[type="password"] { flex: 1; }

.segment { display: flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; height: 46px; }
.segment button {
  flex: 1; border: none; background: var(--surface); color: var(--muted);
  font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.segment button.on.anime { background: color-mix(in srgb, var(--series-2) 18%, var(--surface)); color: var(--series-2); }
.segment button.on.live { background: color-mix(in srgb, var(--series-1) 18%, var(--surface)); color: var(--series-1); }

/* ============ 履歴 ============ */
.chip-row { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 10px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 6px 13px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2); font-size: 12.5px; cursor: pointer; font-family: inherit;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

.list-summary { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }
.history-list { list-style: none; }
.history-list li {
  display: flex; gap: 11px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 13px;
  padding: 9px 12px; margin-bottom: 8px; cursor: pointer;
}
.history-list img, .history-list .noposter { width: 42px; height: 63px; border-radius: 6px; object-fit: cover; flex-shrink: 0; background: var(--surface-2); }
.hl-body { flex: 1; min-width: 0; }
.hl-title { font-size: 14px; font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hl-sub { font-size: 11px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.hl-memo { font-size: 11.5px; color: var(--ink-2); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ 統計 ============ */
.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 13px; padding: 12px 8px; text-align: center; }
.stat-tile .num { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat-tile .lbl { font-size: 10.5px; color: var(--muted); margin-top: 3px; }

.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.chart-card h3 { font-size: 13.5px; margin-bottom: 12px; }
.chart-note { font-size: 11px; color: var(--muted); margin-top: 8px; line-height: 1.5; }

/* 縦棒グラフ */
.vbar-chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; border-bottom: 1px solid var(--baseline); }
.vbar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; min-width: 0; }
.vbar-val { font-size: 9.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.vbar { width: 100%; max-width: 26px; background: var(--seq-450); border-radius: 4px 4px 0 0; min-height: 2px; }
.vbar.zero { background: transparent; }
.vbar-x { display: flex; gap: 4px; margin-top: 5px; }
.vbar-x span { flex: 1; text-align: center; font-size: 9.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* 横棒グラフ */
.hbar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.hbar-label { width: 88px; font-size: 11.5px; color: var(--ink-2); text-align: right; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { flex: 1; height: 18px; display: flex; align-items: center; }
.hbar { height: 14px; background: var(--seq-450); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-val { font-size: 11px; color: var(--ink-2); margin-left: 6px; font-variant-numeric: tabular-nums; }

/* 積み上げ比率バー */
.ratio-bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--page); }
.ratio-seg.anime { background: var(--series-2); }
.ratio-seg.live { background: var(--series-1); }
.ratio-legend { display: flex; gap: 16px; margin-top: 9px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.ratio-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

/* ランキング */
.rank-list { list-style: none; }
.rank-list li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.rank-list li:last-child { border-bottom: none; }
.rank-no { width: 22px; text-align: center; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.rank-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-count { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); flex-shrink: 0; }

/* ============ おすすめ ============ */
.rec-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.rec-item { cursor: pointer; }
.rec-item img, .rec-item .noposter { width: 100%; aspect-ratio: 2/3; border-radius: 10px; object-fit: cover; background: var(--surface-2); height: auto; }
.rec-item .noposter { display: flex; }
.rec-title { font-size: 11px; font-weight: 600; line-height: 1.3; margin-top: 5px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.rec-sub { font-size: 9.5px; color: var(--muted); margin-top: 1px; }
.rec-section-title { font-size: 14px; font-weight: 700; margin: 4px 0 10px; }
.rec-section { margin-bottom: 22px; }

/* ============ 設定 ============ */
.key-status { font-size: 12px; margin-top: 8px; color: var(--muted); }
.key-status.ok { color: var(--good-text); font-weight: 600; }
.key-status.ng { color: var(--danger); font-weight: 600; }
.progress { margin-top: 12px; background: var(--surface-2); border-radius: 99px; height: 22px; position: relative; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: var(--accent); border-radius: 99px; transition: width .2s; }
.progress-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--ink); }

/* ============ モーダル ============ */
.modal { position: fixed; inset: 0; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal-sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 86vh; overflow-y: auto;
  max-width: 640px; margin: 0 auto;
}
.modal-head { display: flex; gap: 13px; margin-bottom: 13px; }
.modal-head .poster { width: 76px; height: 114px; }
.modal-title { font-size: 17px; font-weight: 700; line-height: 1.35; }
.modal-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.modal-sheet .field { margin: 12px 0; }
.danger-btn {
  display: block; width: 100%; padding: 12px; margin-top: 10px;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); border-radius: 12px;
  background: none; color: var(--danger); font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit;
}

/* ============ トースト ============ */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--page);
  padding: 10px 20px; border-radius: 99px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow); white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}

.empty-msg { text-align: center; color: var(--muted); font-size: 13px; padding: 40px 0; line-height: 1.7; }
