:root {
  --bg: #05080d;
  --panel: rgba(12, 20, 30, 0.68);
  --panel-strong: rgba(17, 27, 39, 0.86);
  --line: rgba(173, 255, 219, 0.14);
  --text: #eef7ff;
  --muted: rgba(226, 241, 255, 0.62);
  --green: #31e89a;
  --cyan: #43d9ff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 18% 10%, rgba(49, 232, 154, 0.16), transparent 30%),
    radial-gradient(circle at 82% 4%, rgba(67, 217, 255, 0.16), transparent 28%),
    linear-gradient(145deg, #030609 0%, #071119 48%, #05080d 100%);
  overflow-x: hidden;
}

button,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.studio-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 18px;
  gap: 16px;
}

.studio-topbar,
.history-panel,
.main-panel,
.params-panel,
.prompt-dock {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.studio-topbar {
  height: 74px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(90px, 1fr);
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  border-radius: 22px;
}

.studio-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
}

.brand-orb {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 42% 36%, rgba(255,255,255,0.9), transparent 16%),
    conic-gradient(from 120deg, var(--green), var(--cyan), #7f6bff, var(--green));
  box-shadow: 0 0 32px rgba(49, 232, 154, 0.26);
}

.studio-brand strong,
.studio-brand em {
  display: block;
}

.studio-brand strong {
  font-size: 18px;
  line-height: 1.1;
}

.studio-brand em {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mode-switch {
  position: relative;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 5px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  background: rgba(255,255,255,0.06);
}

.mode-thumb {
  position: absolute;
  left: 5px;
  top: 5px;
  bottom: 5px;
  width: calc(50% - 7px);
  border-radius: 12px;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  box-shadow: 0 12px 34px rgba(49, 232, 154, 0.2);
  transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
}

.studio-shell[data-mode="copilot"] .mode-thumb {
  transform: translateX(calc(100% + 4px));
}

.mode-switch button,
.top-login {
  border: 0;
  border-radius: 12px;
  font-weight: 900;
}

.mode-switch button {
  position: relative;
  z-index: 1;
  min-width: 124px;
  min-height: 42px;
  color: var(--muted);
  background: transparent;
}

.mode-switch button.active {
  color: #06120e;
  background: transparent;
  box-shadow: none;
}

.top-login {
  justify-self: end;
  padding: 12px 20px;
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.06);
}

.studio-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr) 310px;
  gap: 16px;
}

.history-panel,
.main-panel,
.params-panel {
  min-height: 0;
  border-radius: 24px;
}

.history-panel,
.main-panel {
  height: calc(100vh - 74px - 52px);
}

.history-panel,
.params-panel {
  padding: 16px;
}

.panel-heading {
  margin-bottom: 16px;
}

.panel-heading span {
  display: block;
  margin-bottom: 4px;
  color: var(--green);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.panel-heading strong {
  font-size: 18px;
}

.history-list {
  display: grid;
  gap: 11px;
}

.history-empty {
  min-height: 220px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed rgba(255,255,255,0.1);
  border-radius: 18px;
  background: rgba(255,255,255,0.025);
}

.history-empty p {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
}

.history-item {
  width: 100%;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px;
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  background: rgba(255,255,255,0.045);
  text-align: left;
  transition: 0.22s ease;
}

.history-item:hover,
.history-item.active {
  transform: translateY(-2px);
  border-color: rgba(49, 232, 154, 0.36);
  background: rgba(49, 232, 154, 0.08);
  box-shadow: 0 16px 34px rgba(0,0,0,0.24);
}

.history-item img {
  width: 64px;
  height: 58px;
  object-fit: cover;
  border-radius: 12px;
}

.history-item strong,
.history-item em {
  display: block;
  min-width: 0;
}

.history-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.history-item em {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.history-item b {
  padding: 5px 7px;
  color: var(--green);
  border-radius: 999px;
  background: rgba(49, 232, 154, 0.1);
  font-size: 11px;
}

.main-panel {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background:
    radial-gradient(circle at 50% 28%, rgba(67, 217, 255, 0.14), transparent 34%),
    radial-gradient(circle at 30% 75%, rgba(49, 232, 154, 0.12), transparent 28%),
    var(--panel-strong);
}

.canvas-view,
.chat-view {
  min-height: 100%;
  height: auto;
  min-height: 0;
}

.canvas-view {
  display: grid;
  place-items: center;
  padding: 28px;
  min-height: 0;
}

.input-hint {
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 28px;
  z-index: 2;
  padding: 18px 20px;
  color: rgba(238, 247, 255, 0.72);
  border: 1px solid rgba(49, 232, 154, 0.16);
  border-radius: 18px;
  background: rgba(255,255,255,0.045);
  box-shadow: 0 18px 46px rgba(0,0,0,0.18);
  backdrop-filter: blur(12px);
  font-size: 16px;
  font-weight: 800;
}

.canvas-empty {
  max-width: 560px;
  text-align: center;
  padding-bottom: 96px;
  position: relative;
}

.empty-icon {
  position: relative;
  width: 96px;
  height: 96px;
  display: inline-block;
  border-radius: 32px;
  background:
    radial-gradient(circle at 45% 38%, #ffffff, transparent 14%),
    conic-gradient(from 120deg, rgba(49,232,154,0.9), rgba(67,217,255,0.85), rgba(127,107,255,0.8), rgba(49,232,154,0.9));
  box-shadow: 0 0 70px rgba(49, 232, 154, 0.24);
}

.empty-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 360px;
  height: 260px;
  border-radius: 999px;
  background:
    radial-gradient(circle, rgba(49, 232, 154, 0.08), rgba(67, 217, 255, 0.05) 38%, transparent 68%);
  filter: blur(22px);
  transform: translate(-50%, -50%);
  z-index: -1;
  pointer-events: none;
}

.canvas-empty h1 {
  margin: 24px 0 12px;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.12;
}

.canvas-empty h1 span {
  color: var(--green);
}

.canvas-empty p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.8;
}

.canvas-loading,
.generation-card {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 30px;
  border: 1px solid rgba(49, 232, 154, 0.28);
  border-radius: 24px;
  background: rgba(10, 22, 30, 0.62);
  box-shadow: 0 0 0 1px rgba(49,232,154,0.06) inset, 0 0 46px rgba(49, 232, 154, 0.12);
  backdrop-filter: blur(10px);
  animation: pulseBorder 2.4s ease-in-out infinite;
}

.loader-ring,
.mini-spinner {
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: var(--green);
  animation: spin 900ms linear infinite;
}

.loader-ring {
  width: 54px;
  height: 54px;
}

.mini-spinner {
  width: 24px;
  height: 24px;
}

.canvas-loading span,
.generation-card span {
  color: var(--green);
  font-size: 24px;
  font-weight: 950;
}

.result-card {
  width: min(720px, 100%);
  margin: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 26px;
  background: rgba(255,255,255,0.06);
  box-shadow: var(--shadow);
}

.result-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}

.result-card figcaption {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  color: var(--muted);
}

.result-card strong {
  color: var(--text);
}

.chat-view {
  padding: 20px;
  min-height: 0;
  height: 100%;
}

.chat-timeline {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: auto;
  padding: 4px 4px 18px;
}

.message {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.message-user {
  justify-content: flex-end;
}

.message-user .bubble {
  color: #ffffff;
  background: linear-gradient(135deg, #111827, #172033);
  border-color: rgba(255,255,255,0.08);
}

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #06120e;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  font-size: 12px;
  font-weight: 950;
}

.bubble {
  max-width: min(680px, 78%);
  padding: 16px 18px;
  border: 1px solid rgba(49, 232, 154, 0.16);
  border-radius: 18px 18px 18px 6px;
  background:
    linear-gradient(135deg, rgba(49, 232, 154, 0.055), rgba(255,255,255,0.072));
  box-shadow:
    0 14px 38px rgba(0,0,0,0.2),
    0 0 30px rgba(49, 232, 154, 0.055);
  backdrop-filter: blur(12px);
  line-height: 1.7;
}

.message-ai .bubble {
  border-color: rgba(49, 232, 154, 0.18);
}

.message-user .bubble {
  border-radius: 18px 18px 6px 18px;
}

.prompt-quote {
  margin-top: 12px;
  padding: 13px 14px;
  border-left: 3px solid var(--green);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(49,232,154,0.12), rgba(67,217,255,0.06));
  color: rgba(238, 247, 255, 0.92);
  font-weight: 800;
}

.reply-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.reply-actions button {
  min-height: 36px;
  padding: 0 13px;
  color: #06120e;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  font-weight: 900;
}

.typing .bubble {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.generation-card {
  align-items: center;
  text-align: center;
}

.generation-card img {
  width: min(420px, 100%);
  margin-top: 10px;
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.28);
}

.params-panel {
  display: grid;
  align-content: start;
  gap: 16px;
}

.control-group {
  display: grid;
  gap: 9px;
}

.control-group > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

select,
.ratio-grid button,
.count-grid button,
.upload-box {
  color: rgba(226, 241, 255, 0.58);
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.035);
}

select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 13px;
}

.ratio-grid,
.count-grid {
  display: grid;
  gap: 8px;
}

.ratio-grid {
  grid-template-columns: repeat(4, 1fr);
}

.count-grid {
  grid-template-columns: repeat(3, 1fr);
}

.ratio-grid button,
.count-grid button {
  min-height: 40px;
  border-radius: 12px;
  font-weight: 900;
}

.ratio-grid button.active,
.count-grid button.active {
  color: #06120e;
  border-color: transparent;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  box-shadow: 0 0 24px rgba(49, 232, 154, 0.18);
}

.upload-box {
  display: grid;
  gap: 10px;
  padding: 28px 18px;
  border-style: dashed;
  border-radius: 18px;
  text-align: center;
}

.upload-box input {
  display: none;
}

.upload-box span {
  font-weight: 950;
}

.upload-box em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.prompt-dock {
  position: relative;
  z-index: 20;
  padding: 12px;
  border-radius: 22px;
  margin: 0 16px 16px;
}

.prompt-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 12px;
}

textarea {
  width: 100%;
  min-height: 62px;
  resize: none;
  padding: 24px 26px;
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  outline: none;
  background: rgba(1, 7, 12, 0.44);
}

textarea::placeholder {
  color: transparent;
}

textarea:focus {
  border-color: rgba(49, 232, 154, 0.42);
  box-shadow: 0 0 0 4px rgba(49, 232, 154, 0.08);
}

.generate-btn {
  color: #06120e;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  box-shadow: 0 18px 42px rgba(49, 232, 154, 0.2);
  font-weight: 950;
}

.studio-shell[data-mode="copilot"] .params-panel {
  display: none;
}

.studio-shell[data-mode="copilot"] .studio-layout {
  grid-template-columns: 286px minmax(0, 1fr);
}

.studio-shell[data-mode="copilot"] .canvas-view {
  display: none;
}

.studio-shell[data-mode="copilot"] .chat-view {
  display: block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulseBorder {
  0%, 100% { box-shadow: 0 0 0 1px rgba(49,232,154,0.06) inset, 0 0 34px rgba(49, 232, 154, 0.12); }
  50% { box-shadow: 0 0 0 1px rgba(49,232,154,0.22) inset, 0 0 54px rgba(49, 232, 154, 0.2); }
}

@media (max-width: 1080px) {
  .studio-layout {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .params-panel {
    grid-column: 1 / -1;
  }

  .history-panel,
  .main-panel {
    height: auto;
    min-height: 560px;
  }

  .prompt-dock {
    margin: 0 0 0;
  }

  .studio-shell[data-mode="copilot"] .studio-layout {
    grid-template-columns: 220px minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .studio-shell {
    padding: 10px;
    gap: 10px;
  }

  .studio-topbar {
    height: auto;
    grid-template-columns: 1fr;
    justify-items: stretch;
    padding: 14px;
  }

  .top-login {
    display: none;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-switch button {
    min-width: 0;
  }

  .studio-layout,
  .studio-shell[data-mode="copilot"] .studio-layout {
    grid-template-columns: 1fr;
  }

  .studio-shell[data-mode="copilot"] .history-panel {
    order: 2;
  }

  .studio-shell[data-mode="copilot"] .main-panel {
    order: 1;
  }

  .canvas-view,
  .chat-view {
    height: auto;
    min-height: 520px;
  }

  .history-panel,
  .main-panel {
    min-height: auto;
  }

  .canvas-view {
    padding: 22px 14px;
  }

  .input-hint {
    left: 14px;
    right: 14px;
    bottom: 14px;
    font-size: 14px;
  }

  .history-panel,
  .params-panel {
    padding: 14px;
  }

  .bubble {
    max-width: 86%;
  }

  .prompt-dock {
    padding: 10px;
    margin: 0;
  }

  .prompt-wrap {
    grid-template-columns: 1fr;
  }

  .generate-btn {
    min-height: 52px;
  }
}

/* Stage 11 clean result fix */
.stage11-complete-wrap {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 360px !important;
  padding: 32px !important;
}

.stage11-complete-card {
  width: min(520px, 92%);
  padding: 42px 34px;
  border-radius: 28px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 0%, rgba(48, 255, 191, 0.18), transparent 42%),
    rgba(16, 34, 45, 0.82);
  border: 1px solid rgba(80, 255, 205, 0.24);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.35);
}

.stage11-complete-orb {
  width: 72px;
  height: 72px;
  margin: 0 auto 20px;
  border-radius: 24px;
  background: linear-gradient(135deg, #4df7c6, #42d8ff, #9b7cff);
  box-shadow: 0 0 42px rgba(68, 255, 207, 0.45);
}

.stage11-complete-card h2 {
  margin: 0 0 12px;
  font-size: 28px;
  color: #ffffff;
}

.stage11-complete-card p {
  margin: 0;
  color: rgba(226, 241, 247, 0.72);
  line-height: 1.7;
}

/* Stage 11 model picker fix */
.stage11-model-picker {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.stage11-model-card {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(105, 240, 174, 0.16);
  background: rgba(18, 34, 46, 0.72);
  color: #eaf7f4;
  border-radius: 18px;
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.stage11-model-card:hover {
  border-color: rgba(105, 240, 174, 0.38);
  transform: translateY(-1px);
}

.stage11-model-card.active {
  border-color: rgba(58, 255, 190, 0.85);
  box-shadow: 0 0 0 1px rgba(58, 255, 190, 0.24), 0 16px 48px rgba(58, 255, 190, 0.12);
  background: linear-gradient(135deg, rgba(34, 58, 70, 0.9), rgba(13, 28, 36, 0.9));
}

.stage11-model-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stage11-model-name {
  font-weight: 800;
  font-size: 15px;
}

.stage11-model-tag {
  font-size: 12px;
  color: #10221f;
  background: linear-gradient(135deg, #43f5bd, #52d7ff);
  border-radius: 999px;
  padding: 3px 9px;
  font-weight: 800;
  white-space: nowrap;
}

.stage11-model-real {
  margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: rgba(168, 231, 221, 0.86);
  font-size: 12px;
}

.stage11-model-meta {
  margin-top: 6px;
  color: rgba(230, 247, 244, 0.62);
  font-size: 12px;
}

.stage11-model-desc {
  margin-top: 8px;
  color: rgba(230, 247, 244, 0.72);
  font-size: 13px;
  line-height: 1.55;
}

.stage11-model-note {
  margin-top: 12px;
  color: rgba(230, 247, 244, 0.55);
  font-size: 12px;
  line-height: 1.5;
}

.stage11-current-model {
  margin-top: 16px;
  display: inline-flex;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(58, 255, 190, 0.12);
  border: 1px solid rgba(58, 255, 190, 0.28);
  color: rgba(230, 255, 247, 0.88);
  font-size: 13px;
}
