/* 画像まとめ保存 — 写真を見る画面なので暗い配色に固定。強調色は青1色（選択・主ボタンだけ）。 */
:root {
  color-scheme: dark;
  --bg: #0d0f12;
  --surface: #16191e;
  --surface-2: #1f232a;
  --line: #2d323b;
  --text: #f3f5f8;
  --text-2: #b3bac5;
  --text-3: #8a929e;
  --accent: #3b82f6;
  --accent-press: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --danger: #f87171;
  --ok: #4ade80;

  --fs-xs: 12px;
  --fs-s: 14px;
  --fs-m: 16px;
  --fs-l: 20px;
  --fs-xl: 28px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  --r-s: 6px;
  --r-m: 10px;
  --r-full: 999px;

  --t-fast: 140ms;
  --t-mid: 240ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: var(--fs-m);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100svh;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 var(--sp-4); }

/* ---- 上の帯 ---- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) 0 var(--sp-2);
}
.top h1 { font-size: var(--fs-l); margin: 0; letter-spacing: 0.02em; font-weight: 700; }
.top h1 small { display: block; font-size: var(--fs-xs); color: var(--text-3); font-weight: 400; letter-spacing: 0; }

/* ---- ボタン ---- */
.btn {
  min-height: var(--tap); padding: 0 var(--sp-4);
  border-radius: var(--r-m); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
  font-size: var(--fs-s); font-weight: 600; white-space: nowrap;
  transition: transform var(--t-fast) var(--ease-spring), background var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out), opacity var(--t-fast);
}
.btn:hover { border-color: #3d4450; }
.btn:active { transform: scale(0.96); }
.btn:focus-visible, .chk:focus-visible, .thumb:focus-visible, input:focus-visible, .link:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-press); border-color: var(--accent-press); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 54px; font-size: var(--fs-m); border-radius: var(--r-m); width: 100%; }
.link {
  background: none; border: 0; padding: 0 var(--sp-1); min-height: var(--tap);
  color: var(--accent); font-size: var(--fs-s); font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
.link:active { opacity: 0.6; }

/* ---- URL 入力 ---- */
.search { display: grid; grid-template-columns: 1fr auto; gap: var(--sp-2); margin: var(--sp-2) 0 var(--sp-3); }
.search input {
  grid-column: 1 / 2; min-width: 0;
  height: 50px; padding: 0 var(--sp-3);
  border-radius: var(--r-m); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: var(--fs-m);
}
.search input::placeholder { color: var(--text-3); }
.search .go { grid-column: 1 / -1; }

/* ---- 進み具合 ---- */
.status { margin: var(--sp-3) 0; }
.status p { margin: 0 0 var(--sp-2); font-size: var(--fs-s); color: var(--text-2); }
.bar { height: 6px; background: var(--surface-2); border-radius: var(--r-full); overflow: hidden; position: relative; }
.bar i {
  position: absolute; inset: 0 auto 0 0; width: 0%;
  background: var(--accent); border-radius: inherit;
  transition: width var(--t-mid) var(--ease-out);
}
.bar.indeterminate i { width: 35%; animation: slide 1.1s var(--ease-out) infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

/* ---- 結果のまとめ ---- */
.summary { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-3); font-size: var(--fs-s); color: var(--text-2); margin: var(--sp-2) 0; }
.summary b { color: var(--text); font-size: var(--fs-m); }
.pagetitle { font-size: var(--fs-xs); color: var(--text-3); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tools { display: flex; align-items: center; gap: var(--sp-2); margin: var(--sp-2) 0; }
.tools .count { margin-left: auto; font-size: var(--fs-s); color: var(--text-2); }
.tools .count b { color: var(--text); font-variant-numeric: tabular-nums; }
.tools .btn { min-height: 38px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }

/* ---- スワイプで見る ---- */
.stage { position: relative; margin: 0 calc(var(--sp-4) * -1); }
.track {
  display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
  height: min(60svh, 620px);
  background: #08090b;
}
.track::-webkit-scrollbar { display: none; }
.slide {
  flex: 0 0 100%; height: 100%; position: relative;
  scroll-snap-align: center; scroll-snap-stop: always;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.slide img {
  max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain;
  display: block; -webkit-user-drag: none; user-select: none; -webkit-touch-callout: none;
  transition: opacity var(--t-mid) var(--ease-out), filter var(--t-mid) var(--ease-out), transform var(--t-mid) var(--ease-out);
}
.slide .ph { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.slide.off img { opacity: 0.3; filter: grayscale(0.7); transform: scale(0.94); }
.slide .offlabel {
  position: absolute; left: 50%; bottom: var(--sp-4); transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.72); color: var(--text); font-size: var(--fs-s); font-weight: 600;
  padding: var(--sp-1) var(--sp-3); border-radius: var(--r-full); pointer-events: none;
  opacity: 0; transition: opacity var(--t-mid) var(--ease-out);
}
.slide.off .offlabel { opacity: 1; }

/* チェック（保存する／しない） */
.chk {
  position: absolute; top: var(--sp-3); right: var(--sp-3);
  width: 56px; height: 56px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.9); background: rgba(0, 0, 0, 0.45);
  display: grid; place-items: center; padding: 0;
  transition: transform var(--t-fast) var(--ease-spring), background var(--t-fast) var(--ease-out), border-color var(--t-fast);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.chk svg { width: 28px; height: 28px; opacity: 0; transform: scale(0.4); transition: opacity var(--t-fast), transform var(--t-mid) var(--ease-spring); }
.chk[aria-pressed="true"] { background: var(--accent); border-color: #fff; }
.chk[aria-pressed="true"] svg { opacity: 1; transform: scale(1); }
.chk:active { transform: scale(0.88); }

/* 左右の送りボタン（PC 用） */
.nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 64px; border: 0; border-radius: var(--r-s);
  background: rgba(0, 0, 0, 0.45); color: #fff; font-size: 24px; line-height: 1;
  display: none;
}
.nav.prev { left: var(--sp-2); }
.nav.next { right: var(--sp-2); }
@media (hover: hover) and (pointer: fine) { .nav { display: block; } .nav:hover { background: rgba(0, 0, 0, 0.7); } }

.meta { display: flex; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-3); margin: var(--sp-2) 0; font-variant-numeric: tabular-nums; }
.meta .pos { color: var(--text); font-size: var(--fs-s); font-weight: 700; }
.meta .alt { flex: 1; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 下の小さな一覧 */
.strip {
  display: flex; gap: 6px; overflow-x: auto; padding: var(--sp-1) 0 var(--sp-3);
  scrollbar-width: thin; scroll-padding: 0 40%;
}
.thumb {
  flex: 0 0 auto; width: 58px; height: 58px; padding: 0; border: 2px solid transparent;
  border-radius: var(--r-s); background: var(--surface-2); position: relative; overflow: hidden;
  transition: transform var(--t-fast) var(--ease-spring), border-color var(--t-fast), opacity var(--t-fast);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.cur { border-color: var(--accent); }
.thumb.off img { opacity: 0.28; filter: grayscale(0.8); }
.thumb .dot {
  position: absolute; right: 3px; bottom: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; display: grid; place-items: center;
}
.thumb .dot svg { width: 9px; height: 9px; }
.thumb.off .dot { display: none; }
.thumb:active { transform: scale(0.92); }
.thumb.enter { animation: pop var(--t-mid) var(--ease-out) both; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- 空・エラー ---- */
.notice {
  margin: var(--sp-4) 0; padding: var(--sp-4); border-radius: var(--r-m);
  background: var(--surface); border: 1px solid var(--line); font-size: var(--fs-s); color: var(--text-2);
}
.notice h2 { font-size: var(--fs-m); margin: 0 0 var(--sp-1); color: var(--text); }
.notice.err { border-color: rgba(248, 113, 113, 0.5); }
.notice.err h2 { color: var(--danger); }
.notice p { margin: 0 0 var(--sp-2); }
.notice p:last-child { margin-bottom: 0; }

.intro { margin: var(--sp-5) 0; color: var(--text-2); font-size: var(--fs-s); }
.intro ol { margin: 0; padding-left: 1.4em; }
.intro li { margin: var(--sp-1) 0; }

/* ---- 下の保存の帯 ---- */
.spacer { height: 150px; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + var(--safe-b));
  background: linear-gradient(to top, rgba(13, 15, 18, 0.98) 70%, rgba(13, 15, 18, 0));
  transform: translateY(110%); transition: transform var(--t-mid) var(--ease-out);
}
.savebar.show { transform: none; }
.savebar .inner { max-width: 720px; margin: 0 auto; }
.savebar .hint { margin: var(--sp-2) 0 0; font-size: var(--fs-xs); color: var(--text-3); text-align: center; }
.savebar .alt-actions { display: flex; justify-content: center; gap: var(--sp-3); }

/* ---- 下から出る画面（除外した画像・使い方） ---- */
.sheet-back {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.6);
  opacity: 0; transition: opacity var(--t-mid) var(--ease-out);
}
.sheet-back.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 86svh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-5) + var(--safe-b));
  transform: translateY(100%); transition: transform var(--t-mid) var(--ease-out);
}
.sheet.show { transform: none; }
.sheet .inner { max-width: 720px; margin: 0 auto; }
.sheet header { display: flex; align-items: center; justify-content: space-between; position: sticky; top: calc(var(--sp-4) * -1); background: var(--surface); padding: var(--sp-2) 0; z-index: 1; }
.sheet h2 { font-size: var(--fs-l); margin: 0; }
.sheet h3 { font-size: var(--fs-s); color: var(--text-2); margin: var(--sp-4) 0 var(--sp-2); font-weight: 600; }
.sheet p, .sheet li { font-size: var(--fs-s); color: var(--text-2); }
.sheet ol, .sheet ul { padding-left: 1.3em; }
.sheet .note { font-size: var(--fs-xs); color: var(--text-3); }
.exgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.excard { background: var(--surface-2); border-radius: var(--r-s); overflow: hidden; display: flex; flex-direction: column; }
.excard .pic { aspect-ratio: 1; display: grid; place-items: center; background: #0a0b0d; }
.excard .pic img { width: 100%; height: 100%; object-fit: contain; }
.excard .pic .na { font-size: var(--fs-xs); color: var(--text-3); padding: var(--sp-2); text-align: center; }
.excard .sz { font-size: 11px; color: var(--text-3); padding: 2px var(--sp-2) 0; font-variant-numeric: tabular-nums; }
.excard .btn { min-height: 38px; border-radius: 0; border: 0; border-top: 1px solid var(--line); font-size: var(--fs-xs); }
.excard.back .btn { color: var(--ok); }

/* ---- お知らせ ---- */
.toast {
  position: fixed; left: 50%; top: calc(var(--sp-4) + env(safe-area-inset-top, 0px)); z-index: 60;
  transform: translate(-50%, -16px); opacity: 0;
  max-width: calc(100vw - 32px); width: max-content;
  background: #262b33; color: var(--text); border: 1px solid var(--line);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--r-m); font-size: var(--fs-s);
  transition: opacity var(--t-mid) var(--ease-out), transform var(--t-mid) var(--ease-out);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 保存できたときの見せ場（1つだけ） */
.done-burst { position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; pointer-events: none; }
.done-burst .ring {
  width: 120px; height: 120px; border-radius: 50%; background: var(--accent);
  display: grid; place-items: center; animation: burst 900ms var(--ease-spring) both;
  box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5);
}
.done-burst .ring svg { width: 60px; height: 60px; }
@keyframes burst {
  0% { transform: scale(0.3); opacity: 0; box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.55); }
  35% { transform: scale(1.06); opacity: 1; }
  70% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 40px rgba(59, 130, 246, 0); }
  100% { transform: scale(0.96); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .bar.indeterminate i { animation: none; width: 100%; opacity: 0.5; }
}

@media (min-width: 760px) {
  .stage { margin: 0; }
  .track { border-radius: var(--r-m); }
  .search { grid-template-columns: 1fr auto auto; }
  .search .go { grid-column: auto; }
}
