:root {
  color-scheme: dark;
  --surface: #131313;
  --surface-dim: #101010;
  --surface-lowest: #0e0e0e;
  --surface-low: #1b1b1c;
  --surface-container: #202020;
  --surface-high: #2a2a2a;
  --surface-highest: #353535;
  --on-surface: #e5e2e1;
  --on-variant: #bccac4;
  --outline: #86948f;
  --outline-variant: #3d4946;
  --primary: #6de5cb;
  --primary-strong: #4ec9b0;
  --on-primary: #00382e;
  --secondary: #eab9d0;
  --tertiary: #ffc4ad;
  --error: #ffb4ab;
  --shadow: rgba(0, 0, 0, .45);
  --top-height: 48px;
  --footer-height: 32px;
  --activity-width: 48px;
  --font-ui: Inter, "Segoe UI", system-ui, sans-serif;
  --font-code: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
}

:root.light {
  color-scheme: light;
  --surface: #f4f6f6;
  --surface-dim: #e8eceb;
  --surface-lowest: #ffffff;
  --surface-low: #eef2f1;
  --surface-container: #e1e8e6;
  --surface-high: #d3ddda;
  --surface-highest: #c3d1cd;
  --on-surface: #1d2422;
  --on-variant: #50615d;
  --outline: #60746f;
  --outline-variant: #b9c8c4;
  --primary: #006b5b;
  --primary-strong: #00836f;
  --on-primary: #ffffff;
  --secondary: #7a4e64;
  --tertiary: #8b4e35;
  --error: #ba1a1a;
  --shadow: rgba(36, 51, 48, .2);
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  color: var(--on-surface);
  font: 14px/20px var(--font-ui);
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.topbar {
  height: var(--top-height);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  flex: 0 0 auto;
  background: var(--surface);
  border-bottom: 1px solid var(--outline-variant);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: auto;
  height: 32px;
  max-width: 180px;
  object-fit: contain;
}

.brand-copy h1 {
  margin: 0;
  font-size: 20px;
  line-height: 22px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-copy p {
  margin: 0;
  color: var(--on-variant);
  font: 11px/14px var(--font-code);
  text-transform: uppercase;
}

.topnav {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 24px;
  margin-left: auto;
}

.topnav a {
  height: 100%;
  display: flex;
  align-items: center;
  color: var(--on-variant);
  text-decoration: none;
  font: 11px/16px var(--font-code);
  text-transform: uppercase;
  border-bottom: 2px solid transparent;
}

.topnav a:first-child {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.topnav a:hover {
  color: var(--on-surface);
}

.icon-button,
.tool-button,
.activity {
  border: 0;
  background: transparent;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  border-radius: 4px;
  color: var(--on-variant);
  cursor: pointer;
}

.icon-button:hover,
.tool-button:hover,
.activity:hover {
  color: var(--primary);
  background: var(--surface-high);
}

.material-symbols-outlined {
  font-family: "Material Symbols Outlined";
  font-weight: normal;
  font-style: normal;
  font-size: 18px;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: "liga";
  -webkit-font-smoothing: antialiased;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 20;
}

.material-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.shell {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.activitybar {
  width: var(--activity-width);
  flex: 0 0 var(--activity-width);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  background: var(--surface-low);
  border-right: 1px solid var(--outline-variant);
}

.activity {
  width: 40px;
  height: 40px;
  font: 18px/1 var(--font-code);
}

.activity.active {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  border-left: 2px solid var(--primary);
}

.activity:last-child {
  margin-top: auto;
}

.workspace {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: var(--surface-dim);
}

.top-row {
  display: flex;
  min-height: 80px;
  height: 48%;
  overflow: hidden;
}

.top-row.collapsed {
  height: 34px !important;
  min-height: 34px;
  flex: 0 0 34px !important;
}

.top-row.collapsed .editor-wrap,
.top-row.collapsed .cheatsheet-content {
  display: none;
}

.top-row.collapsed .vertical {
  pointer-events: none;
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.input-pane {
  flex: 1 1 auto;
  min-width: 260px;
}

.cheatsheet-pane {
  width: 310px;
  flex: 0 0 310px;
  background: var(--surface-low);
  border-left: 1px solid color-mix(in srgb, var(--outline-variant) 70%, transparent);
}

.cheatsheet-pane.minimized {
  width: 42px !important;
  flex-basis: 42px !important;
  cursor: pointer;
}

.cheatsheet-pane.minimized .cheatsheet-content {
  display: none;
}

.cheatsheet-pane.minimized .pane-header {
  height: 100%;
  flex: 1 1 auto;
  justify-content: center;
  padding: 8px 0;
  border-bottom: 0;
}

.cheatsheet-pane.minimized .pane-header span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  margin: auto;
  white-space: nowrap;
}

.cheatsheet-pane.minimized .pane-header .tool-button {
  display: none;
}

.output-pane {
  flex: 1 1 auto;
  min-height: 120px;
}

.pane-header {
  height: 34px;
  flex: 0 0 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  background: var(--surface-lowest);
  border-bottom: 1px solid var(--outline-variant);
  color: var(--on-variant);
  font: 11px/16px var(--font-code);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
}

.render-status {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 1px 7px;
  border: 1px solid color-mix(in srgb, var(--primary) 18%, transparent);
  border-radius: 7px;
  background: color-mix(in srgb, var(--surface-lowest) 88%, var(--primary));
  color: var(--primary);
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}

.render-status.status-glow {
  animation: status-glow 900ms ease-out;
}

@keyframes status-glow {
  0% {
    box-shadow: 0 0 0 color-mix(in srgb, var(--primary) 0%, transparent);
    border-color: color-mix(in srgb, var(--primary) 18%, transparent);
  }

  28% {
    box-shadow:
      0 0 12px color-mix(in srgb, var(--primary) 38%, transparent),
      inset 0 0 7px color-mix(in srgb, var(--secondary) 14%, transparent);
    border-color: color-mix(in srgb, var(--primary) 55%, transparent);
  }

  100% {
    box-shadow: 0 0 0 color-mix(in srgb, var(--primary) 0%, transparent);
    border-color: color-mix(in srgb, var(--primary) 18%, transparent);
  }
}

.editor-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 48px 1fr;
  background: var(--surface);
}

.line-numbers {
  margin: 0;
  padding: 12px 8px 32px 0;
  overflow: hidden;
  border-right: 1px solid var(--outline-variant);
  background: var(--surface-low);
  color: color-mix(in srgb, var(--on-variant) 55%, transparent);
  text-align: right;
  user-select: none;
  font: 13px/22px var(--font-code);
}

#markdownInput {
  width: 100%;
  height: 100%;
  resize: none;
  border: 0;
  outline: 0;
  padding: 12px 16px 32px;
  overflow: auto;
  background: transparent;
  color: var(--on-surface);
  caret-color: var(--primary);
  font: 13px/22px var(--font-code);
  tab-size: 2;
  white-space: pre;
}

#markdownInput::selection {
  background: color-mix(in srgb, var(--primary) 25%, transparent);
}

.resizer {
  flex: 0 0 auto;
  background: var(--surface-container);
  z-index: 12;
}

.resizer:hover,
.resizer.dragging {
  background: color-mix(in srgb, var(--primary) 45%, var(--surface-container));
}

.vertical {
  width: 4px;
  cursor: col-resize;
}

.horizontal {
  height: 4px;
  cursor: row-resize;
}

.output-scroll {
  flex: 1 1 auto;
  overflow: auto;
  padding: 28px;
  background: var(--surface);
}

.markdown-body {
  color: var(--on-surface);
  font: 15px/1.62 var(--font-ui);
}

.markdown-block {
  contain: layout style;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 1.2em 0 .55em;
  color: var(--on-surface);
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: 0;
}

.markdown-body h1 {
  font-size: 28px;
  padding-bottom: 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--outline-variant) 70%, transparent);
}

.markdown-body h2 { font-size: 22px; }
.markdown-body h3 { font-size: 18px; }
.markdown-body h4 { font-size: 16px; }
.markdown-body h5,
.markdown-body h6 { font-size: 14px; color: var(--on-variant); }

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin: 0 0 16px;
}

.markdown-body a {
  color: var(--primary);
}

.markdown-body strong {
  color: var(--on-surface);
}

.markdown-body em {
  color: var(--secondary);
}

.markdown-body del {
  color: var(--outline);
}

.markdown-body mark {
  padding: 1px 4px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--tertiary) 42%, transparent);
  color: var(--on-surface);
}

.markdown-body code {
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--surface-high);
  color: var(--tertiary);
  font: 13px/1.4 var(--font-code);
}

.markdown-body pre {
  overflow: auto;
  padding: 14px 16px;
  border: 1px solid var(--outline-variant);
  border-radius: 4px;
  background: var(--surface-lowest);
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: var(--on-surface);
}

.markdown-body blockquote {
  padding: 10px 14px;
  border-left: 3px solid var(--primary);
  background: var(--surface-low);
  color: var(--on-variant);
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 26px;
}

.markdown-body li {
  margin: 4px 0;
}

.markdown-body li::marker {
  color: var(--primary);
}

.markdown-body input[type="checkbox"] {
  accent-color: var(--primary);
  margin-right: 8px;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--outline-variant);
  margin: 22px 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--outline-variant);
  padding: 7px 9px;
  vertical-align: top;
}

.markdown-body th {
  background: var(--surface-low);
  color: var(--primary);
  text-align: left;
}

.markdown-body img {
  max-width: 100%;
  border-radius: 4px;
}

.cheatsheet-content {
  flex: 1 1 auto;
  overflow: auto;
  padding: 14px;
}

.cheat-group {
  margin-bottom: 18px;
}

.cheat-group h3 {
  margin: 0 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--surface-high);
  color: var(--primary);
  font: 11px/16px var(--font-code);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.cheat-card {
  display: grid;
  gap: 7px;
  padding: 10px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--on-variant);
  font: 13px/19px var(--font-code);
}

.cheat-card code {
  color: var(--secondary);
  white-space: pre-wrap;
}

.statusbar {
  height: var(--footer-height);
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-top: 1px solid var(--outline-variant);
  background: var(--surface-lowest);
  color: var(--on-variant);
  font: 11px/16px var(--font-code);
}

.statusbar > :last-child {
  justify-self: end;
}

.footer-metrics {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}

.portfolio-link {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--on-variant);
  text-decoration: none;
}

.portfolio-link:hover {
  color: var(--primary);
}

.portfolio-link img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

.publink-only-action {
  display: none !important;
}

body.publink-mode .portfolio-link {
  color: var(--primary);
  text-shadow: 0 0 10px color-mix(in srgb, var(--primary) 48%, transparent);
}

body.publink-mode .portfolio-link img {
  filter: drop-shadow(0 0 7px color-mix(in srgb, var(--primary) 58%, transparent));
}

body.publink-mode .statusbar .portfolio-link,
body.publink-mode .topnav .portfolio-link {
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--primary) 28%, transparent);
  background: color-mix(in srgb, var(--surface-lowest) 88%, var(--primary));
  box-shadow:
    0 0 14px color-mix(in srgb, var(--primary) 24%, transparent),
    inset 0 0 8px color-mix(in srgb, var(--secondary) 12%, transparent);
}

.mobile-only,
.mobile-actions,
.modal {
  display: none;
}

.modal:not(.hidden) {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(8px);
}

.modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(760px, 86dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 42px var(--shadow);
}

.publink-panel {
  width: min(620px, 100%);
  border-color: color-mix(in srgb, var(--primary) 75%, var(--secondary));
  box-shadow:
    0 0 26px color-mix(in srgb, var(--primary) 28%, transparent),
    0 0 54px color-mix(in srgb, var(--secondary) 16%, transparent),
    0 18px 42px var(--shadow);
}

.publink-glow {
  position: absolute;
  inset: -60px -80px auto auto;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, color-mix(in srgb, var(--primary) 36%, transparent), transparent 68%);
  pointer-events: none;
}

.publink-modal-content {
  position: relative;
  padding: 22px 24px 24px;
  color: var(--on-surface);
}

.publink-modal-content h2 {
  margin: 0 0 12px;
  color: var(--primary);
  font-size: 24px;
  line-height: 30px;
  letter-spacing: 0;
}

.publink-modal-content p {
  margin: 0 0 12px;
  color: var(--on-variant);
}

.publink-note {
  margin-top: 16px !important;
  padding-top: 12px;
  border-top: 1px solid var(--outline-variant);
  font-size: 12px;
  line-height: 18px;
  color: color-mix(in srgb, var(--on-variant) 82%, transparent) !important;
}

.hidden {
  display: none !important;
}

@media (max-width: 780px) {
  :root {
    --top-height: 56px;
    --footer-height: 24px;
    --activity-width: 0px;
  }

  .mobile-only {
    display: inline-flex;
  }

  .topbar {
    padding: 0 12px;
    gap: 10px;
  }

  .brand-copy h1 {
    font-size: 18px;
    line-height: 20px;
  }

  .brand-logo {
    height: 30px;
    max-width: 46px;
  }

  .brand-copy p {
    display: none;
  }

  .topnav {
    position: absolute;
    top: var(--top-height);
    left: 0;
    right: 0;
    height: auto;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin: 0;
    padding: 8px 12px 12px;
    border-bottom: 1px solid var(--outline-variant);
    background: var(--surface-lowest);
    box-shadow: 0 10px 28px var(--shadow);
  }

  .topnav.open {
    display: flex;
  }

  .topnav a,
  .nav-footer {
    height: 36px;
    align-items: center;
    border-bottom: 0;
  }

  .nav-footer {
    color: var(--on-variant);
    font: 11px/16px var(--font-code);
  }

  .activitybar,
  .cheatsheet-pane,
  .vertical,
  .horizontal {
    display: none;
  }

  .statusbar {
    display: grid;
    height: var(--footer-height);
    min-height: var(--footer-height);
    grid-template-columns: minmax(0, auto) minmax(0, 1fr);
    gap: 8px;
    padding: 0 8px;
    font-size: 9px;
    line-height: 12px;
  }

  .status-copy {
    display: none;
  }

  .statusbar .portfolio-link {
    justify-self: start;
    max-width: 122px;
    overflow: hidden;
  }

  .statusbar .portfolio-link img {
    width: 14px;
    height: 14px;
  }

  .statusbar .portfolio-link span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .footer-metrics {
    justify-self: end;
    gap: 5px;
    max-width: 100%;
    overflow: hidden;
  }

  #stats {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .render-status {
    min-height: 16px;
    padding: 0 5px;
    border-radius: 6px;
  }

  .shell,
  .workspace,
  .top-row,
  .input-pane,
  .output-pane {
    height: 100%;
    min-height: 0;
  }

  .top-row {
    height: 100% !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
  }

  .top-row.collapsed {
    height: 100% !important;
    min-height: 0;
    flex: 1 1 auto !important;
  }

  .top-row.collapsed .editor-wrap {
    display: grid;
  }

  .workspace {
    position: relative;
  }

  .input-pane,
  .output-pane {
    flex: 1 1 auto !important;
    width: 100% !important;
    min-width: 0;
  }

  .output-pane {
    display: none;
  }

  body.show-output .top-row,
  body.show-output .input-pane {
    display: none;
  }

  body.show-output .output-pane {
    display: flex;
    flex: 1 1 auto !important;
    height: 100% !important;
  }

  .editor-wrap {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: 40px 1fr;
  }

  #markdownInput {
    font-size: 14px;
    line-height: 23px;
    padding-right: 12px;
  }

  .line-numbers {
    font-size: 12px;
    line-height: 23px;
  }

  .output-scroll {
    padding: 20px 52px 20px 18px;
  }

  .mobile-actions {
    position: fixed;
    z-index: 40;
    right: -22px;
    top: 50%;
    bottom: auto;
    left: auto;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 9px 25px 9px 9px;
    border: 1px solid color-mix(in srgb, var(--primary) 55%, transparent);
    border-right: 0;
    border-radius: 14px 0 0 14px;
    background: linear-gradient(135deg, color-mix(in srgb, var(--surface-lowest) 92%, var(--primary)), color-mix(in srgb, var(--surface-lowest) 88%, var(--secondary)));
    box-shadow: 0 0 18px color-mix(in srgb, var(--primary) 24%, transparent), inset 0 0 8px color-mix(in srgb, var(--secondary) 16%, transparent);
  }

  body.show-output .mobile-actions {
    top: 50%;
    bottom: auto;
  }

  .fab {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid color-mix(in srgb, var(--primary) 48%, transparent);
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 0 12px color-mix(in srgb, var(--primary) 18%, transparent);
  }

  .fab.primary {
    color: var(--on-primary);
    background: linear-gradient(135deg, var(--primary-strong), var(--secondary));
  }

  .fab.secondary {
    color: var(--primary);
    background: var(--surface-lowest);
  }

  .portfolio-fab {
    text-decoration: none;
  }

  .portfolio-fab img {
    width: 20px;
    height: 20px;
    object-fit: contain;
  }

  body.publink-mode .publink-only-action {
    display: inline-flex !important;
  }

  body.publink-mode .portfolio-fab {
    border-color: color-mix(in srgb, var(--primary) 68%, transparent);
    background: linear-gradient(135deg, color-mix(in srgb, var(--surface-lowest) 78%, var(--primary)), color-mix(in srgb, var(--surface-lowest) 82%, var(--secondary)));
    box-shadow:
      0 0 15px color-mix(in srgb, var(--primary) 35%, transparent),
      inset 0 0 8px color-mix(in srgb, var(--secondary) 18%, transparent);
  }

  body.publink-mode .portfolio-fab img {
    filter: drop-shadow(0 0 7px color-mix(in srgb, var(--primary) 72%, transparent));
  }

  .output-action,
  body.show-output .input-action {
    display: none;
  }

  body.show-output .output-action {
    display: inline-flex;
  }
}

@media print {
  body * {
    visibility: hidden;
  }

  #markdownOutput,
  #markdownOutput * {
    visibility: visible;
  }

  #markdownOutput {
    position: absolute;
    inset: 0;
    overflow: visible;
    padding: 0;
    color: #111;
    background: #fff;
  }
}
