:root {
  --bg: #0f1115;
  --bg-raised: #161922;
  --bg-input: #1c202b;
  --line: #262b38;
  --text: #e8eaf0;
  --text-dim: #9aa2b4;
  --text-faint: #626b80;
  --accent: #e0b063;
  --danger: #e06b6b;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

/* .sheet や .gate に display を指定しているので、hidden 属性を明示的に勝たせる */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.faint { color: var(--text-faint); font-size: 12px; }

/* ===== 合言葉 ===== */
.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
}
.gate-inner { width: min(340px, 100%); text-align: center; }
.gate-mark {
  width: 52px; height: 52px; margin: 0 auto 20px;
  border: 2px solid var(--accent); border-radius: 8px;
  position: relative;
}
.gate-mark::before, .gate-mark::after {
  content: ""; position: absolute; top: 6px; bottom: 6px; width: 7px;
  background-image: linear-gradient(var(--accent) 50%, transparent 50%);
  background-size: 100% 12px;
}
.gate-mark::before { left: 5px; }
.gate-mark::after { right: 5px; }
.gate-title { margin: 0; font-size: 30px; letter-spacing: .22em; font-weight: 500; }
.gate-sub { margin: 8px 0 28px; color: var(--text-faint); font-size: 13px; }
.gate-form { display: flex; flex-direction: column; gap: 10px; }
.gate-form input {
  padding: 14px 16px; background: var(--bg-input);
  border: 1px solid var(--line); border-radius: var(--radius);
  text-align: center; letter-spacing: .1em;
}
.gate-form input:focus { outline: none; border-color: var(--accent); }
.gate-form button {
  padding: 14px; border-radius: var(--radius);
  background: var(--accent); color: #17171a; font-weight: 700;
}
.gate-error { color: var(--danger); font-size: 13px; min-height: 1.2em; margin: 12px 0 0; }

/* ===== 上のバー ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 12px) 16px 12px;
  background: rgba(15, 17, 21, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; }
.brand { margin: 0; font-size: 19px; letter-spacing: .2em; font-weight: 500; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  color: var(--text-dim); border-radius: 8px;
}
.icon-btn:active { background: var(--bg-raised); }

.searchbar { position: relative; margin-top: 10px; }
.searchbar-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); width: 17px; height: 17px;
}
.searchbar input {
  width: 100%; padding: 10px 34px; -webkit-appearance: none;
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: 10px; font-size: 15px;
}
.searchbar input:focus { outline: none; border-color: #39405280; }
.searchbar input::-webkit-search-cancel-button { display: none; }
.searchbar-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; color: var(--text-faint); font-size: 18px;
}

.shelf-meta { padding: 14px 16px 4px; color: var(--text-faint); font-size: 12px; max-width: 720px; margin: 0 auto; }

/* ===== 棚（ポスターが主役の並び） ===== */
.list {
  display: grid; gap: 18px 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));   /* スマホは2列 */
  padding: 6px 16px calc(110px + var(--safe-b));
  max-width: 1200px; margin: 0 auto;
}
@media (min-width: 560px) { .list { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 820px) { .list { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1080px) { .list { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.tile { display: block; text-align: left; min-width: 0; }
.tile-poster {
  position: relative; width: 100%; aspect-ratio: 2/3;
  border-radius: 10px; overflow: hidden; background: var(--bg-raised);
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
  transition: transform .15s;
}
.tile:active .tile-poster { transform: scale(.97); }
.tile-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-times {
  position: absolute; top: 8px; right: 8px;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(15,17,21,.82); color: var(--accent);
  font-size: 11px; font-weight: 700; border: 1px solid #e0b06366;
}
.tile-title {
  margin-top: 8px; font-size: 13px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile-year { color: var(--text-dim); font-size: 12px; }
.tile-sub { margin-top: 3px; font-size: 11px; color: var(--text-faint); display: flex; align-items: center; gap: 4px; }
.eye { width: 13px; height: 13px; flex: none; stroke-width: 1.7; }

.poster-blank {
  width: 100%; height: 100%; display: grid; place-items: center; padding: 10px;
  color: var(--text-dim); font-size: 13px; text-align: center; line-height: 1.5;
  border: 1px dashed var(--line); border-radius: 10px;
}

/* ===== 1作品の画面 ===== */
.film-body { overflow-y: auto; padding-bottom: calc(40px + var(--safe-b)); }
.film-hero { display: flex; gap: 16px; padding: 18px 16px 16px; }
.film-poster {
  width: 42%; max-width: 220px; flex: none; aspect-ratio: 2/3;
  border-radius: 10px; overflow: hidden; background: var(--bg-raised);
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
}
.film-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.film-meta { min-width: 0; display: flex; flex-direction: column; gap: 7px; padding-top: 4px; }
.film-title { font-size: 19px; font-weight: 600; line-height: 1.4; }
.film-sub { font-size: 13px; color: var(--text-dim); line-height: 1.6; }
.film-seen { font-size: 13px; color: var(--text); line-height: 1.6; }
.card-rating { font-size: 12px; color: var(--text-faint); }
.card-rating span { margin-left: 4px; font-size: 11px; opacity: .8; }
.age { color: var(--text-dim); }
.times {
  margin-left: 8px; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; color: var(--accent); border: 1px solid #e0b06355;
}

.person-link {
  color: var(--accent); text-align: left; line-height: inherit;
  border-bottom: 1px solid #e0b06333;
}
.person-link:active { opacity: .6; }

/* アコーディオン */
.acc { border-top: 1px solid var(--line); }
.acc > summary {
  list-style: none; cursor: pointer; user-select: none;
  padding: 11px 14px; font-size: 13px; color: var(--text-dim);
  display: flex; align-items: center; justify-content: space-between;
}
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary::after {
  content: ""; width: 7px; height: 7px; margin-right: 3px;
  border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor;
  transform: rotate(45deg) translateY(-2px); transition: transform .15s;
}
.acc[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.acc-body { padding: 2px 14px 14px; }
.acc-loading { padding: 18px 16px; color: var(--text-faint); font-size: 13px; text-align: center; }

.fact { display: flex; gap: 12px; font-size: 13px; line-height: 1.75; color: var(--text-dim); padding: 2px 0; }
.fact > b { width: 58px; flex: none; color: var(--text-faint); font-weight: 400; font-size: 12px; padding-top: 1px; }
.fact > span { min-width: 0; }
.fact--block { display: block; }
.fact--block > b { display: block; width: auto; margin-bottom: 2px; }
.cast { list-style: none; margin: 0; padding: 0; }
.cast li { padding: 3px 0; font-size: 13px; }
.character { margin-left: 8px; font-size: 11.5px; color: var(--text-faint); }
.more > summary {
  list-style: none; cursor: pointer; padding: 6px 0; font-size: 12.5px; color: var(--text-faint);
}
.more > summary::-webkit-details-marker { display: none; }
.more[open] > summary { display: none; }
.overview { margin: 12px 0 0; font-size: 13.5px; line-height: 1.9; color: var(--text-dim); }

/* 見た日とメモ */
.views { list-style: none; margin: 0; padding: 0; }
.view { padding: 9px 0; border-bottom: 1px solid var(--line); }
.view:first-child { padding-top: 2px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.view-date { font-size: 13.5px; }
.view-actions { display: flex; gap: 14px; flex: none; }
.view-actions button { font-size: 12.5px; color: var(--text-dim); }
.view-actions .danger { color: var(--danger); }
.view-note { margin-top: 5px; font-size: 13px; line-height: 1.75; color: var(--text-dim); white-space: pre-wrap; }
.view-note--empty { color: var(--text-faint); font-size: 12px; }
.add-view {
  margin-top: 12px; width: 100%; padding: 10px;
  border: 1px dashed #e0b06366; border-radius: 9px;
  color: var(--accent); font-size: 13.5px;
}

.empty { padding: 60px 32px; text-align: center; color: var(--text-faint); font-size: 14px; line-height: 1.9; }

.fab {
  position: fixed; right: 18px; bottom: calc(20px + var(--safe-b)); z-index: 30;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #17171a;
  display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }
.fab:active { transform: scale(.94); }

/* ===== シート ===== */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; }
.sheet-panel {
  width: 100%; max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--line);
  animation: rise .22s ease-out;
}
.sheet-panel--full { height: 100%; max-height: 100%; border-radius: 0; }
@keyframes rise { from { transform: translateY(16px); opacity: .6; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 12px) 14px 12px;
  border-bottom: 1px solid var(--line); flex: none;
}
.sheet-title { font-size: 14px; color: var(--text-dim); text-align: center; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-close, .sheet-action { font-size: 15px; color: var(--text-dim); padding: 4px 2px; min-width: 52px; }
.sheet-action { text-align: right; }
.sheet-close { text-align: left; }
.sheet-action--primary { color: var(--accent); font-weight: 700; }

.sheet-searchbar { padding: 12px 14px; flex: none; }
.sheet-searchbar input {
  width: 100%; padding: 13px 14px; -webkit-appearance: none;
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: 10px; font-size: 16px;
}
.sheet-searchbar input:focus { outline: none; border-color: var(--accent); }
.sheet-status { padding: 0 16px 8px; font-size: 12px; color: var(--text-faint); min-height: 18px; }

.results { list-style: none; margin: 0; padding: 0 8px calc(24px + var(--safe-b)); overflow-y: auto; }
.result {
  display: flex; gap: 12px; align-items: center; width: 100%;
  padding: 8px; border-radius: 10px; text-align: left;
}
.result:active { background: var(--bg-raised); }
.result img, .result .noposter {
  width: 46px; height: 69px; flex: none; border-radius: 5px;
  object-fit: cover; background: var(--bg-raised);
}
.result-title { font-size: 15px; line-height: 1.35; }
.result-sub { margin-top: 3px; font-size: 12px; color: var(--text-faint); }
.result-done { margin-left: auto; flex: none; font-size: 11px; color: var(--accent); }

/* ===== 記録 ===== */
.record-body { padding: 18px 16px calc(28px + var(--safe-b)); overflow-y: auto; }
.record-head { display: flex; gap: 14px; align-items: flex-start; }
.record-poster { width: 62px; border-radius: 6px; flex: none; }
.record-title { font-size: 18px; line-height: 1.4; font-weight: 600; }
.record-sub { margin-top: 5px; font-size: 12.5px; color: var(--text-faint); line-height: 1.6; }

.manual-fields { margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.manual-fields label, .watched-row { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-dim); }
.manual-row { display: flex; gap: 12px; }
.manual-row label { flex: 1; min-width: 0; }
.manual-fields input, .watched-row input {
  width: 100%;
  padding: 11px 12px; background: var(--bg-input); -webkit-appearance: none;
  border: 1px solid var(--line); border-radius: 9px; font-size: 16px; color: var(--text);
  min-height: 46px;
}
.manual-fields input:focus, .watched-row input:focus { outline: none; border-color: var(--accent); }
.watched-row { margin-top: 20px; }
.record-age { margin-top: 6px; font-size: 12px; color: var(--text-faint); min-height: 1.2em; }

.note-input {
  width: 100%; margin-top: 14px; padding: 13px 14px; resize: vertical;
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: 10px; font-size: 16px; line-height: 1.7;
}
.note-input:focus { outline: none; border-color: var(--accent); }

/* ===== 人物 ===== */
.person-body { overflow-y: auto; padding: 0 16px calc(40px + var(--safe-b)); }
.person-hero { display: flex; gap: 14px; align-items: center; padding: 18px 0 6px; }
.person-hero img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex: none; }
.person-name { font-size: 20px; font-weight: 600; }
.role { padding-top: 18px; }
.role h3 {
  margin: 0 0 4px; font-size: 15px; font-weight: 600;
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.role h3 span { font-size: 12px; font-weight: 400; color: var(--accent); }
.role-sub { margin: 12px 0 4px; font-size: 11px; letter-spacing: .1em; color: var(--text-faint); }
.pfs { list-style: none; margin: 0; padding: 0; }
.pf { display: flex; gap: 12px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); }
.pf img, .pf .noposter { width: 38px; height: 57px; border-radius: 4px; object-fit: cover; flex: none; background: var(--bg-raised); }
.pf-info { min-width: 0; flex: 1; }
.pf-title { font-size: 14px; line-height: 1.4; }
.pf-title .faint { margin-left: 4px; }
.pf-character { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }
.pf-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.upcoming { color: var(--accent); }
.pf-record {
  flex: none; padding: 6px 12px; border-radius: 999px;
  border: 1px solid #e0b06366; color: var(--accent); font-size: 12.5px;
}

/* ===== よく見る人 ===== */
.tabs { display: flex; gap: 6px; padding: 12px 14px 4px; flex: none; }
.tab {
  flex: 1; padding: 8px 0; border-radius: 999px; font-size: 13.5px;
  color: var(--text-dim); background: var(--bg-input); border: 1px solid var(--line);
}
.tab.on { background: var(--accent); color: #17171a; border-color: var(--accent); font-weight: 700; }
.ranking-body { overflow-y: auto; padding: 6px 16px calc(40px + var(--safe-b)); }
.rank { list-style: none; margin: 0; padding: 0; }
.rank-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 2px; border-bottom: 1px solid var(--line); color: var(--text);
}
.rank-no { width: 28px; flex: none; text-align: right; color: var(--text-faint); font-size: 13px; }
.rank-name { flex: 1; min-width: 0; font-size: 14.5px; }
.rank-n { flex: none; color: var(--accent); font-size: 13px; }

/* ===== 設定とこのアプリ ===== */
.about-body { overflow-y: auto; padding: 26px 20px calc(40px + var(--safe-b)); }
.about-lead { margin: 0 0 6px; font-size: 15px; line-height: 2; color: var(--text-dim); }
.setting .watched-row { margin-top: 18px; }
.mine-save { margin-top: 12px; padding: 9px 20px; background: var(--accent); color: #17171a; border-radius: 999px; font-weight: 700; font-size: 13px; }
.about-link { display: inline-block; color: var(--accent); font-size: 14px; text-decoration: none; border-bottom: 1px solid currentColor; padding-bottom: 2px; }
.about-note { margin: 10px 0 0; font-size: 12px; color: var(--text-faint); line-height: 1.8; }
.about-body hr { margin: 28px 0; border: none; border-top: 1px solid var(--line); }
.attribution { color: var(--text-faint); font-size: 11.5px; line-height: 1.8; }
.attribution p { margin: 0 0 6px; }
.tmdb-logo { width: 96px; margin-bottom: 12px; display: block; }
.tmdb-fallback { display: block; margin-bottom: 10px; font-size: 11px; letter-spacing: .18em; color: var(--text-dim); }

/* ===== トースト ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  z-index: 90; padding: 11px 20px; border-radius: 999px;
  background: #e8eaf0; color: #14161c; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 6px 22px rgba(0,0,0,.45);
  animation: rise .2s ease-out;
}
