:root {
  color-scheme: dark;
  --bg: #090909;
  --panel: #111111;
  --panel-raised: #181716;
  --line: #302c29;
  --text: #f4f0ea;
  --muted: #9d9690;
  --accent: #ff573d;
  --accent-deep: #c93321;
  --focus: #ff9585;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 80% 14%, rgba(255, 87, 61, 0.08), transparent 28rem),
    var(--bg);
  color: var(--text);
}

button, select, input { font: inherit; }
button, label, select { -webkit-tap-highlight-color: transparent; }

button:focus-visible, select:focus-visible, input[type="color"]:focus-visible, .drop-zone:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.app-shell {
  width: min(1120px, calc(100% - 40px));
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 80px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 650;
  text-decoration: none;
}

.brand-mark {
  width: 22px;
  height: 16px;
  border: 2px solid var(--accent);
  box-shadow: inset 6px 0 0 transparent, inset -6px 0 0 transparent;
  position: relative;
}

.brand-mark::before, .brand-mark::after {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 2px;
  background: var(--accent);
}
.brand-mark::before { left: 4px; }
.brand-mark::after { right: 4px; }

.top-links {
  display: flex;
  align-items: center;
  gap: 18px;
}

.nav-link {
  color: var(--muted);
  font-size: 0.82rem;
  text-decoration: none;
}

.nav-link:hover { color: var(--text); }

.privacy-note { color: var(--muted); font-size: 0.82rem; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 20px clamp(36px, 7vw, 90px);
  align-items: center;
  min-height: calc(100vh - 80px);
  padding: 28px 0 20px;
}

.eyebrow {
  margin: 0 0 22px;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  letter-spacing: 0.18em;
}

h1 {
  max-width: 760px;
  margin: 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(3.2rem, 6.5vw, 6rem);
  font-weight: 400;
  line-height: 0.94;
  letter-spacing: -0.055em;
}

.lead {
  max-width: 460px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.7;
}

.control-panel {
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(20, 19, 18, 0.82);
  backdrop-filter: blur(20px);
}

.drop-zone {
  display: flex;
  min-height: 112px;
  cursor: pointer;
  border: 1px dashed #514a45;
  background: #0d0d0d;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.drop-zone:hover, .drop-zone.is-dragging {
  border-color: var(--accent);
  background: #15100f;
}
.drop-zone.is-dragging { transform: scale(0.985); }
.drop-zone input { position: absolute; opacity: 0; pointer-events: none; }
.drop-zone strong { margin-top: 8px; font-size: .92rem; }
.drop-zone > span:last-child { margin-top: 6px; color: var(--muted); font-size: 0.84rem; }

.upload-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--accent);
}
.upload-icon svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; }

.settings { display: grid; grid-template-columns: 1fr 1fr; margin: 10px 0; border-top: 1px solid var(--line); }
.setting-row {
  display: flex;
  min-width: 0;
  margin: 0;
  padding: 9px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.9rem;
}
.setting-row:nth-child(odd) { padding-left: 0; border-right: 1px solid var(--line); }
.setting-row:nth-child(even) { padding-right: 0; padding-left: 12px; }
.setting-row--full {
  grid-column: 1 / -1;
  padding-left: 0 !important;
  padding-right: 0 !important;
  border-right: 0 !important;
}

.setting-row legend { float: left; padding: 0; }
.setting-row legend + * { clear: none; }
.fit-setting { flex-wrap: wrap; gap: 8px; }
.setting-description { flex-basis: 100%; margin: 0; font-size: .72rem; line-height: 1.5; }
.playback-tip { margin: 8px 0 0; color: var(--muted); font-size: .72rem; text-align: center; line-height: 1.5; }
.setting-row.is-disabled { opacity: .42; }

.switch { position: relative; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-track {
  display: block;
  width: 46px;
  height: 26px;
  border: 1px solid #4a4541;
  border-radius: 999px;
  background: #242220;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 160ms ease, background 160ms ease;
}
.switch input:checked + .switch-track { border-color: var(--accent); background: var(--accent-deep); }
.switch input:checked + .switch-track::after { transform: translateX(20px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 3px; }

select {
  min-height: 36px;
  padding: 0 30px 0 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  appearance: none;
  background: #1a1918;
  color: var(--text);
}

.select-wrap { position: relative; }
.select-wrap::after {
  content: "⌄";
  position: absolute;
  top: 6px;
  right: 10px;
  color: var(--muted);
  pointer-events: none;
}

.segmented { display: flex; padding: 3px; background: #0b0b0b; }
.segment {
  min-height: 32px;
  padding: 0 13px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.segment.is-active { background: #292624; color: var(--text); }

.primary-button {
  display: flex;
  width: 100%;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 2px;
  align-items: center;
  justify-content: space-between;
  background: var(--accent);
  color: #170503;
  cursor: pointer;
  font-weight: 720;
  transition: background 160ms ease, transform 160ms ease;
}
.primary-button:hover:not(:disabled) { background: #ff705a; }
.primary-button:active:not(:disabled) { transform: scale(0.99); }
.primary-button:disabled { cursor: not-allowed; opacity: 0.32; }
.primary-button svg { width: 21px; fill: currentColor; }
.file-status { margin: 8px 0 0; color: var(--muted); font-size: 0.75rem; text-align: center; }

.filmstrip-section { grid-column: 1 / -1; min-width: 0; padding-top: 2px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-heading h2 { margin: 0 0 2px; font-family: Georgia, "Songti SC", serif; font-size: 1.18rem; font-weight: 400; }
.section-heading p { margin: 0 0 7px; color: var(--muted); font-size: .72rem; }
.text-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.text-button:hover { color: var(--accent); }
.filmstrip {
  position: relative;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  min-height: 142px;
  padding: 22px 10px 24px;
  border: 1px solid #493923;
  background: #241a10;
  scrollbar-color: #48423e transparent;
}
.filmstrip::before,
.filmstrip::after {
  content: "";
  position: absolute;
  z-index: 3;
  right: 0;
  left: 0;
  height: 10px;
  pointer-events: none;
  background: repeating-linear-gradient(90deg, transparent 0 8px, #050505 8px 22px, transparent 22px 30px);
}
.filmstrip::before { top: 5px; }
.filmstrip::after { bottom: 7px; }
.frame { position: relative; flex: 0 0 clamp(132px, 15vw, 176px); height: 94px; margin: 0; overflow: hidden; border: 1px solid #6c5132; background: #151515; transition: opacity 120ms, border-color 120ms, transform 120ms; }
.frame.is-dragging { opacity: .45; transform: scale(.97); }
.frame.is-drop-target { border-color: var(--accent); }
.preview-button {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.preview-button img { display: block; width: 100%; height: 100%; object-fit: cover; }
.preview-button:focus-visible { outline: 2px solid var(--focus); outline-offset: -3px; }
.frame figcaption {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 28px 38px 7px 28px;
  overflow: hidden;
  background: linear-gradient(transparent, rgba(0,0,0,.8));
  color: #fff;
  font-size: 0.68rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}
.drag-handle, .delete-frame {
  position: absolute;
  z-index: 2;
  display: grid;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  place-items: center;
  background: rgba(8,8,8,.72);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.drag-handle { left: 6px; bottom: 5px; cursor: grab; touch-action: none; font-size: 1rem; letter-spacing: -3px; }
.drag-handle:active { cursor: grabbing; }
.delete-frame { top: 6px; right: 6px; font-size: 1.05rem; }
.drag-handle:hover, .delete-frame:hover { background: var(--accent); color: #180503; }

.player {
  position: fixed;
  z-index: 100;
  inset: 0;
  overflow: hidden;
  background: var(--fill-color, #000000);
  cursor: none !important;
}
.player[hidden] { display: none; }
.player > img {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: invert(1);
  user-select: none;
  transform: translate(-50%, -50%);
}
.player > img.is-portrait {
  width: 100vh;
  height: 100vw;
  transform: translate(-50%, -50%) rotate(90deg);
}
.player > img[data-fit="cover"] { object-fit: cover; }
.player > img[data-polarity="positive"] { filter: none; }
.player > img[data-tone="mono"][data-polarity="negative"] { filter: grayscale(1) invert(1); }
.player > img[data-tone="mono"][data-polarity="positive"] { filter: grayscale(1); }
.player-shade, .player-status, .player-controls, .exit-button, .keyboard-tip { display: none !important; }
.player-status { position: absolute; top: max(24px, env(safe-area-inset-top)); left: max(24px, env(safe-area-inset-left)); display: flex; gap: 14px; align-items: center; color: rgba(255,255,255,.86); font-size: .8rem; }
#counter { color: var(--accent); font-family: ui-monospace, monospace; }
#filename { max-width: min(50vw, 420px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-controls { position: absolute; bottom: max(34px, calc(env(safe-area-inset-bottom) + 16px)); left: 50%; display: flex; gap: 11px; transform: translateX(-50%); }
.player-controls button {
  display: grid;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 50%;
  place-items: center;
  background: rgba(10,10,10,.55);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(12px);
}
.player-controls .play-toggle { width: 58px; height: 58px; margin-top: -5px; background: rgba(255,87,61,.9); border-color: transparent; color: #180503; }
.player-controls svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.player-controls .play-toggle svg { fill: currentColor; stroke: none; }
.play-icon { display: none; }
.play-toggle.is-paused .play-icon { display: block; }
.play-toggle.is-paused .pause-icon { display: none; }
.exit-button { position: absolute; top: max(20px, env(safe-area-inset-top)); right: max(20px, env(safe-area-inset-right)); min-height: 40px; padding: 0 16px; border: 1px solid rgba(255,255,255,.25); border-radius: 999px; background: rgba(0,0,0,.4); color: #fff; cursor: pointer; backdrop-filter: blur(12px); }
.keyboard-tip { position: absolute; right: max(24px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom)); margin: 0; color: rgba(255,255,255,.58); font-size: .72rem; }

@media (max-width: 760px) {
  .app-shell { width: min(100% - 28px, 560px); }
  .topbar { min-height: 56px; }
  .privacy-note, .nav-link { font-size: .72rem; }
  .top-links { gap: 12px; }
  .workspace { grid-template-columns: 1fr; gap: 13px; min-height: calc(100vh - 56px); padding: 14px 0 12px; align-content: start; }
  .eyebrow { margin-bottom: 8px; font-size: .66rem; }
  h1 { font-size: clamp(2.45rem, 10vw, 3.35rem); line-height: .9; }
  .lead { margin-top: 10px; font-size: .82rem; line-height: 1.45; }
  .control-panel { padding: 8px; }
  .drop-zone { min-height: 88px; }
  .upload-icon { width: 30px; height: 30px; }
  .upload-icon svg { width: 18px; }
  .drop-zone strong { margin-top: 5px; font-size: .82rem; }
  .drop-zone > span:last-child { margin-top: 2px; font-size: .72rem; }
  .settings { grid-template-columns: 1fr 1fr; margin: 7px 0; }
  .setting-row:nth-child(n) { padding-top: 6px; padding-bottom: 6px; font-size: .77rem; }
  .setting-row:nth-child(odd) { padding-left: 0; padding-right: 6px; border-right: 1px solid var(--line); }
  .setting-row:nth-child(even) { padding-right: 0; padding-left: 7px; }
  .segment { min-height: 28px; padding: 0 9px; }
  select { min-height: 30px; font-size: .76rem; }
  .switch { width: 40px; height: 23px; }
  .switch-track { width: 40px; height: 23px; }
  .switch-track::after { top: 3px; left: 3px; width: 15px; height: 15px; }
  .switch input:checked + .switch-track::after { transform: translateX(18px); }
  .primary-button { min-height: 40px; font-size: .82rem; }
  .file-status { margin-top: 5px; }
  .filmstrip-section { grid-column: 1; }
  .filmstrip { min-height: 116px; padding-top: 20px; padding-bottom: 21px; }
  .frame { flex-basis: 126px; height: 74px; }
  .keyboard-tip { display: none; }
}

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

.fill-setting { flex-wrap: wrap; gap: 8px; }
.fill-options { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.fill-preset, .custom-fill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.fill-preset.is-active { border-color: #655e58; background: #292624; color: var(--text); }
.color-swatch { width: 16px; height: 16px; border: 1px solid #655e58; border-radius: 50%; }
.swatch-black { background: #000; }
.swatch-white { background: #fff; }
.custom-fill:focus-within { color: var(--text); }
#fillColor { width: 26px; height: 26px; padding: 2px; border: 1px solid #655e58; border-radius: 4px; background: transparent; cursor: pointer; }
#fillColor::-webkit-color-swatch-wrapper { padding: 0; }
#fillColor::-webkit-color-swatch { border: 0; border-radius: 2px; }
#fillColor::-moz-color-swatch { border: 0; border-radius: 2px; }

kbd { display: inline-block; min-width: 20px; padding: 1px 5px; border: 1px solid #49433e; border-radius: 4px; background: #1b1917; color: var(--muted); font-family: ui-monospace, SFMono-Regular, monospace; font-size: .7rem; line-height: 1.5; text-align: center; }
.setting-row legend kbd { margin-left: 4px; }
