/* とぎれ — shared styles. Mobile-first, composed at 1600x900 for capture. */

:root {
  --bg: #f6f4ee;
  --bg-elev: #ffffff;
  --bg-soft: #efece3;
  --border: #ddd6c4;
  --text: #262420;
  --text-soft: #57534a;
  --text-faint: #8b8578;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 2px 10px rgba(60, 50, 20, 0.06), 0 1px 2px rgba(60, 50, 20, 0.05);
  --shadow-lg: 0 8px 28px rgba(60, 50, 20, 0.12), 0 2px 6px rgba(60, 50, 20, 0.06);

  --ok: #127d3e;
  --ok-bg: #e6f4ea;
  --caution: #b7791f;
  --caution-bg: #faf1de;
  --edge: #b0491f;
  --edge-bg: #fbe9df;
  --bad: #c23b34;
  --bad-bg: #fbeae8;

  --accent: #2a6f5e;
  --accent-2: #3f8f78;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1a16;
    --bg-elev: #262420;
    --bg-soft: #2c2a24;
    --border: #423e34;
    --text: #f1ede2;
    --text-soft: #cac4b4;
    --text-faint: #948d7c;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);

    --ok: #4bb06e;
    --ok-bg: #17301f;
    --caution: #e0ad4f;
    --caution-bg: #362a13;
    --edge: #dd7a4c;
    --edge-bg: #3a2214;
    --bad: #e4726a;
    --bad-bg: #3a1c19;

    --accent: #5fb39c;
    --accent-2: #7fc9ac;
  }
}

:root[data-theme="dark"] {
  --bg: #1c1a16;
  --bg-elev: #262420;
  --bg-soft: #2c2a24;
  --border: #423e34;
  --text: #f1ede2;
  --text-soft: #cac4b4;
  --text-faint: #948d7c;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);

  --ok: #4bb06e;
  --ok-bg: #17301f;
  --caution: #e0ad4f;
  --caution-bg: #362a13;
  --edge: #dd7a4c;
  --edge-bg: #3a2214;
  --bad: #e4726a;
  --bad-bg: #3a1c19;

  --accent: #5fb39c;
  --accent-2: #7fc9ac;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* Wide (1600x900 capture) layout: keep phone-shaped content centered but
   give it room, screens B/C additionally use a two-column layout above
   this breakpoint. */
@media (min-width: 760px) {
  .app { max-width: 720px; }
  .app.wide { max-width: 1200px; }
}

header.topbar {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 5;
}

header.topbar .brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

header.topbar .brand .mark {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--accent);
}

header.topbar .brand .sub {
  font-size: 12.5px;
  color: var(--text-faint);
}

header.topbar .crumb {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-soft);
}
header.topbar .crumb a { color: var(--accent); text-decoration: none; }
header.topbar .crumb a:hover { text-decoration: underline; }

main {
  flex: 1;
  padding: 18px 20px 32px;
}

footer.foot {
  padding: 16px 20px 28px;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}
footer.foot a { color: var(--text-faint); }

h1.pagetitle {
  font-size: 21px;
  font-weight: 800;
  margin: 4px 0 4px;
}

p.lede {
  color: var(--text-soft);
  font-size: 14.5px;
  margin: 0 0 20px;
}

.note {
  font-size: 12.5px;
  color: var(--text-faint);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 14px 0;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-soft);
  margin: 22px 0 10px;
  letter-spacing: 0.02em;
}

/* --- form controls (screen A) ------------------------------------------ */

fieldset {
  border: none;
  margin: 0 0 22px;
  padding: 0;
}

legend {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 10px;
  padding: 0;
}

.ward-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
@media (min-width: 560px) {
  .ward-grid { grid-template-columns: repeat(3, 1fr); }
}

.ward-option {
  position: relative;
}
.ward-option input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}
.ward-option label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  cursor: pointer;
  transition: border-color .12s, background .12s;
  height: 100%;
}
.ward-option input:checked + label {
  border-color: var(--accent);
  background: var(--ok-bg);
}
.ward-option input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.ward-option .wname {
  font-weight: 700;
  font-size: 14.5px;
}
.ward-option .wbadge {
  font-size: 11px;
  color: var(--text-faint);
}
.ward-option.status-no_data label { opacity: 0.55; }
.ward-option.status-zero label { opacity: 0.7; }
.ward-option.status-thin .wbadge { color: var(--edge); }
.ward-option.status-normal .wbadge { color: var(--ok); }

.tol-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.tol-option { position: relative; }
.tol-option input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}
.tol-option label {
  display: block;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  cursor: pointer;
  font-size: 14.5px;
  transition: border-color .12s, background .12s;
}
.tol-option input:checked + label {
  border-color: var(--accent);
  background: var(--ok-bg);
  font-weight: 700;
}
.tol-option input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  transition: transform .08s, filter .12s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}
.btn-primary:disabled {
  background: var(--border);
  color: var(--text-faint);
  cursor: not-allowed;
}
.btn-ghost {
  background: var(--bg-elev);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary {
  background: var(--bg-soft);
  color: var(--text);
  border: 1.5px solid var(--border);
}

/* --- tier chip / badge --------------------------------------------------- */

.tier-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 800;
  border-radius: 999px;
  padding: 4px 10px 4px 8px;
}
.tier-chip .ic { font-size: 13px; }
.tier-anshin { background: var(--ok-bg); color: var(--ok); }
.tier-chuui { background: var(--caution-bg); color: var(--caution); }
.tier-edge { background: var(--edge-bg); color: var(--edge); }

.rest-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
}
.rest-badge.ok { background: var(--ok-bg); color: var(--ok); }
.rest-badge.desert { background: var(--bad-bg); color: var(--bad); }
.rest-badge .ic { font-size: 15px; }

/* --- candidate cards (screen B) ----------------------------------------- */

.candidate-card {
  display: block;
  background: var(--bg-elev);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: box-shadow .12s, transform .08s;
}
.candidate-card:hover { box-shadow: var(--shadow-lg); }
.candidate-card:active { transform: scale(0.995); }

.candidate-card .row-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.candidate-card .cname {
  font-weight: 800;
  font-size: 15.5px;
  line-height: 1.35;
}
.candidate-card .metrics {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  margin: 6px 0 8px;
  flex-wrap: wrap;
}
.candidate-card .metrics .len { color: var(--text-soft); font-weight: 700; }
.candidate-card .metrics .sep { color: var(--text-faint); font-weight: 400; }
.candidate-card .metrics .gap { }
.candidate-card .metrics .gap.tier-anshin-text { color: var(--ok); }
.candidate-card .metrics .gap.tier-chuui-text { color: var(--caution); }
.candidate-card .metrics .gap.tier-edge-text { color: var(--edge); }

.candidate-card .row-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.candidate-card .route {
  font-size: 12.5px;
  color: var(--text-faint);
}

.group-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-soft);
  margin: 20px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.group-heading .count { color: var(--text-faint); font-weight: 500; }

/* --- screen B board: map + list ------------------------------------------ */

.board {
  display: flex;
  flex-direction: column;
}

@media (min-width: 900px) {
  .board {
    display: grid;
    grid-template-columns: minmax(300px, 400px) 1fr;
    align-items: start;
    gap: 24px;
  }
  .board-map {
    position: sticky;
    top: 100px;
  }
}

/* --- map (inline SVG, no external tiles) -------------------------------- */

.map-wrap {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.map-wrap svg { display: block; width: 100%; height: auto; }
.map-caption {
  font-size: 11.5px;
  color: var(--text-faint);
  padding: 6px 4px 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  font-size: 12px;
  color: var(--text-soft);
  padding: 8px 4px 0;
}
.legend .item { display: inline-flex; align-items: center; gap: 5px; }
.legend .swatch { width: 12px; height: 12px; flex: none; }

/* --- screen C: detail ---------------------------------------------------- */

.metric-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}
.metric-box {
  background: var(--bg-elev);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.metric-box .mlabel {
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 700;
  margin-bottom: 4px;
}
.metric-box .mval {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.metric-box .mval .unit { font-size: 14px; font-weight: 700; margin-left: 2px; }
.metric-box .msub { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; }

.gap-bar-wrap {
  margin: 18px 0;
}
.gap-bar {
  display: flex;
  width: 100%;
  height: 26px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.gap-bar .green { background: var(--ok); }
.gap-bar .red { background: var(--bad); }
.gap-bar-caption {
  font-size: 13px;
  color: var(--text-soft);
  margin-top: 8px;
  font-weight: 600;
}
.gap-bar-schematic-note {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 4px;
}

.badge-block {
  margin: 14px 0;
}
.badge-block .rest-badge, .badge-block .bailout-badge {
  width: 100%;
}
.rest-breakdown {
  display: flex;
  gap: 14px;
  font-size: 12.5px;
  color: var(--text-soft);
  margin-top: 6px;
  padding-left: 2px;
  flex-wrap: wrap;
}
.rest-breakdown span b { color: var(--text); }

.bailout-badge {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}
.bailout-badge .bmain { font-weight: 700; }
.bailout-badge .bsub { color: var(--text-faint); font-size: 12px; }

.route-svg-wrap {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin: 16px 0 6px;
}
.route-svg-wrap svg { display: block; width: 100%; height: auto; }

.endpoints {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-soft);
  padding: 0 4px;
}
.endpoints .type { color: var(--text-faint); }

/* --- screen D: empty state ------------------------------------------------ */

.empty-state {
  background: var(--bg-elev);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.empty-state .icon { font-size: 30px; margin-bottom: 8px; }
.empty-state h2 {
  font-size: 17px;
  margin: 0 0 8px;
}
.empty-state p {
  font-size: 14.5px;
  color: var(--text-soft);
  margin: 0 0 4px;
}
.adjacent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.adjacent-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-soft);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: inherit;
  font-size: 14px;
  font-weight: 700;
}
.adjacent-link .cnt { color: var(--text-faint); font-weight: 500; font-size: 12.5px; }
.adjacent-link:hover { border-color: var(--accent); }

/* --- screen E: compare card ---------------------------------------------- */

.demo-flag {
  display: inline-block;
  background: var(--bad);
  color: #fff;
  font-size: 12.5px;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 999px;
  margin-bottom: 16px;
}
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.compare-col {
  background: var(--bg-elev);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  box-shadow: var(--shadow);
}
.compare-col.fail { border-color: var(--bad); }
.compare-col .status {
  font-size: 11.5px;
  font-weight: 800;
  border-radius: 999px;
  padding: 4px 10px;
  display: inline-block;
  margin-bottom: 10px;
}
.compare-col.pass .status { background: var(--ok-bg); color: var(--ok); }
.compare-col.fail .status { background: var(--bad-bg); color: var(--bad); }
.compare-col .cname { font-weight: 800; font-size: 14.5px; margin-bottom: 10px; min-height: 40px; }
.compare-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: 13.5px;
}
.compare-row:first-of-type { border-top: none; }
.compare-row .k { color: var(--text-faint); }
.compare-row .v { font-weight: 800; }
.compare-row .v.highlight { color: var(--bad); font-size: 15px; }
.compare-row .v.highlight.pass-side { color: var(--ok); }

.compare-vs {
  text-align: center;
  font-weight: 800;
  color: var(--text-faint);
  font-size: 13px;
  margin: 4px 0;
}

.compare-takeaway {
  margin-top: 18px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  line-height: 1.7;
}

@media (min-width: 760px) {
  .compare-grid { grid-template-columns: 1fr auto 1fr; align-items: center; }
  .compare-vs { writing-mode: horizontal-tb; }
}

/* --- utility --------------------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; }
.center { text-align: center; }
.mt-24 { margin-top: 24px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
