/* ================= 配信サービス風デザイン ================= */
:root {
  --bg: #0b0b0f;
  --surface: #15151c;
  --surface-2: #1e1e27;
  --surface-3: #282834;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f5f7;
  --sub: #a1a1ad;
  --faint: #6b6b78;
  --accent: #ff5a4e;
  --accent-2: #e0246f;
  --grad: linear-gradient(135deg, #ff7a45 0%, #e0246f 100%);
  --star: #ffc83d;
  --star-off: rgba(255, 255, 255, 0.18);
  --danger: #ff5a5f;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --pad: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body { padding-bottom: calc(110px + var(--safe-bottom)); overflow-x: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus:not(:focus-visible) { outline: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* iOS で入力時に拡大されないよう 16px 以上にする */
input, select, textarea {
  font-size: 16px;
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  min-height: 46px;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s, background 0.15s;
}
textarea { resize: vertical; line-height: 1.6; min-height: 84px; }
input::placeholder, textarea::placeholder { color: var(--faint); }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--sub) 50%), linear-gradient(135deg, var(--sub) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); background-color: var(--surface-3); }
input[type="date"] { display: block; }

/* ================= ヘッダー ================= */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) var(--pad) 10px;
  background: linear-gradient(to bottom, rgba(11, 11, 15, 0.95), rgba(11, 11, 15, 0.75));
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--grad);
  box-shadow: 0 4px 14px rgba(224, 36, 111, 0.45);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; left: 11px; top: 8px;
  border-left: 9px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent;
}
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: 0.02em; }
.topbar-actions { display: flex; gap: 8px; }
.round-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
}
.round-btn svg { width: 20px; height: 20px; }
.round-btn:active { background: rgba(255, 255, 255, 0.14); }

/* ================= 看板（最近見た作品） ================= */
.hero {
  position: relative; margin: 4px var(--pad) 18px; border-radius: 20px; overflow: hidden;
  min-height: 210px; display: flex; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer;
  isolation: isolate;
}
.hero-bg {
  position: absolute; inset: -30px; z-index: -2;
  background-size: cover; background-position: center;
  filter: blur(26px) saturate(140%) brightness(0.75); transform: scale(1.1);
}
.hero::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(90deg, rgba(11, 11, 15, 0.92) 0%, rgba(11, 11, 15, 0.55) 60%, rgba(11, 11, 15, 0.25) 100%);
}
.hero-inner { display: flex; gap: 16px; padding: 18px; align-items: flex-end; width: 100%; }
.hero-poster {
  position: relative; flex: none; width: 108px; aspect-ratio: 2 / 3; border-radius: 12px; overflow: hidden;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.6); background: var(--surface-3);
}
.hero-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-poster .noart { font-size: 12px; }
.hero-text { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; color: #ffb199; text-transform: uppercase; }
.hero-title { font-size: 21px; font-weight: 800; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hero-season { font-size: 12px; color: var(--sub); margin-top: -2px; }
.hero-meta { font-size: 12px; color: var(--sub); }
.hero-syn { font-size: 12.5px; color: #d4d4dc; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }

/* ================= タブ・検索 ================= */
.tabs {
  display: flex; gap: 22px; padding: 0 var(--pad); margin-bottom: 12px;
  border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative; background: none; border: none; padding: 10px 0 12px;
  font-size: 15px; font-weight: 600; color: var(--faint); white-space: nowrap;
}
.tabs button.active { color: var(--text); }
.tabs button.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; border-radius: 3px; background: var(--grad);
}

.toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 0 var(--pad); }
.search { position: relative; display: block; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--faint); }
.search input { padding-left: 40px; border-radius: 999px; background: var(--surface); }
.toolbar select { width: auto; max-width: 9.5em; text-overflow: ellipsis; border-radius: 999px; background-color: var(--surface); font-size: 16px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 20px var(--pad) 10px; }
.section-head h2 { margin: 0; font-size: 18px; font-weight: 800; }
.section-head span { font-size: 13px; color: var(--faint); }

/* ================= ポスターの並び ================= */
.grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 12px;
  padding: 0 var(--pad);
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }

.tile { background: none; border: none; padding: 0; text-align: left; color: inherit; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.tile-art {
  position: relative; width: 100%; aspect-ratio: 2 / 3; border-radius: 12px; overflow: hidden;
  background: var(--surface-2);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45), inset 0 0 0 1px var(--line);
  transition: transform 0.18s ease;
}
.tile:active .tile-art { transform: scale(0.96); }
.tile-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-art::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 45%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent); pointer-events: none; z-index: 1;
}
.tile-rating {
  position: absolute; right: 6px; bottom: 6px; z-index: 2;
  font-size: 11.5px; font-weight: 800; color: #fff; display: flex; align-items: center; gap: 2px;
}
.tile-rating i { font-style: normal; color: var(--star); }
.tile-kind {
  position: absolute; left: 6px; top: 6px; z-index: 2;
  font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.55); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.tile-title { font-size: 13px; font-weight: 700; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.tile-sub { font-size: 11px; color: var(--faint); margin-top: -4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.art-img { position: relative; z-index: 1; }

/* 画像が無いときの表紙 */
.noart {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 10px;
  text-align: center; font-weight: 800; font-size: 13px; line-height: 1.35; color: rgba(255, 255, 255, 0.9);
  background: linear-gradient(160deg, #2b2b3a, #15151c);
  word-break: break-word;
}
.noart.k-映画 { background: linear-gradient(160deg, #24365e, #10131f); }
.noart.k-アニメ { background: linear-gradient(160deg, #5e2450, #1b1018); }
.noart.k-ドラマ { background: linear-gradient(160deg, #1f5a45, #0f1a16); }

.empty { text-align: center; color: var(--sub); margin: 40px var(--pad); }
.empty p { margin: 6px 0; font-weight: 700; color: var(--text); }
.empty .hint { font-weight: 400; color: var(--sub); }
.empty-mark { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; background: var(--grad); opacity: 0.85; box-shadow: 0 10px 30px rgba(224, 36, 111, 0.35); }

.fab {
  position: fixed; right: 20px; bottom: calc(22px + var(--safe-bottom)); z-index: 25;
  width: 62px; height: 62px; border-radius: 50%; border: none; color: #fff;
  background: var(--grad);
  box-shadow: 0 10px 28px rgba(224, 36, 111, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }
.fab svg { width: 28px; height: 28px; stroke-width: 2.6; }

/* ================= 星 ================= */
.stars { display: inline-flex; gap: 2px; line-height: 1; vertical-align: middle; }
.star {
  font-size: 14px;
  background: linear-gradient(90deg, var(--star) var(--fill, 0%), var(--star-off) var(--fill, 0%));
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.stars-input { gap: 8px; margin: 4px 0 0; touch-action: manipulation; }
.stars-input .star { font-size: 40px; user-select: none; -webkit-user-select: none; }
.rating-num { font-size: 13px; font-weight: 800; color: var(--star); margin-left: 6px; vertical-align: middle; }

/* ================= 下から出る画面（共通） ================= */
dialog.sheet {
  width: 100%; max-width: 680px; height: 100%; max-height: 100%;
  margin: 0 auto; padding: 0; border: none; overflow-x: hidden;
  background: var(--bg); color: var(--text);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.7); }
dialog.sheet[open] { animation: up 0.26s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes up { from { transform: translateY(36px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet-head {
  position: sticky; top: 0; z-index: 3;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: rgba(11, 11, 15, 0.86); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 800; }
.sheet-head > :last-child { justify-self: end; }
.sheet-head > :first-child { justify-self: start; }
.sheet-body { padding: 16px var(--pad) calc(48px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 6px; }
.sheet-body h3 { margin: 0 0 6px; font-size: 15px; font-weight: 800; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; }

.link-btn { background: none; border: none; color: var(--sub); padding: 6px 4px; font-size: 16px; }
.link-btn.strong { color: var(--accent); font-weight: 800; }

.field-label { display: block; margin-top: 14px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; color: var(--sub); }
.hint { margin: 2px 0; font-size: 12px; color: var(--faint); }

.row { display: flex; gap: 8px; align-items: stretch; }
.row input { flex: 1; min-width: 0; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; white-space: nowrap;
  background: var(--grad); color: #fff; border: none; font-weight: 800;
  box-shadow: 0 6px 16px rgba(224, 36, 111, 0.3);
}
.btn:active { filter: brightness(0.92); }
.btn-ghost { background: rgba(255, 255, 255, 0.06); color: var(--text); border: 1px solid var(--line-strong); font-weight: 600; box-shadow: none; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(255, 90, 95, 0.5); box-shadow: none; margin-top: 30px; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: 0.5; }

/* 写真で調べる（大きなボタン） */
.photo-drop {
  display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 16px; cursor: pointer;
  background: linear-gradient(135deg, rgba(255, 122, 69, 0.16), rgba(224, 36, 111, 0.16));
  border: 1.5px dashed rgba(255, 122, 69, 0.55);
}
.photo-drop svg { flex: none; width: 34px; height: 34px; color: #ff9a76; }
.photo-drop span { display: flex; flex-direction: column; }
.photo-drop b { font-size: 16px; }
.photo-drop small { font-size: 12px; color: var(--sub); }
.photo-drop:has(input:disabled) { opacity: 0.5; }
.or { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12px; margin: 4px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.status { margin: 4px 0 0; font-size: 13px; color: var(--sub); }
.status.busy::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px;
  border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status.error { color: var(--danger); }

.candidates { display: flex; flex-direction: column; gap: 8px; }
.cand {
  display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: start;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 8px;
  text-align: left; width: 100%;
}
.cand:active { border-color: var(--accent); }
.cand-art { position: relative; width: 56px; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden; background: var(--surface-3); }
.cand-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cand-art .noart { font-size: 9px; padding: 4px; }
.cand-title { font-weight: 800; font-size: 15px; line-height: 1.3; }
.cand-sub { font-size: 12px; color: var(--sub); }
.cand-ov { font-size: 12px; color: var(--faint); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ai-tag { color: #ff9a76; font-weight: 800; }

.poster-edit { display: flex; gap: 14px; align-items: flex-end; margin-top: 6px; }
.poster-box {
  position: relative; width: 100px; aspect-ratio: 2 / 3; border-radius: 12px; overflow: hidden; flex: none;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  color: var(--faint); font-size: 12px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}
.poster-box img { width: 100%; height: 100%; object-fit: cover; }
.poster-actions { display: flex; flex-direction: column; gap: 8px; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 12px; padding: 4px; border: 1px solid var(--line); }
.segmented label { position: relative; overflow: hidden; }
.segmented input { position: absolute; inset: 0; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 9px 0; border-radius: 9px; color: var(--sub); font-weight: 600; transition: background 0.15s; }
.segmented input:checked + span { background: var(--grad); color: #fff; font-weight: 800; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 6px; }
.chip {
  border: 1px solid var(--line-strong); background: transparent; color: var(--sub);
  border-radius: 999px; padding: 6px 13px; font-size: 13.5px;
}
.chip.on { background: rgba(255, 90, 78, 0.16); color: #fff; border-color: var(--accent); }

.service-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.service-list li {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-2); border-radius: 12px; padding: 10px 14px;
}
.service-list button { background: none; border: none; color: var(--danger); font-size: 14px; }

.about p { font-size: 13px; color: var(--sub); margin: 4px 0; }
.tmdb-logo { display: inline-block; margin: 2px 0 4px; color: var(--text); }

/* ================= 作品の詳細 ================= */
dialog.detail { background: var(--bg); }
.d-hero { position: relative; isolation: isolate; padding: calc(var(--safe-top) + 64px) var(--pad) 22px; display: flex; justify-content: center; overflow: hidden; }
.d-bg {
  position: absolute; inset: -40px; z-index: -2; background-size: cover; background-position: center;
  filter: blur(34px) saturate(150%) brightness(0.7); transform: scale(1.15);
}
.d-hero::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(to bottom, rgba(11, 11, 15, 0.2) 0%, rgba(11, 11, 15, 0.55) 55%, var(--bg) 100%); }
.d-poster {
  position: relative; width: min(54vw, 230px); aspect-ratio: 2 / 3; border-radius: 16px; overflow: hidden;
  background: var(--surface-2); box-shadow: 0 24px 50px rgba(0, 0, 0, 0.65), inset 0 0 0 1px var(--line);
}
.d-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.d-poster .noart { font-size: 18px; padding: 16px; }
.d-close {
  position: absolute; z-index: 2; left: 14px; top: calc(var(--safe-top) + 12px);
}
.d-edit-top { position: absolute; z-index: 2; right: 14px; top: calc(var(--safe-top) + 12px); width: auto; padding: 0 16px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.d-body { padding: 0 var(--pad) calc(48px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 10px; }
.d-tags { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.tag { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); color: #ddd; }
.tag.kind { background: var(--grad); color: #fff; }
.d-title { margin: 2px 0 0; font-size: 24px; font-weight: 900; line-height: 1.3; text-align: center; }
.d-season { text-align: center; color: var(--sub); font-size: 14px; margin-top: -6px; }
.d-rating { text-align: center; }
.d-rating .star { font-size: 24px; }
.d-rating .rating-num { font-size: 18px; }
.d-info { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.d-info div { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.d-info small { display: block; font-size: 11px; color: var(--faint); font-weight: 700; letter-spacing: 0.04em; }
.d-info b { font-size: 15px; }
.d-section h3 { margin: 12px 0 6px; font-size: 15px; font-weight: 800; }
.d-syn { margin: 0; color: #d6d6de; font-size: 14.5px; line-height: 1.8; }
.d-genres { display: flex; flex-wrap: wrap; gap: 6px; }

/* ================= 集計 ================= */
.stat-big { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat-box { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.stat-box b { display: block; font-size: 30px; font-weight: 900; line-height: 1.15; }
.stat-box.accent b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat-box span { font-size: 12px; color: var(--sub); }
.stat-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.stat-table td { padding: 8px 2px; border-bottom: 1px solid var(--line); }
.stat-table tr:last-child td { border-bottom: none; }
.stat-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-bottom)); transform: translateX(-50%);
  background: rgba(30, 30, 39, 0.95); border: 1px solid var(--line-strong); color: #fff;
  padding: 11px 20px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 50;
  max-width: 90vw; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
