:root {
  color-scheme: dark;
  --bg: #080808;
  --panel: #121212;
  --panel-2: #191919;
  --line: rgba(255, 255, 255, 0.12);
  --muted: #a3a3a3;
  --text: #f7f7f7;
  --pink: #ff2e93;
  --pink-2: #ff63ad;
  --green: #4ade80;
  --amber: #fbbf24;
  --danger: #ff5c5c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at 50% -20%, #25121c 0, var(--bg) 42%); color: var(--text); }
button, input, textarea { font: inherit; }
button, label.upload-button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  padding: 12px clamp(16px, 4vw, 52px);
  border-bottom: 1px solid var(--line);
  background: rgba(8, 8, 8, 0.88);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand img { border-radius: 50%; }
.brand div { display: grid; gap: 2px; }
.brand span, .eyebrow { margin: 0; color: var(--pink-2); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.17em; }
.brand strong { font-size: 1.15rem; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.connection-state { color: var(--muted); font-size: 0.78rem; }

main { width: min(1420px, 100%); margin: 0 auto; padding: clamp(22px, 4vw, 54px); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(1.75rem, 4vw, 3.2rem); line-height: 1.05; letter-spacing: -0.045em; }
h2 { margin-bottom: 0; font-size: clamp(1.3rem, 3vw, 2rem); letter-spacing: -0.025em; }
p { color: var(--muted); line-height: 1.55; }

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 9px 18px;
  color: var(--text);
  background: transparent;
  font-weight: 750;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, opacity 140ms ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: 0.42; transform: none; }
.button.primary { color: #090909; background: linear-gradient(135deg, var(--pink-2), var(--pink)); }
.button.secondary { border-color: rgba(255, 46, 147, 0.65); background: rgba(255, 46, 147, 0.1); }
.button.ghost { border-color: var(--line); background: rgba(255, 255, 255, 0.035); }
.button.danger { border-color: rgba(255, 92, 92, 0.35); color: #ff8f8f; }
.button.wide { width: 100%; }

.auth-view { min-height: calc(100vh - 150px); display: grid; place-items: center; }
.auth-card { width: min(460px, 100%); padding: clamp(24px, 6vw, 50px); border: 1px solid var(--line); border-radius: 28px; background: rgba(18, 18, 18, 0.94); box-shadow: 0 30px 100px rgba(0, 0, 0, 0.45); text-align: center; }
.auth-card > img { margin-bottom: 18px; border-radius: 50%; }
.auth-card h1 { margin-top: 10px; font-size: clamp(1.7rem, 7vw, 2.5rem); }
.auth-card form { display: grid; gap: 12px; margin-top: 24px; text-align: left; }
.auth-card label { color: #ddd; font-size: 0.82rem; font-weight: 700; }
.auth-card input { width: 100%; min-height: 58px; border: 1px solid var(--line); border-radius: 15px; color: var(--text); background: #090909; font-size: 1.65rem; font-weight: 800; letter-spacing: 0.3em; text-align: center; }
.form-status { min-height: 1.5em; margin: 12px 0 0; color: var(--muted); font-size: 0.82rem; }
.form-status.error { color: #ff8f8f; }
.form-status.success { color: var(--green); }

.hero { display: flex; align-items: end; justify-content: space-between; gap: 30px; }
.hero > div:first-child { max-width: 720px; }
.hero .eyebrow { margin-bottom: 10px; }
.hero-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.upload-button input { display: none; }
.status-strip { display: flex; align-items: center; gap: 12px; margin: 28px 0 52px; padding: 14px 18px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 255, 255, 0.025); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 14px currentColor; }
.status-dot.clean { color: var(--green); background: var(--green); }
.status-dot.dirty { color: var(--amber); background: var(--amber); }
.status-strip div { display: grid; gap: 2px; }
.status-strip small { color: var(--muted); }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.section-heading .eyebrow { margin-bottom: 7px; }

.gallery-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(12px, 2vw, 22px); }
.gallery-card { overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); cursor: grab; }
.gallery-card.dragging { opacity: 0.45; }
.gallery-card.drag-target { outline: 2px solid var(--pink); outline-offset: 3px; }
.card-preview { position: relative; aspect-ratio: 16 / 10; background-color: #202020; background-position: center; background-size: cover; }
.card-preview::after { position: absolute; inset: 0; content: ""; background: linear-gradient(180deg, transparent 45%, rgba(0,0,0,.72)); }
.card-order, .card-type { position: absolute; z-index: 1; top: 12px; border-radius: 999px; padding: 6px 9px; background: rgba(0, 0, 0, 0.72); font-size: 0.68rem; font-weight: 800; }
.card-order { left: 12px; }
.card-type { right: 12px; color: var(--pink-2); }
.card-copy { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; }
.card-copy div:first-child { display: grid; min-width: 0; gap: 3px; }
.card-copy strong, .card-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-copy small { color: var(--muted); }
.card-buttons { display: flex; gap: 5px; }
.card-buttons button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; color: var(--text); background: #191919; cursor: pointer; }
.card-buttons button.edit { width: auto; border-radius: 999px; padding: 0 13px; color: var(--pink-2); }

dialog { padding: 0; border: 1px solid var(--line); color: var(--text); background: var(--panel); box-shadow: 0 40px 140px rgba(0, 0, 0, .7); }
dialog::backdrop { background: rgba(0, 0, 0, 0.78); backdrop-filter: blur(8px); }
.tile-dialog { width: min(760px, calc(100% - 24px)); border-radius: 24px; }
.tile-dialog form { padding: clamp(20px, 4vw, 34px); }
.dialog-head, .editor-head { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.dialog-head .eyebrow, .editor-head .eyebrow { margin-bottom: 7px; }
.icon-button { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: white; background: #191919; font-size: 1.65rem; cursor: pointer; }
.tile-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tile-fields label { display: grid; gap: 7px; color: #d7d7d7; font-size: .8rem; font-weight: 750; }
.tile-fields .full { grid-column: 1 / -1; }
.tile-fields input, .tile-fields textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px; color: var(--text); background: #090909; }
.dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 26px; }
.dialog-actions > div { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.video-dialog { width: min(1600px, calc(100% - 20px)); height: min(940px, calc(100% - 20px)); border-radius: 24px; }
.video-editor { min-height: 100%; padding: clamp(16px, 2.5vw, 30px); }
.editor-workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(310px, 390px); gap: 26px; }
.preview-panel { min-width: 0; }
.video-stage { position: relative; overflow: hidden; display: grid; aspect-ratio: 16/9; place-items: center; border: 1px solid var(--line); border-radius: 18px; background: #000; touch-action: none; }
.video-stage video { width: 100%; height: 100%; object-fit: contain; transform-origin: 50% 50%; transition: transform 90ms linear; }
.video-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.video-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: #050505; }
.transport { display: grid; grid-template-columns: auto auto minmax(80px, 1fr) auto; align-items: center; gap: 10px; margin-top: 14px; }
.transport span { color: #bbb; font: 700 .74rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.transport input, .zoom-control input { width: 100%; accent-color: var(--pink); }
.round-button { width: 42px; height: 42px; border: 0; border-radius: 50%; color: #090909; background: var(--pink); cursor: pointer; }
.marking-help { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; color: var(--muted); font-size: .76rem; }
.marking-help strong { color: #ddd; }
.control-panel { overflow-y: auto; max-height: 760px; padding-right: 6px; }
.control-section { padding: 18px 0; border-top: 1px solid var(--line); }
.control-section:first-child { padding-top: 0; border-top: 0; }
.control-title { display: flex; gap: 12px; align-items: start; margin-bottom: 14px; }
.control-title > span { display: grid; width: 28px; height: 28px; flex: 0 0 auto; place-items: center; border-radius: 50%; color: #090909; background: var(--pink); font-size: .75rem; font-weight: 900; }
.control-title div { display: grid; gap: 3px; }
.control-title small { color: var(--muted); line-height: 1.35; }
.time-buttons, .button-stack { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.time-buttons .button { min-width: 0; padding-inline: 12px; font-size: .78rem; }
.time-buttons span { color: var(--pink-2); font: 700 .7rem ui-monospace, monospace; }
.button-stack { grid-template-columns: 1fr; }
.zoom-control { display: grid; grid-template-columns: 1fr 60px; gap: 12px; align-items: center; }
.zoom-control output { color: var(--pink-2); font-weight: 900; text-align: right; }
.toggle { display: flex; align-items: center; gap: 9px; margin-top: 12px; color: #ccc; font-size: .82rem; }
.toggle input { accent-color: var(--pink); }
.tracking-progress { overflow: hidden; height: 5px; margin-top: 12px; border-radius: 99px; background: #272727; }
.tracking-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--pink); transition: width 100ms linear; }
.keyframe-heading { display: flex; justify-content: space-between; margin-bottom: 10px; }
.text-button { border: 0; color: var(--pink-2); background: none; cursor: pointer; }
.keyframe-list { display: grid; max-height: 170px; gap: 6px; overflow-y: auto; }
.keyframe-list p { margin: 0; font-size: .78rem; }
.keyframe-row { display: grid; grid-template-columns: 68px 1fr auto; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.04); font-size: .75rem; }
.keyframe-row button { border: 0; color: #aaa; background: none; cursor: pointer; }
.keyframe-row .source { color: var(--pink-2); }
.export-section { position: sticky; bottom: 0; padding-top: 16px; background: linear-gradient(180deg, transparent, var(--panel) 16px); }
.render-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

@media (max-width: 980px) {
  .editor-workspace { grid-template-columns: 1fr; }
  .control-panel { overflow: visible; max-height: none; }
  .video-dialog { height: calc(100% - 12px); width: calc(100% - 12px); }
  .export-section { position: static; }
}

@media (max-width: 760px) {
  .connection-state { display: none; }
  main { padding: 22px 14px 44px; }
  .hero { align-items: stretch; flex-direction: column; }
  .hero-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .gallery-grid { grid-template-columns: 1fr 1fr; }
  .tile-fields { grid-template-columns: 1fr; }
  .tile-fields .full { grid-column: auto; }
  .dialog-actions { align-items: stretch; flex-direction: column-reverse; }
  .dialog-actions > div { display: grid; width: 100%; grid-template-columns: 1fr 1fr; }
  .dialog-actions > div .primary { grid-column: 1 / -1; }
  .dialog-actions > .danger { width: 100%; }
  .video-editor { padding: 14px; }
  .editor-head { margin-bottom: 14px; }
  .marking-help { flex-direction: column; }
}

@media (max-width: 480px) {
  .brand span { display: none; }
  .gallery-grid { grid-template-columns: 1fr; }
  .hero-actions { grid-template-columns: 1fr; }
  .transport { grid-template-columns: auto 1fr auto; }
  .transport input { grid-column: 1 / -1; grid-row: 2; }
  .time-buttons { grid-template-columns: 1fr; }
}

