:root {
  --bg: #f5efe6;
  --bg-deep: #eadfcd;
  --panel: rgba(255, 252, 248, 0.84);
  --ink: #1f1f1b;
  --muted: #746d63;
  --line: rgba(35, 31, 28, 0.12);
  --shadow: 0 28px 80px rgba(72, 55, 38, 0.12);
  --accent: #1b5b93;
  --danger: #9d3b35;
  --grid-line: rgba(27, 91, 147, 0.03);
  --toggle-bg: rgba(255, 255, 255, 0.72);
  --toggle-active-bg: #1f1f1b;
  --toggle-active-text: #fbf7f1;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  font-family: "Roboto Mono", monospace;
  background:
    radial-gradient(circle at top left, rgba(27, 91, 147, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(132, 86, 29, 0.12), transparent 26%),
    linear-gradient(180deg, #f8f4ee 0%, var(--bg) 100%);
}

body[data-theme="dark"] {
  --bg: #181a1d;
  --bg-deep: #202328;
  --panel: rgba(29, 32, 37, 0.88);
  --ink: #f1f2f4;
  --muted: #a8acb3;
  --line: rgba(255, 255, 255, 0.3);
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
  --accent: #b8c6d8;
  --danger: #ff9b93;
  --grid-line: rgba(230, 234, 240, 0.08);
  --toggle-bg: rgba(255, 255, 255, 0.08);
  --toggle-active-bg: #f1f2f4;
  --toggle-active-text: #181a1d;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.07), transparent 24%),
    radial-gradient(circle at bottom right, rgba(210, 216, 224, 0.04), transparent 24%),
    linear-gradient(180deg, #141619 0%, var(--bg) 100%);
}

.page-shell {
  width: min(1320px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0 32px;
}

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

.brand {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: lowercase;
}

.brand-sub {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: 0.1em;
  vertical-align: bottom;
  opacity: 0.1;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-left: auto;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.topnav a {
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1;
  text-decoration: none !important;
  text-transform: lowercase;
  transition: opacity 140ms ease;
}

.topnav a:link,
.topnav a:visited,
.topnav a:hover,
.topnav a:active {
  text-decoration: none !important;
}

.topnav a:hover {
  opacity: 0.68;
}

.mode-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 10px;
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--toggle-bg);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.mode-toggle span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  line-height: 1;
  border: 1px solid transparent;
}

.mode-toggle[data-active="light"] span[data-key="light"],
.mode-toggle[data-active="dark"] span[data-key="dark"],
.mode-toggle[data-active="horizontal"] span[data-key="horizontal"],
.mode-toggle[data-active="vertical"] span[data-key="vertical"] {
  background: transparent;
  border-color: currentColor;
  color: var(--ink);
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: start;
  width: 100%;
}

.composer,
.viewer {
  display: block;
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.composer {
  position: relative;
  z-index: 2;
  padding: 18px;
}

.composer-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.composer-root {
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(247, 245, 242, 0.88), rgba(236, 232, 226, 0.78)),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    linear-gradient(var(--grid-line) 1px, transparent 1px);
  background-size: auto, 28px 28px, 28px 28px;
  border: 1px solid rgba(27, 31, 35, 0.065);
  padding: 24px;
}

body[data-theme="dark"] .composer-root {
  background:
    linear-gradient(180deg, rgba(31, 34, 39, 0.9), rgba(27, 30, 35, 0.82)),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    linear-gradient(var(--grid-line) 1px, transparent 1px);
  border-color: rgba(255, 255, 255, 0.34);
}

#spec-input {
  width: 100%;
  min-height: 60px;
  resize: vertical;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.6;
}

#spec-input::placeholder {
  color: #968e82;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  margin-bottom: 14px;
}

.action-group {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-left: auto;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1;
  margin-left: 4px;
  /* text-transform: lowercase; */
}

.examples-menu {
  position: relative;
}

.help-menu {
  position: relative;
}

.help-button {
  appearance: none;
  border: 1px solid rgba(27, 91, 147, 0.22);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(27, 91, 147, 0.12);
  color: rgba(27, 91, 147, 0.96);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  text-transform: lowercase;
  cursor: pointer;
}

body[data-theme="dark"] .help-button {
  border-color: rgba(184, 198, 216, 0.28);
  background: rgba(184, 198, 216, 0.08);
  color: var(--accent);
}

.examples-button {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.04);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  text-transform: lowercase;
  cursor: pointer;
}

body[data-theme="dark"] .examples-button {
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
}

.examples-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: min(460px, 76vw);
  max-height: 320px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  z-index: 40;
}

.help-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  font-size: 12px;
  line-height: 1.45;
}

.help-row + .help-row {
  margin-top: 8px;
  /* margin-bottom: 16px; */
}

.help-row code {
  font: inherit;
  font-weight: 1000;
  font-size: 16px;
  color: var(--accent);
}

.help-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 100;
}

.help-modal[hidden] {
  display: none !important;
}

.help-scrim {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
}

body[data-theme="dark"] .help-scrim {
  background: rgba(255, 255, 255, 0.9);
}

.help-dialog {
  position: relative;
  width: min(720px, calc(100vw - 40px));
  max-height: calc(100vh - 60px);
  overflow: auto;
  padding: 28px 28px 24px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  backdrop-filter: blur(22px);
  box-shadow: var(--shadow);
}

.help-close {
  appearance: none;
  position: absolute;
  top: 16px;
  right: 16px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.help-title {
  margin: 0 0 10px;
  font-size: 24px;
  font-weight: 2000;
  letter-spacing: 0.1em;
  color: rgb(4, 27, 48);
}

.help-content {
  display: grid;
  gap: 18px;
}

.help-section {
  display: grid;
  gap: 12px;
}

.help-intro {
  margin: 0;
  font-size: 13px;
  line-height: 1.62;
}

.help-heading {
  margin: 0;
  font-size: 18px;
  font-weight: 2000;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  color: rgb(4, 27, 48);
}

.help-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 20px;
}

.help-column {
  display: grid;
  align-content: start;
  gap: 12px;
}

.help-card {
  padding: 14px 16px;
  border: 1px solid rgba(27, 91, 147, 0.12);
  border-radius: 18px;
  background: rgba(27, 91, 147, 0.08);
}

body[data-theme="dark"] .help-card {
  border-color: rgba(184, 198, 216, 0.18);
  background: rgba(184, 198, 216, 0.08);
}

.example-option {
  width: 100%;
  display: block;
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
  cursor: pointer;
}

.help-note {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(185, 142, 200, 0.08);
  color: #7a5a86;
  font-size: 12px;
  line-height: 1.6;
}

body[data-theme="dark"] .help-note {
  background: rgba(185, 142, 200, 0.12);
  color: #dbc7e3;
}

.help-note-sharing {
  background: rgba(27, 91, 147, 0.08);
  color: #2d5f8d;
}

body[data-theme="dark"] .help-note-sharing {
  background: rgba(184, 198, 216, 0.12);
  color: #d8e2ee;
}

@media (max-width: 720px) {
  .help-columns {
    grid-template-columns: 1fr;
  }
}

.example-option:hover {
  background: rgba(27, 91, 147, 0.08);
}

#render-button {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: var(--ink);
  color: #fbf7f1;
  font: inherit;
  font-size: 12px;
  text-transform: lowercase;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease;
}

#render-button[data-tone="ready"] {
  background: var(--ink);
  color: #fbf7f1;
}

#render-button[data-tone="muted"] {
  background: rgba(31, 31, 27, 0.72);
  color: #f6efe6;
}

#render-button[data-tone="danger"] {
  background: rgba(157, 59, 53, 0.92);
  color: #fff7f6;
}

body[data-theme="dark"] #render-button[data-tone="ready"] {
  background: #eef3fb;
  color: #111723;
}

body[data-theme="dark"] #render-button[data-tone="muted"] {
  background: rgba(238, 243, 251, 0.72);
  color: #111723;
}

body[data-theme="dark"] #render-button[data-tone="danger"] {
  background: #ff8d87;
  color: #111723;
}

#render-button:hover {
  transform: translateY(-1px);
}

#render-button:disabled {
  cursor: wait;
  opacity: 0.6;
  transform: none;
}

.viewer {
  width: 100%;
  min-height: 68vh;
  position: relative;
  padding: 24px;
  overflow: hidden;
}

.graph-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  margin-bottom: 12px;
}

.graph-tool {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.52);
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  line-height: 1;
  text-transform: lowercase;
  cursor: pointer;
}

body[data-theme="dark"] .graph-tool {
  background: rgba(255, 255, 255, 0.06);
}

.graph-root {
  display: grid;
  place-items: center;
  position: relative;
  min-height: 60vh;
  overflow: auto;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(247, 245, 242, 0.88), rgba(236, 232, 226, 0.78)),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    linear-gradient(var(--grid-line) 1px, transparent 1px);
  background-size: auto, 28px 28px, 28px 28px;
  border: 1px solid rgba(27, 31, 35, 0.065);
  padding: 24px;
  cursor: grab;
}

body[data-theme="dark"] .graph-root {
  background:
    linear-gradient(180deg, rgba(31, 34, 39, 0.9), rgba(27, 30, 35, 0.82)),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    linear-gradient(var(--grid-line) 1px, transparent 1px);
  border-color: rgba(255, 255, 255, 0.34);
}

.graph-root svg {
  max-width: 100%;
  height: auto;
}

.graph-root.is-dragging {
  cursor: grabbing;
}

.graph-root svg[data-zoomable="true"] {
  max-width: 100%;
}

.graph-copybar {
  position: absolute;
  right: 42px;
  top: 90px;
  display: flex;
  gap: 8px;
}

.graph-copy {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  text-transform: lowercase;
  cursor: pointer;
}

body[data-theme="dark"] .graph-copy {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
}

.graph-root .flowchart-link,
.graph-root .edgePath path,
.graph-root .edge-thickness-normal,
.graph-root .edge-thickness-thick {
  stroke: #2c3e50 !important;
  fill: none !important;
}

.graph-root .arrowheadPath {
  stroke: #2c3e50 !important;
  fill: #2c3e50 !important;
}

.graph-root marker path,
.graph-root .marker path,
.graph-root .arrowMarkerPath {
  stroke: #2c3e50 !important;
  fill: #2c3e50 !important;
}

body[data-theme="dark"] .graph-root .flowchart-link,
body[data-theme="dark"] .graph-root .edgePath path,
body[data-theme="dark"] .graph-root .edge-thickness-normal,
body[data-theme="dark"] .graph-root .edge-thickness-thick {
  stroke: #eef3fb !important;
  fill: none !important;
}

body[data-theme="dark"] .graph-root .arrowheadPath {
  stroke: #eef3fb !important;
  fill: #eef3fb !important;
}

body[data-theme="dark"] .graph-root marker path,
body[data-theme="dark"] .graph-root .marker path,
body[data-theme="dark"] .graph-root .arrowMarkerPath {
  stroke: #eef3fb !important;
  fill: #eef3fb !important;
}

.graph-root.is-empty::before {
  content: " ";
  width: min(40vw, 320px);
  height: min(24vw, 180px);
  border-radius: 999px;
  background: radial-gradient(circle, rgba(27, 91, 147, 0.1), transparent 68%);
}

.error-output {
  margin: 16px 0 0;
  padding: 16px 18px;
  border-radius: 18px;
  background: rgba(157, 59, 53, 0.08);
  border: 1px solid rgba(157, 59, 53, 0.18);
  color: var(--danger);
  font: inherit;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.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;
}

@media (max-width: 960px) {
  .page-shell {
    width: min(100vw - 20px, 100%);
    padding-top: 12px;
  }

  .viewer,
  .graph-root {
    min-height: 62vh;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .help-button,
  .examples-button,
  #render-button {
    padding: 6px 7px;
    font-size: 6px;
    border-radius: 7px;
  }
}
