:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --fg: #141821;
  --muted: #646b78;
  --line: #e3e6ec;
  --night: #0f1b33;
  --night-fg: #f3f5fa;
  --accent: #c9821a;
  --accent-soft: #fbf1e1;
  --pass: #2f7d5b;
  --danger: #b42318;
  --heart: #d6336c;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(15 27 51 / 6%), 0 4px 16px rgb(15 27 51 / 6%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1222;
    --surface: #131c30;
    --fg: #e9ecf3;
    --muted: #9aa3b5;
    --line: #243049;
    --night: #070d1a;
    --accent: #f0a83c;
    --accent-soft: #2b2416;
    --pass: #5cc597;
    --danger: #f97066;
    --heart: #f06595;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button,
select {
  font: inherit;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---- ヘッダ ---- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--night);
  color: var(--night-fg);
  padding-top: env(safe-area-inset-top);
}

.top-inner {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0.75rem 1rem 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-mark {
  width: 0.5rem;
  height: 2.2rem;
  border-radius: 3px;
  background: linear-gradient(var(--accent), #e8c27a);
}

.brand h1 {
  font-size: 1.1rem;
  letter-spacing: 0.04em;
}

.brand-sub {
  font-size: 0.75rem;
  opacity: 0.75;
}

.howto-link {
  margin-left: auto;
  color: inherit;
  font-size: 0.8rem;
  opacity: 0.8;
}

.howto-link + .clock {
  margin-left: 0.6rem;
}

.clock {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  opacity: 0.9;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.6rem;
}

.tabs button {
  flex: 1;
  border: 0;
  background: none;
  color: inherit;
  opacity: 0.7;
  padding: 0.55rem 0;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  opacity: 1;
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.badge:not(:empty) {
  display: inline-block;
  min-width: 1.3rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: #1b1405;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ---- 本体 ---- */
.app {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0.9rem 1rem calc(5rem + env(safe-area-inset-bottom));
}

.view {
  display: grid;
  /* minmax(0, 1fr): select の長い選択肢に列幅を引っ張られて横にはみ出さないように */
  grid-template-columns: minmax(0, 1fr);
  gap: 0.8rem;
}

.view[hidden] {
  display: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 1rem;
}

.error {
  margin-bottom: 0.8rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

/* ---- 便の選択 ---- */
.picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.7rem;
}

.chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  border-radius: 999px;
  padding: 0.25rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--night);
  border-color: var(--night);
  color: var(--night-fg);
}

.field {
  display: grid;
  gap: 0.25rem;
}

.field-label {
  font-size: 0.75rem;
  color: var(--muted);
}

select {
  width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg);
}

.picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ghost,
.primary {
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.ghost {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--fg);
}

.ghost[aria-pressed="true"] {
  background: var(--accent);
  color: #1b1405;
}

.primary {
  border: 0;
  background: #06c755; /* LINE のログインボタンの色 */
  color: #fff;
  font-weight: 600;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---- いまの位置 ---- */
.status {
  background: var(--night);
  color: var(--night-fg);
  border-color: var(--night);
}

.eyebrow {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 600;
}

.where {
  font-size: 1.45rem;
  margin: 0.15rem 0 0.9rem;
  line-height: 1.3;
}

.progress {
  position: relative;
  height: 3.2rem;
  margin: 0 0.4rem;
}

.track {
  position: absolute;
  top: 0.95rem;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 2px;
  background: rgb(255 255 255 / 18%);
}

.fill {
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: var(--accent);
  transition: width 0.9s linear;
}

.train {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 1.15rem;
  transition: left 0.9s linear;
}

.stops {
  position: absolute;
  inset: 0;
}

.stop {
  position: absolute;
  top: 0.8rem;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: var(--night);
  border: 2px solid var(--night-fg);
}

.stop-name {
  position: absolute;
  top: 0.9rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  white-space: nowrap;
  opacity: 0.75;
}

/* 端の駅名がはみ出さないよう、最初と最後は寄せる */
.stop:first-child .stop-name {
  left: 0;
  transform: none;
}

.stop:last-child .stop-name {
  left: auto;
  right: 0;
  transform: none;
}

.next {
  margin-top: 0.2rem;
  font-size: 0.95rem;
}

.live {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  opacity: 0.7;
}

/* ---- 追い抜き ---- */
.overtake-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
}

.counter {
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

#ot-done {
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--accent);
}

.counter .of {
  margin-left: 0.2rem;
  color: var(--muted);
}

.ot-list {
  list-style: none;
  margin: 0.8rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.ot {
  display: grid;
  grid-template-columns: 1.3rem auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  background: var(--bg);
  font-size: 0.9rem;
}

.ot-mark {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 0.75rem;
}

.ot.passed .ot-mark {
  background: var(--pass);
  border-color: var(--pass);
  color: #fff;
}

.ot-type {
  font-size: 0.75rem;
  padding: 0.05rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.ot-text {
  min-width: 0;
}

.ot-when {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ot.passed .ot-text,
.ot.passed .ot-type {
  color: var(--muted);
}

/* ---- スポット ---- */
.spot-list {
  list-style: none;
  margin: 0.7rem 0 0;
  padding: 0;
  display: grid;
}

.spot,
.fav {
  display: grid;
  grid-template-columns: 2rem 1fr auto auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--line);
}

.fav {
  grid-template-columns: 2rem 1fr;
  align-items: start;
}

.spot:first-child,
.fav:first-child {
  border-top: 0;
}

.spot-icon {
  font-size: 1.35rem;
  text-align: center;
}

.spot-body {
  display: grid;
  min-width: 0;
}

.spot-body strong {
  overflow-wrap: anywhere;
}

.spot-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.spot-when {
  font-size: 0.8rem;
  color: var(--accent);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.heart {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.35rem;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  cursor: pointer;
}

.heart.saved {
  color: var(--heart);
}

.fav-actions {
  display: flex;
  gap: 1rem;
  margin-top: 0.3rem;
}

.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
}

.link.danger {
  color: var(--danger);
}

.empty {
  display: grid;
  gap: 0.2rem;
  padding: 1.5rem 0;
  text-align: center;
  color: var(--muted);
}

.login {
  display: grid;
  gap: 0.7rem;
  justify-items: start;
  margin-top: 0.7rem;
}

/* ---- 通知 ---- */
.toasts {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(0.8rem + env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  padding: 0 1rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  width: min(100%, 38rem);
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius);
  background: var(--night);
  color: var(--night-fg);
  box-shadow: 0 8px 28px rgb(0 0 0 / 30%);
  animation: toast-in 0.25s ease-out;
  transition: opacity 0.5s, transform 0.5s;
}

.toast.leaving {
  opacity: 0;
  transform: translateY(8px);
}

.toast-icon {
  font-size: 1.4rem;
  text-align: center;
}

.toast-text {
  display: grid;
  min-width: 0;
}

.toast-text span {
  font-size: 0.8rem;
  opacity: 0.8;
}

.toast-action {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .fill,
  .train,
  .toast {
    transition: none;
    animation: none;
  }
}

/* ---- 出典 ---- */
.credits {
  margin-top: 1.5rem;
  display: grid;
  gap: 0.25rem;
  font-size: 0.72rem;
  color: var(--muted);
}

/* 途中の停車駅名は重なるので出さない（次の停車駅は文で出している） */
.stop:not(:first-child):not(:last-child) .stop-name {
  display: none;
}

/* ---- 席のおすすめ ---- */
.eyebrow-muted {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.seat h3 {
  margin: 0.1rem 0 0.15rem;
  font-size: 1.05rem;
}

.seat-rows {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.6rem;
}

.seat-row {
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 1fr);
  align-items: start;
  gap: 0.4rem;
}

.seat-row-label {
  font-size: 0.8rem;
  font-weight: 600;
  padding-top: 0.15rem;
}

.seat-highlights {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.seat-highlights li {
  display: inline-flex;
  gap: 0.3rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  font-size: 0.82rem;
}

/* ---- すれ違い ---- */
.passing {
  margin-top: 0.8rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}

.passing-count {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  font-variant-numeric: tabular-nums;
}

.passing-label {
  font-size: 0.85rem;
  margin-right: 0.3rem;
}

#ps-done {
  font-size: 1.5rem;
  font-weight: 700;
}

/* 地下区間の脇のスポット（見えない） */
.spot.under {
  opacity: 0.55;
}

/* ---- 乗車記録 ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 0.7rem;
}

.stat {
  display: grid;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  background: var(--bg);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.badge-grid {
  list-style: none;
  margin: 0.7rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
  gap: 0.5rem;
}

.badge-item {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 0.1rem;
  padding: 0.6rem 0.4rem;
  border-radius: 12px;
  border: 1px dashed var(--line);
  color: var(--muted);
}

.badge-item.earned {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--fg);
}

.badge-icon {
  font-size: 1.6rem;
}

.badge-item strong {
  font-size: 0.82rem;
}

.badge-desc {
  font-size: 0.68rem;
  line-height: 1.35;
}

.ride {
  display: grid;
  padding: 0.55rem 0;
  border-top: 1px solid var(--line);
}

.ride:first-child {
  border-top: 0;
}

/* ---- 使い方ページ（howto.html） ---- */
.howto-top {
  padding-bottom: 0.75rem;
}

.howto {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.8rem;
}

.howto h2 {
  font-size: 1.05rem;
  margin-bottom: 0.4rem;
}

.howto p + p,
.howto ul + p,
.howto ol + p {
  margin-top: 0.5rem;
}

.howto ul,
.howto ol {
  margin: 0.3rem 0 0;
  padding-left: 1.3rem;
}

.howto li + li {
  margin-top: 0.3rem;
}

.howto a {
  color: var(--accent);
  overflow-wrap: anywhere;
}

.howto-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.howto .link-button {
  display: inline-block;
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  background: var(--accent-soft);
  color: var(--fg);
  text-decoration: none;
  font-size: 0.9rem;
}

.howto .link-button.solid {
  background: var(--accent);
  color: #1b1405;
  font-weight: 600;
}

.credits a {
  color: inherit;
}
