*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --paper: #f3f1ea;
  --surface: #fffdf7;
  --surface-2: #e8e6dd;
  --surface-3: #d9d7cf;
  --ink: #171b1c;
  --muted: #5e6769;
  --faint: #7d8788;
  --line: #cbc8bd;
  --line-strong: #8c928f;
  --blue: #0f5f87;
  --blue-soft: #d7edf6;
  --green: #247450;
  --green-soft: #dcefe5;
  --amber: #9a6500;
  --amber-soft: #f6e5bd;
  --red: #a3372f;
  --red-soft: #f2d7d4;
  --shadow: 0 16px 34px rgba(29, 31, 27, 0.08);
  --mono: "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(23, 27, 28, 0.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 27, 28, 0.045) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.45;
}

a {
  color: var(--blue);
}

button,
input,
select,
summary {
  font: inherit;
}

button,
summary,
select,
input {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid rgba(15, 95, 135, 0.36);
  outline-offset: 2px;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  min-height: 3.35rem;
  padding: 0.78rem 1.2rem;
  background: #101314;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.back-link {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: rgba(255, 255, 255, 0.58);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.back-link:hover {
  color: #fff;
}

.back-link svg {
  width: 1rem;
  height: 1rem;
}

.tool-title {
  grid-column: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  font-size: 0.875rem;
  font-weight: 760;
  white-space: nowrap;
}

.tool-title svg {
  width: 1.1rem;
  height: 1.1rem;
  color: #9ed6e9;
  flex: 0 0 auto;
}

.unit-toggle {
  justify-self: end;
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(2.35rem, 1fr));
  gap: 2px;
  padding: 3px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

.unit-toggle label {
  cursor: pointer;
}

.unit-toggle input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.unit-toggle span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 1.55rem;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.unit-toggle input:checked + span {
  background: #fff;
  color: #101314;
}

.shell {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: clamp(18px, 3vw, 34px) 0 42px;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(22rem, 0.7fr);
  gap: 1rem;
  align-items: end;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--blue);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  max-width: 12ch;
  font-size: clamp(2.2rem, 6vw, 4.5rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.intro > p {
  color: var(--muted);
  max-width: 42rem;
}

.input-panel,
.diagram-section,
.table-section,
.conflicts-section,
.lighting-note,
.source-note {
  background: rgba(255, 253, 247, 0.94);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.input-panel {
  margin-bottom: 14px;
}

.input-panel > summary {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  min-height: 3rem;
  padding: 0.82rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-weight: 760;
  list-style: none;
}

.input-panel > summary::-webkit-details-marker,
.subdetails > summary::-webkit-details-marker {
  display: none;
}

.summary-hint {
  color: var(--faint);
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
}

.panel-body {
  padding: 1rem;
}

.form-section + .form-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.form-section > h2,
.hardware-card h3 {
  margin-bottom: 0.72rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field-grid,
.hardware-grid {
  display: grid;
  gap: 0.72rem;
}

.field-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.hardware-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.hardware-card {
  display: grid;
  align-content: start;
  gap: 0.72rem;
  padding: 0.88rem;
  background: #f8f6ef;
  border: 1px solid var(--line);
}

.hardware-card.wide {
  grid-column: 1 / -1;
}

.field,
.mini-field {
  display: grid;
  gap: 0.32rem;
  min-width: 0;
}

.field > span:first-child,
.mini-field > span:first-child {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.number-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
}

.number-wrap:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(15, 95, 135, 0.13);
}

input,
select {
  min-width: 0;
  min-height: 2.5rem;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0.55rem 0.62rem;
  border-radius: 0;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(15, 95, 135, 0.13);
}

.number-wrap input {
  border: 0;
  min-height: 2.45rem;
  background: transparent;
  box-shadow: none;
}

.unit-label {
  padding: 0 0.58rem;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.72rem;
  white-space: nowrap;
}

.check-field {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.45rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
}

.check-field input {
  width: 1rem;
  min-height: 1rem;
  accent-color: var(--blue);
}

.check-field.tight {
  min-height: 1.8rem;
}

.subdetails {
  margin-top: 0.78rem;
  padding: 0.75rem;
  background: #f8f6ef;
  border: 1px dashed var(--line-strong);
}

.subdetails > summary {
  cursor: pointer;
  color: var(--blue);
  font-size: 0.86rem;
  font-weight: 780;
}

.subdetails[open] > summary {
  margin-bottom: 0.72rem;
}

.monitor-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.72rem;
}

.monitor-card {
  min-width: 0;
  margin: 0;
  padding: 0.7rem;
  border: 1px solid var(--line);
  background: var(--surface);
}

.monitor-card[hidden],
.is-hidden {
  display: none !important;
}

.monitor-card legend {
  padding: 0 0.25rem;
  color: var(--blue);
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 760;
}

.monitor-card .mini-field + .mini-field,
.monitor-card .mini-field + .check-field {
  margin-top: 0.55rem;
}

.check-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.2rem 0.7rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

button[type="submit"] {
  min-height: 2.6rem;
  padding: 0 1rem;
  border: 1px solid #0a425d;
  background: var(--blue);
  color: #fff;
  font-weight: 780;
  cursor: pointer;
}

button[type="submit"]:hover {
  background: #0b4d6f;
}

#status {
  color: var(--muted);
  font-size: 0.86rem;
}

.diagram-section,
.table-section,
.conflicts-section,
.lighting-note,
.source-note {
  margin-top: 14px;
  padding: 1rem;
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: baseline;
  margin-bottom: 0.8rem;
}

.section-header h2,
.conflicts-section h2,
.lighting-note h2,
.source-note h2 {
  font-family: var(--mono);
  font-size: 0.86rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-header p,
.source-note p,
.lighting-note p {
  color: var(--muted);
  font-size: 0.9rem;
}

.svg-frame {
  overflow-x: auto;
  border: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(23, 27, 28, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 27, 28, 0.05) 1px, transparent 1px),
    #fbfaf5;
  background-size: 20px 20px;
}

.svg-frame svg {
  display: block;
  width: 100%;
  min-width: 600px;
  height: auto;
}

.svg-label {
  font-family: var(--mono);
  font-size: 12px;
  fill: #263132;
}

.svg-label.small {
  font-size: 10px;
  fill: #566062;
}

.svg-muted {
  stroke: #9aa09b;
}

.svg-ink {
  stroke: #202829;
}

.svg-blue {
  stroke: var(--blue);
}

.svg-green {
  stroke: var(--green);
}

.svg-red {
  stroke: var(--red);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  padding: 0.72rem 0.78rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.88rem;
}

th {
  background: #ebe8df;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td:nth-child(2),
td:nth-child(3) {
  font-family: var(--mono);
  font-size: 0.82rem;
}

tr:last-child td {
  border-bottom: 0;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  min-height: 1.25rem;
  margin-left: 0.28rem;
  padding: 0 0.34rem;
  background: var(--blue-soft);
  color: #0a425d;
  border: 1px solid rgba(15, 95, 135, 0.22);
  font-family: var(--mono);
  font-size: 0.68rem;
  white-space: nowrap;
}

.conflicts-section {
  border-color: color-mix(in srgb, var(--red), var(--line) 58%);
  background: color-mix(in srgb, var(--red-soft), #fff 68%);
}

.conflict-card {
  margin-top: 0.72rem;
  padding: 0.78rem;
  border: 1px solid rgba(163, 55, 47, 0.34);
  background: rgba(255, 253, 247, 0.76);
}

.conflict-card h3 {
  margin: 0 0 0.35rem;
  color: var(--red);
  font-size: 0.98rem;
}

.conflict-card p {
  margin: 0;
  color: #4c3230;
}

.lighting-note {
  border-color: color-mix(in srgb, var(--green), var(--line) 55%);
}

.source-note {
  box-shadow: none;
}

@media (max-width: 880px) {
  .intro,
  .field-grid,
  .field-grid.compact,
  .hardware-grid,
  .monitor-grid {
    grid-template-columns: 1fr;
  }

  .intro {
    align-items: start;
  }

  .top-bar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.75rem;
  }

  .tool-title {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: start;
  }

  .unit-toggle {
    grid-column: 2;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 16px, 42rem);
  }

  .panel-body,
  .diagram-section,
  .table-section,
  .conflicts-section,
  .lighting-note,
  .source-note {
    padding: 0.8rem;
  }

  .check-list {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
