@font-face { font-family: "IBM Plex Mono"; src: url("../fonts/IBMPlexMono-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("../fonts/IBMPlexMono-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "VT323"; src: url("../fonts/VT323-Regular.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Press Start 2P"; src: url("../fonts/PressStart2P-Regular.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "UnifrakturMaguntia"; src: url("../fonts/UnifrakturMaguntia-Book.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Pirata One"; src: url("../fonts/PirataOne-Regular.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Grenze Gotisch"; src: url("../fonts/GrenzeGotisch.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Jacquard 24"; src: url("../fonts/Jacquard24-Regular.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Noto Sans Runic"; src: url("../fonts/NotoSansRunic-Regular.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Noto Sans Symbols 2 Subset"; src: url("../fonts/NotoSansSymbols2-Subset.woff2") format("woff2"); font-display: swap; }

:root {
  --bg: #0d0a08;
  --bg-2: #14100d;
  --panel: #17120f;
  --panel-2: #1f1813;
  --line: #3a2b21;
  --line-2: #4d3a2c;
  --text: #ecdfcd;
  --muted: #a8957f;
  --ember: #ff5a2a;
  --ember-2: #ff8a3d;
  --ember-dim: #7a2a12;
  --gold: #e8b34a;
  --danger: #ff4d4d;
  --radius: 8px;
  --ui: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --display: "Pirata One", "UnifrakturMaguntia", Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--ui);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
a { color: var(--ember-2); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ember-2); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { border-color: var(--ember-dim); background: #2a1f18; }
.btn svg { width: 16px; height: 16px; fill: currentColor; flex: none; }
.btn.primary { background: linear-gradient(180deg, #ff6a35, #d9431b); border-color: #ff7a45; color: #1a0b04; font-weight: 700; }
.btn.primary:hover { box-shadow: 0 0 18px rgba(255, 90, 42, .45); }
.btn.ghost { background: transparent; }
.btn.icon { width: 32px; padding: 0; font-weight: 700; }
.btn.small { min-height: 26px; padding: 2px 8px; font-size: 12px; }
.btn.icon.small { width: 26px; }
.btn.mono { font-variant-numeric: tabular-nums; min-width: 54px; }
.btn.rec { width: 100%; margin-top: 4px; }
.btn.rec.on { background: #3a0d0d; border-color: var(--danger); color: #ffd6d6; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 16px rgba(255, 77, 77, .5); } }
.link { background: none; border: 0; padding: 4px 0; color: var(--text); cursor: pointer; text-align: left; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link:hover { color: var(--ember-2); }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; width: 26px; height: 26px; border-radius: 6px; }
.icon-btn:hover { color: var(--danger); background: #2a1515; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #1a130e, #120d0a);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 6px; }
.brand-name {
  font: 28px/1 "UnifrakturMaguntia", var(--display);
  color: #ffd9b8;
  text-shadow: 0 0 10px rgba(255, 90, 42, .75), 0 0 26px rgba(255, 90, 42, .35);
  letter-spacing: .5px;
}
.brand-tag { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.actions.right { margin-left: auto; }
.lang select { height: 32px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel-2); padding: 0 6px; }
body.desktop .web-only { display: none; }

/* ---------- workspace ---------- */
.workspace { flex: 1; display: flex; min-height: 0; }
.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 90, 42, .06), transparent 60%),
    repeating-conic-gradient(#110d0b 0 25%, #0e0b09 0 50%) 0 0 / 24px 24px;
}
.viewport {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 24px;
}
.viewport.scroll { overflow: auto; place-items: start; cursor: grab; }
.viewport.scroll > canvas { margin: auto; }
.viewport.panning { cursor: grabbing; }
#out {
  display: block;
  max-width: none;
  box-shadow: 0 10px 50px rgba(0, 0, 0, .7), 0 0 0 1px #2a2018;
  background: repeating-conic-gradient(#1b1714 0 25%, #141110 0 50%) 0 0 / 16px 16px;
  image-rendering: auto;
}
.statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  background: rgba(13, 10, 8, .92);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.statusbar .spacer { flex: 1; }

.empty-state, .drop-overlay {
  position: absolute;
  inset: 0 0 40px 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 10px;
}
.stage.empty .empty-state { display: flex; }
.empty-state h1 { margin: 0; font: 44px/1.1 "UnifrakturMaguntia", var(--display); color: #ffd9b8; text-shadow: 0 0 18px rgba(255, 90, 42, .6); font-weight: 400; }
.empty-state p { max-width: 420px; color: var(--muted); margin: 0 0 8px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
body.dragging .drop-overlay {
  display: flex;
  background: rgba(13, 10, 8, .85);
  border: 2px dashed var(--ember);
  margin: 12px;
  border-radius: 14px;
  z-index: 5;
}
.drop-overlay strong { font: 36px/1 var(--display); color: var(--ember-2); }
.spinner {
  position: absolute;
  top: 50%; left: 50%;
  width: 34px; height: 34px;
  margin: -17px;
  border: 3px solid var(--ember-dim);
  border-top-color: var(--ember-2);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  display: none;
}
.stage.busy .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
.rec-badge {
  position: absolute;
  top: 14px; left: 14px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(58, 13, 13, .9);
  color: #ffd6d6;
  border: 1px solid var(--danger);
  display: none;
}
body.recording .rec-badge { display: block; }

/* ---------- panel ---------- */
.panel {
  width: 340px;
  flex: none;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  scrollbar-color: var(--line-2) transparent;
}
.panel details { border-bottom: 1px solid var(--line); }
.panel summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  font: 21px/1.1 var(--display);
  color: #f4d8bd;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: "+"; font: 16px var(--ui); color: var(--muted); }
.panel details[open] summary::after { content: "−"; }
.panel summary:hover { color: var(--ember-2); }
.sec-body { padding: 2px 14px 14px; display: grid; gap: 10px; }
.row { display: grid; gap: 5px; }
.row > label, .row label > span { color: var(--muted); }
.row.range label { display: flex; justify-content: space-between; gap: 8px; }
.row.range output { color: var(--text); font-variant-numeric: tabular-nums; }
.row.inline { grid-template-columns: 1fr auto; align-items: center; }
.row.check label { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); }
.row.check span { color: var(--text) !important; }
.hint { color: var(--muted); font-size: 11px; line-height: 1.35; }

select, input[type="text"], textarea {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--bg-2);
  padding: 5px 8px;
}
textarea { resize: vertical; min-height: 54px; }
select:hover, input[type="text"]:hover, textarea:hover { border-color: var(--ember-dim); }
.color { display: grid; grid-template-columns: 44px 1fr; gap: 6px; }
input[type="color"] { width: 44px; height: 32px; padding: 2px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--bg-2); cursor: pointer; }
input[type="checkbox"] { accent-color: var(--ember); width: 16px; height: 16px; margin: 0; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; background: transparent; cursor: pointer; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--ember-dim), var(--line-2)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 3px; transform: rotate(45deg); background: var(--ember-2); box-shadow: 0 0 8px rgba(255, 106, 53, .7); border: 0; }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--ember-dim), var(--line-2)); }
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 3px; transform: rotate(45deg); background: var(--ember-2); border: 0; }

.src-info { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); }
.src-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-ctrls { display: flex; gap: 4px; }

.glyphs {
  font-size: 18px;
  line-height: 1.25;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #070605;
  color: #ffcf9f;
  text-shadow: 0 0 8px rgba(255, 90, 42, .6);
  word-break: break-all;
  max-height: 96px;
  overflow: hidden;
}

.swatches { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.swatch {
  position: relative;
  height: 34px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
}
.swatch span {
  position: absolute;
  left: 6px; bottom: 3px;
  font-size: 10.5px;
  color: #fff;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
}
.swatch.active { outline: 2px solid var(--ember-2); outline-offset: 1px; }

.export { display: grid; gap: 8px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.btn-grid .btn { width: 100%; }
.btn-grid .btn.primary { grid-column: span 2; }
.preset-block { display: grid; gap: 8px; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.presets { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 180px; overflow: auto; }
.presets li { display: flex; align-items: center; gap: 4px; padding: 0 4px 0 8px; border-radius: 6px; background: var(--bg-2); }
.presets li.empty { color: var(--muted); padding: 6px 8px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: 56px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 8px 14px;
  border-radius: var(--radius);
  background: #241a13;
  border: 1px solid var(--ember-dim);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .6);
  transition: opacity .2s, transform .2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); background: #2a1212; }

/* ---------- dialogs ---------- */
.dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 18px 20px 20px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .8);
}
.dialog.wide { width: min(1040px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(5, 3, 2, .75); backdrop-filter: blur(3px); }
.dialog header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog h2 { margin: 0; font: 30px/1.1 var(--display); color: #ffd9b8; font-weight: 400; }
.dialog h3 { margin: 16px 0 6px; font: 20px/1.1 var(--display); color: #f4d8bd; font-weight: 400; }
.demo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 12px; }
.demo-card {
  display: grid;
  gap: 4px;
  padding: 0 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.demo-card:hover { border-color: var(--ember); transform: translateY(-2px); box-shadow: 0 8px 26px rgba(255, 90, 42, .18); }
.demo-card img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; background: #000; display: block; }
.demo-card strong { padding: 6px 10px 0; font: 19px/1.1 var(--display); font-weight: 400; color: #f4d8bd; }
.demo-card small { padding: 0 10px; color: var(--muted); font-size: 10.5px; line-height: 1.3; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.keys dd { margin: 0; color: var(--muted); }
kbd { display: inline-block; padding: 1px 6px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; background: var(--bg-2); font: 11px var(--ui); }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  body { overflow: auto; }
  .workspace { flex-direction: column; }
  .stage { min-height: 62vh; }
  .panel { width: auto; border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .brand-tag { display: none; }
  .actions.right { margin-left: 0; }
  .btn span { display: none; }
  .btn.primary span, .row-btns .btn span, .btn-grid .btn span { display: inline; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition: none !important; }
}
