/* マルスシミュレーター PWA */
:root {
  --ink: #1d2b2a;
  --muted: #5b6b68;
  --line: #cfd8d5;
  --bg: #f3f5f4;
  --panel: #ffffff;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --ok: #2e7d32;
  --ng: #c62828;
  --warn: #b26a00;
  --font: "BIZ UDPGothic", "BIZ UDGothic", "Yu Gothic UI", "Yu Gothic", "Meiryo", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --mono: "BIZ UDGothic", "MS Gothic", "Osaka-Mono", "Noto Sans Mono CJK JP", monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 12px; cursor: pointer;
  min-height: 36px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: bold; }
button.toggle[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: bold; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 上の帯 */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 8px 14px;
  background: var(--accent); color: #fff;
}
.top h1 { font-size: 18px; margin: 0; }
.top .boot { flex: 1; font-size: 13px; opacity: .9; min-width: 10em; }
.top .boot.error { color: #ffd1d1; font-weight: bold; }
.top-actions { display: flex; gap: 6px; }
.top-actions button { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.5); min-height: 32px; }

/* 2段組（狭い画面は1段） */
.layout { display: grid; grid-template-columns: minmax(330px, 430px) minmax(0, 1fr); gap: 12px; padding: 12px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; }

/* 入力 */
.box { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 10px; padding: 6px 10px 10px; }
.box legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.station-row { display: grid; grid-template-columns: 2.6em 1fr auto; gap: 8px; align-items: center; }
.station-label { font-weight: bold; font-size: 17px; }
.station-input { font-size: 20px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; width: 100%; min-width: 0; }
.station-input:focus, .cell-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.station-input.set, .cell-input.set { background: #f4f8ff; }
.single { font-size: 13px; white-space: nowrap; }
.swap-row { text-align: center; margin: 6px 0; }
.passenger-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.passenger-label { font-weight: bold; margin-top: 6px; font-size: 14px; }

.route-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; font-weight: bold; margin: 6px 0 4px; }
.no-correction { white-space: nowrap; font-weight: normal; }
.route-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
@media (max-width: 860px) { .route-wrap { max-height: none; } }
table.route { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.route th { position: sticky; top: 0; background: #eef2f1; font-size: 12px; font-weight: normal; color: var(--muted); padding: 3px; z-index: 1; }
table.route th.no { width: 2.6em; }
table.route th.ops { width: 2.4em; }
table.route td { border-top: 1px solid #e5ebe9; padding: 2px; }
table.route td.no { text-align: center; font-size: 12px; color: var(--muted); }
table.route tr.active td.no { background: var(--accent); color: #fff; border-radius: 4px; }
.cell-input { width: 100%; border: 1px solid transparent; border-radius: 4px; padding: 5px 6px; font-size: 16px; background: transparent; min-width: 0; }
.cell-input:hover { border-color: var(--line); }
.row-del { min-height: 28px; padding: 0 6px; border-color: transparent; color: var(--muted); }
.row-actions, .main-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.main-actions .primary { flex: 2; min-height: 44px; font-size: 17px; }
.main-actions button { flex: 1; }
.status { min-height: 1.5em; margin-top: 8px; font-weight: bold; font-size: 14px; }
.status.error { color: var(--ng); }
.status.query { color: var(--accent); }

/* 候補一覧 */
.candidates {
  position: absolute; z-index: 20; margin: 0; padding: 4px 0; list-style: none; background: #fff;
  border: 1px solid var(--accent); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.18);
  max-height: 50vh; overflow: auto; min-width: 12em;
}
.candidates .head { font-size: 12px; color: var(--muted); padding: 2px 10px 4px; border-bottom: 1px solid #eef2f1; cursor: default; }
.candidates li.item { padding: 5px 10px; cursor: pointer; white-space: nowrap; }
.candidates li.item[aria-selected="true"], .candidates li.item:hover { background: var(--accent); color: #fff; }
.candidates .key { display: inline-block; min-width: 1.6em; color: var(--muted); font-family: var(--mono); }
.candidates li.item[aria-selected="true"] .key, .candidates li.item:hover .key { color: #dbe4ff; }
.candidates .kana { font-size: 12px; color: var(--muted); margin-left: .6em; }
.candidates li.item[aria-selected="true"] .kana, .candidates li.item:hover .kana { color: #dbe4ff; }

/* 結果 */
.stale { background: #fff3cd; border: 1px solid #f0c36d; border-radius: 6px; padding: 4px 10px; margin-bottom: 8px; font-weight: bold; }
.ticket { min-height: 120px; text-align: center; }
.ticket svg { display: inline-block; max-width: 100%; height: auto; }
.caption { text-align: center; font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.result-buttons { text-align: center; margin-bottom: 6px; }
.checks { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-bottom: 10px; font-size: 14px; }
.check { border-top: 1px solid #e5ebe9; }
.check:first-child { border-top: none; }
.check > summary, .check > .row { display: grid; grid-template-columns: 9.5em 3.2em 1fr; gap: 6px; padding: 4px 8px; cursor: default; list-style: none; }
.check > summary { cursor: pointer; }
.check > summary::-webkit-details-marker { display: none; }
.check > summary .item::before { content: "▸ "; color: var(--muted); }
.check[open] > summary .item::before { content: "▾ "; }
.check .item { font-weight: bold; }
.check .value { overflow-wrap: anywhere; }
.st { font-weight: bold; text-align: center; }
.st.OK { color: var(--ok); }
.st.NG { color: var(--ng); }
.st.注意 { color: var(--warn); }
.check ul { margin: 0; padding: 2px 12px 8px calc(9.5em + 3.2em + 20px); list-style: none; font-size: 13px; }
.check li { overflow-wrap: anywhere; }
.check li.NG { color: var(--ng); }
.check li.注意 { color: var(--warn); }
@media (max-width: 560px) {
  .check > summary, .check > .row { grid-template-columns: 7.5em 2.6em 1fr; }
  .check ul { padding-left: 16px; }
}
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { border-radius: 6px 6px 0 0; border-bottom: none; min-height: 34px; }
.tabs button[aria-selected="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.tab-panel { padding-top: 8px; }
.result-text, .json-text, .memo-box {
  font-family: var(--mono); font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; background: #fafcfb;
  border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin: 0;
}
.result-text { min-height: 6em; }
.panel-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.memo-head { font-weight: bold; }
.memo-status { color: var(--ng); font-size: 14px; }
.memo-part { margin-top: 10px; }
.memo-part-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.memo-title { font-size: 14px; margin: 12px 0 4px; }
.memo-part-head .memo-title { margin: 0; }
.memo-part-head button { min-height: 28px; padding: 2px 10px; font-size: 13px; }
table.memo-rows { border-collapse: collapse; width: 100%; font-size: 14px; }
table.memo-rows th, table.memo-rows td { border: 1px solid var(--line); padding: 3px 6px; text-align: left; }
table.memo-rows th { background: #eef2f1; font-weight: normal; }

/* ダイアログ */
.dialog { border: none; border-radius: 10px; padding: 0; width: min(520px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.dialog.wide { width: min(900px, 96vw); }
.dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog form { padding: 14px 16px; }
.dialog h2 { font-size: 17px; margin: 0 0 8px; }
.dialog .detail { margin: 0 0 4px; }
.dialog .preview { font-family: var(--mono); font-size: 13px; background: #f4f6f5; border-radius: 6px; padding: 6px 8px; overflow-wrap: anywhere; }
.choice-list { margin: 0; padding: 0; list-style: none; max-height: 55vh; overflow: auto; }
.choice-list button { width: 100%; text-align: left; margin: 2px 0; }
.choice-list .key { display: inline-block; min-width: 1.8em; color: var(--muted); font-family: var(--mono); }
.dialog fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.json-text { max-height: 65vh; overflow: auto; }

.update {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 30; background: var(--ink); color: #fff;
  border-radius: 8px; padding: 8px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.update button { margin-left: 8px; }
.foot { padding: 4px 16px 20px; font-size: 12px; color: var(--muted); }
.foot p { margin: 4px 0; }
.selftest { white-space: pre-wrap; font-size: 12px; }

/* 狭い画面では券面を幅いっぱいに（85mm と 120mm の長さの違いは説明の文で示す） */
@media (max-width: 560px) {
  .ticket svg { width: 100% !important; }
}
