:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #faf9f7);
  --fg: var(--tg-theme-text-color, #1e2225);
  --muted: color-mix(in srgb, var(--fg) 72%, var(--bg));
  --line: color-mix(in srgb, var(--fg) 17%, var(--bg));
  --surface: color-mix(in srgb, var(--fg) 6%, var(--bg));
  --accent: var(--tg-theme-button-color, #246059);
  --on-accent: var(--tg-theme-button-text-color, #fff);
  --ink-accent: color-mix(in srgb, var(--accent) 58%, var(--fg));
  --gap: clamp(12px, 3.5vw, 24px);
  --edge: max(var(--gap), var(--tg-content-safe-area-inset-left, 0px),
              var(--tg-content-safe-area-inset-right, 0px));
  font: 16px/1.45 system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: var(--tg-theme-bg-color, #1b2021); --fg: var(--tg-theme-text-color, #eeede6);
          --accent: var(--tg-theme-button-color, #75c2b4); --on-accent: var(--tg-theme-button-text-color, #132421); }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); scrollbar-color: var(--line) var(--bg); }
::selection { background: var(--accent); color: var(--on-accent); }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .53; }
:focus-visible { outline: 2px solid var(--ink-accent); outline-offset: 3px; }
main, #detail { width: min(100%, 960px); margin: auto; padding: 0 var(--edge) 28px; }
body.selecting main { padding-bottom: 176px; }
.toolbar {
  position: sticky;
  z-index: 1;
  top: 0;
  padding-top: max(16px, var(--tg-content-safe-area-inset-top, 0px));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.title-row, .list-options, .detail-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-size: clamp(28px, 6.6vw, 40px); line-height: 1.12; letter-spacing: -.035em; margin: 0; font-weight: 690; }
nav { display: flex; margin: 12px 0 0; gap: clamp(10px, 4vw, 28px); }
nav button {
  min-height: 44px; white-space: nowrap; padding: 0 2px;
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  font-weight: 590; font-size: .875rem;
}
nav button[aria-pressed=true] { color: var(--fg); border-bottom-color: var(--accent); }
.list-options { padding: 5px 0; min-height: 50px; font-size: .85rem; color: var(--muted); }
select { max-width: 58%; min-height: 44px; border: 0; background: var(--bg); color: var(--fg); }
.group + .group { margin-top: 25px; }
.group h2 { margin: 0 0 9px; font-size: .95rem; font-weight: 620; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px var(--gap); }
@media (min-width: 650px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start;
  padding: 0 0 10px; border: 0; background: none; text-align: left; min-width: 0; }
.cover {
  position: relative; display: block; overflow: hidden; border-radius: 12px;
  background: var(--surface); aspect-ratio: 4 / 5; isolation: isolate;
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover img[data-broken] { visibility: hidden; }
.cover-note { position: absolute; inset: auto 0 0; padding: 70px 9px 8px;
  background: linear-gradient(transparent, rgb(0 0 0 / .75)); color: white;
  font-size: .76rem; font-weight: 650; pointer-events: none; }
.cover-fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px;
  text-align: center; color: var(--muted); font-size: .84rem; }
.tile[aria-pressed=true] .cover { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile[aria-pressed=true] .cover::after { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px var(--accent); border-radius: inherit; }
.tile-check { position: absolute; z-index: 1; top: 8px; right: 8px; width: 27px; height: 27px;
  display: grid; place-items: center; border-radius: 50%; background: var(--bg); border: 1px solid var(--line); }
.tile[aria-pressed=true] .tile-check { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.tile[aria-pressed=true] .tile-check::after { content: ''; width: 5px; height: 10px;
  border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.tile-caption { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; margin-top: 6px; }
.tile-meta { display: block; font-size: .76rem; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.action, .primary { min-height: 44px; padding: 8px 11px; border-radius: 9px; font-weight: 610; }
.action { border: 1px solid var(--line); background: var(--surface); }
.action[aria-pressed=true] { border-color: var(--accent); color: var(--ink-accent); }
.primary { border: 1px solid transparent; background: var(--accent); color: var(--on-accent); }
.schedule-button { background: #6941a5; color: #fff; }
.empty { text-align: center; color: var(--muted); margin: 48px auto; max-width: 32ch; }
.selection { position: fixed; z-index: 2; inset: auto 0 0; border-top: 1px solid var(--line); background: var(--bg);
  padding: 10px var(--edge) max(14px, env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px)); }
.selection-inner { width: min(100%, 912px); margin: auto; }
.selection strong { display: block; margin-bottom: 8px; font-size: .88rem; }
.label-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.label-actions button { flex: 1 1 auto; font-size: .85rem; }
.notice { position: fixed; z-index: 3; inset: auto auto 12px 50%; transform: translateX(-50%); width: max-content;
  max-width: calc(100% - 32px); margin: 0; padding: 9px 14px; border-radius: 10px; background: var(--fg); color: var(--bg);
  font-size: .85rem; pointer-events: none; }
#detail { max-width: 640px; padding-top: max(12px, var(--tg-content-safe-area-inset-top, 0px)); }
.detail-nav { margin-bottom: 12px; }
.detail-nav span { color: var(--muted); font-size: .82rem; text-align: center; }
.stage { display: grid; place-items: center; min-height: 155px; border-radius: 12px; background: var(--surface); overflow: hidden; }
.stage img, .stage video { width: 100%; display: block; max-height: min(58vh, 600px); object-fit: contain; }
.clip-play { margin: 12px; }
.stage:has(img) { touch-action: pan-y; }
.photo-nav { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 9px 0; font-size: .84rem; }
.photo-nav button { min-width: 44px; }
.detail-meta { color: var(--muted); font-size: .86rem; margin: 14px 0; }
.caption { margin: 14px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-actions { display: grid; gap: 12px; margin-top: 15px; }
