:root {
  --ink: #0b2231;
  --ink-soft: #526874;
  --navy: #071d2b;
  --navy-raised: #0d2a3c;
  --paper: #ffffff;
  --canvas: #e6edee;
  --line: #c7d5d8;
  --mint: #2ee0b0;
  --mint-dark: #08795f;
  --red: #ff6b5f;
  --red-dark: #a72e2a;
  --amber: #ffc857;
  --white: #f8fbfb;
  --rail-muted: #9eb2bc;
  --rail-subtle: #8fa6b0;
  --rail-index: #78909b;
  --button-ink: #03241c;
  --shadow: 0 18px 50px rgba(7, 29, 43, 0.13);
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  min-width: 320px;
  background-color: var(--canvas);
  background-image:
    linear-gradient(rgba(7, 29, 43, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(7, 29, 43, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
}

button, a { font: inherit; }
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 4px solid var(--amber);
  outline-offset: 3px;
}

.app-shell { min-height: 100svh; padding: 18px 22px 22px; }

.masthead {
  min-height: 76px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 28px;
  padding: 0 8px 16px;
}

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 10px; background: var(--navy); position: relative;
}
.brand-mark::before { content: ""; width: 23px; height: 23px; background: var(--mint); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.brand-mark i { position: absolute; width: 9px; height: 10px; bottom: 11px; background: var(--paper); }
.eyebrow, .section-kicker { margin: 0; font: 700 10px/1.2 "SFMono-Regular", Consolas, monospace; letter-spacing: .16em; color: var(--ink-soft); }
.brand-name { margin: 3px 0 0; font: 800 22px/1 var(--font, "Hiragino Sans", sans-serif); letter-spacing: -.03em; }
.thesis { text-align: center; font-weight: 800; font-size: clamp(16px, 1.2vw, 22px); line-height: 1.35; letter-spacing: -.02em; }
.thesis p { margin: 0; }
.live-badge { justify-self: end; padding: 10px 14px; border: 1px solid #9eb0b6; border-radius: 999px; font: 700 12px/1 "SFMono-Regular", monospace; letter-spacing: .08em; background: rgba(255,255,255,.58); }
.live-badge span { display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--mint-dark); box-shadow: 0 0 0 4px rgba(46,224,176,.17); }

.workbench {
  height: calc(100svh - 116px);
  min-height: 660px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(350px, 25vw);
  background: rgba(248, 251, 251, .82);
  border: 1px solid rgba(7, 29, 43, .14);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.document-bay { min-width: 0; padding: clamp(18px, 2vw, 34px); display: flex; flex-direction: column; }
.bay-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 16px; }
.bay-heading h1 { margin: 5px 0 0; font-size: clamp(24px, 2vw, 38px); line-height: 1.08; letter-spacing: -.045em; }
.bay-note { flex: 0 0 auto; margin: 0; font: 700 11px/1 "SFMono-Regular", monospace; color: var(--ink-soft); white-space: nowrap; }

.document-switcher { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 14px; }
.document-switcher button { min-width: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.58); color: var(--ink-soft); text-align: left; cursor: pointer; }
.document-switcher span, .document-switcher small { display: block; }
.document-switcher span { font-size: 13px; font-weight: 800; }
.document-switcher small { margin-top: 2px; font: 700 8px/1.2 "SFMono-Regular", monospace; letter-spacing: .08em; }
.document-switcher button[aria-selected="true"] { border-color: var(--navy); background: var(--navy); color: var(--white); box-shadow: inset 0 -3px 0 var(--mint); }
.scenario-panel { min-height: 0; flex: 1; display: flex; }
.scenario-panel[hidden] { display: none; }
.scenario-panel .sheet-comparison { width: 100%; }

.sheet-comparison { min-height: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 42px minmax(0, 1fr); gap: 12px; align-items: stretch; }
.sheet-card { min-width: 0; display: flex; flex-direction: column; }
.sheet-label { display: flex; align-items: center; gap: 9px; margin: 0 0 8px; font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.sheet-label span { padding: 5px 8px; border-radius: 4px; font: 800 10px/1 "SFMono-Regular", monospace; letter-spacing: .08em; background: var(--ink); color: var(--white); }
.sheet-after .sheet-label span { background: var(--mint-dark); }

.quote-sheet { position: relative; min-height: 0; flex: 1; padding: clamp(20px, 2vw, 34px); background: var(--paper); border: 1px solid #d3dddf; box-shadow: 0 13px 28px rgba(7,29,43,.1); overflow: hidden; }
.quote-logo { display: flex; align-items: center; gap: 9px; font: 800 clamp(9px, .75vw, 13px)/1.15 "SFMono-Regular", monospace; letter-spacing: .06em; }
.quote-logo b { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 8px; background: var(--navy); color: var(--mint); }
.quote-logo small { display: block; margin-top: 3px; font-size: 8px; letter-spacing: .12em; color: var(--ink-soft); }
.quote-title { position: absolute; top: 30px; right: 30px; font-size: clamp(15px, 1.25vw, 22px); font-weight: 800; letter-spacing: .14em; }
.customer-block { position: relative; width: 57%; margin-top: clamp(18px, 2.1vw, 34px); padding: 6px 8px 9px; border-bottom: 2px solid var(--navy); }
.customer-block small { display: block; margin-bottom: 4px; font-size: 8px; color: var(--ink-soft); }
.customer-block strong { font-size: clamp(11px, .95vw, 16px); }
.quote-meta { position: absolute; top: clamp(83px, 8vw, 123px); right: clamp(20px, 2vw, 34px); width: 34%; margin: 0; font-size: 8px; }
.quote-meta div { position: relative; display: grid; grid-template-columns: 1fr 1.7fr; gap: 5px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.quote-meta dt { color: var(--ink-soft); }
.quote-meta dd { margin: 0; text-align: right; font-weight: 700; }
.quote-lead { margin: clamp(15px, 1.7vw, 27px) 0 9px; font-size: 8px; color: var(--ink-soft); }
.quote-table { border-top: 1px solid var(--navy); }
.table-row { display: grid; grid-template-columns: .8fr 1.6fr .8fr; font-size: clamp(8px, .58vw, 10px); border-bottom: 1px solid var(--line); }
.table-row span { padding: clamp(5px, .55vw, 9px); }
.table-row span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.table-head { background: var(--navy); color: white; font-weight: 700; }
.formula-row { position: relative; display: flex; justify-content: flex-end; gap: 22px; padding: 9px 4px 7px; font-size: clamp(9px, .65vw, 11px); }
.formula-row span { color: var(--ink-soft); }
.formula-row em { margin-left: 5px; padding: 2px 4px; border: 1px solid var(--line); border-radius: 3px; font: 700 6px/1 monospace; color: var(--mint-dark); }
.grand-total { position: relative; display: flex; justify-content: space-between; align-items: center; margin-top: 4px; padding: clamp(10px, 1vw, 16px); background: #eaf4f2; color: var(--navy); font-size: clamp(9px, .7vw, 12px); font-weight: 800; }
.grand-total strong { font-size: clamp(15px, 1.4vw, 24px); font-variant-numeric: tabular-nums; }
.quote-footnote { margin: clamp(10px, 1vw, 16px) 0 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: 8px; color: var(--ink-soft); }

.changed-cell { transition: outline-color .32s ease, background-color .32s ease; }
.changed-cell i { display: none; position: absolute; z-index: 3; width: 22px; height: 22px; place-items: center; border-radius: 50%; background: var(--mint-dark); color: white; font: 800 10px/1 "SFMono-Regular", monospace; box-shadow: 0 0 0 4px white; }
.change-1 i { left: -11px; top: -11px; }
.change-2 i, .change-3 i { right: -11px; top: -11px; }
.change-4 i { left: -11px; top: -11px; }
.sheet-after .quote-sheet::after { content: "検査前"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.76); color: var(--ink-soft); font: 800 12px/1 "SFMono-Regular", monospace; letter-spacing: .18em; transition: opacity .25s ease; }
.is-running .sheet-after .quote-sheet::after { content: "検査中"; }
.is-pass .sheet-after .quote-sheet::after, .is-blocked .sheet-after .quote-sheet::after { opacity: 0; pointer-events: none; }
.is-pass .changed-cell { outline: 2px solid var(--mint-dark); outline-offset: 3px; background-color: rgba(46,224,176,.12); }
.is-pass .changed-cell i { display: grid; }

.transfer-axis { display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink-soft); }
.transfer-axis span { width: 1px; flex: .45; background: var(--line); }
.transfer-axis::after { content: ""; width: 1px; flex: .45; background: var(--line); }
.transfer-axis b { width: 34px; height: 34px; margin: 8px 0 3px; display: grid; place-items: center; border: 1px solid var(--ink); border-radius: 50%; font: 800 14px/1 monospace; }
.transfer-axis small { font: 700 7px/1 monospace; letter-spacing: .09em; }
.fault-callout { display: none; position: absolute; right: 18px; bottom: 112px; z-index: 5; align-items: center; gap: 8px; padding: 9px 11px; background: var(--red-dark); color: white; box-shadow: 0 8px 20px rgba(167,46,42,.28); font-size: 8px; }
.fault-callout b { display: grid; place-items: center; width: 22px; height: 22px; border: 1px solid white; border-radius: 50%; }
.is-blocked .fault-callout { display: flex; }
.is-blocked .fault-target { outline: 3px solid var(--red); outline-offset: 2px; background: rgba(255,107,95,.14); }

.inspection-rail { min-width: 0; padding: clamp(22px, 2vw, 36px); display: flex; flex-direction: column; background: var(--navy); color: var(--white); }
.rail-topline { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(255,255,255,.2); padding-bottom: 13px; }
.rail-topline p, .rail-topline span { margin: 0; font: 700 10px/1 "SFMono-Regular", monospace; letter-spacing: .13em; }
.rail-topline span { color: var(--amber); }
.verdict { padding: clamp(20px, 2.3vh, 30px) 0; }
.verdict small { color: var(--rail-muted); font-size: 11px; }
.verdict strong { display: block; margin-top: 4px; font-size: clamp(38px, 3.1vw, 58px); line-height: 1; letter-spacing: -.06em; }
.verdict p { margin: 10px 0 0; min-height: 2.8em; color: #bfd0d6; font-size: clamp(12px, .95vw, 17px); line-height: 1.4; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid rgba(255,255,255,.22); }
.metrics div { padding: clamp(12px, 1.3vw, 20px); }
.metrics div + div { border-left: 1px solid rgba(255,255,255,.22); }
.metrics small { display: block; color: var(--rail-muted); font-size: 10px; }
.metrics strong { display: block; margin-top: 3px; font: 800 clamp(30px, 2.3vw, 44px)/1 "SFMono-Regular", monospace; }

.layer-list { list-style: none; margin: clamp(16px, 2vh, 24px) 0; padding: 0; }
.layer-list li { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.13); }
.layer-list li > span { font: 700 10px/1 monospace; color: var(--rail-index); }
.layer-list b { display: block; font-size: clamp(12px, .9vw, 16px); }
.layer-list small { display: block; margin-top: 2px; color: var(--rail-subtle); font-size: 9px; }
.layer-list em { font: 800 9px/1 monospace; color: var(--rail-subtle); }
.layer-list li.done em { color: var(--mint); }
.layer-list li.blocked em { color: var(--red); }

.actions { display: grid; gap: 8px; margin-top: auto; }
.actions button { min-height: 54px; padding: 10px 14px; border: 0; border-radius: 8px; text-align: left; cursor: pointer; transition: transform .15s ease, background-color .15s ease; }
.actions button:hover:not(:disabled) { transform: translateY(-1px); }
.actions button:disabled { cursor: wait; opacity: .55; }
.actions button span, .actions button small { display: block; }
.actions button span { font-weight: 800; font-size: 15px; }
.actions button small { margin-top: 2px; font-size: 9px; opacity: .72; }
.primary-action { background: var(--mint); color: var(--button-ink); }
.guard-action { background: transparent; border: 1px solid rgba(255,255,255,.38) !important; color: white; }
.reset-action { min-height: 36px !important; text-align: center !important; background: transparent; color: var(--rail-muted); font-size: 11px; }
.downloads { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 9px; }
.downloads[hidden] { display: none; }
.downloads a { padding: 9px; border-radius: 6px; background: rgba(46,224,176,.13); color: var(--mint); text-align: center; text-decoration: none; font-size: 10px; font-weight: 700; }
#download-windows { grid-column: 1 / -1; }
.is-pass .inspection-rail { box-shadow: inset 5px 0 0 var(--mint); }
.is-pass .verdict strong, .is-pass #run-state { color: var(--mint); }
.is-blocked .inspection-rail { box-shadow: inset 5px 0 0 var(--red); }
.is-blocked .verdict strong, .is-blocked #run-state, .is-blocked #violation-count { color: var(--red); }
.is-error .inspection-rail { box-shadow: inset 5px 0 0 var(--amber); }
.is-error .verdict strong { color: var(--amber); }

@media (max-width: 1279px) {
  .app-shell { padding: 10px; }
  .masthead { min-height: 64px; }
  .workbench { height: calc(100svh - 84px); grid-template-columns: minmax(0, 1fr) 340px; border-radius: 16px; }
  .document-bay { padding: 18px; }
  .inspection-rail { padding: 20px; }
  .quote-sheet { padding: 20px; }
}

@media (min-width: 901px) and (max-height: 760px) {
  .app-shell { padding: 8px 10px 10px; }
  .masthead { min-height: 56px; padding-bottom: 8px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand-name { font-size: 19px; }
  .workbench { height: calc(100svh - 74px); min-height: 0; }
  .document-bay { padding: 14px 18px; }
  .bay-heading { margin-bottom: 8px; }
  .document-switcher { margin-bottom: 8px; }
  .document-switcher button { padding: 6px 9px; }
  .bay-heading h1 { font-size: 25px; }
  .quote-sheet { padding: 17px 20px; }
  .inspection-rail { padding: 15px 20px; }
  .verdict { padding: 12px 0; }
  .verdict strong { font-size: 36px; }
  .verdict p { margin-top: 6px; min-height: 1.5em; }
  .metrics div { padding: 9px 13px; }
  .metrics strong { font-size: 28px; }
  .layer-list { margin: 9px 0; }
  .layer-list li { padding: 7px 0; }
  .actions button { min-height: 44px; padding: 7px 12px; }
  .actions button span { font-size: 13px; }
  .reset-action { min-height: 28px !important; }
}

@media (max-width: 900px) {
  .app-shell { padding: 0; }
  .masthead { grid-template-columns: 1fr auto; padding: 13px 15px; }
  .thesis { display: none; }
  .workbench { height: auto; min-height: 0; display: flex; flex-direction: column; border-radius: 0; }
  .document-switcher { position: sticky; top: 0; z-index: 10; padding: 8px 0; background: var(--canvas); }
  .document-switcher small { display: none; }
  .sheet-comparison { grid-template-columns: 1fr; }
  .transfer-axis { display: none; }
  .quote-sheet { min-height: 540px; }
  .inspection-rail { min-height: 650px; }
}

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