/* Mermaid Viewer Online — global styles.
   Design: "chart-room" aesthetic — ink navy, chart-paper background,
   teal/coral/amber accents echoing the node-graph logo. */

:root {
  --paper: #f6f4ee;
  --paper-2: #efece3;
  --card: #ffffff;
  --ink: #14283a;
  --ink-soft: #51677a;
  --ink-faint: #8aa0b0;
  --line: #e2dccd;
  --line-soft: #ece7db;
  --accent: #0e7c86;
  --accent-deep: #0a5b63;
  --teal: #2dd4bf;
  --coral: #ff5d8f;
  --amber: #f0a52a;
  --ok: #14855c;
  --err: #d64545;
  --code-bg: #0e2233;
  --code-ink: #d7e5ee;
  --shadow: 0 1px 2px rgba(20, 40, 58, .06), 0 8px 24px -12px rgba(20, 40, 58, .18);
  --shadow-lg: 0 2px 6px rgba(20, 40, 58, .08), 0 24px 48px -24px rgba(20, 40, 58, .35);
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, "JetBrains Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans SC", "Noto Sans JP", "Noto Sans KR", sans-serif;
}

[data-theme="dark"] {
  --paper: #0b1826;
  --paper-2: #0e1f30;
  --card: #102334;
  --ink: #dbe7f0;
  --ink-soft: #93a9b9;
  --ink-faint: #5f7488;
  --line: #1d3245;
  --line-soft: #17293a;
  --accent: #35c4c9;
  --accent-deep: #22a8ad;
  --ok: #3ecf8e;
  --err: #ff7b72;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px -14px rgba(0, 0, 0, .6);
  --shadow-lg: 0 2px 8px rgba(0, 0, 0, .5), 0 28px 56px -24px rgba(0, 0, 0, .8);
}

/* ------------------------------------------------------------------ reset */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
img, svg { vertical-align: middle; }
button { font: inherit; color: inherit; }
code, pre, kbd { font-family: var(--mono); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 200;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px;
  transition: top .15s;
}
.skip-link:focus { top: 12px; }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h2 { font-size: clamp(1.45rem, 2.6vw, 2rem); }
h3 { font-size: 1.06rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--coral); outline-offset: 2px; border-radius: 4px; }

/* ----------------------------------------------------------------- header */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: 18px; min-height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-name { font-weight: 700; font-size: 1.02rem; letter-spacing: -.02em; white-space: nowrap; }
.brand-name em { font-style: normal; color: var(--accent); }
.main-nav { display: flex; gap: 4px; margin-left: auto; }
.main-nav a {
  text-decoration: none; color: var(--ink-soft); font-size: .9rem;
  padding: 7px 11px; border-radius: 8px; white-space: nowrap;
}
.main-nav a:hover { color: var(--ink); background: var(--line-soft); }
.header-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 9px; cursor: pointer;
  background: transparent; border: 1px solid var(--line); color: var(--ink-soft);
}
.icon-btn:hover { color: var(--ink); background: var(--line-soft); }
.ico-sun { display: none; }
[data-theme="dark"] .ico-moon { display: none; }
[data-theme="dark"] .ico-sun { display: block; }

/* language dropdown */
.lang-switch { position: relative; }
.lang-switch summary {
  list-style: none; display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 12px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); color: var(--ink-soft); background: var(--card); font-size: .9rem;
}
.lang-switch summary::-webkit-details-marker { display: none; }
.lang-switch summary:hover { color: var(--ink); }
.lang-switch[open] summary { border-color: var(--accent); color: var(--accent); }
.lang-switch ul {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 120; margin: 0; padding: 6px;
  list-style: none; min-width: 160px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-lg);
}
.lang-switch a {
  display: block; padding: 7px 12px; border-radius: 8px; text-decoration: none;
  color: var(--ink); font-size: .92rem;
}
.lang-switch a:hover { background: var(--line-soft); }
.lang-switch a[aria-selected="true"] { color: var(--accent); font-weight: 600; }

/* ------------------------------------------------------------------- hero */
.hero {
  padding: clamp(44px, 7vw, 84px) 0 clamp(30px, 4vw, 46px);
  background:
    radial-gradient(1100px 420px at 85% -10%, color-mix(in srgb, var(--teal) 14%, transparent), transparent 65%),
    radial-gradient(800px 380px at 8% 0%, color-mix(in srgb, var(--coral) 9%, transparent), transparent 60%);
  border-bottom: 1px solid var(--line);
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.3rem);
  letter-spacing: -.025em;
  margin-bottom: .35em;
}
.hero h1::after {
  content: ""; display: block; width: 92px; height: 5px; margin-top: 18px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--teal), var(--coral) 55%, var(--amber));
}
.hero-sub {
  font-size: clamp(1.02rem, 1.6vw, 1.2rem);
  color: var(--ink-soft);
  max-width: 46em;
}
.hero-badges {
  list-style: none; display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0 26px; padding: 0;
}
.hero-badges li {
  font-size: .84rem; font-weight: 600; color: var(--accent-deep);
  background: color-mix(in srgb, var(--teal) 13%, var(--card));
  border: 1px solid color-mix(in srgb, var(--teal) 34%, transparent);
  padding: 5px 13px; border-radius: 99px;
}
.cta {
  display: inline-block; text-decoration: none; cursor: pointer;
  background: var(--accent); color: #fff;
  font-weight: 600; font-size: .98rem;
  padding: 12px 26px; border-radius: 11px;
  border: 1px solid color-mix(in srgb, var(--accent) 70%, #000 12%);
  box-shadow: 0 10px 22px -10px color-mix(in srgb, var(--accent) 75%, transparent);
  transition: transform .12s, box-shadow .12s;
}
.cta:hover { transform: translateY(-1px); box-shadow: 0 14px 26px -10px color-mix(in srgb, var(--accent) 80%, transparent); }

/* ------------------------------------------------------------------- tool */
.tool-section { padding: clamp(34px, 5vw, 60px) 0 10px; }
.tool-section h2 { margin-bottom: .3em; }
.tool-section > .wrap > p { max-width: 52em; color: var(--ink-soft); }

.tool-shell {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.06fr);
  gap: 16px; margin-top: 22px;
  align-items: stretch;
}
.pane {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 560px; overflow: hidden;
}
.pane-toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px;
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  background: var(--paper-2);
}
.pane-title {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-faint); padding: 0 6px;
}
.toolbar-spacer { flex: 1; }
.tb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 5px; }
.tb-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; background: transparent; color: var(--ink-soft);
  font-size: .84rem; font-weight: 600;
  padding: 6px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.tb-btn:hover { background: var(--line-soft); color: var(--ink); }
.tb-btn.icon-only { padding: 6px 8px; }
.tb-fix {
  color: var(--coral);
  background: color-mix(in srgb, var(--coral) 10%, transparent);
  border-color: color-mix(in srgb, var(--coral) 32%, transparent);
}
.tb-fix:hover { background: color-mix(in srgb, var(--coral) 18%, transparent); color: var(--coral); }
.tb-export {
  color: var(--accent-deep);
  background: color-mix(in srgb, var(--teal) 12%, transparent);
  border-color: color-mix(in srgb, var(--teal) 30%, transparent);
}
.tb-export:hover { background: color-mix(in srgb, var(--teal) 20%, transparent); color: var(--accent-deep); }
[data-theme="dark"] .tb-export { color: var(--teal); }
.tb-select select {
  font: inherit; font-size: .84rem; color: var(--ink-soft);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 8px; cursor: pointer;
}

/* editor */
.editor-frame {
  position: relative; flex: 1; min-height: 320px;
  display: flex; background: var(--code-bg); overflow: hidden;
}
.gutter {
  flex: 0 0 auto; padding: 14px 8px 14px 14px; text-align: right;
  color: #4d6a80; background: #0b1b29; font-family: var(--mono);
  font-size: 13.5px; line-height: 21px; white-space: pre; overflow: hidden;
  user-select: none; border-right: 1px solid #1a3245;
  max-height: 100%;
}
.editor-scroll { position: relative; flex: 1; overflow: hidden; }
.hl-layer, #codeInput {
  margin: 0; padding: 14px 16px;
  font-family: var(--mono); font-size: 13.5px; line-height: 21px;
  tab-size: 2; white-space: pre; word-wrap: normal; overflow-wrap: normal;
}
.hl-layer {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
  color: var(--code-ink); min-width: max-content; min-height: 100%;
}
.hl-layer code { display: block; white-space: pre; }
#codeInput {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; resize: none; border: 0; outline: none;
  background: transparent; color: transparent; caret-color: #7ee0d3;
  overflow: auto; min-width: max-content; min-width: 100%;
}
#codeInput::placeholder { color: #48657c; }
.hl-layer .k { color: #56c8bd; font-weight: 600; }
.hl-layer .a { color: #ff8fb1; }
.hl-layer .s { color: #f2b544; }
.hl-layer .c { color: #55708a; font-style: italic; }
.hl-layer .str { color: #a4d977; }
.hl-layer .l { color: #c6a4ff; }

/* status strip + issues */
.status-strip {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; border-top: 1px solid var(--line);
  font-size: .84rem; background: var(--paper-2);
}
.status-pill {
  display: inline-flex; align-items: center; gap: 7px; font-weight: 600;
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 99px; background: var(--ink-faint); }
.status-pill.ok { color: var(--ok); } .status-pill.ok .dot { background: var(--ok); }
.status-pill.error { color: var(--err); } .status-pill.error .dot { background: var(--err); }
.status-pill.idle { color: var(--ink-faint); }
.status-meta { color: var(--ink-faint); }

.issues-panel { border-top: 1px solid var(--line); background: var(--paper-2); max-height: 200px; overflow: auto; }
.issues-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px 4px; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-faint); font-weight: 700;
}
.issues-count { color: var(--coral); }
.issues-list { list-style: none; margin: 0; padding: 4px 8px 10px; }
.issue {
  display: flex; align-items: baseline; gap: 8px;
  font-size: .85rem; padding: 5px 8px; border-radius: 7px;
}
.issue:hover { background: var(--line-soft); }
.issue-ico { flex: 0 0 auto; }
.issue-msg { color: var(--ink-soft); }
.issue.fixable .issue-msg { color: var(--ink); }
.issue-line {
  margin-left: auto; border: 0; background: none; cursor: pointer;
  color: var(--accent); font-size: .8rem; font-weight: 600; white-space: nowrap;
}
.issue-line:hover { text-decoration: underline; }

/* preview */
.canvas-area {
  position: relative; flex: 1; min-height: 320px; overflow: hidden;
  background:
    linear-gradient(45deg, color-mix(in srgb, var(--ink-faint) 7%, transparent) 25%, transparent 25%, transparent 75%, color-mix(in srgb, var(--ink-faint) 7%, transparent) 75%),
    linear-gradient(45deg, color-mix(in srgb, var(--ink-faint) 7%, transparent) 25%, transparent 25%, transparent 75%, color-mix(in srgb, var(--ink-faint) 7%, transparent) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 11px 11px;
  background-color: var(--card);
  cursor: grab; touch-action: none;
}
.canvas-area:active { cursor: grabbing; }
.zoom-stage { position: absolute; inset: 0; transform-origin: 0 0; }
.svg-host { display: inline-block; }
.svg-host svg { display: block; max-width: none; }
.zoom-badge {
  position: absolute; left: 12px; bottom: 12px;
  background: var(--code-bg); color: #cfe3ee; font-size: .76rem; font-weight: 600;
  padding: 3px 9px; border-radius: 99px; pointer-events: none;
}
.empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--ink-faint); padding: 30px; text-align: center; pointer-events: none;
}
.render-error {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent); padding: 26px;
}
.render-error-inner {
  max-width: 520px; max-height: 100%; overflow: auto; text-align: center;
}
.render-error strong { color: var(--err); display: block; margin-bottom: 10px; }
.render-error pre {
  text-align: left; font-size: .8rem; line-height: 1.5; white-space: pre-wrap;
  background: var(--code-bg); color: #ffd9d9; padding: 12px 14px; border-radius: 10px;
  margin: 0 0 14px;
}
.stats-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 14px; border-top: 1px solid var(--line);
  font-size: .8rem; color: var(--ink-faint); background: var(--paper-2);
}
.stats-bar .toolbar-spacer { flex: 1; }
.dotsep { opacity: .5; }
#statsSaved { color: var(--ok); font-weight: 600; }
.tool-note { text-align: center; color: var(--ink-faint); font-size: .86rem; margin: 14px 0 0; }

/* fullscreen pane */
.pane-preview:fullscreen { border-radius: 0; }
.pane-preview:fullscreen .canvas-area { background-color: var(--card); }

/* --------------------------------------------------------------- sections */
.section { padding: clamp(40px, 6vw, 72px) 0; border-top: 1px solid var(--line); }
.section > .wrap > p { max-width: 52em; color: var(--ink-soft); }

/* diagram cards */
.cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 16px; margin-top: 26px;
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.card-demo {
  height: 150px; display: flex; align-items: center; justify-content: center;
  padding: 10px; border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, var(--paper-2), var(--card));
  overflow: hidden;
}
.card-demo svg { max-width: 100%; max-height: 100%; width: auto; height: auto; }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; flex: 1; }
.card-body p { font-size: .88rem; color: var(--ink-soft); flex: 1; }
.link-btn {
  align-self: flex-start; border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--accent); font-weight: 600; font-size: .86rem;
}
.link-btn:hover { text-decoration: underline; }

/* syntax */
.syntax-cols {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 26px; margin-top: 24px; align-items: start;
}
.syntax-table-wrap { overflow-x: auto; }
.syntax-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.syntax-table th {
  text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-faint); padding: 8px 10px; border-bottom: 2px solid var(--line);
}
.syntax-table td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); }
.syntax-table code {
  background: var(--paper-2); border: 1px solid var(--line);
  padding: 2px 7px; border-radius: 6px; font-size: .82rem; white-space: nowrap;
}
.syntax-snippets { display: grid; gap: 14px; }
.syntax-snippets h3 { margin-bottom: 2px; }
.snippet {
  text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; transition: border-color .15s, box-shadow .15s;
}
.snippet:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.snippet h4 { font-size: .84rem; margin: 0 0 8px; color: var(--ink-soft); font-weight: 600; }
.snippet pre {
  margin: 0; background: var(--code-bg); color: var(--code-ink);
  padding: 12px 14px; border-radius: 8px; font-size: .8rem; line-height: 1.55; overflow-x: auto;
}

/* export */
.export-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-top: 24px; }
.export-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow);
  border-top: 3px solid var(--teal);
}
.export-card:nth-child(2) { border-top-color: var(--coral); }
.export-card:nth-child(3) { border-top-color: var(--amber); }
.export-card p { font-size: .9rem; color: var(--ink-soft); margin: 0; }

/* faq */
.faq-list { display: grid; gap: 10px; max-width: 820px; }
.faq-item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 4px 18px; box-shadow: var(--shadow);
}
.faq-item summary {
  cursor: pointer; font-weight: 600; padding: 12px 0; list-style: none;
  display: flex; align-items: center; gap: 10px;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::before {
  content: "+"; flex: 0 0 auto; width: 22px; height: 22px; display: inline-flex;
  align-items: center; justify-content: center;
  border-radius: 7px; background: var(--paper-2); color: var(--accent);
  font-weight: 700; font-size: .95rem; transition: transform .15s;
}
.faq-item[open] summary::before { content: "–"; }
.faq-item p { color: var(--ink-soft); font-size: .93rem; margin: 0; padding: 0 0 14px 32px; }

/* ----------------------------------------------------------------- footer */
.site-footer { border-top: 1px solid var(--line); background: var(--paper-2); margin-top: 30px; }
.footer-grid { padding: 36px 24px 20px; }
.footer-blurb, .footer-brand p { color: var(--ink-soft); font-size: .9rem; max-width: 34em; }
.footer-base { padding: 14px 24px 26px; color: var(--ink-faint); font-size: .8rem; }
.footer-base p { margin: 0; }

/* ----------------------------------------------------------------- toasts */
.toast-region {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 300;
  pointer-events: none;
}
.toast {
  background: var(--code-bg); color: #e6f1f8;
  padding: 10px 20px; border-radius: 10px; font-size: .88rem; font-weight: 500;
  box-shadow: var(--shadow-lg); opacity: 1; transition: opacity .4s, transform .4s;
}
.toast.ok { border-left: 3px solid var(--teal); }
.toast.err { border-left: 3px solid var(--coral); }
.toast.info { border-left: 3px solid var(--amber); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ------------------------------------------------------------------- 404 */
.page-404 { display: grid; place-items: center; min-height: 100vh; text-align: center; }
.code404 { font-size: 6rem; font-weight: 800; color: var(--accent); margin: 0; line-height: 1; }
.sub404 { color: var(--ink-soft); }

/* -------------------------------------------------------------- responsive */
@media (max-width: 1020px) {
  .main-nav { display: none; }
}
@media (max-width: 900px) {
  .tool-shell { grid-template-columns: 1fr; }
  .pane { min-height: 420px; }
  .syntax-cols { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .wrap { padding: 0 16px; }
  .header-inner { gap: 10px; }
  .brand-name { font-size: .92rem; }
  .brand-name em { display: none; }
  .lang-switch summary { padding: 0 8px; font-size: .84rem; }
  .hero-badges li { font-size: .78rem; }
  .tb-btn span:not(.pane-title) { display: inline; }
  .tb-btn { padding: 6px 7px; font-size: .8rem; }
  .pane { min-height: 380px; }
}
@media print {
  .site-header, .tool-section, .site-footer, .toast-region { display: none; }
}

/* ---------------------------------------------------------------prefers */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}
