:root {
  color-scheme: dark;
  --bg: #101014;
  --bg-deep: #08080b;
  --panel: #191a20;
  --panel-2: #20222a;
  --panel-3: #272a33;
  --line: rgba(255,255,255,.10);
  --line-strong: rgba(255,255,255,.20);
  --text: #f2f0eb;
  --muted: #9d9d98;
  --accent: #d99b68;
  --accent-2: #9f8cd8;
  --success: #79d1a0;
  --danger: #e26d5c;
  --shadow: 0 26px 80px rgba(0,0,0,.52);
  --radius: 18px;
  --font: "Avenir Next", "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-width: 1120px;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 18% 0%, rgba(217,155,104,.12), transparent 28%),
    radial-gradient(circle at 85% 15%, rgba(159,140,216,.11), transparent 30%),
    linear-gradient(180deg, #141419 0%, #0d0d11 45%, #08080b 100%);
  overflow: hidden;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,.014) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.012) 0 1px, transparent 1px 4px);
  z-index: 4;
}
button, a { font: inherit; }
button { cursor: pointer; }
img { user-select: none; }

.app-shell {
  position: relative;
  z-index: 1;
  height: 100dvh;
  padding: 14px;
  display: grid;
  grid-template-rows: auto minmax(0,1fr);
  gap: 10px;
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(38,40,49,.98), rgba(21,22,27,.96));
  box-shadow: 0 12px 38px rgba(0,0,0,.26), inset 0 1px rgba(255,255,255,.06);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand > div:last-child { display: grid; gap: 1px; }
.brand strong { font-size: 17px; letter-spacing: .04em; }
.brand small { color: var(--muted); font-size: 10px; letter-spacing: .18em; text-transform: uppercase; }
.brand-logo {
  display: block;
  height: 40px;
  width: auto;
  padding: 3px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.52);
  background: #fff;
  box-shadow: 0 0 20px rgba(255,255,255,.13), 0 9px 22px rgba(0,0,0,.28);
  transition: transform .18s ease, box-shadow .18s ease;
}
.brand-logo:hover {
  transform: translateY(-1px) scale(1.015);
  box-shadow: 0 0 27px rgba(255,255,255,.20), 0 11px 26px rgba(0,0,0,.32);
}

#corner-logo {
  position: fixed;
  right: 18px;
  bottom: 16px;
  z-index: 24;
  display: block;
  height: 34px;
  width: auto;
  padding: 3px 8px;
  border-radius: 9px;
  border: 1px solid rgba(255,255,255,.48);
  background: #fff;
  box-shadow: 0 0 20px rgba(255,255,255,.12), 0 9px 22px rgba(0,0,0,.30);
  pointer-events: none;
  user-select: none;
}

.status-group { display: flex; align-items: center; gap: 7px; }
.chip {
  min-height: 25px; display: inline-flex; align-items: center;
  padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
  background: rgba(255,255,255,.035); font-size: 10px;
  letter-spacing: .06em; white-space: nowrap;
}
.chip.active {
  color: #d9f5e6; border-color: rgba(121,209,160,.42);
  background: rgba(121,209,160,.10);
  box-shadow: 0 0 18px rgba(121,209,160,.08);
}

.studio-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(134px,18%) minmax(0,1fr) minmax(136px,16%);
  gap: 10px;
}
.deck {
  min-height: 0; position: relative; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(32,34,42,.97), rgba(17,18,23,.98)),
    radial-gradient(circle at 50% 120%, rgba(217,155,104,.07), transparent 60%);
  box-shadow: var(--shadow), inset 0 1px rgba(255,255,255,.055);
}
.deck::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0,0,0,.35), transparent 10%, transparent 90%, rgba(0,0,0,.35));
}
.deck-head {
  position: absolute; z-index: 3; inset: 10px 12px auto;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  pointer-events: none;
}
.deck-head > div:first-child { display: grid; gap: 1px; }
.deck-head strong { font-size: 13px; letter-spacing: .05em; }
.deck-head small { color: var(--muted); font-size: 9px; letter-spacing: .04em; }
.deck-actions { display: flex; align-items: center; gap: 7px; pointer-events: auto; }
#works-label { color: var(--muted); font-size: 10px; }

.quiet-button {
  min-height: 28px; padding: 5px 10px; border-radius: 9px;
  border: 1px solid var(--line-strong); color: var(--text);
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.03));
  box-shadow: inset 0 1px rgba(255,255,255,.10), 0 6px 15px rgba(0,0,0,.20);
  text-decoration: none; font-size: 10px; letter-spacing: .04em;
  transition: transform .15s, border-color .15s, background .15s;
}
.quiet-button:hover { border-color: rgba(217,155,104,.52); transform: translateY(-1px); }
.quiet-button:active { transform: translateY(1px); }
.organize-button {
  min-height: 34px; padding: 7px 14px; border-radius: 11px; font-size: 11px;
}
#hardware-connect {
  min-width: 152px; min-height: 50px; padding: 12px 15px; border-radius: 13px;
  font-size: 12px; font-weight: 650; letter-spacing: .05em;
}

.source-surface {
  position: absolute; inset: 0;
  padding: 36px 24px 10px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.018), transparent 32%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.018) 0 1px, transparent 1px 86px);
}
.source-card {
  position: absolute; width: 72px; height: 98px; padding: 4px;
  border-radius: 10px; overflow: hidden;
  border: 1px solid rgba(255,255,255,.15);
  background: linear-gradient(160deg, #343743, #171820);
  box-shadow: 0 16px 31px rgba(0,0,0,.40), inset 0 1px rgba(255,255,255,.12);
  cursor: grab; touch-action: none;
}
.source-card img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  border-radius: 7px; background: #101018; pointer-events: none;
}
.source-card.selected {
  border-color: rgba(217,155,104,.85);
  box-shadow: 0 0 0 2px rgba(217,155,104,.25), 0 20px 38px rgba(0,0,0,.48);
}
.source-card.dragging { cursor: grabbing; z-index: 30 !important; }
.source-card .card-index {
  position: absolute; right: 5px; bottom: 5px; width: 17px; height: 17px;
  display: grid; place-items: center; border-radius: 50%;
  background: rgba(9,9,12,.78); border: 1px solid rgba(255,255,255,.18);
  color: #d8d5cd; font-size: 8px; pointer-events: none;
}
.source-card.selected .card-index { color: #111; background: #d99b68; border-color: #d99b68; }
.source-empty, .works-empty {
  position: absolute; left: 50%; top: 53%; transform: translate(-50%,-50%);
  display: grid; place-items: center; gap: 4px; pointer-events: none; text-align: center;
}
.source-empty span, .works-empty span {
  font-size: 13px; letter-spacing: .30em; color: rgba(255,255,255,.44); text-transform: uppercase;
}
.source-empty small, .works-empty small { color: rgba(255,255,255,.24); font-size: 9px; }
.works-surface {
  position: absolute; inset: 0; padding: 34px 24px 10px;
  display: flex; flex-wrap: wrap; align-content: flex-start; justify-content: center; gap: 6px 10px;
  background:
    linear-gradient(180deg, rgba(0,0,0,.20), transparent 25%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.014) 0 1px, transparent 1px 74px);
}
.works-surface.organized {
  flex-wrap: nowrap; justify-content: flex-start; gap: 0;
}
.work-card {
  position: relative; flex: 0 0 auto; width: 72px; height: 98px; padding: 3px;
  border-radius: 10px; overflow: hidden;
  border: 1px solid rgba(255,255,255,.15);
  background: linear-gradient(160deg, #343743, #151620);
  box-shadow: 0 18px 34px rgba(0,0,0,.42), inset 0 1px rgba(255,255,255,.10);
  animation: workDrop .62s cubic-bezier(.2,.85,.25,1) both;
}
.work-card img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 6px; }
.work-card .work-meta {
  position: absolute; left: 5px; right: 5px; bottom: 5px; display: grid; gap: 1px;
  padding: 3px 4px; border-radius: 6px;
  background: rgba(8,8,11,.76); color: #d8d5cd; font-size: 7px;
}
.work-card .work-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.work-card .work-meta span { color: #8e8d88; }
@keyframes workDrop {
  0% { transform: translateY(-34px) rotate(var(--tilt)) scale(1.05); opacity: 0; }
  55% { transform: translateY(5px) rotate(calc(var(--tilt) + 1deg)) scale(.99); opacity: 1; }
  78% { transform: translateY(-2px) rotate(var(--tilt)) scale(1); }
  100% { transform: translateY(0) rotate(var(--tilt)) scale(1); opacity: 1; }
}

.middle-layout {
  min-height: 0; display: grid;
  grid-template-columns: minmax(0,1fr) 292px;
  gap: 10px;
}
.machine-panel, .control-panel {
  min-height: 0; position: relative; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(34,36,45,.98), rgba(14,15,20,.99));
  box-shadow: var(--shadow), inset 0 1px rgba(255,255,255,.06);
}
.machine-panel { position: relative; padding: 10px 12px; display: grid; grid-template-rows: auto minmax(0,1fr) auto; }
.machine-topline { position: relative; z-index: 5; }
.machine-label { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.machine-label strong { font-size: 11px; letter-spacing: .12em; white-space: nowrap; }
.machine-label small { color: var(--muted); font-size: 8px; white-space: nowrap; }
.homework-mode { color: #d8cdbd; font-size: 8px; white-space: nowrap; }
.view-button {
  height: 24px; border: 0; border-radius: 7px; color: var(--muted);
  background: transparent; font-size: 9px; letter-spacing: .05em;
}
.view-button.active {
  color: #171613; background: linear-gradient(180deg, #e8b489, #c88151);
  box-shadow: 0 4px 12px rgba(217,155,104,.20);
}

.style-wheel {
  position: absolute; z-index: 1; left: 12px; right: 12px; top: 28px; bottom: 9px;
  min-height: 0; width: auto; display: grid; place-items: center; overflow: hidden;
}
.wheel-hub {
  position: relative; width: 100%; height: 100%;
  display: grid; place-items: center; min-height: 0;
}
.stage-stack {
  position: relative; width: auto; height: 100%; max-width: 100%; aspect-ratio: 1;
  display: grid; grid-template-columns: 1fr;
  border-radius: 20px; overflow: hidden;
  border: 1px solid rgba(255,255,255,.15);
  background: #08090c;
  box-shadow: 0 28px 68px rgba(0,0,0,.58), inset 0 1px rgba(255,255,255,.08);
}
.stage-stack.comparing {
  width: auto; height: 100%; max-width: 100%; aspect-ratio: 2 / 1;
  grid-template-columns: repeat(2, minmax(0,1fr)); gap: 2px;
  border-radius: 16px;
}
.stage-pane { position: relative; min-width: 0; margin: 0; overflow: hidden; background: #08090c; }
.stage-pane img, .stage-pane canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.stage-pane figcaption {
  position: absolute; z-index: 4; left: 7px; bottom: 7px;
  padding: 3px 7px; border-radius: 7px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(8,9,12,.74); color: #e5e1d8;
  font-size: 8px; letter-spacing: .10em; pointer-events: none;
}
.original-pane { display: none; }
.stage-stack.comparing .original-pane { display: block; }
.stage-stack.comparing .effect-pane { border-left: 1px solid rgba(255,255,255,.12); }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-glass { display: none; }
.ai-result-layer {
  position: absolute; inset: 0; z-index: 3; display: none; background: #08090c;
}
.ai-result-layer.show { display: block; }
.ai-result-layer img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-result-layer span {
  position: absolute; right: 7px; top: 7px; z-index: 4; padding: 4px 7px; border-radius: 7px;
  border: 1px solid rgba(159,140,216,.55); color: #e7e2ff;
  background: rgba(15,14,24,.84); font-size: 8px; letter-spacing: .10em;
}
.mask-ring {
  position: absolute; z-index: 2; pointer-events: none;
  border: 2px solid rgba(255,240,220,.92);
  border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.45), 0 0 26px rgba(255,224,190,.32), inset 0 0 22px rgba(255,224,190,.15);
  opacity: .95;
}
.mask-ring.extreme { opacity: .28; }
.stage-caption {
  position: absolute; z-index: 6; left: 14px; right: 12px; bottom: 10px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  pointer-events: none;
}
.stage-caption > small {
  max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 3px 7px; border-radius: 7px; color: #d9d6cd;
  background: rgba(8,9,12,.68); font-size: 9px;
}
.caption-metrics {
  width: 112px; display: grid; gap: 4px; justify-items: stretch; pointer-events: none;
}
.caption-metrics > span {
  display: block; width: 100%; text-align: center;
  padding: 3px 7px; border-radius: 7px; border: 1px solid var(--line);
  color: #c9c6bd; background: rgba(0,0,0,.20); font-size: 9px; white-space: nowrap;
}
.caption-metrics .dial-module {
  width: 112px; display: grid; justify-items: end; gap: 3px;
  padding: 0; border: 0; background: none; box-shadow: none; pointer-events: auto;
}
.caption-metrics .dial-orbit,
.caption-metrics .dial { pointer-events: auto; }
.dial-orbit {
  position: relative; width: 76px; height: 76px;
  display: grid; place-items: center; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.68);
  background: #ece5ef;
  box-shadow: 0 8px 18px rgba(0,0,0,.30), inset 0 2px 5px rgba(255,255,255,.85);
}
.dial {
  position: relative; z-index: 1; width: 48px; height: 48px;
  border: 0; border-radius: 50%; background: transparent;
  touch-action: none; margin: 0; padding: 0;
}
.dial-face {
  position: absolute; inset: 0; border-radius: 50%;
  background: #ff0028;
  border: 1px solid rgba(178,0,26,.55);
  box-shadow: inset 0 2px 5px rgba(255,255,255,.24), 0 5px 12px rgba(178,0,26,.32);
}
.dial-face::after { content: none; }
.dial-marker {
  position: absolute; left: calc(50% - 2px); top: 4px; width: 4px; height: 9px;
  border-radius: 3px; background: #fff; box-shadow: 0 0 7px rgba(255,255,255,.82); z-index: 2;
}
.dial:active .dial-face { transform: scale(.97); }
.dial-readout {
  min-width: 100%; display: grid; place-items: center; gap: 0;
  padding: 2px 4px; border-radius: 7px; text-align: center;
  border: 1px solid var(--line); background: rgba(0,0,0,.44);
}
.dial-readout strong { font-size: 8.5px; line-height: 1.2; }
.dial-readout span { color: var(--muted); font-size: 7.5px; }

dialog {
  width: min(980px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  border: 1px solid var(--line-strong); border-radius: 18px; padding: 0;
  color: var(--text); background: #101117; box-shadow: 0 40px 110px rgba(0,0,0,.72);
}
dialog::backdrop { background: rgba(4,4,7,.76); backdrop-filter: blur(8px); }
.dialog-shell { display: grid; }
.dialog-shell header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.dialog-shell header > div { display: grid; gap: 2px; }
.dialog-shell strong { font-size: 15px; }
.dialog-shell small { color: var(--muted); font-size: 10px; }
.dialog-actions { display: flex; gap: 7px; }
.dialog-compare { padding: 14px; display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; }
.dialog-compare figure { margin: 0; display: grid; gap: 6px; }
.dialog-compare figcaption { color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.dialog-compare img {
  width: 100%; max-height: 62dvh; object-fit: contain; display: block;
  border-radius: 12px; border: 1px solid var(--line); background: #08090c;
}

.toast {
  position: fixed; z-index: 30; left: 50%; bottom: 18px;
  transform: translate(-50%, 12px); padding: 8px 12px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: rgba(17,18,23,.96); color: var(--text); font-size: 11px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%,0); }

.control-panel {
  padding: 14px; min-height: 0; display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.22) transparent;
}
.control-panel::-webkit-scrollbar { width: 5px; }
.control-panel .function-grid { flex: 0 0 auto; align-content: start; }
.panel-title { display: grid; gap: 1px; }
.panel-title strong { font-size: 12px; letter-spacing: .17em; }
.panel-title small { color: var(--muted); font-size: 9px; }

.function-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 6px; }
.function-button {
  min-height: 45px; padding: 5px 4px; display: grid; gap: 1px; place-items: center;
  border-radius: 10px; border: 1px solid var(--line); color: var(--muted);
  background: linear-gradient(180deg, rgba(255,255,255,.065), rgba(255,255,255,.016));
  box-shadow: inset 0 1px rgba(255,255,255,.07);
  transition: color .15s, border-color .15s, transform .15s, background .15s;
}
.function-button strong { color: var(--text); font-size: 12px; }
.function-button span { font-size: 7.5px; letter-spacing: .01em; text-align: center; }
.function-button:hover { border-color: rgba(255,255,255,.28); transform: translateY(-1px); }
.function-button:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.function-button.active {
  color: #f5e8da; border-color: rgba(217,155,104,.62);
  background: linear-gradient(180deg, rgba(217,155,104,.24), rgba(217,155,104,.07));
}
.control-hints { display: grid; gap: 4px; color: var(--muted); font-size: 8.5px; }
.control-hints span { padding-left: 10px; position: relative; }
.control-hints span::before {
  content: ""; position: absolute; left: 0; top: 4px; width: 4px; height: 4px;
  border-radius: 50%; background: var(--accent);
}
.hardware-module {
  display: grid; gap: 5px; flex: 0 0 auto; margin-top: auto; padding: 7px;
  border: 1px solid var(--line); border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.018));
}
.hardware-module header { display: flex; align-items: start; justify-content: space-between; gap: 7px; }
.hardware-module header > div:first-child { display: grid; gap: 1px; }
.hardware-module strong { font-size: 8.5px; letter-spacing: .10em; }
.hardware-module small { color: var(--muted); font-size: 7.5px; line-height: 1.25; }
.hardware-module .quiet-button:not(#hardware-connect) { min-height: 23px; padding: 3px 7px; font-size: 8px; }
.hardware-protocol {
  min-height: 19px; display: flex; align-items: center; overflow: hidden;
  padding: 3px 5px; border-radius: 7px; border: 1px dashed rgba(255,255,255,.14);
  color: var(--muted); background: rgba(0,0,0,.20);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 7.2px; white-space: nowrap; text-overflow: ellipsis;
}
.hardware-module[data-state="connected"] .hardware-protocol {
  color: #b9f0d4; border-color: rgba(121,209,160,.34);
}
.hardware-module[data-state="error"] .hardware-protocol {
  color: #ffc9c0; border-color: rgba(226,109,92,.35);
}

@media (max-width: 1320px) {
  .brand { gap: 9px; }
  .brand-logo { height: 36px; padding: 3px 7px; }
  #corner-logo { height: 30px; right: 15px; bottom: 13px; }
  .middle-layout { grid-template-columns: minmax(0,1fr) 264px; }
  .control-panel { padding: 11px; }
  .hardware-module { padding: 5px; }
  .hardware-module .quiet-button:not(#hardware-connect) { min-height: 20px; }
  #hardware-connect { min-height: 46px; min-width: 128px; }
  .style-wheel { top: 27px; }
  .dial-orbit { width: 72px; height: 72px; }
  .dial { width: 46px; height: 46px; }
}
@media (max-height: 850px) {
  .brand-logo { height: 34px; }
  #corner-logo { height: 29px; }
  .app-shell { padding: 10px; }
  .topbar { min-height: 50px; }
  .brand strong { font-size: 15px; }
  .machine-panel { padding: 10px 12px 9px; }
  .source-card, .work-card { width: 66px; height: 90px; }
  .control-panel { gap: 7px; padding: 10px; }
  .caption-metrics, .dial-module { width: 102px; }
  .style-wheel { top: 26px; bottom: 8px; }
  .dial-orbit { width: 70px; height: 70px; }
  .dial { width: 45px; height: 45px; }
  .function-grid { gap: 4px; }
  .function-button { min-height: 39px; padding: 3px 3px; }
  .function-button strong { font-size: 10px; }
  .function-button span { font-size: 7px; }
  .control-hints { display: none; }
}

dialog.compare-pulse { animation: comparePulse .55s ease-out; }
@keyframes comparePulse {
  0% { box-shadow: 0 0 0 0 rgba(217,155,104,.42), 0 40px 110px rgba(0,0,0,.72); }
  100% { box-shadow: 0 0 0 16px rgba(217,155,104,0), 0 40px 110px rgba(0,0,0,.72); }
}
