:root {
  color-scheme: light;
  --bg: #f5f7f5;
  --surface: #ffffff;
  --surface-soft: #eef3f1;
  --ink: #1c2522;
  --muted: #64736d;
  --line: #d7e0dc;
  --accent: #247c6d;
  --accent-dark: #145e53;
  --accent-soft: #d9efea;
  --warn: #a65028;
  --warn-bg: #fff2e9;
  --shadow: 0 18px 45px rgba(21, 42, 36, 0.11);
  font-family: "Segoe UI", "Noto Sans TC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(36, 124, 109, 0.08), transparent 36%),
    linear-gradient(315deg, rgba(93, 116, 71, 0.11), transparent 42%),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.workspace {
  max-width: 1240px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.08;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.summary-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 138px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 8px 25px rgba(31, 48, 43, 0.06);
}

#statusDot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 410px) 1fr;
  gap: 22px;
  align-items: start;
}

.panel,
.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.input-panel {
  position: sticky;
  top: 20px;
  padding: 20px;
}

.results {
  display: grid;
  gap: 18px;
}

.panel {
  padding: 20px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-head.compact {
  margin-top: 18px;
  margin-bottom: 12px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-dark);
  cursor: pointer;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input:disabled {
  color: #8a9692;
  background: #f1f4f3;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid.two {
  grid-template-columns: 1fr 1fr;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 42px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.segmented button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.segmented button.active {
  background: var(--surface);
  color: var(--accent-dark);
  box-shadow: 0 3px 11px rgba(21, 42, 36, 0.12);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  cursor: pointer;
}

.switch input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.conditional-fields[hidden],
.shape-dimension[hidden] {
  display: none;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.metric {
  min-height: 102px;
  padding: 17px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 27px;
  line-height: 1.05;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.die-diagram {
  display: grid;
  grid-template-columns: 0.95fr 1.7fr 0.72fr 1fr;
  height: 92px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  margin-bottom: 16px;
}

.zone {
  position: relative;
  min-width: 0;
}

.zone::before,
.zone::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #36514a;
}

.zone::before {
  top: 27px;
}

.zone::after {
  bottom: 27px;
}

.entry {
  background: #f7fbfa;
}

.cone {
  background: #e0f0ec;
  clip-path: polygon(0 16%, 100% 32%, 100% 68%, 0 84%);
}

.bearing {
  background: #c9e1dc;
  clip-path: polygon(0 32%, 100% 32%, 100% 68%, 0 68%);
}

.exit {
  background: #f7fbfa;
  clip-path: polygon(0 32%, 100% 20%, 100% 80%, 0 68%);
}

.section-profile {
  height: 178px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  overflow: hidden;
}

.section-profile svg {
  width: 100%;
  height: 100%;
  display: block;
}

.die-body {
  fill: url("#steelGradient");
  stroke: #45645d;
  stroke-width: 2;
}

.die-bore {
  fill: none;
  stroke: #17352f;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.center-line {
  stroke: #7d918b;
  stroke-width: 1.4;
  stroke-dasharray: 7 7;
}

.profile-labels text {
  fill: #244740;
  font-size: 19px;
  font-weight: 800;
}

.table {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.row {
  display: grid;
  grid-template-columns: minmax(130px, 1.1fr) minmax(140px, 1fr) minmax(110px, 0.8fr);
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.formula-row {
  grid-template-columns: minmax(130px, 0.9fr) minmax(110px, 0.55fr) minmax(220px, 1.4fr);
}

.formula-row input {
  min-height: 34px;
}

.row:last-child {
  border-bottom: 0;
}

.row.header {
  background: #edf4f1;
  color: var(--accent-dark);
  font-weight: 800;
}

.cell {
  min-width: 0;
  padding: 10px 12px;
  overflow-wrap: anywhere;
}

.cell + .cell {
  border-left: 1px solid var(--line);
}

.warning {
  min-height: 22px;
  margin: 13px 0 0;
  color: var(--warn);
  font-weight: 700;
}

.warning.active {
  padding: 10px 12px;
  border: 1px solid #ffd2b8;
  border-radius: 8px;
  background: var(--warn-bg);
}

.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.import-actions input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-button,
.import-actions button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-dark);
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 800;
}

.file-button {
  display: inline-flex;
  align-items: center;
}

.import-actions button:hover,
.file-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.helper-text {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .layout {
    display: grid;
  }

  .input-panel {
    position: static;
  }

  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .grid.two,
  .metrics {
    grid-template-columns: 1fr;
  }

  .row {
    grid-template-columns: 1fr;
  }

  .cell + .cell {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
