:root {
  --navy: #123a5a;
  --navy-2: #1c4e73;
  --blue: #2e86c1;
  --blue-soft: #e8f1f8;
  --bg: #f3f5f7;
  --panel: #ffffff;
  --line: #dbe3ea;
  --text: #1c2b36;
  --muted: #6b7c8c;
  --green: #2e8b74;
  --green-soft: #e6f4f0;
  --red: #c0392b;
  --red-soft: #fbeceb;
  --gold: #a67c00;
  --font: "Yu Gothic UI", "Yu Gothic", "Meiryo", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--blue); text-decoration: none; }

/* Header */
.s-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 54px;
  padding: 0 16px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.s-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 14px;
  color: var(--navy);
}

.s-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  letter-spacing: .04em;
}

.s-link {
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--navy);
  background: #fff;
  font-family: inherit;
  cursor: pointer;
}

/* Layout */
.s-main {
  width: min(640px, 100% - 24px);
  margin: 0 auto;
  padding: 18px 0 36px;
}

.s-intro h1 {
  margin: 0 0 6px;
  font-size: 21px;
  color: var(--navy);
  letter-spacing: .01em;
}

.s-intro p {
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--muted);
}

/* Mode pills */
.s-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 2px 12px;
}

.s-mode {
  flex: 0 0 auto;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--navy);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.s-mode.is-active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

/* Card & fields */
.s-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 16px;
  box-shadow: 0 1px 2px rgba(16, 42, 67, .05), 0 8px 22px rgba(16, 42, 67, .05);
}

.s-field { padding: 13px 0; border-bottom: 1px solid #eef2f6; }
.s-field:last-child { border-bottom: none; }

.s-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 8px;
}

.s-label .s-unit { font-size: 11px; font-weight: 600; color: var(--muted); }

.s-row {
  display: grid;
  grid-template-columns: 1fr 108px;
  gap: 12px;
  align-items: center;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: #dbe6ef;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8.5px;
  border-radius: 50%;
  background: var(--navy);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(18, 58, 90, .3);
}

input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: #dbe6ef;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--navy);
  border: 3px solid #fff;
}

.s-number {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f7fafc;
  padding: 4px 8px;
}

.s-number input {
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  color: var(--navy);
  text-align: right;
  padding: 2px 0;
}

.s-number input:focus { outline: none; }
.s-number span { font-size: 10.5px; color: var(--muted); white-space: nowrap; }

select[data-key] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f7fafc;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
}

/* Advanced */
.s-advanced {
  border-top: 1px solid #eef2f6;
  margin-top: 2px;
}

.s-advanced > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 0;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--navy-2);
  position: relative;
  padding-right: 26px;
}

.s-advanced > summary::-webkit-details-marker { display: none; }
.s-advanced > summary::after {
  content: "＋";
  position: absolute;
  right: 4px;
  top: 12px;
  color: var(--muted);
}
.s-advanced[open] > summary::after { content: "−"; }

/* Results */
.s-results {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(16, 42, 67, .05), 0 8px 22px rgba(16, 42, 67, .05);
}

.s-kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.s-kpi {
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.s-kpi .k-label { display: block; font-size: 10.5px; color: var(--muted); font-weight: 700; }
.s-kpi .k-value { font-size: 19px; font-weight: 800; color: var(--navy); line-height: 1.35; }
.s-kpi .k-value small { font-size: 11px; font-weight: 700; color: var(--muted); margin-left: 2px; }
.s-kpi.is-warn { background: var(--red-soft); border-color: #f0c8c4; }
.s-kpi.is-warn .k-value { color: var(--red); }
.s-kpi.is-good { background: var(--green-soft); border-color: #cbe7df; }
.s-kpi.is-good .k-value { color: var(--green); }

.s-chart { margin: 14px 0 4px; }
.s-chart svg { width: 100%; height: auto; display: block; }

.s-message {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--blue-soft);
  color: var(--navy);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.7;
}

.s-message.is-warn { background: var(--red-soft); color: var(--red); }
.s-message.is-good { background: var(--green-soft); color: var(--green); }

.s-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.s-actions .s-btn-primary { grid-column: 1 / -1; }

.s-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 18px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 800;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: center;
}

.s-btn-text {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
  font-size: 12px;
  font-weight: 700;
  padding: 9px;
}

.s-btn-primary {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 6px 16px rgba(18, 58, 90, .22);
}

.s-btn-ghost {
  background: #fff;
  color: var(--navy);
  border-color: var(--line);
}

.s-note {
  margin: 16px 2px 0;
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.7;
}

.s-footer {
  width: min(640px, 100% - 24px);
  margin: 0 auto;
  padding: 0 0 34px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 11px;
}

.s-footer a { color: var(--muted); font-weight: 700; }

/* Print report（画面では非表示） */
.s-print { display: none; }

/* Dialog */
.s-dialog {
  width: min(440px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 20px 60px rgba(16, 42, 67, .3);
}

.s-dialog::backdrop { background: rgba(18, 58, 90, .45); }
.s-dialog h2 { margin: 0 0 12px; font-size: 17px; color: var(--navy); }
.s-dialog p { margin: 0 0 12px; font-size: 12.5px; line-height: 1.8; color: #46596a; }
.s-dialog-actions { margin-top: 6px; text-align: right; }
.s-dialog-actions .s-btn { padding: 10px 20px; }

@media (max-width: 380px) {
  .s-row { grid-template-columns: 1fr 92px; gap: 8px; }
  .s-kpi .k-value { font-size: 17px; }
}

@media print {
  @page { size: A4 portrait; margin: 14mm; }

  html, body { background: #fff; }

  .s-header, .s-main, .s-footer, .s-dialog { display: none !important; }
  .s-print { display: block !important; color: #1c2b36; font-size: 11px; line-height: 1.6; }

  .p-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    border-bottom: 2px solid #123a5a;
    padding-bottom: 6px;
    margin-bottom: 14px;
  }

  .p-brand { font-weight: 800; color: #123a5a; }
  .p-date { font-size: 10px; color: #6b7c8c; }

  .p-title { margin: 0 0 4px; font-size: 20px; color: #123a5a; }
  .p-sub { margin: 0 0 12px; font-size: 11px; color: #6b7c8c; }

  .p-kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
  }

  .p-kpis .s-kpi { background: #f7fafc; border: 1px solid #dbe3ea; border-radius: 8px; padding: 8px 10px; }
  .p-kpis .k-label { display: block; font-size: 9px; color: #6b7c8c; font-weight: 700; }
  .p-kpis .k-value { font-size: 16px; font-weight: 800; color: #123a5a; }
  .p-kpis .k-value small { font-size: 9px; color: #6b7c8c; margin-left: 2px; }
  .p-kpis .is-warn { background: #fbeceb; border-color: #f0c8c4; }
  .p-kpis .is-warn .k-value { color: #c0392b; }
  .p-kpis .is-good { background: #e6f4f0; border-color: #cbe7df; }
  .p-kpis .is-good .k-value { color: #2e8b74; }

  .p-chart { margin: 6px 0 10px; }
  .p-chart svg { width: 100%; height: auto; display: block; }

  .p-message {
    margin: 0 0 12px;
    padding: 8px 10px;
    border-radius: 8px;
    background: #e8f1f8;
    color: #123a5a;
    font-size: 11px;
    font-weight: 700;
  }
  .p-message.is-warn { background: #fbeceb; color: #c0392b; }
  .p-message.is-good { background: #e6f4f0; color: #2e8b74; }

  .p-section-title { margin: 0 0 6px; font-size: 12px; color: #123a5a; }

  .p-table { width: 100%; border-collapse: collapse; font-size: 10px; }
  .p-table th, .p-table td { border-bottom: 1px solid #eef2f6; padding: 4px 6px; text-align: left; }
  .p-table th { width: 55%; color: #6b7c8c; font-weight: 700; }
  .p-table td { text-align: right; font-weight: 700; color: #1c2b36; }

  .p-note {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #dbe3ea;
    font-size: 9px;
    line-height: 1.7;
    color: #6b7c8c;
  }

  .p-kpis, .p-chart, .p-message, .p-table, .p-note { break-inside: avoid; }
}
