/* ============================================================
   ABEMA 無料作品リスト — design system
   Tokens → base → layout → components → states → responsive
   ============================================================ */

/* ---------- 1. Design tokens ---------- */
:root {
  /* color: light theme (default) */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1b1f24;
  --text-2: #57606c;
  --text-3: #626b78;
  --border: #dfe3e8;
  --border-strong: #c9cfd7;

  --accent: #e91b2c;            /* ABEMA red — badges/links/focus only */
  --accent-hover: #c81423;
  --focus-ring: rgba(233, 27, 44, 0.45);

  --free-bg: #e3f5ea;   --free-fg: #116932;   --free-line: #b5e3c6;
  --part-bg: #fdf1dc;   --part-fg: #8a5a00;   --part-line: #f0d9ab;
  --paid-bg: #eceff2;   --paid-fg: #57606c;   --paid-line: #d6dbe1;

  --danger-bg: #fdeaea; --danger-fg: #a11220;

  /* typography */
  --font-body: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI",
    "Meiryo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs-base: 16px;
  --fs-sm: 0.8125rem;   /* 13px */
  --fs-xs: 0.75rem;     /* 12px */
  --fw-bold: 700;

  /* spacing (4px grid) */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;

  /* shape & elevation */
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-2: 0 4px 14px rgba(16, 24, 40, 0.08);

  /* motion */
  --t-fast: 120ms ease;
  --t-med: 150ms ease;

  --header-h: 60px;
}

/* dark theme via OS preference */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1b1e23;
    --surface-2: #23272e;
    --text: #eceef1;
    --text-2: #a8b0bb;
    --text-3: #8f98a4;
    --border: #2c3138;
    --border-strong: #3c434c;

    --accent: #ff4d5c;          /* lightened for AA contrast on dark */
    --accent-hover: #ff707c;
    --focus-ring: rgba(255, 77, 92, 0.55);

    --free-bg: #12301d;  --free-fg: #7fd99c;  --free-line: #1f4a2d;
    --part-bg: #33270e;  --part-fg: #ecc06a;  --part-line: #4d3a15;
    --paid-bg: #262b31;  --paid-fg: #a8b0bb;  --paid-line: #363c44;

    --danger-bg: #3a1518; --danger-fg: #ff9aa2;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 4px 14px rgba(0, 0, 0, 0.5);
  }
}

/* ---------- 2. Base / reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, p, ul, fieldset { margin: 0; padding: 0; }
ul { list-style: none; }
fieldset { border: 0; min-inline-size: auto; }
img, svg { vertical-align: middle; }

a { color: var(--accent); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--accent-hover); text-decoration: underline; }

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

.container {
  width: 100%;
  max-width: 980px;
  margin-inline: auto;
  padding-inline: var(--s-4);
}

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

/* ---------- 3. Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 980px;
  margin-inline: auto;
  padding: var(--s-2) var(--s-4);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--s-4);
  flex-wrap: wrap;
}

.brand a {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s-2);
  font-size: 1.25rem;
  font-weight: var(--fw-bold);
  letter-spacing: 0.02em;
  color: var(--accent);
}
.brand a:hover { text-decoration: none; }
.brand-sub {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: var(--text);
}

.search-box {
  position: relative;
  flex: 1 1 240px;
  min-width: 200px;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: var(--s-3);
  color: var(--text-3);
  pointer-events: none;
}

#q {
  width: 100%;
  min-height: 44px;
  padding: 0 40px 0 38px;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}
#q::placeholder { color: var(--text-3); }
#q:hover { border-color: var(--border-strong); }
#q:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
#q::-webkit-search-cancel-button { display: none; }

.clear-btn {
  position: absolute;
  right: var(--s-2);
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  color: var(--text-3);
  background: none;
  border: 0;
  border-radius: 50%;
  transition: color var(--t-fast), background var(--t-fast);
}
.clear-btn:hover { color: var(--text); background: var(--surface-2); }

/* ---------- 4. Filters ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
  padding-block: var(--s-4) var(--s-2);
}

.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg label { position: relative; display: inline-flex; }
.seg input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.seg span {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  min-height: 44px;
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-2);
  border-radius: 999px;
  transition: background var(--t-fast), color var(--t-fast);
}
.seg input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}
.seg input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.seg input:hover:not(:checked) + span { color: var(--text); }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
  margin-left: auto;
}

.select-wrap {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}
.lbl { font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; }

select {
  min-height: 44px;
  padding: 0 var(--s-6) 0 var(--s-3);
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--text);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a93a0' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right var(--s-2) center / 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
select:hover { border-color: var(--border-strong); }
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.check-wrap {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 44px;
  font-size: var(--fs-sm);
  cursor: pointer;
  user-select: none;
}
.check-wrap input {
  width: 18px; height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- 5. Results head ---------- */
.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding-block: var(--s-2) var(--s-3);
}
#result-count { font-size: var(--fs-sm); color: var(--text-2); }
#result-count strong { color: var(--text); font-size: 1rem; }

.btn-reset {
  min-height: 44px;
  padding: 0 var(--s-4);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 1px solid currentColor;
  border-radius: 999px;
  transition: background var(--t-fast), color var(--t-fast);
}
.btn-reset:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- 6. Work list rows ---------- */
.work-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding-bottom: var(--s-4);
}

.work {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.work:hover { border-color: var(--border-strong); box-shadow: var(--shadow-2); }
.work.is-open { border-color: var(--accent); }

.work-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  cursor: pointer;
  border-radius: var(--radius);
}
.work-row:focus-visible { outline-offset: -2px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  line-height: 1.7;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: 999px;
}
.badge--all_free  { background: var(--free-bg); color: var(--free-fg); border-color: var(--free-line); }
.badge--partial_free { background: var(--part-bg); color: var(--part-fg); border-color: var(--part-line); }
.badge--paid      { background: var(--paid-bg); color: var(--paid-fg); border-color: var(--paid-line); }

.w-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.w-title {
  font-weight: var(--fw-bold);
  font-size: 0.9375rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.w-title a { color: var(--text); }
.w-title a:hover { color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: var(--s-1); }
.chip {
  font-size: var(--fs-xs);
  color: var(--text-2);
  background: var(--surface-2);
  padding: 0 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip--more { background: none; color: var(--text-3); padding-inline: 2px; }

.w-counts {
  font-size: var(--fs-sm);
  color: var(--text-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.w-deadline {
  font-size: var(--fs-sm);
  color: var(--text-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}
.w-deadline .dl-past { color: var(--text-3); }
.mini-badge {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: var(--danger-fg);
  background: var(--danger-bg);
  padding: 0 6px;
  border-radius: 999px;
  line-height: 1.7;
}

.chevron {
  color: var(--text-3);
  transition: transform var(--t-med);
  flex-shrink: 0;
}
.work.is-open .chevron { transform: rotate(180deg); }

/* episode panel */
.ep-panel {
  border-top: 1px dashed var(--border);
  padding: var(--s-3) var(--s-4) var(--s-4);
}
.ep-scroll { overflow-x: auto; }

.ep-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.ep-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-3);
  padding: var(--s-1) var(--s-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ep-table td {
  padding: var(--s-2);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.ep-table tr:last-child td { border-bottom: 0; }
.ep-table .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap; }
.ep-table .ep-season { color: var(--text-2); white-space: nowrap; }
.ep-table .ep-title { min-width: 220px; overflow-wrap: anywhere; }
.ep-table .ep-free { white-space: nowrap; }
.ep-table .ep-end { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-2); }
.ep-table .is-past { color: var(--text-3); }

.badge-free {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: var(--free-fg);
  background: var(--free-bg);
  border: 1px solid var(--free-line);
  padding: 0 8px;
  border-radius: 999px;
  line-height: 1.7;
}
.ep-dash { color: var(--text-3); }

.spinner {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  padding: var(--s-2) 0;
}
.spinner::before {
  content: "";
  width: 16px; height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 7. States / misc ---------- */
.sentinel { height: 1px; }

.more-wrap { display: flex; justify-content: center; padding-block: var(--s-2) var(--s-6); }
.btn-more {
  min-height: 44px;
  padding: 0 var(--s-8);
  font-weight: var(--fw-bold);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.btn-more:hover { background: var(--surface-2); }

.state-box {
  text-align: center;
  padding: var(--s-10) var(--s-4);
  color: var(--text-2);
}
.state-title { font-size: 1.0625rem; font-weight: var(--fw-bold); color: var(--text); }
.state-sub { margin-top: var(--s-2); font-size: var(--fs-sm); }
.state-error .state-title { color: var(--danger-fg); }
.btn-retry {
  margin-top: var(--s-4);
  min-height: 44px;
  padding: 0 var(--s-6);
  font-weight: var(--fw-bold);
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  transition: background var(--t-fast);
}
.btn-retry:hover { background: var(--accent-hover); }

.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.site-footer p {
  padding-block: var(--s-4);
  font-size: var(--fs-xs);
  color: var(--text-3);
  line-height: 1.8;
}

/* ---------- 8. Responsive (<640px: cards) ---------- */
@media (max-width: 639px) {
  .header-inner { gap: var(--s-2); padding-block: var(--s-2); }
  .brand a { font-size: 1.125rem; }

  .filters { flex-direction: column; align-items: stretch; gap: var(--s-2); }
  .seg { width: 100%; justify-content: flex-start; }
  .filter-row { margin-left: 0; justify-content: space-between; gap: var(--s-2); }
  .sort-wrap { margin-left: auto; }

  .work-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "badge chev"
      "main  main"
      "meta  meta";
    row-gap: var(--s-2);
    padding: var(--s-3);
  }
  .work .badge { grid-area: badge; justify-self: start; }
  .work .w-main { grid-area: main; }
  .work .w-meta { grid-area: meta; display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-2) var(--s-4); }
  .work .chevron { grid-area: chev; }

  .w-deadline { white-space: normal; }
  .ep-panel { padding: var(--s-3); }
}

/* desktop: meta cells inline (counts + deadline share a row cell group) */
@media (min-width: 640px) {
  .w-meta { display: contents; }
}
