* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #1e1e2e;
  --surface: #282840;
  --border: #3e3e5e;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #6c8cff;
  --accent-hover: #8aa4ff;
  --error: #ff6b6b;
  --success: #6bff9b;
}

html {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* The tool fills the viewport; the crawlable copy scrolls below it. */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 1.25rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
}

main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.editor-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

.toolbar-selectors,
.toolbar-transport {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.4rem 0.7rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  min-width: 2rem;
  text-align: center;
}

.toolbar button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.toolbar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Depressed/active state for transport buttons */
.toolbar button.active {
  background: var(--accent-hover);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

#examples-select,
#dialect-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
}

#examples-select:hover,
#dialect-select:hover {
  border-color: var(--accent);
}

.dialect-badge {
  display: none;
  font-size: 0.75rem;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 0.15rem 0.5rem;
  white-space: nowrap;
}

.dialect-badge.visible {
  display: inline-block;
}

.dialect-badge[title] {
  cursor: help;
}

.toolbar label {
  font-size: 0.875rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  /* Translated labels ("扫描周期 (ms)：") are longer than the English ones and
     must not wrap the toolbar onto a second row. */
  white-space: nowrap;
}

.toolbar input[type="number"] {
  width: 5rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.875rem;
}

/* Transport info (duration + cycles) in toolbar */
.transport-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
  font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
  /* The cycle counter reads "6 个周期" in Chinese; keep it on one line. */
  white-space: nowrap;
}

.transport-separator {
  color: var(--border);
}

.editor-wrapper {
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--surface);
}

.editor-gutter {
  padding: 1rem 0.5rem 1rem 0.75rem;
  font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  tab-size: 2;
  color: var(--text-muted);
  background: var(--surface);
  border-right: 1px solid var(--border);
  text-align: right;
  white-space: pre;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  min-width: 3ch;
  flex: 0 0 auto;
}

#editor {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  color: var(--text);
  border: none;
  padding: 1rem;
  font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  tab-size: 2;
  overflow: auto;
  white-space: pre;
}

.output-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.output-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  border-bottom: 2px solid transparent;
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 1rem;
  font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
  font-size: 0.875rem;
}

.panel.active {
  display: block;
}

.placeholder {
  color: var(--text-muted);
  font-style: italic;
}

table.var-table {
  width: 100%;
  border-collapse: collapse;
}

table.var-table th,
table.var-table td {
  text-align: left;
  padding: 0.3rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

table.var-table th {
  color: var(--text-muted);
  font-weight: 500;
}

/* Sparkline column */
.sparkline-cell {
  width: 130px;
  min-width: 130px;
  padding: 0.2rem 0.5rem;
}

.sparkline-cell .uplot {
  display: inline-block;
}

.diagnostic-item {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.diagnostic-code {
  color: var(--error);
  font-weight: 600;
}

a.diagnostic-code {
  text-decoration: underline;
  cursor: pointer;
}

a.diagnostic-code:hover {
  color: #ff9b9b;
}

.diagnostic-message {
  margin-left: 0.5rem;
}

.diagnostic-location {
  color: var(--text-muted);
  margin-left: 0.5rem;
  font-size: 0.8rem;
}

.diagnostic-help {
  display: block;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-size: 0.85rem;
}

.error-message {
  color: var(--error);
  padding: 0.5rem 0;
}

/* --- P9999 "Submit Code" report panel --- */

.report-panel {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: rgba(108, 140, 255, 0.08);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-family: system-ui, -apple-system, sans-serif;
}

.report-title {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.report-consent {
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
  margin-bottom: 0.6rem;
}

.report-consent strong {
  color: var(--text);
}

.report-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.submit-code-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.4rem 0.9rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.submit-code-btn:hover {
  background: var(--accent-hover);
}

.report-github-link {
  color: var(--accent);
  font-size: 0.8rem;
  text-decoration: underline;
}

.report-github-link:hover {
  color: var(--accent-hover);
}

.report-confirmation {
  color: var(--success);
  font-family: system-ui, -apple-system, sans-serif;
  font-weight: 500;
}

.success-message {
  color: var(--success);
}

table.var-table tr.changed td {
  background: rgba(107, 255, 155, 0.15);
}

table.var-table td.value-invalid {
  color: var(--text-muted);
  font-style: italic;
}

.raw-bytes-note {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-family: system-ui, -apple-system, sans-serif;
  font-style: italic;
  margin-top: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: rgba(255, 200, 50, 0.08);
  border: 1px solid rgba(255, 200, 50, 0.2);
  border-radius: 4px;
}

footer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.4rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Footer interlinks: the same row on every page, wrapping instead of pushing the
   status line off a narrow window. */
.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem 1rem;
  margin-left: auto;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}

.footer-links a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* --- Embed mode --- */

body.embed header,
body.embed footer,
body.embed #pause-btn,
body.embed #examples-select,
body.embed #dialect-select {
  display: none;
}

body.embed {
  height: 100%;
}

body.embed main {
  flex-direction: column;
}

body.embed .editor-section {
  border-right: none;
  border-bottom: 1px solid var(--border);
  flex: 1 1 70%;
}

body.embed .output-section {
  flex: 1 1 30%;
  /* Keep the variables table tall enough to show the header plus at
     least three rows even when the editor is short. Matches
     _MIN_VISIBLE_VARS in docs/extensions/ironplc_playground.py
     (~73 px of chrome + 3 × ~30 px rows). */
  min-height: 170px;
}

body.embed .toolbar {
  padding: 0.35rem 0.75rem;
}

body.embed #editor {
  padding: 0.75rem;
  font-size: 0.8rem;
}

body.embed .editor-gutter {
  padding: 0.75rem 0.4rem 0.75rem 0.5rem;
  font-size: 0.8rem;
}

body.embed .panel {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
}

body.embed .sparkline-cell {
  width: 80px;
  min-width: 80px;
}

/* --- Responsive: mobile standalone --- */

@media (max-width: 768px) {
  main {
    flex-direction: column;
  }

  .editor-section {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex: 1 1 50%;
  }

  .output-section {
    flex: 1 1 50%;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .toolbar-selectors,
  .toolbar-transport {
    width: 100%;
  }
}

/* --- Crawlable copy -------------------------------------------------------
   Everything below the tool: what the page is, which dialects it supports, what
   it refuses to do, and the FAQ whose answers also become FAQPage structured
   data. Plain text on purpose — no accordions, no client-side reveal. */

.intro {
  max-width: 52rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  line-height: 1.8;
  border-top: 1px solid var(--border);
}

.intro h1 {
  font-size: 1.5rem;
  line-height: 1.4;
  margin-bottom: 1rem;
}

.intro h2 {
  font-size: 1.05rem;
  color: var(--accent);
  margin: 2rem 0 0.5rem;
}

.intro .lede {
  font-size: 1rem;
  color: var(--text);
}

.intro p,
.intro li,
.intro dd,
.intro td {
  color: var(--text);
}

.intro ul,
.intro ol {
  padding-left: 1.4rem;
}

.intro li {
  margin: 0.25rem 0;
}

.intro a {
  color: var(--accent);
}

.intro code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05rem 0.25rem;
  font-size: 0.85em;
}

.intro table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.9rem;
}

.intro th,
.intro td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: left;
  vertical-align: top;
}

.intro th {
  background: var(--surface);
  font-weight: 600;
}

.faq-list dt {
  font-weight: 600;
  margin-top: 1rem;
}

.faq-list dd {
  margin: 0.25rem 0 0;
}

.related ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  list-style: none;
  padding-left: 0;
}

/* An embedded playground is a widget: the host page owns the prose. */
body.embed .intro {
  display: none;
}
