:root {
  color-scheme: dark;
  --bg: #080b10;
  --bg-soft: #0d1219;
  --panel: #111822;
  --panel-raised: #151e2a;
  --panel-deep: #0b1119;
  --line: #293647;
  --line-soft: #202b39;
  --text: #f0f4f8;
  --muted: #91a0b2;
  --muted-2: #66778b;
  --accent: #f2a13e;
  --accent-bright: #ffd080;
  --accent-dark: #bb651d;
  --blue: #63b9ff;
  --green: #54d79e;
  --red: #ff807d;
  --shadow: 0 22px 60px rgba(0,0,0,.30);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 8% -6%, rgba(78,120,168,.17), transparent 30rem),
    radial-gradient(circle at 92% 3%, rgba(242,161,62,.11), transparent 26rem),
    linear-gradient(180deg, #090d13 0%, #070a0f 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
  line-height: 1.55;
}
button, input, select { font: inherit; }
button { color: inherit; }
input, select { font-variant-numeric: tabular-nums; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 11px clamp(16px, 4vw, 56px);
  border-bottom: 1px solid rgba(255,255,255,.07);
  background: rgba(8,11,16,.88);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-logo {
  display: block;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  object-fit: contain;
  filter: drop-shadow(0 9px 22px rgba(230,0,18,.18));
}
.brand h1 { margin: 0; font-size: clamp(18px,2vw,24px); letter-spacing: .01em; }
.brand p { margin: 0; color: var(--muted-2); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.header-meta { display: flex; align-items: center; gap: 12px; }
.logic-badge {
  padding: 6px 10px;
  border: 1px solid rgba(84,215,158,.24);
  border-radius: 999px;
  background: rgba(84,215,158,.07);
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
}
.version { color: var(--muted-2); font-size: 11px; letter-spacing: .08em; }

main {
  width: min(1520px, calc(100% - 28px));
  margin: 0 auto;
  padding: 30px 0 64px;
}
.hero {
  display: grid;
  grid-template-columns: minmax(0,1.45fr) minmax(360px,.75fr);
  gap: 34px;
  align-items: end;
  padding: 18px 10px 34px;
}
.eyebrow, .step {
  color: var(--accent);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .18em;
}
.hero h2 {
  margin: 8px 0 12px;
  font-size: clamp(32px,4.4vw,62px);
  line-height: 1.08;
  letter-spacing: -.045em;
}
.hero h2 em { color: var(--accent-bright); font-style: normal; }
.hero-copy { max-width: 760px; margin: 0; color: #b4c0ce; font-size: clamp(14px,1.45vw,17px); }
.workflow-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border: 1px solid rgba(242,161,62,.24);
  border-radius: 15px;
  background: linear-gradient(135deg, rgba(242,161,62,.09), rgba(17,24,34,.78));
  box-shadow: inset 0 1px rgba(255,255,255,.025);
}
.workflow-card div { display: grid; gap: 1px; min-width: 78px; }
.workflow-card b { color: var(--accent); font-size: 10px; letter-spacing: .12em; }
.workflow-card span { color: #d4dde7; font-size: 11px; font-weight: 700; white-space: nowrap; }
.workflow-card i { width: 24px; height: 1px; background: #3e4b5b; }

.workspace {
  display: grid;
  grid-template-columns: minmax(330px,400px) minmax(0,1fr);
  gap: 20px;
  align-items: start;
}
.panel {
  border: 1px solid rgba(255,255,255,.075);
  border-radius: var(--radius);
  background: linear-gradient(155deg, rgba(21,30,42,.98), rgba(13,19,28,.99));
  box-shadow: var(--shadow);
}
.input-panel {
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 104px);
  overflow: auto;
  padding: 20px;
  scrollbar-width: thin;
  scrollbar-color: #35475e transparent;
}
.panel-heading, .status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.panel-heading h3, .status-line h3, .export-panel h3 {
  margin: 2px 0 0;
  font-size: 20px;
}
.input-heading { margin-bottom: 14px; }

.setup-schematic {
  padding: 8px 7px 2px;
  border: 1px solid #273648;
  border-radius: 15px;
  background:
    linear-gradient(rgba(255,255,255,.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.022) 1px, transparent 1px),
    #0a111a;
  background-size: 18px 18px;
}
.setup-schematic svg { display: block; width: 100%; height: auto; }
.schematic-chain { fill: none; stroke: url(#chainGlow); stroke-width: 4; stroke-linecap: round; opacity: .95; }
.schematic-chain.lower { stroke-width: 3; }
.schematic-disc { fill: rgba(99,185,255,.04); stroke: #71859b; stroke-width: 2; }
.schematic-disc.rear { fill: rgba(242,161,62,.035); }
.schematic-hub { fill: var(--accent); }
.schematic-axis, .schematic-tick { stroke: #52647a; stroke-width: 1; }
.schematic-label { fill: #78899c; font-size: 9px; font-weight: 700; letter-spacing: .12em; }
.schematic-label.strong { fill: #e7edf4; font-size: 12px; letter-spacing: 0; }
.schematic-label.axis-label { fill: #aab7c5; letter-spacing: 0; }
.schematic-label.sag-label { fill: var(--accent-bright); letter-spacing: 0; }

.input-section {
  margin-top: 15px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}
.section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; }
.section-title > span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(242,161,62,.34);
  border-radius: 9px;
  background: rgba(242,161,62,.075);
  color: var(--accent);
  font-size: 10px;
  font-weight: 900;
}
.section-title h4 { margin: 0; color: #e2e8ef; font-size: 13px; }
.section-title p { margin: 0; color: var(--muted-2); font-size: 9px; }

.field { display: grid; gap: 6px; margin: 10px 0; color: #b9c5d2; font-size: 12px; }
.field.compact { grid-template-columns: minmax(100px,1fr) minmax(120px,1fr); align-items: center; gap: 10px; }
.dual-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
input, select {
  width: 100%;
  min-height: 41px;
  padding: 8px 11px;
  border: 1px solid #35465b;
  border-radius: 10px;
  outline: none;
  background: #0b121b;
  color: var(--text);
  transition: border-color .16s, box-shadow .16s, background .16s;
}
input:hover, select:hover { border-color: #495c73; }
input:focus, select:focus {
  border-color: var(--accent);
  background: #0d151f;
  box-shadow: 0 0 0 3px rgba(242,161,62,.12);
}
input:disabled { opacity: .42; cursor: not-allowed; }
.inline-input, .input-with-unit { display: flex; align-items: center; gap: 8px; }
.inline-input .prefix { color: var(--muted); white-space: nowrap; font-weight: 800; }
.input-with-unit > span { min-width: 30px; color: var(--muted); font-size: 11px; }

.primary-readout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 11px 12px;
  border: 1px solid rgba(242,161,62,.26);
  border-radius: 11px;
  background: rgba(242,161,62,.06);
}
.primary-readout span { color: var(--muted); font-size: 10px; }
.primary-readout strong { color: var(--accent-bright); font-size: 15px; font-variant-numeric: tabular-nums; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 10px 0; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: grid;
  place-items: center;
  min-height: 38px;
  padding: 7px;
  border: 1px solid #35455a;
  border-radius: 10px;
  background: #0b121b;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}
.segmented input:checked + span {
  border-color: var(--accent);
  background: rgba(242,161,62,.11);
  color: var(--accent-bright);
}
.mode-field { transition: opacity .18s, filter .18s; }
.mode-field.inactive-mode { opacity: .34; filter: saturate(.3); }

.source-summary {
  display: grid;
  gap: 3px;
  margin-top: 10px;
  padding: 10px 11px;
  border: 1px solid rgba(99,185,255,.23);
  border-radius: 10px;
  background: rgba(99,185,255,.055);
}
.source-summary span { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .05em; }
.source-summary strong { color: #d8eaff; font-size: 12px; }

.derived-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 7px; margin-top: 8px; }
.derived-grid.two { grid-template-columns: repeat(2,minmax(0,1fr)); }
.derived-grid > div {
  min-width: 0;
  padding: 9px;
  border: 1px solid #273547;
  border-radius: 10px;
  background: #0b121b;
}
.derived-label { color: var(--muted-2); font-size: 9px; }
.derived-grid strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: #e5ecf3;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.field-help { margin: 7px 1px 0; color: var(--muted-2); font-size: 10px; line-height: 1.5; }
.comparison-line.warning-text { color: #efbd79; }

.auto-calc-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 17px;
  padding: 11px 12px;
  border: 1px solid rgba(84,215,158,.23);
  border-radius: 11px;
  background: rgba(84,215,158,.055);
}
.auto-calc-note i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(84,215,158,.09);
}
.auto-calc-note div { display: grid; gap: 1px; }
.auto-calc-note strong { color: var(--green); font-size: 11px; }
.auto-calc-note span { color: var(--muted); font-size: 9px; }

.button {
  min-height: 39px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 800;
  font-size: 11px;
  transition: transform .14s, filter .14s, border-color .14s;
}
.button:hover { filter: brightness(1.08); }
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .38; cursor: not-allowed; filter: none; }
.button-primary { background: linear-gradient(135deg,var(--accent),#d77724); color: #1b1005; }
.button-secondary { border-color: #405873; background: #142337; }
.button-ghost { border-color: #35455a; background: transparent; color: #b7c3cf; }

.output-column { display: grid; gap: 18px; min-width: 0; }
.result-summary, .visual-panel, .details-panel, .export-panel { padding: 21px; }
.status-line { align-items: flex-start; }
.status-line p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.status-badge {
  min-width: 82px;
  padding: 7px 11px;
  border-radius: 999px;
  text-align: center;
  font-size: 11px;
  font-weight: 900;
}
.status-badge.neutral { background: #222d3a; color: var(--muted); }
.status-badge.good { background: rgba(84,215,158,.12); color: var(--green); }
.status-badge.bad { background: rgba(255,128,125,.12); color: var(--red); }

.cad-metric-grid {
  display: grid;
  grid-template-columns: repeat(6,minmax(0,1fr));
  gap: 8px;
  margin-top: 17px;
}
.metric {
  min-width: 0;
  padding: 12px 11px;
  border: 1px solid #2a394b;
  border-radius: 12px;
  background: #0b121b;
}
.metric.emphasis {
  border-color: rgba(242,161,62,.4);
  background: linear-gradient(155deg,rgba(242,161,62,.10),rgba(11,18,27,.9));
}
.metric span { display: block; min-height: 28px; color: var(--muted); font-size: 9px; line-height: 1.35; }
.metric strong {
  display: inline-block;
  max-width: 100%;
  margin-top: 3px;
  overflow: hidden;
  color: #f4f7fa;
  font-size: clamp(20px,2.25vw,30px);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.025em;
  text-overflow: ellipsis;
  vertical-align: baseline;
}
.metric.emphasis strong { color: var(--accent-bright); }
.metric small { margin-left: 2px; color: var(--muted-2); font-size: 9px; }
.cad-value-note { margin: 12px 2px 0; color: var(--muted-2); font-size: 10px; }

.visual-heading { align-items: end; }
.view-options { display: flex; gap: 12px; color: var(--muted); font-size: 10px; }
.view-options label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.view-options input { width: auto; min-height: auto; }
.preview-wrap {
  position: relative;
  margin-top: 13px;
  overflow: hidden;
  border: 1px solid #263649;
  border-radius: 14px;
  background:
    linear-gradient(rgba(255,255,255,.023) 1px, transparent 1px),
    linear-gradient(90deg,rgba(255,255,255,.023) 1px, transparent 1px),
    #080e16;
  background-size: 24px 24px;
}
.preview-wrap::after {
  content: "CHAIN CENTER LINE";
  position: absolute;
  right: 13px;
  bottom: 9px;
  color: rgba(121,140,162,.34);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .16em;
  pointer-events: none;
}
#previewSvg { display: block; width: 100%; height: min(55vw,500px); min-height: 330px; }
.preview-placeholder { fill: #657488; font-size: 14px; }
.preview-legend { display: flex; flex-wrap: wrap; gap: 15px; margin-top: 11px; color: var(--muted-2); font-size: 9px; }
.preview-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-line { width: 21px; height: 0; border-top: 3px solid var(--accent); }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--blue); }
.legend-dot.joint { background: var(--green); }
.legend-circle { width: 11px; height: 11px; border: 1px solid #788ba1; border-radius: 50%; }

.export-panel { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.export-panel p { max-width: 560px; margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.export-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; flex-shrink: 0; }

.coordinate-origin {
  padding: 6px 9px;
  border: 1px solid #35465a;
  border-radius: 999px;
  color: var(--muted);
  font-size: 9px;
}
.construction-method {
  margin-top: 14px;
  padding: 15px;
  border: 1px solid rgba(242,161,62,.24);
  border-radius: 14px;
  background: linear-gradient(155deg,rgba(242,161,62,.055),rgba(8,14,22,.55));
}
.construction-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}
.construction-head span { color: var(--accent); font-size: 9px; font-weight: 900; letter-spacing: .1em; }
.construction-head h4 { margin: 2px 0 0; font-size: 14px; }
.axis-chip {
  padding: 6px 9px;
  border: 1px solid #334357;
  border-radius: 8px;
  background: rgba(11,18,27,.75);
  color: #9dabb9;
  font-size: 9px;
  white-space: nowrap;
}
.construction-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.construction-grid > div {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid #29394b;
  border-radius: 10px;
  background: rgba(9,15,23,.75);
}
.construction-grid span { display: block; color: var(--muted-2); font-size: 9px; }
.construction-grid strong {
  display: block;
  margin-top: 4px;
  color: #edf3f8;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.construction-method > p { margin: 11px 1px 0; color: var(--muted); font-size: 10px; }

.work-details {
  margin-top: 14px;
  overflow: hidden;
  border: 1px solid #2b394a;
  border-radius: 12px;
  background: rgba(7,12,19,.28);
}
.work-details > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  cursor: pointer;
  list-style: none;
}
.work-details > summary::-webkit-details-marker { display: none; }
.work-details > summary span { font-size: 12px; font-weight: 800; }
.work-details > summary small { color: var(--muted-2); font-size: 9px; }
.work-details > summary::after { content: "＋"; color: var(--accent); font-weight: 900; }
.work-details[open] > summary::after { content: "－"; }
.work-details[open] > summary { border-bottom: 1px solid #263445; }
.detail-content { padding: 8px 14px 14px; }
.detail-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.detail-columns dl, .reference-details dl { margin: 0; }
.detail-columns dl div, .reference-details dl div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 1px;
  border-bottom: 1px solid var(--line-soft);
}
.detail-columns dt, .reference-details dt { color: var(--muted); font-size: 10px; }
.detail-columns dd, .reference-details dd {
  margin: 0;
  color: #e2e8ef;
  font-size: 11px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.reference-details {
  margin-top: 12px;
  padding: 11px 12px;
  border: 1px solid #293748;
  border-radius: 10px;
}
.reference-details > summary { cursor: pointer; color: #b8c4d1; font-size: 10px; font-weight: 750; }

.warning-box {
  margin-top: 14px;
  padding: 12px 13px;
  border: 1px solid rgba(242,161,62,.32);
  border-radius: 11px;
  background: rgba(242,161,62,.07);
  color: #f0d2a7;
  font-size: 10px;
}
.hidden { display: none !important; }

.tool-note {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
  padding: 0 9px;
}
.tool-note span { color: var(--accent); font-size: 9px; font-weight: 900; letter-spacing: .15em; }
.tool-note p { margin: 0; color: var(--muted-2); font-size: 9px; line-height: 1.7; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  width: min(1520px,calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 8px 34px;
  border-top: 1px solid rgba(255,255,255,.055);
  color: #617286;
  font-size: 9px;
}

@media (max-width: 1240px) {
  .cad-metric-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media (max-width: 1040px) {
  .hero { grid-template-columns: 1fr; }
  .workflow-card { max-width: 620px; }
  .workspace { grid-template-columns: 1fr; }
  .input-panel { position: static; max-height: none; }
}
@media (max-width: 760px) {
  main { width: min(100% - 18px,1520px); padding-top: 15px; }
  .site-header { padding-inline: 12px; }
  .header-meta .logic-badge { display: none; }
  .version { display: none; }
  .hero { padding: 14px 3px 25px; gap: 22px; }
  .hero h2 { font-size: 35px; }
  .workflow-card { overflow-x: auto; }
  .input-panel, .result-summary, .visual-panel, .details-panel, .export-panel { padding: 16px; }
  .dual-fields, .derived-grid, .derived-grid.two, .detail-columns { grid-template-columns: 1fr; }
  .cad-metric-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .construction-head, .export-panel { align-items: stretch; flex-direction: column; }
  .construction-grid { grid-template-columns: 1fr; }
  .export-actions { display: grid; grid-template-columns: 1fr; width: 100%; }
  .coordinate-origin { display: none; }
  .view-options { flex-direction: column; gap: 3px; }
  #previewSvg { min-height: 280px; }
}
@media (max-width: 430px) {
  .brand p { display: none; }
  .cad-metric-grid { grid-template-columns: 1fr; }
  .field.compact { grid-template-columns: 1fr; }
  .segmented { grid-template-columns: 1fr; }
  .workflow-card i { min-width: 15px; }
  .work-details > summary small { display: none; }
  footer { flex-direction: column; gap: 3px; }
}


/* v0.1.9: more realistic setup schematic */
.setup-schematic { min-height: 176px; }
.setup-sprocket .gear-body { stroke-width: 1.4; filter: drop-shadow(0 5px 5px rgba(0,0,0,.38)); }
.setup-sprocket .gear-ring { fill: none; stroke: rgba(218,228,238,.48); stroke-width: 1; }
.setup-sprocket .gear-inner { fill: rgba(5,10,16,.68); stroke: rgba(196,209,220,.38); stroke-width: 1; }
.setup-sprocket .gear-hole { fill: #071019; stroke: rgba(217,226,235,.48); stroke-width: .8; }
.setup-sprocket .gear-hub { fill: #101a25; stroke: #cfdae4; stroke-width: 1; }
.setup-chain-main { fill: none; stroke: #d5933d; stroke-width: 4.6; stroke-linecap: round; stroke-linejoin: round; opacity: .82; }
.setup-chain-plate { stroke: #e8b66d; stroke-width: 2.2; stroke-linecap: round; opacity: .72; }
.setup-chain-roller { fill: #c9d0d6; stroke: #4c5967; stroke-width: .8; }
.setup-chain-pin { fill: #303d4b; }
.export-side { display: grid; justify-items: end; gap: 8px; }
.output-feedback { min-height: 17px; color: var(--green); font-size: 10px; font-weight: 750; text-align: right; }
.output-feedback.error { color: var(--red); }
.print-sheet { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff !important; color: #000 !important; }
  body > .site-header, body > main, body > footer { display: none !important; }
  .print-sheet { display: block !important; background: #fff; color: #000; }
  .print-sheet .print-title { margin: 0 0 5mm; font: 700 12pt Arial, sans-serif; }
  .print-sheet .print-note { margin: 0 0 5mm; font: 9pt Arial, sans-serif; }
  .print-sheet svg { display: block; max-width: none; }
}
@media (max-width: 760px) {
  .export-side { justify-items: stretch; width: 100%; }
  .output-feedback { text-align: left; }
}


/* v0.1.11: native file links and direct print */
.export-actions a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.disabled-link {
  opacity: .38;
  pointer-events: none;
  cursor: not-allowed;
}
.output-caution {
  max-width: 520px;
  margin: 0;
  color: var(--muted-2);
  font-size: 9px;
  line-height: 1.45;
  text-align: right;
}
@media (max-width: 760px) {
  .output-caution { text-align: left; }
}

@media (max-width: 430px) {
  .brand-logo { width: 44px; height: 44px; flex-basis: 44px; }
}
