:root {
  color-scheme: dark;
  --cactus: #38d996;
  --night: #0b0f14;
  --panel: rgba(17, 24, 33, 0.78);
  --panel-strong: rgba(18, 28, 39, 0.96);
  --code-blue: #5aa9ff;
  --soft-purple: #9b7cff;
  --white: #f5f7fa;
  --warning: #ffb020;
  --danger: #ff5c5c;
  --line: #263241;
  --muted: #9ca8b8;
  --radius: 8px;
  font-family: "Inter", "HarmonyOS Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--white);
  background:
    radial-gradient(circle at 20% 12%, rgba(56, 217, 150, 0.18), transparent 26rem),
    radial-gradient(circle at 82% 4%, rgba(90, 169, 255, 0.13), transparent 28rem),
    linear-gradient(180deg, #0b0f14 0%, #101721 52%, #0b0f14 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), transparent 86%);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

img {
  max-width: 100%;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 10, 14, 0.82);
  backdrop-filter: blur(20px);
}

.auth-screen[hidden] {
  display: none;
}

.auth-card {
  width: min(460px, 100%);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.42);
}

.auth-brand,
.brand,
.sidebar-head,
.panel-head,
.preview-toolbar,
.card-title,
.section-head,
.user-card,
.draft-list button,
.comment-row,
.mobile-topbar {
  display: flex;
  align-items: center;
}

.auth-brand {
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
  text-align: center;
}

.auth-brand strong,
.auth-brand span,
.brand strong,
.brand small,
.user-card strong,
.user-card small {
  display: block;
}

.auth-brand strong,
.brand strong {
  font-size: 16px;
}

.auth-brand span,
.brand small,
.user-card small {
  color: var(--muted);
  font-size: 12px;
}

.cactus-logo {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(56, 217, 150, 0.42);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent),
    rgba(56, 217, 150, 0.12);
  box-shadow: 0 0 28px rgba(56, 217, 150, 0.24);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  color: inherit;
  padding: 0;
}

.auth-brand .cactus-logo {
  flex-basis: 76px;
  width: 76px;
  height: 76px;
  border-radius: 24px;
  font-size: 46px;
}

.sidebar .cactus-logo,
.mobile-brand .cactus-logo {
  flex-basis: 42px;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  font-size: 26px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.auth-tabs button,
.quiet-button,
.icon-button,
.tab,
.file,
.side-nav button,
.new-project-button {
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease, transform 160ms ease;
}

.auth-tabs button {
  min-height: 40px;
  border-radius: 999px;
}

.auth-tabs button.active,
.auth-tabs button:hover,
.quiet-button:hover,
.icon-button:hover,
.tab.active,
.tab:hover,
.file.active,
.file:hover,
.side-nav button.active,
.side-nav button:hover,
.new-project-button:hover {
  border-color: rgba(56, 217, 150, 0.45);
  color: var(--white);
  background: rgba(56, 217, 150, 0.11);
}

.auth-form,
.tab-panel {
  display: none;
}

.auth-form.active,
.tab-panel.active {
  display: grid;
}

.auth-form,
.settings-form,
.publish-form,
.prompt-box {
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: #d7e0ea;
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  color: var(--white);
  background: rgba(0, 0, 0, 0.22);
  outline: 0;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  padding: 12px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(56, 217, 150, 0.55);
  box-shadow: 0 0 0 3px rgba(56, 217, 150, 0.08);
}

.primary-button {
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  color: #06110d;
  background: linear-gradient(135deg, var(--cactus), #8df3c4);
  font-weight: 800;
  box-shadow: 0 12px 34px rgba(56, 217, 150, 0.22);
}

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

.app-shell {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 240ms ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 78px minmax(0, 1fr);
}

.app-shell[hidden] {
  display: none;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100vh;
  padding: 14px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(8, 12, 17, 0.82);
  backdrop-filter: blur(20px);
  transition: width 240ms ease, transform 240ms ease;
}

.sidebar.collapsed {
  width: 78px;
  padding: 12px 10px;
  align-items: center;
}

.sidebar.collapsed .brand-copy,
.sidebar.collapsed .new-project-button,
.sidebar.collapsed .side-nav,
.sidebar.collapsed .conversation-panel,
.sidebar.collapsed .user-card {
  display: none;
}

.sidebar.collapsed .sidebar-head {
  flex-direction: column;
  justify-content: flex-start;
}

.sidebar.collapsed .brand {
  justify-content: center;
}

.sidebar.collapsed #collapseSidebar {
  transform: rotate(180deg);
}

.sidebar-head {
  justify-content: space-between;
  gap: 10px;
}

.brand {
  min-width: 0;
  gap: 10px;
}

.brand-copy {
  min-width: 0;
}

.brand-copy strong {
  white-space: nowrap;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  color: var(--white);
  background: rgba(255, 255, 255, 0.04);
}

.new-project-button {
  min-height: 42px;
  border-radius: 999px;
  color: var(--white);
  font-weight: 800;
}

.side-nav,
.conversation-list,
.draft-list,
.step-list,
.work-feed,
.settings-form,
.publish-form,
.comment-list {
  display: grid;
  gap: 8px;
}

.side-nav button {
  padding: 11px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  text-align: left;
}

.sidebar-label {
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.conversation-panel {
  min-height: 0;
  overflow: auto;
}

.conversation-item {
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  color: #d7e0ea;
  background: rgba(255, 255, 255, 0.035);
  font-size: 13px;
  text-align: left;
}

.user-card {
  gap: 10px;
  width: 100%;
  margin-top: auto;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  color: var(--white);
  background: rgba(255, 255, 255, 0.04);
  text-align: left;
}

.user-card img,
.work-author img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(56, 217, 150, 0.14);
}

.workspace {
  position: relative;
  z-index: 1;
  min-width: 0;
  padding: 18px;
}

.side-nav,
.new-project-button,
.user-card,
.sidebar-head {
  position: relative;
  z-index: 1001;
}

.mobile-topbar {
  display: none;
  justify-content: space-between;
  margin-bottom: 12px;
}

.mobile-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.app-page {
  position: absolute;
  inset: 18px 18px auto auto;
  width: calc(100% - 36px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.986);
  filter: blur(8px);
  pointer-events: none;
  transition:
    opacity 320ms ease,
    transform 320ms ease,
    filter 320ms ease,
    visibility 0s linear 320ms;
}

.app-page.active {
  position: relative;
  inset: auto;
  width: 100%;
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  filter: blur(0);
  pointer-events: auto;
  transition:
    opacity 420ms ease,
    transform 420ms ease,
    filter 420ms ease;
}

.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.85fr);
  gap: 16px;
  min-height: calc(100vh - 36px);
}

.panel {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(20px);
}

.result-panel,
.ai-panel,
.mini-panel {
  min-width: 0;
  padding: 16px;
}

.panel-head,
.preview-toolbar,
.card-title,
.section-head {
  justify-content: space-between;
  gap: 14px;
}

.panel-head {
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--cactus);
  font-size: 12px;
  font-weight: 800;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.12;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
  padding: 8px 11px;
  border: 1px solid rgba(56, 217, 150, 0.32);
  border-radius: 999px;
  color: #c9ffe8;
  background: rgba(56, 217, 150, 0.1);
  font-size: 13px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--cactus);
  box-shadow: 0 0 18px rgba(56, 217, 150, 0.82);
  animation: pulse 1.8s infinite;
}

.tabbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.tab {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
}

.preview-toolbar {
  min-height: 44px;
  color: var(--muted);
  font-size: 13px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.preview-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 540px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

#workPreview {
  width: 100%;
  height: 510px;
  border: 0;
  border-radius: var(--radius);
  background: #f5f7fa;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.42);
}

.empty-preview {
  position: absolute;
  inset: 14px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  background: rgba(0, 0, 0, 0.18);
}

.empty-preview strong {
  color: var(--white);
  font-size: 22px;
}

.has-preview .empty-preview {
  display: none;
}

.phone-frame #workPreview {
  width: min(360px, 100%);
  height: 640px;
}

.phone-frame.preview-stage {
  min-height: 672px;
}

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

.file-tree {
  display: grid;
  align-content: start;
  gap: 8px;
}

.file {
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius);
  text-align: left;
}

.code-view {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  overflow: hidden;
}

.code-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.22);
}

.code-head span,
.soft-copy,
.section-head p,
.card-title span {
  color: var(--muted);
  font-size: 13px;
}

pre {
  max-height: 520px;
  min-height: 400px;
  margin: 0;
  padding: 16px;
  overflow: auto;
  color: #dfe9f5;
  background: rgba(0, 0, 0, 0.24);
  font-family: "SF Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.58;
}

.thinking-grid,
.workspace-page,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.thinking-grid article {
  min-height: 170px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.16);
}

.thinking-grid span {
  display: block;
  margin-bottom: 8px;
  color: var(--cactus);
  font-size: 12px;
  font-weight: 800;
}

.thinking-grid p,
.thinking-grid li {
  color: #d7e0ea;
  line-height: 1.7;
}

.metric-grid,
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.metric-grid b,
.stat-grid span {
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.16);
  font-weight: 400;
}

.metric-grid strong,
.stat-grid strong {
  display: block;
  color: var(--white);
  font-size: 28px;
}

.publish-form {
  max-width: 720px;
}

.cover-preview {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.cover-preview img,
.work-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ai-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-stream {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 260px;
  max-height: 48vh;
  overflow: auto;
}

.message {
  max-width: 94%;
  padding: 12px;
  border-radius: var(--radius);
  font-size: 14px;
}

.message strong {
  display: block;
  margin-bottom: 5px;
}

.message p {
  margin-bottom: 0;
  color: #d7e0ea;
  line-height: 1.65;
  white-space: pre-wrap;
}

.message.ai {
  border: 1px solid rgba(56, 217, 150, 0.18);
  background: rgba(56, 217, 150, 0.08);
}

.message.user {
  align-self: flex-end;
  border: 1px solid rgba(90, 169, 255, 0.22);
  background: rgba(90, 169, 255, 0.1);
}

.prompt-box div {
  display: flex;
  gap: 10px;
}

.prompt-box select {
  max-width: 140px;
}

.generation-card {
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.16);
}

.step-list {
  padding: 0;
  margin: 14px 0 0;
  list-style: none;
}

.step-list li {
  position: relative;
  padding-left: 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.step-list li::before {
  position: absolute;
  left: 0;
  top: 2px;
  width: 14px;
  height: 14px;
  border: 1px solid var(--line);
  border-radius: 50%;
  content: "";
}

.step-list li.done {
  color: #dbf8eb;
}

.step-list li.done::before {
  border-color: rgba(56, 217, 150, 0.8);
  background: var(--cactus);
}

.step-list li.running::before {
  border-color: var(--code-blue);
  box-shadow: 0 0 16px rgba(90, 169, 255, 0.7);
  animation: pulse 1.2s infinite;
}

.community-console {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
}

.work-feed {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.work-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: var(--panel);
  transition: transform 180ms ease, border-color 180ms ease;
}

.work-cover {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  color: var(--muted);
  background:
    linear-gradient(135deg, rgba(56, 217, 150, 0.14), rgba(90, 169, 255, 0.1)),
    rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.work-author {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.work-card h3 {
  margin: 0;
  font-size: 18px;
}

.work-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.tag-row span {
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  color: #d7e0ea;
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
}

.card-actions,
.comment-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.card-actions button,
.comment-row button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  color: var(--white);
  background: rgba(255, 255, 255, 0.05);
}

.comment-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.comment-list {
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.comment-list p {
  padding: 9px 10px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 360px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  text-align: center;
}

.draft-list button {
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  color: var(--white);
  background: rgba(0, 0, 0, 0.16);
}

.settings-grid {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
}

.server-hint {
  display: block;
  margin: 12px 0;
  padding: 12px;
  border-radius: var(--radius);
  color: #dfe9f5;
  background: rgba(0, 0, 0, 0.28);
  white-space: pre-wrap;
}

.danger {
  border-color: rgba(255, 92, 92, 0.28);
  color: #ffd0d0;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid rgba(56, 217, 150, 0.36);
  border-radius: var(--radius);
  color: #dbf8eb;
  background: rgba(11, 15, 20, 0.94);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.42);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.admin-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 10, 14, 0.78);
  backdrop-filter: blur(18px);
}

.admin-modal[hidden] {
  display: none;
}

.admin-card {
  display: grid;
  gap: 12px;
  width: min(480px, 100%);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.44);
}

.admin-brand {
  margin-bottom: 4px;
}

.admin-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.62;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.18);
  }
}

@media (max-width: 1120px) {
  .studio-grid,
  .workspace-page,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .work-feed {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 30;
    width: 286px;
    transform: translateX(-105%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-topbar {
    display: flex;
  }

}

@media (max-width: 720px) {
  .workspace {
    padding: 10px;
  }

  .panel-head,
  .preview-toolbar,
  .section-head,
  .prompt-box div,
  .community-console {
    align-items: flex-start;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .prompt-box select {
    max-width: none;
  }

  h1 {
    font-size: 30px;
  }

  .preview-stage {
    min-height: 430px;
    padding: 8px;
  }

  #workPreview {
    height: 408px;
  }

  .code-layout,
  .thinking-grid,
  .work-feed,
  .metric-grid,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .file-tree {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .file {
    padding: 0 8px;
    text-align: center;
  }
}
