:root {
  color-scheme: light;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-synthesis: none;
  --navy: #08263f;
  --navy-soft: #173d5b;
  --mustard: #c48600;
  --mustard-pale: #f5e8bd;
  --paper: #f7f4ee;
  --surface: #fffdf8;
  --line: #c9c5bb;
  --muted: #626b74;
  --danger: #a9322b;
  --danger-pale: #f9e3df;
  --safe: #276148;
  --safe-pale: #e2efe7;
  --warning: #805a00;
  --warning-pale: #fff2c9;
}

* { box-sizing: border-box; }
html { background: var(--paper); scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--navy); }
button, input, textarea, select { font: inherit; }
button, a, summary, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  transform: translateY(-170%);
  padding: 10px 14px;
  background: white;
  color: var(--navy);
  border: 2px solid var(--navy);
}
.skip-link:focus { transform: translateY(0); }

.app-bar {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: var(--navy);
  color: white;
  border-bottom: 1px solid #24445e;
}

.brand-link {
  min-width: 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: white;
  text-decoration: none;
}
.brand-mark {
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--mustard);
  color: var(--navy);
  font-weight: 900;
}
.brand-copy { min-width: 0; display: grid; line-height: 1.05; }
.brand-copy strong { font-size: 17px; letter-spacing: .12em; }
.brand-copy small { margin-top: 4px; color: #d8e2ea; font-size: 12px; }
.connection-state {
  max-width: 140px;
  padding: 6px 8px;
  border: 1px solid #70889a;
  border-radius: 4px;
  color: #eef4f8;
  font-size: 12px;
  line-height: 1.25;
  text-align: right;
}
.connection-state[data-online="false"] { border-color: #e8bd4b; color: #ffe9a3; }

.candidate-boundary {
  min-height: 35px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  background: #ece8df;
  border-bottom: 1px solid var(--line);
  color: #4d5660;
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
}
.candidate-boundary strong { color: var(--navy); white-space: nowrap; }

.page-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 14px 14px calc(88px + env(safe-area-inset-bottom));
}
.return-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  margin-left: -8px;
  padding: 8px;
  color: var(--navy);
  font-weight: 800;
  text-decoration: none;
}
.page-heading { max-width: 720px; margin: 4px 0 14px; }
.eyebrow { margin: 0 0 5px; color: var(--mustard); font-size: 13px; font-weight: 900; letter-spacing: .08em; }
h1 { margin: 0; font-size: clamp(30px, 8vw, 44px); line-height: 1.12; letter-spacing: -.025em; }
.lead { margin: 9px 0 0; color: var(--muted); font-size: 16px; line-height: 1.55; }

.truth-boundary {
  display: grid;
  gap: 3px;
  margin: 16px 0;
  padding: 12px 14px;
  background: var(--warning-pale);
  border-left: 5px solid var(--mustard);
  color: #5f480e;
  line-height: 1.5;
}
.truth-boundary strong { color: var(--navy); }

.work-layout { display: grid; gap: 18px; }
.status-column { min-width: 0; }
.package-status {
  padding: 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 5px solid var(--mustard);
}
.package-status[data-tone="safe"] { border-top-color: var(--safe); background: var(--safe-pale); }
.package-status[data-tone="danger"] { border-top-color: var(--danger); background: var(--danger-pale); }
.status-kicker { margin: 0 0 3px; color: var(--muted); font-size: 12px; font-weight: 800; }
.package-status h2 { margin: 0; font-size: 23px; line-height: 1.25; }
.package-status > p:not(.status-kicker) { margin: 7px 0; line-height: 1.45; }
.status-issues { margin: 9px 0 13px; padding-left: 20px; color: #5d4b27; font-size: 14px; line-height: 1.5; }
.status-issues:empty { display: none; }
.save-state { color: var(--muted); font-size: 13px; }
.source-summary { margin: 10px 0 13px; border-top: 1px solid rgba(8, 38, 63, .22); }
.source-summary summary { min-height: 44px; display: flex; align-items: center; font-weight: 900; cursor: pointer; }
.source-status-list { display: grid; gap: 8px; padding-bottom: 10px; }
.source-status-row { min-width: 0; padding: 8px; background: rgba(255, 255, 255, .65); border-left: 4px solid var(--safe); }
.source-status-row[data-status="missing"] { border-left-color: var(--mustard); }
.source-status-row[data-status="expired"] { border-left-color: var(--danger); }
.source-status-row strong, .source-status-row small { display: block; overflow-wrap: anywhere; }
.source-status-row small { margin-top: 3px; color: var(--muted); line-height: 1.4; }

.trip-form { min-width: 0; background: var(--surface); border: 1px solid var(--line); }
.form-section { padding: 20px 16px; border-bottom: 1px solid var(--line); scroll-margin-top: 80px; }
.form-section:last-child { border-bottom: 0; }
.section-heading { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 10px; margin-bottom: 16px; }
.section-index { color: var(--mustard); font-size: 13px; font-weight: 900; letter-spacing: .08em; }
.section-heading h2 { margin: 0; font-size: 23px; line-height: 1.25; }
.section-heading p { margin: 5px 0 0; color: var(--muted); line-height: 1.5; }

.field-grid { display: grid; gap: 14px; }
.field { min-width: 0; display: grid; gap: 6px; }
.field > span, .choice-fieldset legend { font-weight: 800; line-height: 1.4; }
.field b, .choice-fieldset b { margin-left: 4px; color: var(--danger); font-size: 11px; font-weight: 900; }
input, textarea, select {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 10px 11px;
  background: white;
  color: var(--navy);
  border: 1px solid #8e969b;
  border-radius: 2px;
  line-height: 1.4;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid #e7b53f;
  outline-offset: 2px;
}
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border: 2px solid var(--danger); }

.choice-fieldset {
  display: grid;
  gap: 8px;
  margin: 18px 0 14px;
  padding: 13px;
  border: 1px solid var(--line);
}
.choice-fieldset label { min-height: 44px; display: flex; align-items: center; gap: 9px; }
.choice-fieldset input { flex: 0 0 auto; width: 22px; min-height: 22px; }
.sub-panel, .source-block {
  margin: 14px 0;
  padding: 14px;
  background: #f0f3f4;
  border-left: 4px solid var(--navy-soft);
}
.source-block h3 { margin: 0; font-size: 18px; }
.source-block > p { margin: 5px 0 13px; color: var(--muted); line-height: 1.5; }
.file-field { display: grid; gap: 8px; font-weight: 800; }
.gpx-result { margin-top: 10px; color: var(--muted); font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.gpx-result[data-tone="safe"] { color: var(--safe); }
.gpx-result[data-tone="danger"] { color: var(--danger); }

.compact-select { max-width: 520px; }
.point-list { display: grid; gap: 12px; margin-top: 14px; }
.point-editor { padding: 14px; background: #f3f1eb; border-left: 4px solid var(--mustard); }
.point-editor-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.point-editor-header h3 { margin: 0; font-size: 18px; }
.point-editor .field-grid { gap: 11px; }
.point-empty { margin: 12px 0; padding: 12px; color: var(--muted); border: 1px dashed #9fa3a2; }
.fixed-limit { margin: 13px 0 0; color: #665427; font-size: 14px; line-height: 1.5; }

.primary-action, .secondary-action, .danger-action, .import-action {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 2px;
  font-weight: 900;
  cursor: pointer;
}
.primary-action { width: 100%; background: var(--navy); color: white; border: 2px solid var(--navy); }
.secondary-action, .import-action { background: white; color: var(--navy); border: 1px solid var(--navy); }
.danger-action { background: white; color: var(--danger); border: 1px solid var(--danger); }
.remove-point { min-width: 44px; min-height: 44px; padding: 7px; background: transparent; color: var(--danger); border: 0; font-weight: 900; cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }

.backup-tools { margin-top: 15px; border-top: 1px solid var(--line); }
.backup-tools summary { min-height: 48px; display: flex; align-items: center; font-weight: 900; cursor: pointer; }
.backup-tools p { color: var(--muted); line-height: 1.5; }
.secondary-actions { display: grid; gap: 10px; }
.import-action { position: relative; }
.import-action input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.mobile-save-bar {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 12px max(8px, env(safe-area-inset-bottom));
  background: rgba(247, 244, 238, .96);
  border-top: 1px solid var(--line);
}
.desktop-save { display: none; }

dialog { width: min(calc(100% - 28px), 460px); padding: 20px; border: 2px solid var(--navy); color: var(--navy); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { margin-top: 0; }
dialog p { line-height: 1.55; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  width: min(calc(100% - 28px), 440px);
  transform: translateX(-50%);
  padding: 11px 14px;
  background: var(--navy);
  color: white;
  border: 1px solid white;
  line-height: 1.45;
}

@media (min-width: 720px) {
  .page-shell { padding: 24px 24px 60px; }
  .candidate-boundary { justify-content: flex-start; padding-inline: max(24px, calc((100vw - 1080px) / 2)); }
  .field-grid.two-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid.two-column .full { grid-column: 1 / -1; }
  .form-section { padding: 26px 28px; }
  .secondary-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 940px) {
  .work-layout { grid-template-columns: minmax(0, 1fr) 290px; align-items: start; }
  .trip-form { grid-column: 1; grid-row: 1; }
  .status-column { grid-column: 2; grid-row: 1; position: sticky; top: 82px; }
  .desktop-save { display: inline-flex; }
  .mobile-save-bar { display: none; }
  .toast { bottom: 24px; }
}

@media (max-width: 480px) {
  .candidate-boundary { align-items: flex-start; text-align: left; }
  .connection-state { max-width: 118px; }
  .brand-copy small { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .section-heading { grid-template-columns: 28px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
