:root {
  color-scheme: dark;
  --bg: oklch(0.12 0.012 245);
  --surface: oklch(0.16 0.014 245);
  --surface-2: oklch(0.19 0.014 245);
  --surface-3: oklch(0.23 0.014 245);
  --text: oklch(0.94 0.014 80);
  --muted: oklch(0.68 0.018 250);
  --soft: oklch(0.79 0.02 246);
  --line: oklch(0.3 0.018 245);
  --line-soft: oklch(0.25 0.016 245);
  --gold: oklch(0.72 0.11 74);
  --gold-soft: oklch(0.82 0.08 78);
  --blue: oklch(0.68 0.065 230);
  --danger: oklch(0.68 0.14 35);
  --radius: 8px;
  --shadow-preview: 0 34px 80px oklch(0.02 0.01 245 / 0.62);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  background:
    linear-gradient(180deg, oklch(0.16 0.018 245), var(--bg) 36rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--gold-soft);
  outline-offset: 3px;
}

a {
  color: inherit;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  padding: 18px;
  gap: 10px;
}

.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 376px;
  gap: 18px;
  min-height: 0;
  max-width: 1680px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.preview-panel,
.control-panel {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: oklch(0.155 0.014 245);
}

.preview-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 18px;
  overflow: hidden;
}

.section-head,
.control-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.kicker {
  margin: 0 0 7px;
  color: var(--gold-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  max-width: 780px;
  font-size: 28px;
  line-height: 1.08;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
  line-height: 1.2;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--soft);
  background: oklch(0.12 0.01 245);
  font-size: 12px;
}

.preview-actions {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.scene-switcher {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
  margin: 14px 0 10px;
}

.youtube-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.youtube-url-field {
  margin-top: 0;
}

.scene-button,
.scene-upload,
.preset-button,
.button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.scene-button,
.scene-upload {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 3px;
  padding: 10px 12px;
  text-align: left;
}

.scene-button span,
.scene-upload span {
  font-size: 13px;
  font-weight: 650;
}

.scene-button small,
.scene-upload small {
  color: var(--muted);
  font-size: 11px;
}

.scene-button:hover,
.scene-upload:hover,
.preset-button:hover,
.button-secondary:hover,
.button-plain:hover {
  background: var(--surface-3);
  border-color: oklch(0.43 0.024 245);
}

.scene-button.is-active,
.preset-button.is-active {
  border-color: oklch(0.7 0.09 74);
  color: var(--gold-soft);
  background: oklch(0.2 0.026 74);
}

.scene-upload input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.stage-frame {
  position: relative;
  flex: 0 1 auto;
  align-self: center;
  width: min(100%, calc((100dvh - 246px) * 16 / 9));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: oklch(0.08 0.01 245);
  box-shadow: var(--shadow-preview);
}

.stage-frame.is-checker {
  background:
    linear-gradient(45deg, oklch(0.78 0.01 80) 25%, transparent 25%),
    linear-gradient(-45deg, oklch(0.78 0.01 80) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, oklch(0.78 0.01 80) 75%),
    linear-gradient(-45deg, transparent 75%, oklch(0.78 0.01 80) 75%),
    oklch(0.9 0.008 80);
  background-position: 0 0, 0 18px, 18px -18px, -18px 0;
  background-size: 36px 36px;
}

.stage-frame.is-checker .scene-grade {
  display: none;
}

.scene-media,
.scene-grade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene-media {
  object-fit: cover;
  background: oklch(0.08 0.01 245);
}

.youtube-frame {
  border: 0;
}

.is-hidden {
  display: none;
}

.scene-grade {
  background:
    linear-gradient(90deg, oklch(0.02 0.01 245 / 0.42), transparent 28%, transparent 62%, oklch(0.02 0.01 245 / 0.26)),
    linear-gradient(180deg, oklch(0.02 0.01 245 / 0.18), transparent 38%, oklch(0.02 0.01 245 / 0.5)),
    linear-gradient(0deg, oklch(0.06 0.012 245 / 0.24), transparent);
  pointer-events: none;
}

.badge-canvas,
.blur-plate {
  position: absolute;
  left: calc(var(--badge-x, 6) * 1%);
  bottom: calc(var(--badge-y, 7) * 1%);
  width: calc(var(--badge-scale, 16) * 1%);
  max-width: 260px;
  min-width: 72px;
  aspect-ratio: 1;
}

.blur-plate {
  z-index: 1;
  border-radius: calc(var(--badge-radius-preview, 21) * 1%);
  background: oklch(0.92 0.01 80 / 0.025);
  backdrop-filter: blur(calc(var(--preview-blur, 10) * 1px));
  -webkit-backdrop-filter: blur(calc(var(--preview-blur, 10) * 1px));
  clip-path: inset(0 round calc(var(--badge-radius-preview, 21) * 1%));
  contain: paint;
  overflow: hidden;
  opacity: var(--badge-backdrop-opacity, 0.7);
}

.blur-plate {
  left: calc((var(--badge-x, 6) + var(--badge-pad-pct, 0.736)) * 1%);
  bottom: calc((var(--badge-y, 7) + var(--badge-pad-pct, 0.736)) * 1%);
  width: calc(var(--badge-inner-scale, 14.528) * 1%);
  max-width: 236px;
  min-width: 65px;
}

.badge-canvas {
  z-index: 2;
  filter: drop-shadow(0 18px 22px oklch(0.02 0.01 245 / var(--badge-shadow-opacity, 0.48)));
}

.safe-corner {
  position: absolute;
  left: 4%;
  bottom: 5%;
  width: 22%;
  aspect-ratio: 1;
  border: 1px dashed oklch(0.86 0.01 80 / 0.07);
  border-radius: 8px;
  pointer-events: none;
}

.preview-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.preview-meta p {
  margin-bottom: 0;
}

.preview-meta a {
  color: var(--soft);
  text-underline-offset: 3px;
}

.control-panel {
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding: 14px;
}

.control-section {
  padding: 16px 0;
  border-top: 1px solid var(--line-soft);
}

.control-section:first-child {
  padding-top: 2px;
  border-top: 0;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.custom-preset-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  margin-top: 14px;
}

.preset-name-field {
  margin-top: 0;
}

.custom-preset-grid {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.custom-preset-grid[hidden] {
  display: none;
}

.custom-preset-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 8px;
}

.custom-preset-load {
  min-width: 0;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-preset-delete {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface-2);
  cursor: pointer;
}

.custom-preset-delete:hover {
  border-color: oklch(0.5 0.06 35);
  color: oklch(0.78 0.1 35);
  background: oklch(0.2 0.025 35);
}

.preset-button {
  padding: 10px;
  font-size: 12px;
  font-weight: 700;
}

.field,
.range-field,
.swatch-field {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.field span,
.range-field label,
.swatch-field span {
  color: var(--soft);
  font-size: 13px;
  font-weight: 620;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: oklch(0.12 0.012 245);
  padding: 0 10px;
}

.range-field {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.range-field input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--gold);
}

.range-scale {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  margin-top: -3px;
  color: var(--muted);
  font-size: 11px;
}

.range-field output {
  color: var(--gold-soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.swatch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.swatch-field input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  padding: 2px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 750;
  text-align: center;
}

.button-primary {
  border-color: oklch(0.74 0.1 74);
  color: oklch(0.15 0.012 70);
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
}

.button-primary:hover {
  transform: translateY(-1px);
}

.button-secondary,
.button-plain {
  background: var(--surface-2);
}

.button-plain {
  color: var(--muted);
}

.export-section {
  display: grid;
  gap: 8px;
}

.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--text);
  background: oklch(0.18 0.014 245);
  box-shadow: 0 18px 48px oklch(0.02 0.01 245 / 0.5);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.app-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  width: 100%;
  max-width: 1680px;
  min-height: 28px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.app-footer p {
  margin: 0;
}

.app-footer a {
  color: var(--soft);
  text-decoration: none;
}

.app-footer a:hover {
  color: var(--gold-soft);
}

.language-switcher {
  display: inline-flex;
  gap: 4px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 3px;
  background: oklch(0.12 0.012 245);
}

.language-button {
  min-width: 34px;
  min-height: 26px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}

.language-button:hover,
.language-button.is-active {
  color: var(--gold-soft);
  background: oklch(0.2 0.026 74);
}

@media (max-width: 1180px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .app-footer {
    flex-wrap: wrap;
  }

  .control-panel {
    max-height: none;
  }

  .control-section {
    padding: 18px 0;
  }

  .stage-frame {
    width: 100%;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  h1 {
    font-size: 22px;
  }

  .section-head {
    display: block;
  }

  .preview-actions {
    justify-content: space-between;
    margin-top: 12px;
  }

  .youtube-tools,
  .custom-preset-tools {
    grid-template-columns: 1fr;
  }

  .status-pill {
    display: inline-flex;
  }

  .scene-switcher,
  .preset-grid,
  .swatch-grid {
    grid-template-columns: 1fr;
  }

  .preview-panel,
  .control-panel {
    padding: 12px;
  }

  .badge-canvas {
    min-width: 62px;
  }

  .preview-meta {
    display: block;
  }

  .preview-meta a {
    display: inline-block;
    margin-top: 6px;
  }
}

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