:root {
  color-scheme: light;
  --page-bg: #eef1f4;
  --surface: #ffffff;
  --surface-muted: #f5f7f9;
  --editor-bg: #fcfcfd;
  --text: #202124;
  --text-strong: #25282b;
  --text-muted: #697077;
  --border: #d8dde3;
  --border-soft: #dfe3e7;
  --accent: #176b52;
  --accent-strong: #155c47;
  --button-bg: #e9edf0;
  --button-text: #303438;
  --focus: #7ab5a3;
  --code-bg: #24282d;
  --code-text: #dce3e8;
  --toast-bg: #25292d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--page-bg);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #111416;
  --surface: #191d20;
  --surface-muted: #14181b;
  --editor-bg: #161a1d;
  --text: #e7eaed;
  --text-strong: #f1f3f4;
  --text-muted: #a6adb3;
  --border: #343a3f;
  --border-soft: #2d3338;
  --accent: #58b996;
  --accent-strong: #75c8a9;
  --button-bg: #2b3136;
  --button-text: #e2e6e9;
  --focus: #58b996;
  --code-bg: #101315;
  --code-text: #e1e6ea;
  --toast-bg: #e6eaed;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { overflow: hidden; background: var(--page-bg); }
button, textarea { font: inherit; }
button { letter-spacing: 0; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: var(--accent);
  font-weight: 800;
}

.brand > span:last-child { min-width: 0; display: grid; gap: 2px; }
.brand strong { font-size: 14px; }
.brand small, .save-status { color: var(--text-muted); font-size: 12px; }
.header-actions, .output-actions { display: flex; align-items: center; gap: 8px; }

.app-shell {
  height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(380px, 1fr);
}

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

.input-pane { border-right: 1px solid var(--border); }
.output-pane { background: var(--surface-muted); }

.pane-header, .output-toolbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
}

.pane-header > div { display: flex; align-items: baseline; gap: 10px; }
.pane-header h1 { margin: 0; font-size: 14px; }
.pane-header span { color: var(--text-muted); font-size: 12px; }

#markdown-input {
  width: 100%;
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  padding: 24px;
  color: var(--text-strong);
  background: var(--editor-bg);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
  tab-size: 2;
}

.tabs { display: flex; align-self: stretch; gap: 18px; }

.tab {
  position: relative;
  border: 0;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.tab.active { color: var(--accent-strong); }
.tab.active::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
}

.primary-button, .secondary-button, .text-button, .icon-button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.primary-button { padding: 0 13px; color: #ffffff; background: var(--accent); }
.secondary-button { padding: 0 12px; color: var(--button-text); background: var(--button-bg); }
.text-button { padding: 0 4px; color: var(--accent-strong); background: transparent; }
.icon-button { width: 34px; padding: 0; color: var(--button-text); background: var(--button-bg); }
button:hover { filter: brightness(0.96); }
:root[data-theme="dark"] button:hover { filter: brightness(1.12); }
button:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button svg { width: 16px; height: 16px; }

#preview-output {
  width: calc(100% - 28px);
  height: calc(100% - 28px);
  margin: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.code-output {
  flex: 1;
  min-height: 0;
  margin: 0;
  overflow: auto;
  padding: 24px;
  color: var(--code-text);
  background: var(--code-bg);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 14px;
  color: #ffffff;
  background: var(--toast-bg);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  font-size: 13px;
}

.toast.visible { opacity: 1; transform: translateY(0); }
:root[data-theme="dark"] .toast { color: #171a1d; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

@media (max-width: 780px) {
  body { overflow: auto; }
  .topbar { position: sticky; top: 0; z-index: 10; }
  .save-status, .brand small { display: none; }
  .app-shell { height: auto; min-height: calc(100vh - 64px); grid-template-columns: 1fr; }
  .input-pane { min-height: 55vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .output-pane { min-height: 65vh; }
  #markdown-input { min-height: 48vh; }
}

@media (max-width: 520px) {
  .topbar { padding: 0 12px; }
  .header-actions .secondary-button { display: none; }
  .output-toolbar { min-height: 94px; align-items: stretch; flex-direction: column; padding: 10px 12px; }
  .tabs { min-height: 34px; justify-content: space-between; }
  .output-actions { justify-content: flex-end; }
}
