:root,
[data-theme="dark"] {
  --ink: #0b0b0d;
  --surface: #131316;
  --surface-elev: #1b1b1f;
  --border: #2a2a2f;
  --border-strong: #3e3e45;
  --paper: #fafafa;
  --text: #e7e7ea;
  --text-dim: #85858c;
  --text-faint: #4a4a51;
  --accent: #ff5b2e;
  --accent-dim: #b33b17;
  --input-bg: #060608;
  --code-bg: #060608;
  --header-bg: rgba(11, 11, 13, 0.82);
  --modal-bg: rgba(6, 6, 8, 0.96);
  --grain-blend: overlay;
  --grain-opacity: 0.03;
  --thumb-shadow: inset 0 0 80px rgba(0, 0, 0, 0.35);
  --duration-bg: rgba(0, 0, 0, 0.72);
  --duration-border: rgba(255, 255, 255, 0.08);
}

[data-theme="light"] {
  --ink: #ffffff;
  --surface: #f6f6f7;
  --surface-elev: #ededef;
  --border: #e4e4e6;
  --border-strong: #c6c6ca;
  --paper: #0a0a0c;
  --text: #18181b;
  --text-dim: #6a6a70;
  --text-faint: #a9a9ae;
  --accent: #d8431a;
  --accent-dim: #8f2d10;
  --input-bg: #ffffff;
  --code-bg: #0a0a0c;
  --header-bg: rgba(255, 255, 255, 0.85);
  --modal-bg: rgba(255, 255, 255, 0.96);
  --grain-blend: multiply;
  --grain-opacity: 0.015;
  --thumb-shadow: inset 0 0 40px rgba(0, 0, 0, 0.12);
  --duration-bg: rgba(0, 0, 0, 0.72);
  --duration-border: rgba(255, 255, 255, 0.14);
}

@media (prefers-color-scheme: light) {
  [data-theme="auto"] {
    --ink: #ffffff;
    --surface: #f6f6f7;
    --surface-elev: #ededef;
    --border: #e4e4e6;
    --border-strong: #c6c6ca;
    --paper: #0a0a0c;
    --text: #18181b;
    --text-dim: #6a6a70;
    --text-faint: #a9a9ae;
    --accent: #d8431a;
    --accent-dim: #8f2d10;
    --input-bg: #ffffff;
    --code-bg: #0a0a0c;
    --header-bg: rgba(255, 255, 255, 0.85);
    --modal-bg: rgba(255, 255, 255, 0.96);
    --grain-blend: multiply;
    --grain-opacity: 0.015;
    --thumb-shadow: inset 0 0 40px rgba(0, 0, 0, 0.12);
    --duration-bg: rgba(0, 0, 0, 0.72);
    --duration-border: rgba(255, 255, 255, 0.14);
  }
}

:root {
  --font-display: 'Fraunces', 'Times New Roman', serif;
  --font-body: 'Instrument Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;

  --max: 1440px;
  --pad-x: clamp(20px, 4vw, 56px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.3s ease, color 0.3s ease;
}

button, input, select, [role="button"] { touch-action: manipulation; }

/* Film grain overlay (sits under interactive layers) */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.9'/></svg>");
}

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

a { color: inherit; }

/* ——————————————————————— HEADER ——————————————————————— */
header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 18px var(--pad-x);
  display: flex;
  align-items: center;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.brand-mark {
  font-family: var(--font-display);
  font-weight: 300;
  font-style: italic;
  font-size: 22px;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 144, "SOFT" 100;
}

.brand-mark em {
  color: var(--accent);
  font-style: italic;
}

.brand-sep {
  width: 1px;
  height: 18px;
  background: var(--border-strong);
}

.brand-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}

header .spacer { flex: 1; }

header .user {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

header button.logout {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  padding: 0 0 0 18px;
  margin-left: 18px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border-left: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.2s;
}

header button.logout:hover { color: var(--accent); }
header button.logout::after { content: ' →'; opacity: 0.6; }

.theme-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  overflow: hidden;
}

.theme-switch button {
  background: transparent;
  border: 0;
  padding: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.theme-switch button + button { border-left: 1px solid var(--border); }
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
}

.theme-switch svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* count */
.count {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* collection chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 28px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 7px 14px;
  cursor: pointer;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}

.chip:hover { color: var(--text); border-color: var(--border-strong); }

.chip[aria-pressed="true"] {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
}

.chip-count {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.chip[aria-pressed="true"] .chip-count {
  color: var(--ink);
  opacity: 0.7;
}

.card-collection {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.card-collection::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--accent);
}

/* ——————————————————————— HERO ——————————————————————— */
main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 56px var(--pad-x) 120px;
}

/* ——————————————————————— TOOLBAR ——————————————————————— */
.toolbar {
  display: flex;
  gap: 32px;
  align-items: center;
  padding: 0 0 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}

.search input {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 0;
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  min-width: 280px;
  transition: border-color 0.2s;
}

.search input::placeholder {
  color: var(--text-faint);
  font-style: italic;
}

.search input:focus {
  border-color: var(--accent);
}

.search input:focus-visible,
.setting input[type="text"]:focus-visible,
.setting input[type="number"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chip:focus-visible,
.theme-switch button:focus-visible,
.modal-header .close:focus-visible,
button.btn-primary:focus-visible,
button.btn-ghost:focus-visible,
header button.logout:focus-visible,
.toggle:focus-visible,
.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ——————————————————————— GRID ——————————————————————— */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 56px 36px;
}

.card {
  position: relative;
  cursor: pointer;
  animation: rise 0.7s cubic-bezier(0.2, 0.75, 0.25, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--surface);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: border-color 0.35s, transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.card-thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: var(--thumb-shadow);
  pointer-events: none;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.35s;
  filter: saturate(0.9) contrast(1.05);
}

.card:hover .card-thumb {
  border-color: var(--accent);
}

.card:hover .card-thumb img {
  transform: scale(1.04);
  filter: saturate(1.1) contrast(1.05);
}

.card-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 12px 14px;
  pointer-events: none;
}

.card-duration {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #f4ede0;
  background: var(--duration-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 4px 8px;
  border: 1px solid var(--duration-border);
}

.card-body {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.card-title {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 15px;
  line-height: 1.35;
  letter-spacing: -0.005em;
  margin: 0 0 10px;
  color: var(--paper);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.card-meta .dot {
  color: var(--text-faint);
}

.empty, .loading {
  padding: 120px 0;
  text-align: center;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-dim);
}

.loading {
  position: relative;
}
.loading::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 40px;
  height: 1px;
  background: var(--accent);
  animation: loadbar 1.1s ease-in-out infinite alternate;
}

@keyframes loadbar {
  from { width: 14px; opacity: 0.3; }
  to { width: 60px; opacity: 1; }
}

/* ——————————————————————— DENIED ——————————————————————— */
.denied {
  padding: 120px 0;
  max-width: 520px;
}

.denied .kicker {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 20px;
}

.denied h2 {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 32px;
  line-height: 1.15;
  margin: 0 0 20px;
  color: var(--paper);
  letter-spacing: -0.02em;
}

.denied h2 em {
  font-style: normal;
  color: var(--accent);
}

.denied p {
  font-size: 15px;
  color: var(--text-dim);
  margin: 0 0 36px;
  line-height: 1.6;
}

.denied p code {
  font-family: var(--font-mono);
  color: var(--text);
  font-size: 13px;
}

/* ——————————————————————— BUTTONS ——————————————————————— */
button.btn-primary {
  background: var(--accent);
  color: var(--ink);
  border: 0;
  padding: 12px 22px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
button.btn-primary:hover { background: var(--paper); }
button.btn-primary.done { background: var(--paper); color: var(--ink); }

button.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 11px 22px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
button.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ——————————————————————— MODAL ——————————————————————— */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200;
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.modal-backdrop.open {
  display: grid;
  opacity: 1;
  grid-template-columns: 1fr 440px;
}

.modal-preview {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #000;
  position: relative;
  overflow: hidden;
}

.modal-close-mobile { display: none; }

.modal-frame {
  flex: 1;
  position: relative;
  min-height: 0;
  background: #000;
}

.modal-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.modal-frame::before {
  content: '';
  position: absolute;
  top: 20px;
  left: 24px;
  z-index: 2;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--paper);
  opacity: 0.5;
  padding-left: 16px;
  border-left: 2px solid var(--accent);
}

.modal-footer {
  background: var(--header-bg);
  border-top: 1px solid var(--border);
  padding: 20px 32px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.snippet-block {
  min-width: 0;
}

.snippet-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.snippet-label .btn-ghost {
  padding: 5px 10px;
  font-size: 9px;
  letter-spacing: 0.2em;
}
.snippet-label .btn-ghost.done { background: var(--accent); color: var(--ink); border-color: var(--accent); }

.snippet pre {
  margin: 0;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.55;
  color: #e7e7ea;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 96px;
  overflow: auto;
}

/* Settings panel */
.modal-settings {
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.modal-header {
  padding: 22px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.modal-header-title {
  flex: 1;
  min-width: 0;
}

.modal-header-kicker {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 8px;
}

.modal-header h2 {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 17px;
  line-height: 1.3;
  margin: 0;
  color: var(--paper);
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.modal-header .close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, border-color 0.2s;
  line-height: 1;
}

.modal-header .close:hover { color: var(--accent); border-color: var(--accent); }

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 28px 28px;
}

.settings-group {
  padding: 20px 0 12px;
  border-bottom: 1px solid var(--border);
}

.settings-group:last-child { border-bottom: 0; }

.settings-group-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.settings-group-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.setting {
  padding: 8px 0;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 28px;
}

.setting-row label {
  font-family: var(--font-body);
  font-size: 13px;
  flex: 1;
  cursor: pointer;
  color: var(--text);
  letter-spacing: 0;
}

.setting-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 4px;
  line-height: 1.45;
  font-style: italic;
  max-width: 90%;
}

.setting input[type="text"],
.setting input[type="number"] {
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  width: 110px;
  outline: none;
  transition: border-color 0.2s;
}
.setting input[type="text"]:focus,
.setting input[type="number"]:focus { border-color: var(--accent); }

.setting input[type="text"]::placeholder,
.setting input[type="number"]::placeholder {
  color: var(--text-faint);
}

.size-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.size-inputs input { width: 100px; }
.size-inputs .times { color: var(--text-faint); font-family: var(--font-mono); font-size: 12px; }

/* toggle */
.toggle {
  position: relative;
  width: 34px;
  height: 18px;
  appearance: none;
  background: var(--border-strong);
  border-radius: 0;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
  border: 1px solid transparent;
}

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--text-dim);
  transition: transform 0.2s, background 0.2s;
}

.toggle:checked { background: var(--accent); }
.toggle:checked::after { transform: translateX(16px); background: var(--ink); }

@media (max-width: 960px) {
  main { padding-top: 40px; padding-bottom: 80px; }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 36px 20px;
  }

  .toolbar { flex-direction: column; align-items: stretch; gap: 12px; }
  .search input { min-width: 0; width: 100%; }

  .modal-backdrop.open {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    overflow-y: auto;
  }

  .modal-preview {
    flex-shrink: 0;
  }

  .modal-frame {
    aspect-ratio: 16 / 9;
    flex: none;
    min-height: 0;
  }

  .modal-footer {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px 20px;
  }

  .modal-settings {
    border-left: 0;
    border-top: 1px solid var(--border);
    max-height: none;
    min-height: 360px;
  }

  .modal-header { padding: 18px 20px; }
  .settings-body { padding: 0 20px 24px; }
}

@media (max-width: 640px) {
  .header-inner { padding: 12px 16px; gap: 10px; }
  .brand-mark { font-size: 19px; }
  .brand-sep, .brand-meta { display: none; }

  header .user {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 10px;
  }

  header button.logout {
    padding: 6px 0 6px 12px;
    margin-left: 12px;
    font-size: 9px;
    letter-spacing: 0.18em;
  }

  .theme-switch button { width: 36px; height: 32px; }
  .theme-switch svg { width: 15px; height: 15px; }

  .grid { grid-template-columns: 1fr; gap: 28px; }

  .modal-header .close {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }

  .toggle { width: 40px; height: 22px; }
  .toggle::after { width: 16px; height: 16px; }
  .toggle:checked::after { transform: translateX(18px); }

  .setting { padding: 10px 0; }
  .setting-row { min-height: 36px; }

  .snippet pre { font-size: 12px; max-height: 120px; }

  .denied h2 { font-size: 26px; }
}

@media (max-width: 420px) {
  header .user { display: none; }
  .denied h2 { font-size: 24px; }
  .settings-group-label { font-size: 10px; }
}
