:root {
  --bg: #0d0a1f;
  --bg-2: #151033;
  --surface: rgb(28 22 60 / .78);
  --surface-2: #241d4d;
  --border: #33296a;
  --text: #f4f0ff;
  --muted: #a79fcf;
  --sakura: #ff7eb6;
  --sakura-soft: #ffb3d1;
  --sky: #7dd3fc;
  --mint: #6ee7b7;
  --gold: #fbbf24;
  --radius: 16px;
  --font-display: "M PLUS Rounded 1c", "Nunito", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
img { display: block; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--sakura); outline-offset: 2px; }

/* ---------- Night sky + sakura ---------- */
.sky {
  position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden;
  background:
    radial-gradient(900px 500px at 8% -10%, rgb(255 126 182 / .20), transparent 60%),
    radial-gradient(800px 500px at 100% 10%, rgb(125 211 252 / .14), transparent 60%),
    radial-gradient(700px 600px at 50% 120%, rgb(139 92 246 / .22), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}
/* Manga-style halftone dots */
.sky::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(rgb(255 255 255 / .05) 1px, transparent 1.2px);
  background-size: 18px 18px;
  mask-image: linear-gradient(180deg, #000, transparent 70%);
}
.petals i {
  position: absolute; top: -40px; display: block;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 22C5 15 4 8 9 3l3 3 3-3c5 5 4 12-3 19z' fill='%23ffb3d1'/%3E%3C/svg%3E") center / contain no-repeat;
  animation-name: fall, sway;
  animation-timing-function: linear, ease-in-out;
  animation-iteration-count: infinite, infinite;
  animation-direction: normal, alternate;
}
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
@keyframes sway { from { margin-left: -30px; } to { margin-left: 30px; } }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: rgb(13 10 31 / .72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgb(255 255 255 / .06);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 22px; letter-spacing: .01em; }
.brand-name b {
  background: linear-gradient(90deg, var(--sakura), var(--sky));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-kanji {
  font-family: var(--font-display); font-weight: 800; font-size: 13px;
  padding: 1px 7px; border-radius: 6px; background: var(--sakura); color: #2a0b1c;
  transform: rotate(-6deg);
}
.nav { display: flex; gap: 6px; }
.nav a, .nav button {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 999px; border: 1px solid transparent;
  background: none; color: var(--muted); text-decoration: none; font-weight: 700; cursor: pointer;
}
.nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav a:hover, .nav button:hover { color: var(--text); background: rgb(255 255 255 / .05); }
.nav [aria-current="page"] { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.nav [aria-current="page"] svg { stroke: var(--sakura); }
.count-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: grid; place-items: center; font-size: 12px; background: var(--sakura); color: #2a0b1c;
}

.nav .install-btn { color: var(--sakura-soft); border-color: rgb(255 126 182 / .35); }

/* Account panel (Mi lista) */
.account {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 18px; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
}
.account-cta { background: linear-gradient(120deg, rgb(255 126 182 / .18), rgb(125 211 252 / .08) 70%), var(--surface); border-color: rgb(255 126 182 / .4); }
.account-avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; border: 2px solid var(--sakura); }
.account-text { flex: 1; min-width: 220px; display: grid; gap: 2px; }
.account-text .muted { font-size: 13px; }
.link-btn { display: inline-flex; align-items: center; text-decoration: none; }
.primary-btn { background: var(--sakura); border-color: var(--sakura); color: #2a0b1c; }
.primary-btn:hover { background: var(--sakura-soft); }
.list-status { font-size: 12px; font-weight: 800; color: var(--sky); }
.list-status.status-planning { color: var(--muted); }
.follow-btn[aria-busy="true"] { opacity: .6; cursor: progress; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 24px; z-index: 50; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  padding: 12px 16px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); font-weight: 700; font-size: 14px;
  box-shadow: 0 16px 40px -12px rgb(0 0 0 / .6); animation: pop .2s ease-out;
}
@media (max-width: 720px) { .toasts { bottom: 90px; } }

/* iPhone install instructions */
.ios-help {
  width: min(420px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--border); border-radius: 20px;
  background: var(--bg-2); color: var(--text);
}
.ios-help::backdrop { background: rgb(5 3 15 / .7); }
.ios-help h2 { margin: 0 0 10px; font-size: 20px; }
.ios-help ol { padding-left: 20px; line-height: 1.7; }

/* ---------- Layout ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 40px) 40px; }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.section-head h1 { margin: 0; font-size: clamp(26px, 4vw, 36px); }
.section-head p { margin: 4px 0 0; }
.eyebrow { margin: 0 0 4px; font-family: var(--font-display); font-weight: 700; font-size: 13px; letter-spacing: .12em; color: var(--sakura); }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px 40px; }
.footer a { color: var(--sakura-soft); }

.round-btn, .chip-btn {
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 700;
  transition: border-color .15s, background .15s;
}
.round-btn { width: 40px; height: 40px; border-radius: 50%; font-size: 22px; line-height: 1; }
.chip-btn { height: 40px; padding: 0 18px; border-radius: 999px; }
.round-btn:hover, .chip-btn:hover { border-color: var(--sakura); }
.chip-btn:disabled { opacity: .6; cursor: default; }
.week-nav { display: flex; gap: 8px; align-items: center; }

/* ---------- Hero: next episode ---------- */
.hero {
  --tint: var(--sakura);
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px;
  margin-bottom: 28px; padding: 18px 22px;
  border-radius: 22px; border: 1px solid var(--border);
  background:
    linear-gradient(110deg, color-mix(in srgb, var(--tint) 30%, transparent), transparent 60%),
    var(--surface);
  box-shadow: 0 20px 60px -30px color-mix(in srgb, var(--tint) 80%, transparent);
}
.hero::after {
  content: "次回"; position: absolute; right: -10px; bottom: -36px;
  font: 800 130px/1 var(--font-display); color: rgb(255 255 255 / .04); pointer-events: none;
}
.hero-cover { width: 84px; height: 118px; object-fit: cover; border-radius: 12px; box-shadow: 0 8px 24px rgb(0 0 0 / .4); }
.hero-title { margin: 0 0 4px; font-size: clamp(18px, 2.6vw, 26px); }
.hero-text p { margin: 0; }
.hero-count { display: grid; justify-items: end; gap: 6px; text-align: right; z-index: 1; }
.hero-count strong { font: 800 clamp(22px, 3.4vw, 34px)/1 var(--font-display); font-variant-numeric: tabular-nums; color: var(--sakura-soft); }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 700; font-size: 13px; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--sakura); color: #2a0b1c; }
.seg .flag { font-family: var(--font-display); font-size: 11px; opacity: .75; margin-right: 2px; }

/* ---------- Day tabs ---------- */
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day {
  position: relative; display: grid; justify-items: center; gap: 1px;
  padding: 12px 4px 10px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; overflow: hidden;
  transition: transform .15s, border-color .15s;
}
.day:hover { transform: translateY(-2px); border-color: var(--sakura); }
.day-kanji { font: 800 13px var(--font-display); color: var(--sakura-soft); opacity: .8; }
.day-wd { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.day-num { font: 800 24px/1.1 var(--font-display); color: var(--text); }
.day-count { font-size: 12px; }
.day[aria-selected="true"] {
  border-color: var(--sakura); color: var(--text);
  background: linear-gradient(170deg, rgb(255 126 182 / .32), rgb(125 211 252 / .10) 70%), var(--surface);
  box-shadow: 0 10px 30px -14px var(--sakura);
}
.day.is-today::before {
  content: "今日"; position: absolute; top: 6px; right: 6px;
  font: 800 10px var(--font-display); padding: 1px 5px; border-radius: 5px; background: var(--sky); color: #052033;
}

/* ---------- Day panel & episode cards ---------- */
.day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 26px 0 14px; }
.day-head h2 { margin: 0; font-size: 20px; }
.day-head h2::first-letter { text-transform: uppercase; }
.empty { color: var(--muted); }
.ep-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.ep-card {
  --tint: var(--sakura);
  position: relative; display: flex; gap: 14px; padding: 12px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: linear-gradient(135deg, color-mix(in srgb, var(--tint) 14%, transparent), transparent 55%), var(--surface);
  transition: transform .18s, border-color .18s, box-shadow .18s;
}
.ep-card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--tint) 70%, white 10%); box-shadow: 0 16px 40px -22px var(--tint); }
.ep-card.is-upcoming { opacity: .78; }
.ep-card.is-followed { border-color: color-mix(in srgb, var(--sakura) 60%, var(--border)); }
.ep-cover { flex: none; }
.ep-cover img { width: 76px; height: 108px; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.ep-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding-right: 34px; }
.ep-top { display: flex; align-items: center; gap: 8px; }
.ep-time { font: 800 16px var(--font-display); font-variant-numeric: tabular-nums; }
.ep-rel { font-size: 12px; font-weight: 700; padding: 1px 9px; border-radius: 999px; background: rgb(255 255 255 / .06); color: var(--muted); white-space: nowrap; }
.is-aired .ep-rel { background: rgb(110 231 183 / .14); color: var(--mint); }
.ep-title { font-weight: 800; text-decoration: none; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ep-title:hover { color: var(--sakura-soft); }
.ep-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ep-meta { margin-top: auto; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.ep-num { font-weight: 800; margin-right: 2px; }
.tag { padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); font-size: 12px; font-weight: 700; color: var(--muted); }
.tag-final { border-color: var(--gold); color: var(--gold); }
.tag-new { border-color: var(--sky); color: var(--sky); }
.tag-score { border-color: transparent; background: rgb(251 191 36 / .12); color: var(--gold); }
.now-line { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; font: 800 13px var(--font-display); color: var(--sakura); letter-spacing: .04em; }
.now-line::before, .now-line::after { content: ""; flex: 1; height: 2px; border-radius: 2px; background: linear-gradient(90deg, transparent, var(--sakura), transparent); }

/* ---------- Follow button ---------- */
.follow-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 32px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--border); background: rgb(13 10 31 / .6); color: var(--muted);
  font-size: 12px; font-weight: 800; cursor: pointer; transition: all .15s;
}
.follow-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
.follow-btn:hover { color: var(--sakura); border-color: var(--sakura); }
.follow-btn[aria-pressed="true"] { color: #2a0b1c; background: var(--sakura); border-color: var(--sakura); }
.follow-btn[aria-pressed="true"] svg { fill: currentColor; }
.ep-card .follow-btn { position: absolute; top: 10px; right: 10px; width: 32px; padding: 0; justify-content: center; }
.ep-card .follow-btn span { display: none; }

/* ---------- Search dialog ---------- */
.search {
  width: min(760px, calc(100vw - 24px)); max-height: min(80vh, 760px);
  margin: 8vh auto auto; padding: 0;
  border: 1px solid var(--border); border-radius: 22px;
  background: var(--bg-2); color: var(--text);
  box-shadow: 0 30px 90px -20px rgb(0 0 0 / .7), 0 0 0 1px rgb(255 126 182 / .12);
  overflow: hidden;
}
.search[open] { display: flex; flex-direction: column; animation: pop .18s ease-out; }
.search::backdrop { background: rgb(5 3 15 / .7); backdrop-filter: blur(4px); }
@keyframes pop { from { opacity: 0; transform: translateY(-10px) scale(.98); } }
.search-bar { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.search-bar svg { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--sakura); stroke-width: 2.2; stroke-linecap: round; }
.search-bar input { flex: 1; min-width: 0; height: 40px; border: 0; outline: 0; background: none; color: var(--text); font: 700 18px var(--font-body); }
.search-bar input::placeholder { color: var(--muted); font-weight: 600; }
.search-bar input::-webkit-search-cancel-button { filter: invert(1) opacity(.5); }
.esc-btn { flex: none; padding: 3px 9px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 800; cursor: pointer; }
.search-body { overflow: auto; padding: 14px 18px 18px; }
.search-hint .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.search-hint .chip-btn { height: 34px; font-size: 13px; }

/* ---------- Result cards (search + Mi lista) ---------- */
.result-list { display: grid; gap: 10px; }
.result-grid { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 14px; }
.result {
  --tint: var(--sakura);
  display: flex; gap: 14px; align-items: flex-start; padding: 12px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: linear-gradient(135deg, color-mix(in srgb, var(--tint) 12%, transparent), transparent 55%), var(--surface);
}
.result-cover img { width: 72px; height: 102px; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.result-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.result-title { font-weight: 800; font-size: 16px; text-decoration: none; }
.result-title:hover, .result-title:focus { color: var(--sakura-soft); }
.result-sub { font-size: 13px; color: var(--muted); }
.result-meta { font-size: 12px; color: var(--muted); }
.result-meta .score { color: var(--gold); }
.next { margin-top: 8px; padding: 8px 12px; border-radius: 12px; background: rgb(13 10 31 / .55); border-left: 3px solid var(--muted); display: grid; gap: 1px; }
.next-label { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.next-count { font: 800 20px/1.25 var(--font-display); font-variant-numeric: tabular-nums; }
.next-when { color: var(--muted); font-size: 12px; }
.next-when::first-letter { text-transform: uppercase; }
.next-ep { border-left-color: var(--mint); }
.next-ep .next-label, .next-ep .next-count { color: var(--mint); }
.next-season, .next-date { border-left-color: var(--sakura); }
.next-season .next-label, .next-season .next-count, .next-date .next-label, .next-date .next-count { color: var(--sakura-soft); }
.next-soon { border-left-color: var(--sky); }
.next-soon .next-label { color: var(--sky); }

/* ---------- Mi lista empty state ---------- */
.empty-state { text-align: center; padding: 50px 16px; border: 1px dashed var(--border); border-radius: 22px; background: var(--surface); }
.empty-state p { margin: 6px 0; }
.empty-kanji { font: 800 64px/1 var(--font-display); color: var(--sakura); opacity: .7; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  body { padding-bottom: 76px; }
  /* backdrop-filter would make the fixed bottom nav position itself inside the header */
  .topbar { justify-content: center; backdrop-filter: none; background: rgb(13 10 31 / .94); }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    justify-content: space-around; gap: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: rgb(13 10 31 / .92); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
  }
  .nav a, .nav button { flex-direction: column; gap: 2px; padding: 6px 14px; font-size: 11px; border-radius: 14px; }
  .nav svg { width: 22px; height: 22px; }
  .count-badge { position: absolute; top: 0; right: 6px; height: 17px; min-width: 17px; font-size: 10px; }
  main { padding-top: 18px; }
  .hero { grid-template-columns: auto 1fr; padding: 14px; gap: 14px; }
  .hero-cover { width: 64px; height: 90px; }
  .hero-count { grid-column: 1 / -1; grid-auto-flow: column; justify-content: space-between; align-items: center; justify-items: start; }
  .filters { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px 4px; scrollbar-width: none; }
  .seg { flex-wrap: nowrap; flex: none; }
  .seg button { white-space: nowrap; }
  .days { display: flex; overflow-x: auto; margin: 0 -16px; padding: 4px 16px 8px; scroll-snap-type: x mandatory; scrollbar-width: none; }
  .day { flex: 0 0 64px; scroll-snap-align: center; }
  .ep-grid, .result-grid { grid-template-columns: 1fr; }
  .search { margin-top: 12px; max-height: calc(100vh - 24px); }
  .search-body { padding: 12px; }
  .result { position: relative; gap: 12px; padding: 10px; }
  .result-cover img { width: 64px; height: 92px; }
  .result-body { padding-right: 36px; }
  .result .follow-btn { position: absolute; top: 10px; right: 10px; width: 32px; padding: 0; justify-content: center; }
  .result .follow-btn span { display: none; }
  .next-count { font-size: 18px; }
}

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