:root {
  color-scheme: dark;
  --bg: #07080d;
  --panel: #101219;
  --panel-2: #151822;
  --line: #2b2f3c;
  --text: #f4f7fb;
  --muted: #8e96a8;
  --cyan: #47f4d4;
  --orange: #ff6652;
  --yellow: #ffcf4a;
  --pink: #ff4ca0;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  overflow-x: hidden;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(1480px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 28px 28px;
}

.topbar {
  height: 86px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 28px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 38px; height: 38px; border: 3px solid var(--cyan); border-right-color: transparent;
  border-radius: 50%; display: grid; place-items: center; transform: rotate(-20deg);
  box-shadow: 0 0 18px rgba(71, 244, 212, .25);
}
.brand-mark i { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); }
.brand strong { display: block; font-size: 20px; letter-spacing: .12em; }
.brand span { display: block; margin-top: 3px; color: var(--muted); font: 600 11px/1 ui-monospace, monospace; letter-spacing: .14em; }

.session-stats { display: flex; gap: 32px; }
.session-stats div { min-width: 72px; }
.session-stats span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.session-stats strong { font: 600 17px/1 ui-monospace, monospace; letter-spacing: .08em; }

.icon-button, .text-button, .secondary-button, .primary-button, .record-button,
.segmented button, .format-row button {
  border: 0; cursor: pointer; transition: transform .16s ease, background .16s ease, color .16s ease, border-color .16s ease;
}
.icon-button:active, .text-button:active, .secondary-button:active, .primary-button:active,
.record-button:active, .segmented button:active, .format-row button:active { transform: translateY(1px); }
.icon-button {
  width: 42px; height: 42px; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center;
}
.icon-button svg, button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button[aria-pressed="false"] { color: var(--muted); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 24px;
  padding-top: 24px;
  align-items: start;
}

.play-column { min-width: 0; }
.stage-frame {
  position: relative;
  width: 100%;
  height: auto;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0a0c12;
  isolation: isolate;
}
.stage-frame::before, .stage-frame::after {
  content: ""; position: absolute; pointer-events: none; z-index: 2;
}
.stage-frame::before { inset: 14px; border: 1px solid rgba(255,255,255,.055); }
.stage-frame::after { left: 50%; top: 0; bottom: 0; border-left: 1px solid rgba(255,255,255,.03); }
.stage-frame.ratio-portrait { width: min(100%, calc((100vh - 188px) * .5625)); max-width: 510px; aspect-ratio: 9 / 16; margin-inline: auto; }
.stage-frame.ratio-square { width: min(100%, calc(100vh - 188px), 860px); aspect-ratio: 1; margin-inline: auto; }
.stage-frame.ratio-wide { width: 100%; aspect-ratio: 16 / 9; margin-block: max(0px, calc((100vh - 188px - (100vw - 430px) * .5625) / 2)); }
#gameCanvas { display: block; width: 100%; height: 100%; }

.stage-overlay { position: absolute; inset: 22px 22px auto; display: flex; justify-content: space-between; z-index: 4; pointer-events: none; }
.stage-overlay span { color: var(--muted); font: 700 11px/1 ui-monospace, monospace; letter-spacing: .12em; }
#motionBadge i { display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
#comboBadge { color: var(--yellow); opacity: 0; transform: translateY(-6px); transition: .25s ease; }
#comboBadge.show { opacity: 1; transform: translateY(0); }

.countdown { position: absolute; inset: auto 22px 22px auto; z-index: 5; color: var(--orange); font: 700 34px/1 ui-monospace, monospace; }
.escape-flash {
  position: absolute; left: 50%; top: 50%; z-index: 6; transform: translate(-50%, -50%) scale(.8);
  color: #fff; font: 900 clamp(34px, 7vw, 88px)/.9 ui-sans-serif, sans-serif; letter-spacing: -.07em;
  opacity: 0; pointer-events: none; white-space: nowrap; text-shadow: 0 0 36px var(--cyan);
}
.escape-flash.show { animation: escape-flash .8s ease-out; }
@keyframes escape-flash { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.65); } 28% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.16); } }

.transport { height: 70px; display: flex; align-items: center; gap: 10px; }
.primary-button, .secondary-button { height: 44px; display: inline-flex; align-items: center; gap: 9px; padding: 0 16px; }
.primary-button { min-width: 116px; justify-content: center; background: var(--cyan); color: #07100f; font-weight: 800; }
.secondary-button { background: var(--panel); border: 1px solid var(--line); font-weight: 700; }
.secondary-button:hover { border-color: #51596d; }
.secondary-button.hot { color: var(--orange); }
.hint { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
kbd { border: 1px solid var(--line); background: var(--panel); padding: 5px 7px; font: 600 10px/1 ui-monospace, monospace; }

.control-panel {
  min-height: calc(100vh - 110px);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 24px;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.eyebrow { color: var(--cyan); font: 700 10px/1 ui-monospace, monospace; letter-spacing: .14em; }
h1 { margin: 7px 0 0; font-size: 24px; letter-spacing: -.03em; }
.text-button { background: transparent; color: var(--muted); padding: 5px 0; font-size: 13px; border-bottom: 1px solid #4b5263; }
.text-button:hover { color: var(--text); }

.control-stack { display: grid; gap: 18px; padding: 22px 0; border-bottom: 1px solid var(--line); }
.range-control { display: block; }
.range-control > span { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.range-control b { font-size: 14px; font-weight: 650; }
.range-control output { color: var(--cyan); font: 600 12px/1 ui-monospace, monospace; }
input[type="range"] { width: 100%; height: 18px; margin: 0; appearance: none; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: #343947; }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%; background: var(--cyan); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--cyan); }
input[type="range"]::-moz-range-track { height: 3px; background: #343947; }
input[type="range"]::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: var(--cyan); border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--cyan); }
.number-control input[type="number"] { width: 100%; height: 40px; border: 1px solid var(--line); background: #0a0c12; color: var(--text); padding: 0 11px; outline: none; font: 650 14px/1 ui-monospace, monospace; }
.number-control input[type="number"]:focus { border-color: var(--cyan); }
.number-control small { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; line-height: 1.35; }

.preset-block, .effects-block, .record-block { padding-top: 20px; }
.section-label { display: flex; justify-content: space-between; color: var(--muted); font: 700 10px/1 ui-monospace, monospace; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 12px; }
.section-label span:last-child { color: var(--text); letter-spacing: 0; }
.segmented, .format-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.segmented button, .format-row button { height: 38px; background: var(--panel-2); color: var(--muted); border: 1px solid transparent; font-size: 13px; font-weight: 650; }
.segmented button:hover, .format-row button:hover { color: var(--text); }
.segmented button.active { color: #08110f; background: var(--cyan); }
.segmented.four { grid-template-columns: repeat(4, 1fr); }
.effects-block { margin-top: 20px; border-top: 1px solid var(--line); }
.effect-label { margin-top: 18px; }
.format-row button.active { color: var(--orange); border-color: var(--orange); }
.format-row button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.format-row i { display: inline-block; border: 1px solid currentColor; }
.portrait-icon { width: 7px; height: 12px; }.square-icon { width: 10px; height: 10px; }.wide-icon { width: 13px; height: 8px; }
.record-block { margin-top: 2px; border-top: 1px solid var(--line); }
.handle-field { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; margin-top: 12px; }
.handle-field span { color: var(--muted); font-size: 12px; }
.handle-field input { width: 100%; min-width: 0; height: 36px; border: 1px solid var(--line); background: #0a0c12; color: var(--text); padding: 0 10px; outline: none; }
.handle-field input:focus { border-color: var(--cyan); }
.record-button { width: 100%; height: 46px; margin-top: 12px; background: var(--orange); color: #160603; font-weight: 850; display: flex; align-items: center; justify-content: center; gap: 10px; }
.record-button.recording { background: var(--text); }
.record-dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.record-button.recording .record-dot { animation: blink .8s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }
.download-link { display: block; margin-top: 12px; color: var(--cyan); font-size: 13px; text-align: center; text-decoration: none; border-bottom: 1px solid var(--cyan); padding-bottom: 4px; }
.download-link[hidden] { display: none; }

@media (max-width: 1020px) {
  .app-shell { padding-inline: 18px; }
  .workspace { grid-template-columns: 1fr; }
  .control-panel { min-height: 0; }
  .stage-frame.ratio-portrait { width: min(100%, calc(72vh * .5625)); }
  .stage-frame.ratio-square { width: min(100%, 72vh); }
  .stage-frame.ratio-wide { width: 100%; margin-block: 0; }
  .control-stack { grid-template-columns: 1fr 1fr; column-gap: 28px; }
}

@media (max-width: 620px) {
  .app-shell { padding: 0 12px 20px; }
  .topbar { height: 72px; gap: 12px; }
  .brand strong { font-size: 17px; }.brand span { display: none; }
  .brand-mark { width: 31px; height: 31px; }
  .session-stats { gap: 13px; }.session-stats div { min-width: 50px; }.session-stats span { font-size: 10px; }.session-stats strong { font-size: 14px; }
  .workspace { padding-top: 12px; gap: 12px; }
  .stage-frame.ratio-portrait { width: min(100%, calc(62vh * .5625)); }
  .stage-frame.ratio-square, .stage-frame.ratio-wide { width: 100%; }
  .transport { height: 64px; }.hint { display: none; }.primary-button { min-width: 0; }.secondary-button, .primary-button { padding-inline: 12px; font-size: 13px; }
  .control-panel { padding: 18px; }.control-stack { grid-template-columns: 1fr; }
}

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