/* 旅のしおり — 時刻表の組版をおもわせる、罫線のほそい表を主役にした一枚構成 */

:root {
  /* 色 */
  --paper:     #f4f6f3;   /* 時刻表の紙 */
  --surface:   #ffffff;
  --surface-2: #eceff0;
  --ink:       #1b2220;
  --ink-soft:  #5e6a66;
  --ink-faint: #8d9893;
  --rule:      #d5dbd6;
  --rule-firm: #aeb7b2;
  --ai:        #1f3a5f;   /* 鉄紺／構造の色 */
  --ai-soft:   #e3eaf2;
  --on-ai:     #ffffff;   /* 鉄紺の上に乗る字 */
  --shu:       #a8402c;   /* 朱／合計と警告 */
  --shu-soft:  #f7e6e1;

  /* 字 */
  --f-display: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --f-body:    "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --f-mono:    "M PLUS 1 Code", ui-monospace, "SFMono-Regular", Menlo, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:     #14181a;
    --surface:   #1c2225;
    --surface-2: #232a2e;
    --ink:       #e4e8e4;
    --ink-soft:  #9ba6a1;
    --ink-faint: #707c77;
    --rule:      #2c3438;
    --rule-firm: #465156;
    --ai:        #8fb3d9;
    --ai-soft:   #1e2c3c;
    --on-ai:     #10171d;
    --shu:       #e2907a;
    --shu-soft:  #38231e;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper:     #14181a;
  --surface:   #1c2225;
  --surface-2: #232a2e;
  --ink:       #e4e8e4;
  --ink-soft:  #9ba6a1;
  --ink-faint: #707c77;
  --rule:      #2c3438;
  --rule-firm: #465156;
  --ai:        #8fb3d9;
  --ai-soft:   #1e2c3c;
  --on-ai:     #10171d;
  --shu:       #e2907a;
  --shu-soft:  #38231e;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 15px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

img { max-width: 100%; }
[hidden] { display: none !important; }

code {
  font-family: var(--f-mono);
  font-size: .88em;
  background: var(--surface-2);
  padding: .1em .4em;
  border-radius: 3px;
}

:focus-visible {
  outline: 2px solid var(--ai);
  outline-offset: 2px;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: 28px 64px;
}

/* ===== 合言葉 ===== */

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}

.gate-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--ai);
  padding: 32px 28px;
  text-align: center;
}

.gate-eyebrow {
  margin: 0;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.gate-title {
  margin: 10px 0 0;
  font-family: var(--f-display);
  font-size: 29px;
  font-weight: 600;
  letter-spacing: .1em;
}

.gate-note {
  margin: 6px 0 22px;
  font-size: 13px;
  color: var(--ink-soft);
}

#gate-form { display: grid; gap: 10px; }

.gate-input {
  font-family: var(--f-mono);
  font-size: 24px;
  letter-spacing: .5em;
  text-align: center;
  padding: 12px 10px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule-firm);
  border-radius: 2px;
  width: 100%;
}

.gate-error {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--shu);
}

/* ===== ホーム ===== */

.site-head {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--ink);
}

.eyebrow {
  margin: 0;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.site-title {
  margin: 4px 0 0;
  font-family: var(--f-display);
  font-size: clamp(26px, 5vw, 36px);
  font-weight: 600;
  letter-spacing: .06em;
  text-wrap: balance;
}

.head-actions { display: flex; gap: 8px; align-items: center; }

.trip-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  margin: 28px 0;
}

.trip-card {
  background: var(--surface);
  border: 0;
  border-left: 3px solid transparent;
  padding: 20px 18px;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: grid;
  gap: 6px;
  align-content: start;
  min-height: 112px;
  transition: border-color .12s, background .12s;
}

.trip-card:hover,
.trip-card:focus-visible { border-left-color: var(--ai); background: var(--surface-2); }

.trip-card-name {
  font-family: var(--f-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .03em;
  line-height: 1.45;
}

.trip-card-meta {
  font-family: var(--f-mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.trip-card-counts {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.empty {
  grid-column: 1 / -1;
  background: var(--surface);
  padding: 44px 24px;
  text-align: center;
  color: var(--ink-soft);
}

.empty strong {
  display: block;
  font-family: var(--f-display);
  font-size: 18px;
  color: var(--ink);
  margin-bottom: 6px;
}

.new-trip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}

.field {
  flex: 1 1 200px;
  min-width: 0;
  font: inherit;
  padding: 9px 12px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule-firm);
  border-radius: 2px;
}

/* ===== 旅行の中身 ===== */

.trip-head { border-bottom: 2px solid var(--ink); padding-bottom: 16px; }

.trip-head-top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.save-zone { display: flex; gap: 8px; align-items: center; }

.save-state {
  font-family: var(--f-mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.save-state[data-kind="dirty"] { color: var(--shu); }
.save-state[data-kind="saved"] { color: var(--ai); }

.trip-name {
  width: 100%;
  margin-top: 12px;
  font-family: var(--f-display);
  font-size: clamp(24px, 5vw, 34px);
  font-weight: 600;
  letter-spacing: .05em;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-bottom: 1px dashed transparent;
  padding: 2px 0;
}

.trip-name:hover { border-bottom-color: var(--rule-firm); }
.trip-name:focus { outline: none; border-bottom-color: var(--ai); }

.trip-meta {
  margin: 6px 0 0;
  font-family: var(--f-mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.banner {
  margin-top: 18px;
  padding: 12px 14px;
  font-size: 13.5px;
  border-left: 3px solid var(--shu);
  background: var(--shu-soft);
  color: var(--ink);
}

.banner-warn strong { color: var(--shu); }

/* ===== タブ ===== */

.tabs {
  display: flex;
  gap: 2px;
  margin-top: 26px;
  border-bottom: 1px solid var(--rule-firm);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  font: inherit;
  font-size: 14px;
  letter-spacing: .08em;
  padding: 10px 20px;
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid transparent;
  border-bottom: 0;
  margin-bottom: -1px;
  cursor: pointer;
}

.tab:hover { color: var(--ink); }

.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--ai);
  border-color: var(--rule-firm);
  font-weight: 700;
  box-shadow: inset 0 2px 0 var(--ai);
}

.panel-wrap {
  background: var(--surface);
  border: 1px solid var(--rule-firm);
  border-top: 0;
  padding: 20px 16px 24px;
}

.panel-hint {
  margin: 0 0 16px;
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--ink-soft);
}

/* ===== ファイルを置くところ ===== */

.drop {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  padding: 14px 16px;
  margin-bottom: 14px;
  border: 1px dashed var(--rule-firm);
  border-radius: 2px;
  background: var(--paper);
  transition: border-color .12s, background .12s;
}

.drop.over {
  border-color: var(--ai);
  border-style: solid;
  background: var(--ai-soft);
}

.drop-note { font-size: 12px; color: var(--ink-faint); }

/* ===== 絞り込み ===== */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 12px;
}

.chips:empty { display: none; }

.chips-label {
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--ink-faint);
  margin-right: 4px;
}

.chip {
  font: inherit;
  font-size: 12.5px;
  line-height: 1;
  padding: 7px 11px;
  border: 1px solid var(--rule-firm);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover { color: var(--ink); border-color: var(--ai); }

.chip.on {
  background: var(--ai);
  border-color: var(--ai);
  color: var(--on-ai);
  font-weight: 700;
}

.chip-n {
  font-family: var(--f-mono);
  font-size: 10.5px;
  opacity: .62;
  font-variant-numeric: tabular-nums;
}

/* ===== 表 ===== */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--rule);
  background: var(--surface);
}

.grid {
  border-collapse: separate;
  border-spacing: 0;
  /* 列幅は colgroup の指定どおりに。はみ出す分は囲いの横スクロールにまかせる */
  table-layout: fixed;
  width: max-content;
  min-width: 100%;
  font-size: 13.5px;
}

.grid th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--ai-soft);
  color: var(--ai);
  font-family: var(--f-body);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-align: left;
  white-space: nowrap;
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule-firm);
  border-right: 1px solid var(--rule);
}

.grid th.group {
  text-align: center;
  border-bottom: 1px solid var(--rule);
}

.grid th.sortable { cursor: pointer; user-select: none; }
.grid th.sortable:hover { filter: brightness(.96); }

.sortmark {
  font-family: var(--f-mono);
  font-size: 10px;
  margin-left: 5px;
  opacity: .3;
}

.sortmark.on { opacity: 1; }

/* 日付の区切り行 */
.grid tr.dayrow td.day-cell {
  background: var(--ai-soft);
  border-bottom: 1px solid var(--rule-firm);
  border-top: 1px solid var(--rule-firm);
  padding: 0;
}

.day-inner {
  position: sticky;
  left: 0;
  width: 260px;           /* 横スクロールしても日付が左端に残る */
  max-width: 100%;
}

.day-input {
  font-family: var(--f-display) !important;
  font-size: 16px !important;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--ai) !important;
  padding: 9px 12px !important;
}

.day-input::placeholder { color: var(--ai); opacity: .4; font-weight: 400; }

.grid tr.dayrow td.ops { background: var(--ai-soft) !important; }

/* 日付の下に繰り返す列見出し */
.grid tr.subhead td {
  background: var(--surface-2);
  color: var(--ink-faint);
  font-size: 11px;
  letter-spacing: .1em;
  padding: 5px 10px;
  white-space: nowrap;
  border-bottom: 1px solid var(--rule-firm);
}

/* ランクの色分け */
td.rank-cell[data-rank="S"] .cell { color: var(--shu); font-weight: 700; }
td.rank-cell[data-rank="A"] .cell { color: var(--ai);  font-weight: 700; }
td.rank-cell[data-rank="B"] .cell { color: var(--ink-soft); }
td.rank-cell[data-rank="C"] .cell { color: var(--ink-faint); }

/* 表示中の合計 */
.sum {
  margin-top: 10px;
  text-align: right;
  font-family: var(--f-mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--shu);
  letter-spacing: .04em;
}

.sum:empty { display: none; }

/* 案が入っている行は左に細い線を出して、確定した行と見分ける */
.grid td.stick.has-plan { box-shadow: inset 3px 0 0 var(--shu); }

.add-row { display: flex; flex-wrap: wrap; gap: 8px; }
.add-row .btn-add { flex: 1 1 200px; margin-top: 12px; }
.btn-add-day { flex-grow: 0 !important; }

.no-rows {
  padding: 26px 14px !important;
  text-align: center;
  color: var(--ink-soft);
  font-size: 12.5px;
}

.grid td {
  padding: 0;
  border-bottom: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
  background: var(--surface);
  vertical-align: top;
}

.grid tr:last-child td { border-bottom: 0; }

/* 1列目は横スクロールしても残す */
.grid th.stick, .grid td.stick {
  position: sticky;
  left: 0;
  z-index: 2;
  border-right: 1px solid var(--rule-firm);
}

.grid th.stick { z-index: 4; }

.cell {
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.6;
  padding: 7px 10px;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-radius: 0;
  display: block;
  min-width: 0;
}

.cell:focus {
  outline: 2px solid var(--ai);
  outline-offset: -2px;
  background: var(--ai-soft);
}

textarea.cell { resize: vertical; min-height: 2.9em; max-height: 168px; overflow-y: auto; }

.cell-mono, .cell-num {
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
}

.cell-num { text-align: right; }

/* 合計 */
.grid td.total, .grid th.total {
  position: sticky;
  right: 0;
  z-index: 2;
  border-left: 1px solid var(--rule-firm);
  background: var(--surface-2);
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding: 7px 10px;
  white-space: nowrap;
  color: var(--shu);
  font-weight: 600;
}

.grid th.total { z-index: 5; background: var(--ai-soft); color: var(--ai); }

.grid tfoot td {
  background: var(--surface-2);
  border-top: 2px solid var(--rule-firm);
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding: 9px 10px;
  font-weight: 600;
  white-space: nowrap;
}

.grid tfoot td.stick {
  text-align: left;
  font-family: var(--f-body);
  letter-spacing: .1em;
  font-size: 11.5px;
  color: var(--ink-soft);
}

.grid tfoot td.total { color: var(--shu); font-size: 15px; }

/* 行の操作 */
.ops {
  width: 1%;
  white-space: nowrap;
  padding: 4px 6px !important;
  background: var(--surface-2) !important;
  text-align: center;
}

.op {
  font: inherit;
  font-size: 12px;
  line-height: 1;
  width: 22px;
  height: 22px;
  padding: 0;
  margin: 0 1px;
  background: transparent;
  color: var(--ink-faint);
  border: 1px solid transparent;
  border-radius: 2px;
  cursor: pointer;
}

.op:hover { color: var(--ink); border-color: var(--rule-firm); background: var(--surface); }
.op-del:hover { color: var(--shu); border-color: var(--shu); }

.open-link {
  font: inherit;
  font-size: 12px;
  text-decoration: none;
  color: var(--ai);
  padding: 0 7px;
  border-left: 1px solid var(--rule);
  align-self: stretch;
  display: grid;
  place-items: center;
}

.open-link[aria-disabled="true"] { color: var(--ink-faint); pointer-events: none; }

.url-cell { display: flex; align-items: stretch; min-width: 0; }
.url-cell .cell { min-width: 0; }

/* ===== ボタン ===== */

.btn {
  font: inherit;
  font-size: 13.5px;
  letter-spacing: .05em;
  padding: 8px 16px;
  border-radius: 2px;
  border: 1px solid var(--rule-firm);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }

.btn-primary {
  background: var(--ai);
  border-color: var(--ai);
  color: var(--on-ai);
  font-weight: 700;
}

.btn-primary:hover { filter: brightness(1.12); background: var(--ai); }

.btn-primary:disabled {
  background: var(--surface-2);
  border-color: var(--rule);
  color: var(--ink-faint);
  cursor: default;
  font-weight: 400;
  filter: none;
}

.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }

.btn-icon { padding: 8px 10px; }

.btn-add {
  margin-top: 12px;
  border-style: dashed;
  color: var(--ink-soft);
  width: 100%;
}

.btn-add:hover { color: var(--ai); border-color: var(--ai); }

.btn-danger-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--ink-faint);
  font-size: 12.5px;
}

.btn-danger-ghost:hover { color: var(--shu); border-color: var(--shu); background: transparent; }

.trip-foot { margin-top: 30px; text-align: right; }

/* ===== 通知 ===== */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 2px;
  z-index: 50;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .22);
}

.toast[data-kind="error"] { background: var(--shu); color: #fff; }

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .18s ease-out; }
  @keyframes rise {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
  }
}

/* ===== 画面がせまいとき ===== */

@media (max-width: 560px) {
  .wrap { padding-block: 20px 56px; }
  .panel-wrap { padding: 16px 10px 20px; }
  .tab { padding: 10px 14px; }
  .trip-list { grid-template-columns: 1fr; }
  .save-zone { flex: 1 1 100%; justify-content: flex-end; }
}
