:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --form: #f2f2f5;
  --ink: #111114;
  --muted: #6b7280;
  --line: #e5e7eb;
  --green: #22a06b;
  --blue: #3b82f6;
  --red: #ef4444;
  --amber: #c08a2e;
  --grey: #9aa0a6;
  --badge-bg: #ffe4e6;
  --badge-ink: #e11d48;
  --focus: #2f7cf6;
}

* { box-sizing: border-box; }

/* Author `display` rules beat the UA rule for [hidden], so make it explicit. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang HK", "Noto Sans TC",
    "Microsoft JhengHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
}

/* Language picker — globe trigger with a drop-down menu */
.topbar { display: flex; justify-content: flex-end; }
.lang-picker { position: relative; }

.lang-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #fff;
  border: 0;
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  transition: box-shadow 0.16s ease, transform 0.16s ease;
}
.lang-trigger:hover { box-shadow: 0 2px 6px rgba(16, 24, 40, 0.14); }
.lang-trigger:active { transform: scale(0.98); }
.lang-globe { color: var(--muted); }
.lang-chevron { color: var(--muted); transition: transform 0.18s ease; }
.lang-trigger[aria-expanded="true"] .lang-chevron { transform: rotate(180deg); }

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  margin: 0;
  padding: 5px;
  list-style: none;
  min-width: 9.5rem;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 26px rgba(16, 24, 40, 0.16);
  transform-origin: top right;
  animation: lang-in 0.16s ease-out;
}
@keyframes lang-in {
  from { opacity: 0; transform: scale(0.94) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.lang-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.lang-menu button:hover { background: var(--form); }
.lang-menu li[aria-selected="true"] button { color: var(--focus); font-weight: 700; }
.lang-check { width: 0.9em; color: var(--focus); }

@media (prefers-reduced-motion: reduce) {
  .lang-menu { animation: none; }
  .lang-chevron { transition: none; }
  .lang-trigger { transition: none; }
}

/* Result card */
.result-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: 0.01em; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.badge {
  flex: 0 0 auto;
  background: var(--badge-bg);
  color: var(--badge-ink);
  border-radius: 999px;
  padding: 5px 12px;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
}
.badge.flat { background: #eef0f3; color: #4b5563; }
.badge.normal { background: #e8f1ff; color: #1d4ed8; }
.badge.non-peak { background: #e7f6ee; color: #157a4d; }
.badge.transition { background: #fdf1df; color: #a2650f; }

.price {
  margin: 10px 0 0;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: clamp(2.1rem, 5vw, 2.9rem);
  line-height: 1;
  letter-spacing: -0.02em;
}
.price .currency { font-size: 0.4em; font-weight: 700; color: var(--muted); margin-right: 6px; }

.hint {
  margin-top: 12px;
  background: var(--form);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.5;
}

/* Journey suggestion — a list of tunnel combinations with totals */
.plan-result { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.plan-note { margin: 0; color: var(--muted); font-size: 0.92rem; }
.plan-route {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 0.92rem;
}
.plan-route.cheapest { background: #e7f6ee; }
.plan-route-name { flex: 1 1 auto; min-width: 0; }
.plan-route.cheapest .plan-route-name { color: #157a4d; font-weight: 700; }
.plan-route-price { font-variant-numeric: tabular-nums; font-weight: 600; }
.plan-route-tag { color: var(--muted); font-size: 0.78rem; }
.plan-route.cheapest .plan-route-tag { color: #157a4d; font-weight: 700; }
.plan-sep { color: var(--muted); margin: 0 2px; }
.plan-disclaimer { margin: 6px 0 0; color: var(--muted); font-size: 0.78rem; }


/* Alternatives for the same trip, inside the result card */
.alt { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.alt-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.alt-title { font-size: 0.9rem; font-weight: 700; }
.alt .compare-list { margin-top: 8px; }
.pick-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* Toll comparison picker */
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 5px 10px;
  font: inherit;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}
.chip.on { border-color: #bcd7ff; background: #e8f1ff; color: var(--focus); font-weight: 700; }
.compare-tag { color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.compare-row.cheapest .compare-tag { color: #157a4d; }

.compare-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.compare-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 9px 12px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.compare-row:hover { background: var(--form); }
.compare-row.cheapest { background: #e7f6ee; color: #157a4d; font-weight: 700; }
.compare-row.cheapest .compare-price { color: #157a4d; }
.compare-price { font-variant-numeric: tabular-nums; }
.compare-note { margin: 8px 0 0; color: var(--muted); font-size: 0.88rem; font-weight: 600; }

/* Chart card */
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.chart-head h2 { font-size: 1rem; margin: 0; }
.now-label { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.now-label strong { color: var(--focus); font-size: 1rem; font-variant-numeric: tabular-nums; }

.chart { position: relative; height: 34px; margin: 12px 0 0; }
.chart-bar { display: flex; height: 100%; border-radius: 8px; overflow: hidden; }
.chart-bar .seg { height: 100%; }
.seg.non-peak { background: var(--green); }
.seg.normal { background: var(--blue); }
.seg.peak { background: var(--red); }
.seg.transition { background: var(--amber); }
.seg.flat { background: var(--grey); }

.chart-marker {
  position: absolute;
  top: -3px;
  width: 3px;
  height: calc(100% + 6px);
  background: #000;
  border-radius: 2px;
  transform: translateX(-1.5px);
}
.chart-marker::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #000;
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 14px; padding: 10px 0 0; margin: 0; }
.legend li { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.85rem; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.non-peak { background: var(--green); }
.dot.normal { background: var(--blue); }
.dot.peak { background: var(--red); }
.dot.transition { background: var(--amber); }
.dot.flat { background: var(--grey); }

/* Form card */
.form-card { background: var(--form); display: flex; flex-direction: column; gap: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { color: var(--muted); font-size: 0.92rem; font-weight: 600; }

select {
  appearance: none;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 12px;
  background: #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24'><path d='M6 9l6 6 6-6' fill='none' stroke='%239aa0a6' stroke-width='2' stroke-linecap='round'/></svg>") no-repeat right 12px center;
  padding: 11px 36px 11px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
}
select:focus-visible, button:focus-visible, input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.time-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.time-selects { display: flex; align-items: center; gap: 8px; }
#hour-select, #minute-select {
  width: auto;
  min-width: 5.5rem;
  text-align: center;
  padding: 11px 34px 11px 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.time-colon { font-weight: 700; font-size: 1.05rem; color: var(--muted); }

#time-slider { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; margin-top: 4px; background: transparent; }
#time-slider::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: #d8d8dd; }
#time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px; margin-top: -7.5px;
  border-radius: 50%; background: #111; border: 0;
}
#time-slider::-moz-range-track { height: 5px; border-radius: 3px; background: #d8d8dd; }
#time-slider::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #111; border: 0; }

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--focus);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.link-btn:disabled { color: var(--muted); cursor: default; }

.date-row { display: flex; align-items: center; gap: 10px; }
.date-input {
  flex: 1;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: #fff;
  padding: 10px 14px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
}
/* Category control: auto / weekday / weekend (overrides the derived schedule) */
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  background: #fff;
  border-radius: 999px;
  padding: 3px;
}
.segmented button {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 8px;
  font: inherit;
  font-size: 0.78rem;
  line-height: 1.3;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}
.segmented button[aria-pressed="true"] { background: #e8f1ff; color: var(--focus); font-weight: 700; }
@media (max-width: 560px) {
  .segmented { flex-direction: column; border-radius: 16px; }
  .segmented button { border-radius: 12px; padding: 10px 12px; text-align: left; }
  /* the mode switch stays a single row whatever the width */
  .mode-toggle { flex-direction: row; border-radius: 999px; }
  .mode-toggle button { border-radius: 999px; padding: 9px 8px; text-align: center; }
}

.notice { margin: 0; color: #a2650f; font-size: 0.85rem; }

.site-footer { color: var(--muted); font-size: 0.78rem; line-height: 1.65; padding: 0 4px; }
.site-footer a { color: var(--focus); }

/* Wide screens: result + chart on the left, form on the right, so the whole
   tool fits one viewport without scrolling. */
@media (min-width: 900px) {
  .wrap {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    grid-template-areas:
      "topbar topbar"
      "result form"
      "chart  form"
      "plan   plan"
      "footer footer";
    align-items: start;
    gap: 14px;
    padding-top: 14px;
  }
  .topbar { grid-area: topbar; }
  #result-card { grid-area: result; }
  #chart-card { grid-area: chart; }
  .form-card { grid-area: form; }
  #plan-card { grid-area: plan; }
  .site-footer { grid-area: footer; }
}
