:root {
  color-scheme: light;
  --ink: #1b2430;
  --muted: #3e4c5e;
  --line: #1b2836;
  --paper: #c5d0dc;
  --card: #f4f7fa;
  --blue: #0e3a5d;
  --blue-dark: #08283f;
  --amber: #6d4b00;
  --amber-bg: #fff4d6;
  --green: #145c32;
  --green-bg: #e5f6ea;
  --red: #8d1d1d;
  --red-bg: #fde8e6;
  --rail: #1b2836;
  --sheet: #fbfcfe;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", Aptos, sans-serif;
  font-size: 20px;
  line-height: 1.45;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(14, 42, 68, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(14, 42, 68, 0.07) 1px, transparent 1px);
  background-size: 28px 28px;
}

body.large { font-size: 24px; }

.top, main, .banner {
  width: min(1080px, calc(100% - 32px));
  margin-left: auto;
  margin-right: auto;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: stretch;
  padding: 22px 0 8px;
}

.title-block {
  flex: 1 1 auto;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  background: var(--sheet);
  border: 1px solid var(--line);
  outline: 1px solid var(--line);
  outline-offset: 4px;
  padding: 14px 16px;
}

.tb-main { flex: 1 1 auto; }

.tb-meta {
  margin: 0;
  min-width: 210px;
  border-left: 1px solid var(--line);
  padding-left: 14px;
}

.tb-meta div {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #c5d0dc;
}

.tb-meta dt {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.tb-meta dd { margin: 0; font-weight: 700; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 12px; }

h1 { font-size: 2.1rem; }

h2 {
  font-size: 1.35rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-bottom: 2px solid var(--line);
  padding-bottom: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.lead, .hint { color: var(--muted); }

.banner {
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid var(--line);
  padding: 14px 16px;
  margin-top: 18px;
}

.tabs {
  width: min(1080px, calc(100% - 32px));
  margin: 18px auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 2px solid var(--line);
}

.tabs button {
  border-radius: 0;
  border: 1px solid var(--line);
  border-bottom: none;
  background: #d5dee8;
  color: var(--ink);
  margin-right: 4px;
}

.tabs button[aria-current="page"] {
  background: var(--blue);
  color: white;
  border-color: var(--blue);
}

main { padding-bottom: 48px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  outline: 1px solid var(--line);
  outline-offset: 3px;
  border-radius: 0;
  padding: 20px;
  margin-bottom: 22px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label, .stack { display: flex; flex-direction: column; gap: 6px; font-weight: 650; }

input, select, textarea, button { font: inherit; }

input, select, textarea {
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: white;
  color: var(--ink);
  width: 100%;
}

textarea { min-height: 140px; resize: vertical; }

button {
  min-height: 52px;
  padding: 10px 16px;
  border-radius: 0;
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

button:hover, button:focus-visible { background: var(--blue-dark); }

button.secondary {
  background: white;
  color: var(--blue);
}

button.quiet {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

button:disabled { opacity: 0.55; cursor: not-allowed; }

a.file-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 10px 16px;
  border-radius: 0;
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
  font-weight: 700;
  text-decoration: none;
}

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.steps-plain { margin: 0; padding-left: 1.2rem; }

.steps-plain li { margin: 8px 0; }

.rung-edit {
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 12px;
  margin: 12px 0;
}

.rung-edit legend { font-weight: 750; padding: 0 6px; }

.check-row, .action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  margin: 8px 0;
}

.check-row label, .action-row label { flex: 1 1 180px; }

.seal {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 650;
  margin: 8px 0;
}

.seal input { width: 28px; height: 28px; min-height: 28px; }

.remove {
  background: white;
  color: var(--red);
  border-color: var(--red);
  flex: 0 0 auto;
}

.track {
  height: 22px;
  background: #d5dee8;
  border-radius: 0;
  overflow: hidden;
  border: 1px solid var(--line);
}

.fill {
  height: 100%;
  width: 0;
  background: var(--blue);
}

.fill.waiting {
  width: 40%;
  animation: slide 1.1s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .fill.waiting { animation: none; width: 100%; opacity: 0.45; }
}

@keyframes slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(280%); }
}

.log { margin: 12px 0 0; padding-left: 1.2rem; }

.log .stopped { color: var(--red); }

.alert {
  background: var(--red-bg);
  color: var(--red);
  border-color: #e3b5b0;
}

.warning-list {
  background: var(--amber-bg);
  padding: 12px 12px 12px 2rem;
  color: var(--amber);
  border: 1px solid var(--line);
}

.rung-card {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 16px;
}

.ladder {
  display: flex;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0;
  background:
    linear-gradient(#d5dee8, #d5dee8) 0 50% / 100% 2px no-repeat;
}

.rail {
  width: 8px;
  background: var(--rail);
  border-radius: 0;
  flex: 0 0 auto;
}

.logic {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 92px;
}

.parallel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-left: 4px solid var(--rail);
  border-right: 4px solid var(--rail);
  padding: 6px;
}

.leg, .series { display: flex; gap: 8px; align-items: center; }

.contact, .coil {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 96px;
  text-align: center;
  background: var(--sheet);
  border: 1px solid var(--line);
  padding: 4px 6px;
}

.sym {
  font-family: Consolas, "Courier New", monospace;
  font-size: 1.3rem;
  letter-spacing: 0.04em;
}

.name { font-size: 0.85rem; max-width: 160px; word-break: break-word; }

.studio-line {
  font-family: Consolas, "Courier New", monospace;
  background: #e7eef5;
  border: 1px solid var(--line);
  padding: 10px;
  overflow-x: auto;
  font-size: 0.95rem;
}

.tag-table, table { width: 100%; border-collapse: collapse; }

th, td {
  text-align: left;
  vertical-align: top;
  padding: 10px 8px;
  border-bottom: 1px solid #c5d0dc;
}

th {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.table-wrap { overflow-x: auto; }

.job-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #c5d0dc;
}

.meta { color: var(--muted); margin: 4px 0 0; }

.found { color: var(--green); font-weight: 700; }

.file-pick input { margin-top: 6px; }

.download-guide {
  background: var(--amber-bg);
  border: 1px solid var(--line);
  padding: 16px;
  margin-top: 16px;
}

.download-guide .row { margin-top: 12px; }

.labs-banner { background: #e7f0ea; }

.labs-next { background: var(--green-bg); }

.sim-sheet, .share-sheet {
  border: 1px solid var(--line);
  background: #f4f7fb;
  padding: 16px;
  margin-top: 16px;
}

.sim-inputs { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin: 12px 0; }
.sim-toggle { min-height: 44px; }
.sim-toggle.off { background: #d9dee8; color: #1c2430; }
.sim-toggle.on { background: #1f7a4d; color: #fff; }
.sim-result { margin-top: 12px; }
.sim-out {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.sim-out.on strong { color: #1f7a4d; }

.hmi-screen {
  background: #d5ddd6;
  border: 8px solid #2a2a2a;
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  min-height: 160px;
}

.hmi-object {
  min-width: 140px;
  min-height: 76px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
}

.hmi-button.green, .hmi-lamp.green { background: #1f6b3a; color: white; }
.hmi-button.red, .hmi-lamp.red { background: #8d1d1d; color: white; }
.hmi-indicator, .hmi-lamp.amber, .hmi-indicator.amber { background: #c98400; color: #1c1915; }
.hmi-indicator.green { background: #1f6b3a; color: white; }
.hmi-button { border-radius: 8px; }
.hmi-lamp, .hmi-indicator { border-radius: 999px; }
.hmi-number { background: white; color: #1c1915; border: 2px solid #2a2a2a; border-radius: 6px; font-family: Consolas, "Courier New", monospace; }
.hmi-object small { font-weight: 500; }

#previewImage { max-width: 100%; max-height: 360px; margin-top: 12px; border: 1px solid var(--line); }

.missing { color: var(--red); font-weight: 700; }

.source-list { margin: 12px 0 0; padding-left: 1.2rem; }

.source-list li { margin: 6px 0; }

.device-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; }

.device-list button { background: white; color: var(--ink); border-color: var(--line); }

.option-sheet {
  border: 1px solid var(--line);
  margin: 12px 0;
  background: white;
}

.option-head {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--blue);
  color: white;
  padding: 8px 12px;
}

.option-head h3 { margin: 0; color: white; }

.stamp {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  padding: 3px 6px;
  white-space: nowrap;
}

.option-sheet > p { margin: 12px; }

.option-list { list-style: none; margin: 0; padding: 0 12px 12px; }

.option-list li {
  border-top: 1px solid #d5dee8;
  padding: 10px 0;
}

.flag {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 6px;
  margin-bottom: 4px;
}

.flag-used { background: var(--green-bg); color: var(--green); }
.flag-check { background: var(--amber-bg); color: var(--amber); }
.flag-avoid { background: var(--red-bg); color: var(--red); }

@media (max-width: 720px) {
  .grid, .title-block, .tb-meta div { grid-template-columns: 1fr; }
  .title-block, .top { flex-direction: column; align-items: stretch; }
  .tb-meta { border-left: none; padding-left: 0; border-top: 1px solid var(--line); padding-top: 10px; min-width: 0; }
  .job-row { flex-direction: column; align-items: stretch; }
}

@media print {
  .top button, .tabs, .banner, .no-print, button { display: none !important; }
  body { background: white; }
  .card, .title-block { outline: none; border: none; padding: 0; }
}
