:root {
  --mermaid-primary: #667eea;
  --mermaid-primary-hover: #5568d3;
  --mermaid-secondary: #764ba2;
  --mermaid-text: #333;
  --mermaid-muted: #667085;
  --mermaid-line: #e0e0e0;
  --mermaid-panel: #f7f7f8;
  --mermaid-success: #23845b;
  --mermaid-danger: #c53b4c;
}

[hidden] {
  display: none !important;
}

body {
  background: transparent;
}

button,
select,
textarea {
  font: inherit;
}

button:focus-visible,
select:focus-visible,
textarea:focus-visible,
.guide-link:focus-visible,
.preview-viewport:focus-visible {
  outline: 3px solid rgba(102, 126, 234, 0.25);
  outline-offset: 2px;
}

.mermaid-container {
  max-width: 1400px;
  padding-bottom: 32px;
}

.mermaid-card {
  padding: clamp(22px, 3vw, 36px);
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.mermaid-card .tool-title {
  margin-bottom: 10px;
  padding-bottom: 12px;
  font-size: clamp(1.9rem, 4vw, 2.5rem);
}

.page-heading p {
  color: #666;
  font-size: 0.98rem;
  line-height: 1.6;
}

.guide-link {
  flex: 0 0 auto;
  margin-top: 6px;
  padding: 10px 14px;
  border: 1px solid var(--mermaid-line);
  border-radius: 8px;
  color: var(--mermaid-primary);
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.guide-link:hover {
  border-color: var(--mermaid-primary);
  background: rgba(102, 126, 234, 0.08);
}

.playground {
  overflow: hidden;
  border: 1px solid var(--mermaid-line);
  border-radius: 12px;
  background: #fff;
}

.workspace-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--mermaid-line);
  background: var(--mermaid-panel);
}

.field-control {
  display: grid;
  gap: 6px;
  color: #555;
  font-size: 0.82rem;
  font-weight: 700;
}

.field-control select {
  min-width: 210px;
  min-height: 42px;
  padding: 0 38px 0 12px;
  border: 1px solid #d8d8dc;
  border-radius: 8px;
  background: #fff;
  color: var(--mermaid-text);
  cursor: pointer;
}

.field-control select:focus {
  border-color: var(--mermaid-primary);
}

.toolbar-actions,
.pane-actions,
.preview-heading {
  display: flex;
  align-items: center;
}

.toolbar-actions,
.pane-actions {
  gap: 8px;
}

.button,
.small-button,
.mobile-tab {
  border: 0;
  cursor: pointer;
  font-weight: 700;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.button {
  min-height: 42px;
  padding: 0 18px;
  border-radius: 8px;
  font-size: 0.92rem;
}

.button:hover,
.small-button:hover,
.mobile-tab:hover {
  transform: none;
}

.button-primary {
  background: var(--mermaid-primary);
  color: #fff;
}

.button-primary:hover {
  background: var(--mermaid-primary-hover);
}

.button-secondary {
  border: 1px solid #d8d8dc;
  background: #fff;
  color: #555;
}

.button-secondary:hover {
  border-color: #bbb;
  background: #f1f1f3;
}

.mobile-tabs {
  display: none;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 520px;
}

.pane {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: #fff;
}

.editor-pane {
  border-right: 1px solid var(--mermaid-line);
}

.pane-header {
  display: flex;
  min-height: 60px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--mermaid-line);
  background: #fff;
}

.pane-header h2 {
  margin: 0;
  color: var(--mermaid-text);
  font-size: 0.98rem;
}

.preview-heading {
  gap: 10px;
}

.line-count {
  color: #8a8f99;
  font-size: 0.78rem;
}

.small-button {
  min-width: 42px;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid #d8d8dc;
  border-radius: 7px;
  background: #fff;
  color: #555;
  font-size: 0.78rem;
}

.small-button:hover {
  border-color: var(--mermaid-primary);
  background: rgba(102, 126, 234, 0.07);
  color: var(--mermaid-primary);
}

.small-button:disabled {
  border-color: #e7e7e8;
  background: #f5f5f6;
  color: #b0b1b5;
  cursor: not-allowed;
}

.square-button {
  width: 36px;
  min-width: 36px;
  padding: 0;
  font-size: 1rem;
}

.render-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--mermaid-muted);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.render-status::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  content: "";
}

.render-status.is-ready::before {
  background: var(--mermaid-success);
}

.render-status.is-loading::before {
  background: #d69a24;
}

.render-status.is-error {
  color: var(--mermaid-danger);
}

.render-status.is-error::before {
  background: var(--mermaid-danger);
}

.editor-frame {
  display: grid;
  min-height: 0;
  flex: 1;
  grid-template-columns: 48px minmax(0, 1fr);
  background: var(--mermaid-panel);
}

.line-numbers {
  overflow: hidden;
  padding: 18px 10px;
  border-right: 1px solid var(--mermaid-line);
  background: #f0f0f2;
  color: #9a9da5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
  text-align: right;
  user-select: none;
}

#codeEditor {
  width: 100%;
  min-height: 0;
  resize: none;
  padding: 18px;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: var(--mermaid-panel);
  color: var(--mermaid-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
  tab-size: 2;
  white-space: pre;
}

#codeEditor::placeholder {
  color: #a5a7ad;
}

.pane-footer {
  display: flex;
  min-height: 38px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 14px;
  border-top: 1px solid var(--mermaid-line);
  background: #fff;
  color: #8a8f99;
  font-size: 0.72rem;
}

kbd {
  padding: 2px 5px;
  border: 1px solid #d7d7da;
  border-radius: 4px;
  background: #f5f5f6;
  color: #62656c;
  font-family: inherit;
  font-size: 0.68rem;
}

.preview-viewport {
  position: relative;
  overflow: auto;
  min-height: 0;
  flex: 1;
  background: #fafafb;
  overscroll-behavior: contain;
}

.preview-surface {
  display: grid;
  min-width: 100%;
  min-height: 100%;
  place-items: center;
  padding: 28px;
}

.diagram-mount {
  display: grid;
  place-items: center;
}

.diagram-mount svg {
  display: block;
  max-width: none;
  height: auto;
}

.preview-empty {
  display: grid;
  gap: 6px;
  place-items: center;
  color: #777;
  text-align: center;
}

.preview-empty strong {
  font-size: 0.96rem;
}

.preview-empty small {
  color: #999;
  font-size: 0.78rem;
}

.error-panel {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border-top: 1px solid #f5c6cb;
  background: #fff1f1;
  color: #8f2c39;
  font-size: 0.78rem;
  line-height: 1.5;
}

.error-panel span {
  max-height: 72px;
  overflow: auto;
  white-space: pre-wrap;
}

.privacy-note {
  margin: 12px 2px 0;
  color: #858891;
  font-size: 0.78rem;
  text-align: right;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 11px 15px;
  border: 1px solid var(--mermaid-line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(44, 62, 80, 0.18);
  color: var(--mermaid-text);
  font-size: 0.84rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.noscript-message {
  position: fixed;
  z-index: 200;
  right: 18px;
  bottom: 18px;
  padding: 12px 15px;
  border-radius: 8px;
  background: #fff1f1;
  color: #8f2c39;
}

@media (max-width: 1040px) {
  .preview-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 800px) {
  .mermaid-container {
    padding-bottom: 16px;
  }

  .mermaid-card {
    padding: 18px;
  }

  .page-heading {
    display: block;
    margin-bottom: 18px;
  }

  .mermaid-card .tool-title {
    font-size: 1.9rem;
  }

  .guide-link {
    display: inline-flex;
    margin-top: 12px;
  }

  .workspace-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .field-control select {
    width: 100%;
    min-width: 0;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .mobile-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 5px;
    border-bottom: 1px solid var(--mermaid-line);
    background: var(--mermaid-panel);
  }

  .mobile-tab {
    min-height: 40px;
    border-radius: 7px;
    background: transparent;
    color: #777;
    font-size: 0.86rem;
  }

  .mobile-tab.is-active {
    background: #fff;
    box-shadow: 0 1px 4px rgba(44, 62, 80, 0.12);
    color: var(--mermaid-primary);
  }

  .workspace-grid {
    display: block;
    min-height: 0;
  }

  .pane {
    display: none;
    height: clamp(420px, 58dvh, 500px);
  }

  .pane.is-mobile-active {
    display: flex;
  }

  .editor-pane {
    border-right: 0;
  }

  .preview-pane {
    height: clamp(360px, 48dvh, 430px);
  }

  #codeEditor {
    font-size: 16px;
  }

  .line-numbers {
    font-size: 14px;
  }

  .preview-header {
    min-height: 96px;
  }

  .preview-actions {
    width: 100%;
  }

  .preview-actions .small-button {
    min-height: 40px;
    flex: 1;
  }

  .preview-actions .square-button {
    flex: 0 0 40px;
  }

  .pane-footer {
    display: none;
  }

  .privacy-note {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .mermaid-card {
    padding: 14px;
  }

  .page-heading p {
    font-size: 0.9rem;
  }

  .preview-surface {
    padding: 18px;
  }
}

body.embed-mode {
  min-height: 100vh;
  padding: 0;
  background: #fafafb;
}

body.embed-mode .mermaid-container {
  width: 100%;
  max-width: none;
  min-height: 100vh;
  padding: 0;
}

body.embed-mode .back-button,
body.embed-mode .page-heading,
body.embed-mode .workspace-toolbar,
body.embed-mode .mobile-tabs,
body.embed-mode .editor-pane,
body.embed-mode .privacy-note,
body.embed-mode .toast {
  display: none !important;
}

body.embed-mode .mermaid-card,
body.embed-mode .playground,
body.embed-mode .workspace-grid {
  min-height: 100vh;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.embed-mode .workspace-grid {
  display: block;
}

body.embed-mode .preview-pane {
  display: flex !important;
  width: 100%;
  height: 100vh;
  min-height: 100vh;
  border: 0;
}

body.embed-mode .preview-header,
body.embed-mode .error-panel {
  display: none;
}

body.embed-mode .preview-viewport {
  min-height: 100vh;
}
