:root {
  --bg-primary: #08111f;
  --bg-secondary: rgba(9, 22, 40, 0.82);
  --panel-border: rgba(159, 189, 255, 0.16);
  --panel-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  --surface-strong: rgba(14, 29, 50, 0.94);
  --surface-muted: rgba(124, 153, 202, 0.1);
  --text-primary: #eaf2ff;
  --text-secondary: #93a6c9;
  --text-soft: #7284a6;
  --accent: #78d8ff;
  --accent-strong: #2ca3dc;
  --accent-warm: #ffd173;
  --danger: #ff7a8f;
  --success: #86e4a5;
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --grid-line: rgba(120, 216, 255, 0.08);
  --font-ui: "Segoe UI Variable", "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  --font-display: "Bahnschrift", "Aptos Display", "Segoe UI Variable", "Microsoft YaHei UI", sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "SFMono-Regular", monospace;
  --editor-width: 520px;
  --resizer-width: 8px;
  --workspace-gap: 6px;
  --panel-padding: 12px;
  --panel-border-width: 1px;
  --inner-border-width: 1px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-ui);
  color: var(--text-primary);
  background:
    radial-gradient(circle at top left, rgba(51, 137, 255, 0.2), transparent 30%),
    radial-gradient(circle at top right, rgba(255, 209, 115, 0.14), transparent 26%),
    linear-gradient(145deg, #050b14 0%, #08111f 46%, #0b1324 100%);
}

body.is-resizing,
body.is-resizing * {
  user-select: none;
  cursor: col-resize !important;
}

body::before {
  position: fixed;
  inset: 0;
  content: "";
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.8), transparent 90%);
  pointer-events: none;
}

button,
textarea {
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.topbar h1,
.panel-header h2,
.section-heading h3 {
  margin: 0;
  font-family: var(--font-display);
}

.topbar h1 {
  font-size: clamp(1.4rem, 2.6vw, 2rem);
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.github-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(147, 166, 201, 0.18);
  border-radius: 14px;
  background: rgba(12, 24, 42, 0.78);
  color: var(--text-primary);
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.github-link:hover,
.github-link:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(120, 216, 255, 0.35);
  background: rgba(17, 34, 58, 0.92);
  outline: none;
}

.github-link svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, var(--editor-width)) var(--resizer-width) minmax(420px, 1fr);
  gap: var(--workspace-gap);
  align-items: stretch;
}

.panel {
  position: relative;
  overflow: hidden;
  border: var(--panel-border-width) solid var(--panel-border);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(17, 34, 58, 0.92), rgba(8, 17, 31, 0.96));
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(18px);
}

.panel::after {
  position: absolute;
  inset: 0;
  content: "";
  border-radius: inherit;
  background: linear-gradient(140deg, rgba(120, 216, 255, 0.08), transparent 36%, rgba(255, 209, 115, 0.08));
  pointer-events: none;
}

.panel-editor,
.panel-preview {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 126px);
  padding: var(--panel-padding);
  min-width: 0;
}

.workspace-resizer {
  position: relative;
  min-width: var(--resizer-width);
  cursor: col-resize;
  touch-action: none;
}

.workspace-resizer::before {
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 50%;
  width: 1px;
  content: "";
  border-radius: 999px;
  background: rgba(147, 166, 201, 0.18);
  transform: translateX(-50%);
  transition: background 180ms ease, box-shadow 180ms ease, width 180ms ease;
}

.workspace-resizer::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 56px;
  content: "";
  border-radius: 999px;
  background:
    radial-gradient(circle, rgba(120, 216, 255, 0.9) 1.2px, transparent 1.3px) center / 8px 12px repeat-y;
  opacity: 0.72;
  transform: translate(-50%, -50%);
  transition: opacity 180ms ease, transform 180ms ease;
}

.workspace-resizer:hover::before,
.workspace-resizer.is-active::before {
  width: 1.5px;
  background: rgba(120, 216, 255, 0.3);
  box-shadow: 0 0 10px rgba(120, 216, 255, 0.1);
}

.workspace-resizer:hover::after,
.workspace-resizer.is-active::after {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.03);
}

.panel-header,
.status-row,
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.panel-header {
  margin-bottom: 12px;
}

.editor-field {
  display: block;
  flex: 1;
  min-height: 280px;
}

#mermaid-input {
  width: 100%;
  height: 100%;
  min-height: 340px;
  padding: 16px;
  border: var(--inner-border-width) solid rgba(147, 166, 201, 0.13);
  border-radius: var(--radius-lg);
  background: rgba(5, 11, 20, 0.85);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.96rem;
  line-height: 1.7;
  resize: vertical;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

#mermaid-input:focus {
  border-color: rgba(120, 216, 255, 0.44);
  box-shadow: 0 0 0 4px rgba(120, 216, 255, 0.1);
}

.status-card,
.controls-section {
  position: relative;
  z-index: 1;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(147, 166, 201, 0.14);
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
}

.status-label {
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.status-pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
}

.status-pill.is-idle {
  background: rgba(120, 216, 255, 0.12);
  color: var(--accent);
}

.status-pill.is-success {
  background: rgba(134, 228, 165, 0.12);
  color: var(--success);
}

.status-pill.is-error {
  background: rgba(255, 122, 143, 0.12);
  color: var(--danger);
}

.status-pill.is-working {
  background: rgba(255, 209, 115, 0.14);
  color: var(--accent-warm);
}

.status-message {
  margin: 10px 0 0;
  color: var(--text-secondary);
  line-height: 1.6;
}

.theme-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.theme-card {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 8px;
  border: 1px solid rgba(147, 166, 201, 0.14);
  border-radius: 18px;
  background: rgba(7, 15, 27, 0.7);
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.theme-card:hover,
.theme-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(120, 216, 255, 0.35);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
  outline: none;
}

.theme-card.is-active {
  border-color: rgba(120, 216, 255, 0.48);
  box-shadow: 0 14px 32px rgba(44, 163, 220, 0.18);
}

.theme-card .swatches {
  display: inline-flex;
  gap: 8px;
  flex-direction: row;
  align-items: center;
  flex-wrap: nowrap;
}

.swatches i {
  display: block;
  width: 16px;
  height: 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

.theme-card::after {
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  padding: 6px 10px;
  border: 1px solid rgba(147, 166, 201, 0.18);
  border-radius: 999px;
  background: rgba(5, 11, 20, 0.96);
  color: var(--text-primary);
  content: attr(aria-label);
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 4;
}

.theme-card:hover::after,
.theme-card:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.primary-button,
.secondary-button,
.ghost-button {
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, opacity 180ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.ghost-button:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.primary-button {
  background: linear-gradient(135deg, #78d8ff, #2ca3dc);
  color: #04101d;
  font-weight: 700;
}

.secondary-button {
  background: rgba(12, 24, 42, 0.92);
  border-color: rgba(147, 166, 201, 0.18);
  color: var(--text-primary);
}

.ghost-button {
  background: rgba(12, 24, 42, 0.72);
  border-color: rgba(147, 166, 201, 0.14);
  color: var(--text-primary);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}

.zoom-controls {
  display: flex;
  gap: 8px;
}

.zoom-controls .ghost-button {
  min-width: 54px;
}

.preview-stage {
  position: relative;
  flex: 1;
  min-height: 540px;
  border: var(--inner-border-width) solid rgba(147, 166, 201, 0.11);
  border-radius: calc(var(--radius-xl) - 8px);
  background: rgba(4, 10, 18, 0.72);
  overflow: hidden;
}

.export-toolbar {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  display: flex;
  gap: 8px;
}

.icon-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(147, 166, 201, 0.18);
  border-radius: 14px;
  background: rgba(7, 15, 27, 0.86);
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, opacity 180ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(120, 216, 255, 0.35);
  background: rgba(14, 29, 50, 0.94);
  outline: none;
}

.icon-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}

.icon-button svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.icon-button::after {
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  padding: 6px 10px;
  border: 1px solid rgba(147, 166, 201, 0.18);
  border-radius: 999px;
  background: rgba(5, 11, 20, 0.96);
  color: var(--text-primary);
  content: attr(data-tooltip);
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.icon-button:hover::after,
.icon-button:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.empty-state,
.preview-surface {
  position: absolute;
  inset: 0;
}

.empty-state {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 32px;
  color: var(--text-secondary);
}

.empty-state[hidden] {
  display: none !important;
}

.empty-state p {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--text-primary);
}

.preview-surface {
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
}

.preview-frame {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: calc(var(--radius-lg) - 4px);
  overflow: hidden;
}

.preview-frame svg {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  cursor: grab;
}

.preview-frame svg:active {
  cursor: grabbing;
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .panel-editor,
  .panel-preview {
    min-height: auto;
  }

  .workspace-resizer {
    display: none;
  }

  .preview-stage {
    min-height: 460px;
  }
}

@media (max-width: 760px) {
  :root {
    --workspace-gap: 4px;
    --panel-padding: 10px;
  }

  .app-shell {
    padding: 16px;
  }

  .topbar {
    margin-bottom: 12px;
  }

  .panel-editor,
  .panel-preview {
    padding: var(--panel-padding);
  }

  #mermaid-input,
  .preview-stage {
    border-color: rgba(147, 166, 201, 0.09);
  }

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

  .panel-header {
    flex-direction: column;
    align-items: stretch;
  }

  .zoom-controls {
    justify-content: flex-start;
  }
}
