:root {
  --bg: #0a0506; --panel: #150b0d; --panel2: #1d1013; --line: #3a1d22; --text: #f1e6e6; --muted: #a88f92;
  --red: #ff2a1a; --red-dim: #b3160b; --ok: #37d67a; --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background-image: radial-gradient(ellipse at 50% -20%, #3a0a0a 0, transparent 60%); background-attachment: fixed; }
[hidden] { display: none !important; }
h1, h2 { font-family: 'Orbitron', system-ui, sans-serif; letter-spacing: .08em; margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 1.5rem; } h2 { font-size: 1rem; }
a { color: inherit; }
.muted, .meta { color: var(--muted); }
.meta { font-size: .85rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .4rem 0 0; }
.noscript { padding: 2rem; text-align: center; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; padding: .55em 1.1em; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s; }
.btn:hover { border-color: #6b2f37; background: #2a161a; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--red-dim); border-color: var(--red); color: #fff; box-shadow: 0 0 18px rgba(255, 42, 26, .25); }
.btn.primary:hover { background: #d11c0e; box-shadow: 0 0 26px rgba(255, 42, 26, .45); }
.btn.danger { color: #ff8f85; }
.btn.danger:hover { background: #3a0f0c; border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: .32em .75em; font-size: .85rem; }
.btn.wide, input.wide { width: 100%; }
:focus-visible { outline: 2px solid #ff8a7a; outline-offset: 2px; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; padding: .55em .7em; border-radius: 8px; border: 1px solid var(--line); background: #0d0607; color: var(--text); font: inherit; }
textarea { resize: vertical; min-height: 2.6em; }
input:focus, select:focus, textarea:focus { border-color: var(--red); outline: none; box-shadow: 0 0 0 3px rgba(255, 42, 26, .2); }
input[type=range] { width: 100%; accent-color: var(--red); }
input[type=checkbox] { accent-color: var(--red); width: 1.05em; height: 1.05em; flex: none; margin: .22em 0 0; }
input[type=color] { width: 2.6em; height: 2.2em; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; flex: none; }
input[type=file] { width: 100%; font: inherit; color: var(--muted); }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; margin-right: .8em; padding: .4em .9em; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; }
.field { display: block; margin-bottom: .3rem; }
.field > span, .field-label, legend { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.field.inline { display: flex; justify-content: space-between; gap: 1em; }
.field.inline output { color: var(--text); font-variant-numeric: tabular-nums; font-size: .85rem; }
.check { display: flex; gap: .6em; align-items: flex-start; cursor: pointer; }
.form-error { color: #ff8f85; margin: .2rem 0; min-height: 1.3em; font-size: .9rem; }
.form-error:empty { display: none; }
.notice { margin: 0; padding: .6rem .8rem; border: 1px solid var(--red); border-radius: 8px; background: #2b0d0a; color: #ffd9d5; font-size: .9rem; }

/* header */
.top { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.2rem; border-bottom: 1px solid var(--line); background: rgba(10, 5, 6, .85); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(8px); }
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; font-family: 'Orbitron', sans-serif; letter-spacing: .25em; font-weight: 700; color: #fff; text-shadow: 0 0 12px rgba(255, 42, 26, .7); }
.top-mid { flex: 1; min-width: 0; }
.top-nav { display: flex; align-items: center; gap: 1rem; }
.top-nav a { color: var(--muted); text-decoration: none; }
.top-nav a:hover { color: #fff; }

/* pages */
.page { max-width: 1240px; margin: 0 auto; padding: 1.6rem 1.2rem 4rem; }
.page.narrow { max-width: 680px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; margin-top: 1.2rem; display: grid; gap: .8rem; justify-items: start; }
.panel > * { margin: 0; }
.panel .field, .panel .list { width: 100%; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .6rem .8rem; background: #0d0607; border: 1px solid var(--line); border-radius: 8px; }
.list li > div { display: grid; min-width: 0; overflow-wrap: anywhere; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.2rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; transition: border-color .2s, box-shadow .2s; }
.card:hover { border-color: #7a2a2a; box-shadow: 0 0 30px rgba(255, 42, 26, .15); }
.card-prev { display: block; aspect-ratio: 16 / 9; background: #000; }
.card-body { padding: .9rem 1rem 1rem; display: grid; gap: .3rem; }
.card-body h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-body p { margin: 0; }
.card-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.empty { grid-column: 1 / -1; text-align: center; padding: 4rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius); display: grid; gap: .8rem; justify-items: center; }
.empty p { margin: 0; color: var(--muted); }

/* auth */
.auth { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1fr); min-height: 100dvh; }
.auth-stage { position: relative; min-height: 38dvh; background: #000; }
.auth-side { display: grid; place-items: center; padding: 2rem 1.4rem; border-left: 1px solid var(--line); background: linear-gradient(180deg, #170a0c, #0a0506); }
.auth-card { width: min(380px, 100%); display: grid; gap: .8rem; }
.auth-card h1 { font-size: 1.9rem; letter-spacing: .3em; color: #fff; text-shadow: 0 0 18px rgba(255, 42, 26, .8); }
.auth-card .lead { margin: 0 0 .4rem; color: var(--muted); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tabs button { padding: .55em; background: transparent; border: 0; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.tabs button[aria-selected=true] { background: var(--panel2); color: #fff; box-shadow: inset 0 -2px 0 var(--red); }
.or { display: flex; align-items: center; gap: .8rem; color: var(--muted); font-size: .85rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
@media (max-width: 820px) {
  .auth { grid-template-columns: 1fr; grid-template-rows: 38dvh auto; }
  .auth-side { border-left: 0; border-top: 1px solid var(--line); place-items: start center; }
}

/* editor */
.ed-bar { display: flex; align-items: center; gap: .8rem; justify-content: flex-end; }
.ed-bar .btn.ghost { margin-right: auto; }
.dirty { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.dirty.on { color: #ffb86b; }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 1.2rem; padding: 1.2rem; max-width: 1700px; margin: 0 auto; align-items: start; }
.ed-prev { position: sticky; top: 4.4rem; display: grid; gap: .8rem; min-width: 0; }
.prev-box { position: relative; width: 100%; background: #000; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: 0 0 50px rgba(255, 42, 26, .12); margin: 0 auto; }
.prev-box.ar-wide { aspect-ratio: 16 / 9; max-height: calc(100dvh - 13rem); max-width: calc((100dvh - 13rem) * 16 / 9); }
.prev-box.ar-phone { aspect-ratio: 9 / 16; height: calc(100dvh - 13rem); width: auto; max-width: 100%; }
.prev-box.ar-square { aspect-ratio: 1; max-height: calc(100dvh - 13rem); max-width: calc(100dvh - 13rem); }
.prev-tools { display: flex; gap: .8rem; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.prev-tools select { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { padding: .4em .8em; background: transparent; border: 0; border-right: 1px solid var(--line); color: var(--muted); font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed=true] { background: var(--red-dim); color: #fff; }
.share { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; padding: .6rem .8rem; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.share > span { color: var(--muted); font-size: .85rem; }
.share-link { flex: 1; min-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; color: #ffb3aa; }
.ed-side { min-width: 0; }
.ed-form { display: grid; gap: .6rem; }
.ed-sec { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.ed-sec > summary { cursor: pointer; padding: .75rem 1rem; font-family: 'Orbitron', sans-serif; letter-spacing: .08em; font-size: .88rem; font-weight: 700; list-style-position: inside; }
.ed-sec[open] > summary { border-bottom: 1px solid var(--line); color: #ff8a7a; }
.ed-sec-body { padding: 1rem; display: grid; gap: .9rem; }
.ed-field { min-width: 0; }
.ed-field > .btn { margin-top: .5rem; white-space: normal; }
.color-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.color-row .field { margin: 0; }
.color-in { display: flex; gap: .4rem; align-items: center; }
.color-in .hex { width: 6.2em; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; padding: .4em .5em; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.units { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .8rem; }
.units legend, .labels legend { grid-column: 1 / -1; }
.labels { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.chip { padding: .28em .8em; border-radius: 99px; border: 1px solid var(--line); background: #0d0607; color: var(--text); font: inherit; font-size: .82rem; cursor: pointer; }
.chip:hover { border-color: var(--red); }
.media { display: grid; gap: .5rem; }
.media-row { display: flex; align-items: center; justify-content: space-between; gap: .8rem; }
.media-name { overflow-wrap: anywhere; font-size: .9rem; }
.media audio { width: 100%; height: 36px; }
@media (max-width: 980px) {
  .editor { grid-template-columns: 1fr; padding: .8rem; }
  .ed-prev { top: 5.4rem; z-index: 5; background: var(--bg); padding-bottom: .4rem; }
  .prev-box.ar-wide, .prev-box.ar-square { max-height: 34dvh; max-width: calc(34dvh * 16 / 9); }
  .prev-box.ar-square { max-width: 34dvh; }
  .prev-box.ar-phone { height: 40dvh; }
  .share { display: none; }
  .top { flex-wrap: wrap; padding: .5rem .8rem; gap: .5rem; }
  .brand span { display: none; }
  /* the editor's buttons get their own row below brand and account links */
  .top-nav { margin-left: auto; }
  .top-mid { order: 3; flex-basis: 100%; }
  .top-mid:empty { display: none; }
  .ed-bar { gap: .4rem; }
  .ed-bar .btn { padding: .4em .7em; font-size: .85rem; }
  .ed-bar .back span, .dirty:not(.on) { display: none; }
  .dirty { font-size: .78rem; }
}

/* modal & toasts */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .75); display: grid; place-items: center; padding: 1rem; z-index: 50; overflow: auto; }
.modal { background: var(--panel); border: 1px solid #6b2f37; border-radius: var(--radius); padding: 1.3rem; width: min(100%, 460px); display: grid; gap: .9rem; box-shadow: 0 0 60px rgba(255, 42, 26, .2); }
.modal:has(.picker) { width: min(100%, 940px); }
.modal p { margin: 0; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; }
.picker { display: grid; gap: .8rem; max-height: 70dvh; overflow: auto; padding: 2px; }
.picker h3 { margin: 0; font-size: .85rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .1em; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .7rem; }
.preset-wrap { position: relative; display: grid; }
.preset-del { position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: rgba(0, 0, 0, .75); color: #ff8f85; font: 700 16px/1 system-ui, sans-serif; cursor: pointer; padding: 0; }
.preset-del:hover { background: var(--red-dim); color: #fff; border-color: var(--red); }

.preset { display: grid; gap: .4rem; padding: .4rem; background: #0d0607; border: 1px solid var(--line); border-radius: 8px; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-align: center; }
.preset:hover { border-color: var(--red); box-shadow: 0 0 20px rgba(255, 42, 26, .3); }
.preset-prev { aspect-ratio: 16 / 9; border-radius: 5px; overflow: hidden; pointer-events: none; }
#toasts { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); display: grid; gap: .5rem; z-index: 60; width: max-content; max-width: calc(100vw - 2rem); }
.toast { padding: .6rem 1rem; border-radius: 8px; background: #10251a; border: 1px solid var(--ok); color: #d9ffe9; box-shadow: 0 6px 24px rgba(0, 0, 0, .6); transition: opacity .4s, transform .4s; }
.toast.err { background: #2b0d0a; border-color: var(--red); color: #ffd9d5; }
.toast.out { opacity: 0; transform: translateY(8px); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
