@font-face {
  font-family: "Ninjala";
  src: url("fonts/ninjala.ttf") format("truetype");
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
}

:root {
  --bg: #0b0f14;
  --bg-elevated: rgba(16, 21, 30, 0.84);
  --bg-panel: rgba(19, 24, 34, 0.92);
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-strong: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f4f7fb;
  --text-muted: rgba(244, 247, 251, 0.74);
  --text-soft: rgba(244, 247, 251, 0.60);
  --accent: #ff2d2d;
  --accent-dark: #c71f1f;
  --accent-soft: rgba(255, 45, 45, 0.14);
  --success: #55d38a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.22);
  --radius-xs: 10px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --panel-width: clamp(300px, 25vw, 332px);
  --border-faint: 1px solid var(--border);
  --border-strong-line: 1px solid var(--border-strong);
  --focus-ring: 0 0 0 3px rgba(255, 45, 45, 0.28);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 45, 45, 0.12), transparent 32%),
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.06), transparent 26%),
    linear-gradient(180deg, #0a0d12 0%, #0d1117 52%, #080b10 100%);
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Barlow Condensed", "DIN Condensed", "Franklin Gothic Medium", "Trebuchet MS", Tahoma, sans-serif;
  line-height: 1.45;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 45, 45, 0.11), transparent 24%),
    radial-gradient(circle at 85% 15%, rgba(255, 255, 255, 0.04), transparent 22%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 26%),
    repeating-linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.015) 0,
      rgba(255, 255, 255, 0.015) 1px,
      transparent 1px,
      transparent 14px
    ),
    linear-gradient(180deg, #091017 0%, #0c1016 100%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at center, transparent 42%, rgba(0, 0, 0, 0.26) 100%);
  opacity: 0.85;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

/* Layout shell */
.editor-shell,
.app-shell,
main,
.page-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--panel-width) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  height: 100vh;
  padding: 10px 0;
}

.sidebar,
.side-panel,
.panel,
.controls,
.editor-panel,
.control-panel {
  min-width: 0;
  padding: 10px;
  border: var(--border-faint);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(22, 28, 39, 0.96), rgba(15, 20, 29, 0.94));
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  max-height: calc(100vh - 20px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.sidebar > *,
.side-panel > *,
.panel > *,
.controls > *,
.editor-panel > *,
.control-panel > * {
  min-width: 0;
}

.preview-area,
.preview-panel,
.stage-area,
.canvas-area {
  min-width: 0;
  display: grid;
  gap: var(--space-4);
}

.preview-panel {
  justify-items: center;
  align-content: start;
  position: sticky;
  top: 10px;
  max-height: calc(100vh - 20px);
}

/* Cards */
.card,
.section-card,
.control-card,
.preview-card,
.stage-card,
.preset-card,
.panel-section {
  border: var(--border-faint);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.025));
  box-shadow: var(--shadow-soft);
}

.card,
.section-card,
.control-card,
.preview-card,
.stage-card,
.preset-card,
.panel-section,
.sidebar section,
.side-panel section,
.panel section,
.controls section,
.editor-panel section,
.control-panel section {
  padding: var(--space-4);
}

/* Headings and helper text */
h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0 0 var(--space-3);
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-family: Impact, Haettenschweiler, "Franklin Gothic Heavy", sans-serif;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(1.2rem, 1rem + 0.9vw, 1.8rem);
}

h2 {
  font-size: 1.02rem;
}

h3 {
  font-size: 0.96rem;
}

p {
  margin: 0 0 var(--space-3);
}

small,
.helper,
.help,
.note,
.muted,
.hint,
.field-hint,
.form-hint {
  color: var(--text-soft);
  font-size: 0.8rem;
  line-height: 1.35;
}

.kicker,
.badge,
.meta,
.caption {
  color: var(--text-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Accordion */
details {
  border: var(--border-faint);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  overflow: clip;
}

details + details {
  margin-top: 6px;
}

details[open] {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.16);
}

details summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 8px 10px;
  cursor: pointer;
  user-select: none;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

details summary::-webkit-details-marker {
  display: none;
}

details summary::after {
  content: "+";
  width: 1.2rem;
  height: 1.2rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.12);
  flex: 0 0 auto;
}

details[open] summary::after {
  content: "–";
  color: var(--text);
  border-color: rgba(255, 45, 45, 0.45);
  background: rgba(255, 45, 45, 0.12);
}

details > :not(summary) {
  padding: 0 10px 10px;
}

.panel-section > .section-body {
  display: grid;
  gap: 8px;
}

.control-panel details.panel-section {
  padding: 0;
}

.control-panel .panel-section > .section-body {
  grid-template-columns: minmax(98px, 118px) minmax(0, 1fr);
  row-gap: 6px;
  column-gap: 8px;
  align-items: center;
}

.control-panel #bgImage {
  display: none;
}

.control-panel .panel-section > .section-body > label:not(.check-row) {
  grid-column: 1;
  margin: 0;
  font-size: 0.72rem;
}

.control-panel .panel-section > .section-body > :is(
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea,
  .bg-thumb-grid,
  .character-thumb-grid,
  .compact-tools,
  .hint
) {
  grid-column: 2;
}

.control-panel .panel-section > .section-body > .check-row {
  grid-column: 2;
  margin: 0;
}

.control-panel .panel-section .hint {
  margin: 0;
  font-size: 0.64rem;
  line-height: 1.22;
  opacity: 0.9;
}

.bg-thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(30px, 1fr));
  gap: 4px;
}

.bg-thumb {
  width: 100%;
  padding: 0;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(5, 9, 14, 0.92);
  aspect-ratio: 3 / 4;
  overflow: hidden;
  min-height: 40px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.bg-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.bg-thumb:hover {
  border-color: rgba(255, 255, 255, 0.30);
}

.bg-thumb.is-selected {
  border-color: rgba(255, 60, 60, 0.92);
  box-shadow:
    0 0 0 1px rgba(255, 60, 60, 0.92),
    0 8px 20px rgba(255, 20, 20, 0.25);
}

.character-thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(30px, 1fr));
  gap: 4px;
  max-height: 110px;
  overflow-y: auto;
  padding-right: 2px;
}

.character-thumb {
  width: 100%;
  padding: 0;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(5, 9, 14, 0.92);
  aspect-ratio: 3 / 4;
  overflow: hidden;
  min-height: 40px;
}

.character-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.character-thumb.is-selected {
  border-color: rgba(255, 60, 60, 0.92);
  box-shadow: 0 0 0 1px rgba(255, 60, 60, 0.92);
}

.is-hidden {
  display: none !important;
}

.panel-header,
.preview-head {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}

.panel-header p,
.preview-head p {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.72rem;
  text-transform: none;
}

/* Forms */
form,
fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-inline-size: 0;
}

fieldset + fieldset {
  margin-top: var(--space-4);
}

label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 600;
}

label[for] {
  cursor: pointer;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  color: var(--text);
  border: var(--border-faint);
  border-radius: 9px;
  background: rgba(3, 6, 10, 0.72);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease, transform 160ms ease;
}

textarea {
  min-height: 58px;
  resize: vertical;
  line-height: 1.16;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-soft) 50%),
    linear-gradient(135deg, var(--text-soft) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

input::placeholder,
textarea::placeholder {
  color: rgba(244, 247, 251, 0.38);
}

input:hover,
select:hover,
textarea:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
summary:focus-visible {
  box-shadow: var(--focus-ring);
  border-color: rgba(255, 45, 45, 0.55);
}

input[type="range"] {
  padding: 0;
  height: 20px;
  background: transparent;
  border: 0;
  appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 45, 45, 0.95), rgba(255, 255, 255, 0.18));
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -4px;
  border: 1px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 45, 45, 0.95), rgba(255, 255, 255, 0.18));
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 1px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
}

.checkbox,
.check-row,
.toggle-row,
.inline-option {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.7rem;
  white-space: nowrap;
}

.checkbox input,
.check-row input,
.toggle-row input,
.inline-option input {
  flex: 0 0 auto;
}

/* Button actions */
.compact-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.compact-tools .btn-secondary {
  min-height: 24px;
  padding: 4px 8px;
  font-size: 0.64rem;
}

button,
.btn,
.button,
a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  font-family: "Barlow Condensed", "Franklin Gothic Medium", "Trebuchet MS", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.panel-actions {
  margin-top: 8px;
  display: grid;
  gap: 6px;
  padding: 0;
}

button:hover,
.btn:hover,
.button:hover,
a.button:hover {
  transform: translateY(-1px);
}

button:active,
.btn:active,
.button:active,
a.button:active {
  transform: translateY(0);
}

button.primary,
.btn.primary,
.button.primary,
button[type="submit"],
button.download,
button.action-primary,
.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, #ff4444, #d51f1f);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 22px rgba(255, 45, 45, 0.18);
}

button.primary:hover,
.btn.primary:hover,
.button.primary:hover,
button[type="submit"]:hover,
button.download:hover,
button.action-primary:hover,
.btn-primary:hover {
  background: linear-gradient(180deg, #ff5454, #c91b1b);
}

button.secondary,
.btn.secondary,
.button.secondary,
button.reset,
button.action-secondary,
a.button.secondary,
.btn-secondary {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-strong);
}

button.secondary:hover,
.btn.secondary:hover,
.button.secondary:hover,
button.reset:hover,
button.action-secondary:hover,
a.button.secondary:hover,
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.24);
}

.actions,
.button-row,
.toolbar,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.actions > *,
.button-row > *,
.toolbar > *,
.form-actions > * {
  flex: 0 0 auto;
}

/* Stage / preview */
.stage-card,
.preview-card,
.canvas-stage,
.preview-stage,
.stage-frame {
  display: grid;
  gap: var(--space-3);
}

.stage-card,
.preview-card,
.stage-frame {
  padding: var(--space-4);
}

.canvas-stage,
.preview-stage,
.canvas-shell,
.stage-frame {
  position: relative;
  width: min(100%, 620px, calc((100vh - 170px) * 0.75));
  width: min(100%, 620px, calc((100dvh - 170px) * 0.75));
  aspect-ratio: 3 / 4;
  margin-inline: auto;
  padding: 0;
  overflow: hidden;
  border-radius: calc(var(--radius-lg) - 4px);
  border: 1px solid rgba(255, 255, 255, 0.09);
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 45, 45, 0.14), transparent 28%),
    linear-gradient(180deg, rgba(10, 14, 20, 0.8), rgba(6, 9, 13, 0.96));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 18px 38px rgba(0, 0, 0, 0.34);
}

.canvas-stage::before,
.preview-stage::before,
.canvas-shell::before,
.stage-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 20%),
    radial-gradient(circle at 50% 80%, rgba(255, 45, 45, 0.08), transparent 40%);
  mix-blend-mode: screen;
}

.canvas-stage > *,
.preview-stage > *,
.canvas-shell > *,
.stage-frame > * {
  position: relative;
  z-index: 1;
}

.preview-wrap,
.canvas-wrap,
.stage-inner {
  display: grid;
  place-items: center;
}

#bannerCanvas {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
  display: block;
}

.stage-header,
.preview-header,
.preview-head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: baseline;
  width: min(100%, 620px);
  margin-inline: auto;
}

/* Utility alignment for compact controls */
.row,
.field-row,
.control-row,
.inline-row {
  display: grid;
  gap: 10px;
}

.two-col,
.split,
.duo {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three-col {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stack {
  display: grid;
  gap: var(--space-3);
}

/* Compact list styling */
ul,
ol {
  margin: 0;
  padding-left: 1.15rem;
}

li + li {
  margin-top: 0.35rem;
}

/* Subtle separators */
hr {
  border: 0;
  border-top: var(--border-faint);
  margin: var(--space-4) 0;
}

/* Responsive */
@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .editor-shell,
  .app-shell,
  main,
  .page-shell {
    width: min(100vw - 20px, 1440px);
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    padding: 12px 0 20px;
  }

  .sidebar,
  .side-panel,
  .panel,
  .controls,
  .editor-panel,
  .control-panel {
    width: 100%;
    max-height: none;
    overflow: visible;
  }

  .preview-panel {
    position: static;
    top: auto;
    max-height: none;
  }

  .canvas-stage,
  .preview-stage,
  .canvas-shell,
  .stage-frame {
    width: min(100%, 560px);
  }
}

@media (max-width: 640px) {
  :root {
    --radius-lg: 18px;
  }

  body {
    background:
      radial-gradient(circle at 20% 0%, rgba(255, 45, 45, 0.14), transparent 20%),
      linear-gradient(180deg, #091017 0%, #0b0f14 100%);
  }

  .editor-shell,
  .app-shell,
  main,
  .page-shell {
    width: min(100vw - 14px, 1440px);
    gap: 14px;
  }

  .sidebar,
  .side-panel,
  .panel,
  .controls,
  .editor-panel,
  .control-panel,
  .card,
  .section-card,
  .control-card,
  .preview-card,
  .stage-card,
  .preset-card {
    padding: 12px;
  }

  details summary {
    padding: 11px 12px;
  }

  details > :not(summary) {
    padding: 0 12px 12px;
  }

  .two-col,
  .split,
  .duo,
  .three-col {
    grid-template-columns: minmax(0, 1fr);
  }

  .actions,
  .button-row,
  .toolbar,
  .form-actions {
    gap: 8px;
  }

  button,
  .btn,
  .button,
  a.button {
    min-height: 38px;
    padding: 9px 12px;
  }

  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    padding: 9px 11px;
  }

  .canvas-stage,
  .preview-stage,
  .canvas-shell,
  .stage-frame {
    width: min(100%, 430px);
  }
}

@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;
  }
}
