:root {
  --void: #090011;
  --panel: #160525;
  --panel2: #210839;
  --ink: #f8f5ff;
  --muted: #a99cbd;
  --pink: #ff2ec4;
  --cyan: #00e5ff;
  --lime: #c6ff00;
  --orange: #ff5b21;
  --purple: #8c52ff;
  --line: #3b1457;
}

* { box-sizing: border-box; }
html { background: var(--void); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -10%, rgba(255,46,196,.25), transparent 34rem),
    radial-gradient(circle at 100% 30%, rgba(0,229,255,.18), transparent 30rem),
    var(--void);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 20px 16px 56px;
}
.hero { display: grid; gap: 8px; margin-bottom: 18px; }
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand {
  margin: 0;
  font-family: Impact, Haettenschweiler, "Arial Black", sans-serif;
  font-size: clamp(40px, 9vw, 82px);
  line-height: .86;
  letter-spacing: -2px;
  transform: skewX(-5deg);
  background: linear-gradient(90deg, var(--pink), var(--cyan) 50%, var(--lime));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 7px 0 rgba(0,0,0,.42));
}
.free-badge {
  flex: 0 0 auto;
  border: 1px solid rgba(198,255,0,.5);
  background: rgba(198,255,0,.1);
  color: var(--lime);
  border-radius: 999px;
  padding: 7px 10px;
  font-weight: 900;
  font-size: 11px;
  letter-spacing: .08em;
}
.tagline { margin: 0; color: var(--muted); font-weight: 650; max-width: 70ch; }

.layout { display: grid; grid-template-columns: minmax(300px, 420px) minmax(320px, 1fr); gap: 20px; align-items: start; }
.panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  background: linear-gradient(180deg, rgba(30,8,49,.94), rgba(14,3,27,.96));
  box-shadow: 0 18px 60px rgba(0,0,0,.34), inset 0 1px 0 rgba(255,255,255,.035);
}
.panel h2 { margin: 0 0 6px; font-family: Impact, "Arial Black", sans-serif; letter-spacing: .04em; font-size: 22px; }
.panel-copy { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.45; }

.trend-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 9px; }
.trend-head strong { font-size: 12px; letter-spacing: .1em; color: var(--lime); }
.trend-source { color: #756a87; font-size: 10px; }
.trend-rail { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.trend-rail::-webkit-scrollbar { display: none; }
.trend-chip {
  flex: 0 0 auto;
  max-width: 230px;
  border: 1px solid #4d1b6d;
  background: #250a3c;
  color: #efe9ff;
  border-radius: 999px;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.trend-chip:hover { border-color: var(--cyan); }

.prompt-wrap { position: relative; }
textarea {
  width: 100%;
  min-height: 92px;
  resize: none;
  border-radius: 15px;
  border: 2px solid #471667;
  outline: none;
  background: #0c0217;
  color: var(--ink);
  padding: 14px 14px 30px;
  font-size: 16px;
  line-height: 1.3;
}
textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(0,229,255,.08); }
.word-meter { position: absolute; right: 10px; bottom: 9px; font-size: 11px; font-weight: 800; color: #7d6f94; }
.word-meter.over { color: var(--orange); }

.control-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-top: 11px; }
.control-field { display: grid; gap: 5px; min-width: 0; }
.control-field > span { color: #7f7190; font-size: 9px; font-weight: 900; letter-spacing: .1em; }
.chaos-select,
.visual-style-select {
  width: 100%;
  min-height: 43px;
  border: 1px solid #4a1a69;
  background: #180527;
  color: var(--ink);
  border-radius: 13px;
  padding: 0 10px;
  font-weight: 850;
  font-size: 12px;
}
.visual-style-select { border-color: rgba(0,229,255,.38); background: linear-gradient(180deg, #10222d, #100719); }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.btn {
  border: 0;
  border-radius: 14px;
  padding: 13px 12px;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 16px;
  letter-spacing: .04em;
  cursor: pointer;
  transition: transform .09s ease, filter .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.btn-primary { color: #080010; background: linear-gradient(100deg, var(--cyan), #93f7ff); }
.btn-rot { color: #080010; background: linear-gradient(100deg, var(--lime), #edffa7); }
.btn-dark { color: var(--ink); border: 1px solid #45165f; background: #1b072b; }
.btn-download { color: #080010; background: linear-gradient(100deg, var(--pink), #ff8cdd); }
.btn:hover:not(:disabled) { filter: brightness(1.07); }

.status-box {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
  border: 1px dashed #42205a;
  border-radius: 13px;
  padding: 10px 11px;
  color: #c8bada;
  font-size: 12px;
  line-height: 1.4;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 16px rgba(198,255,0,.7); flex: 0 0 auto; }
.status-dot.busy { background: var(--cyan); animation: pulse .75s infinite alternate; }
.status-dot.warn { background: var(--orange); }
@keyframes pulse { to { opacity: .3; transform: scale(.72); } }

.sources { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.source-pill { border: 1px solid #362047; background: rgba(255,255,255,.025); border-radius: 999px; padding: 6px 8px; font-size: 10px; color: #9284a6; }
.source-pill b { color: #ded4ed; }
.visual-note {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  border: 1px solid rgba(0,229,255,.16);
  border-radius: 13px;
  padding: 10px;
  background: linear-gradient(120deg, rgba(0,229,255,.055), rgba(255,46,196,.035));
}
.visual-note strong { color: var(--cyan); font-size: 10px; letter-spacing: .1em; }
.visual-note span { color: #8f829f; font-size: 10px; line-height: 1.45; }

.stage-panel { padding: 12px; }
.stage-shell { position: relative; width: min(100%, 480px); margin: 0 auto; }
#videoCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 9 / 16;
  border-radius: 22px;
  background: #050009;
  border: 2px solid #46185f;
  box-shadow: 0 18px 55px rgba(0,0,0,.5), 0 0 0 4px rgba(9,0,17,.85);
}
.canvas-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(5,0,9,.68);
  backdrop-filter: blur(8px);
  color: #fff;
  padding: 6px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .06em;
  pointer-events: none;
}
.player-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(100%, 480px); margin: 11px auto 0; }
.player-controls .btn { font-size: 13px; padding: 11px 8px; border-radius: 12px; }
.download-note { width: min(100%, 480px); margin: 9px auto 0; color: #7e718e; font-size: 10px; line-height: 1.45; text-align: center; }

.mini-facts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-top: 12px; }
.mini-fact { border: 1px solid #321447; background: rgba(255,255,255,.02); border-radius: 13px; padding: 9px; text-align: center; }
.mini-fact b { display: block; color: var(--ink); font-family: Impact, "Arial Black", sans-serif; font-size: 17px; }
.mini-fact span { color: #81758f; font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
footer { margin-top: 20px; color: #5f536e; text-align: center; font-size: 10px; line-height: 1.5; }

@media (max-width: 820px) {
  .app-shell {
    padding-top: max(14px, env(safe-area-inset-top));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(28px, env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
  }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout, .panel, .creator-panel, .stage-panel, .hero, .brand-row { min-width: 0; }
  .creator-panel { order: 1; }
  .stage-panel { order: 2; }
  .brand-row { align-items: flex-start; }
  .stage-shell, .player-controls, .download-note { width: min(100%, calc((100dvh - 190px) * 9 / 16)); }
}

@media (max-width: 430px) {
  .app-shell {
    width: 100%;
    padding-right: max(10px, env(safe-area-inset-right));
    padding-left: max(10px, env(safe-area-inset-left));
  }
  .panel { border-radius: 18px; padding: 13px; }
  .player-controls { grid-template-columns: 1fr 1fr; }
  .control-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .chaos-select, .visual-style-select { min-height: 42px; font-size: 11px; padding-inline: 7px; }
  .brand-row { flex-wrap: wrap; }
  .free-badge { max-width: 100%; }
  .trend-head { align-items: flex-start; }
  .trend-source { text-align: right; }
}

@media (max-width: 350px) {
  .control-grid { grid-template-columns: 1fr; }
}

@media (max-height: 700px) and (max-width: 820px) {
  .stage-shell, .player-controls, .download-note { width: min(100%, calc((100dvh - 150px) * 9 / 16)); }
}

@media (orientation: landscape) and (max-width: 1000px) {
  .stage-shell, .player-controls, .download-note { width: min(100%, calc((100dvh - 120px) * 9 / 16)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
