:root {
  color-scheme: light;
  --ink: #17231d;
  --muted: #66736c;
  --line: #d8ded9;
  --surface: #ffffff;
  --canvas: #f3f6f3;
  --green: #176b52;
  --green-soft: #e6f1ec;
  --red: #b84a38;
  --red-soft: #f7ebe7;
  --gold: #9a6b1f;
  --shadow: 0 8px 24px rgba(23, 35, 29, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(23, 107, 82, 0.28);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 10px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand img {
  border-radius: 8px;
}

.brand span {
  display: grid;
  gap: 1px;
}

.brand strong {
  font-size: 17px;
}

.brand small {
  color: var(--muted);
  font-size: 11px;
}

.screen {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 34px 24px 64px;
}

.connect-screen {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(340px, 440px);
  gap: 64px;
  align-items: center;
  min-height: calc(100vh - 64px);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 14px;
  font-size: 36px;
  line-height: 1.2;
}

h2 {
  font-size: 21px;
}

.connect-command {
  max-width: 440px;
  margin-bottom: 30px;
  color: #3f4d45;
  font-size: 18px;
  line-height: 1.7;
}

.steps {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
}

.steps li {
  display: flex;
  align-items: center;
  gap: 12px;
}

.steps span {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  flex: 0 0 26px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--green);
  background: var(--surface);
  font-size: 12px;
  font-weight: 700;
}

.pairing-tool {
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.qr-frame {
  position: relative;
  width: min(100%, 320px);
  aspect-ratio: 1;
  margin: 0 auto 20px;
  padding: 10px;
  border: 1px solid var(--line);
  background: #fff;
}

.qr-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.qr-loading {
  position: absolute;
  inset: 10px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #fff;
  text-align: center;
}

.pairing-meta {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.pairing-meta > div {
  display: grid;
  gap: 4px;
}

.meta-label {
  color: var(--muted);
  font-size: 12px;
}

.pairing-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 24px;
}

.countdown-wrap {
  text-align: right;
}

.pairing-status {
  min-height: 24px;
  margin: 16px 0;
  color: var(--green);
  text-align: center;
  font-weight: 650;
}

.primary-button,
.quiet-button,
.icon-button {
  min-height: 42px;
  border-radius: 6px;
}

.primary-button {
  width: 100%;
  border: 1px solid var(--green);
  color: #fff;
  background: var(--green);
  font-weight: 700;
}

.primary-button:hover {
  background: #115b45;
}

.quiet-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 0 26px;
  border-bottom: 1px solid var(--line);
}

.section-heading h1 {
  margin: 0;
}

.section-summary {
  max-width: 360px;
  margin: 0;
  color: var(--muted);
  text-align: right;
}

.journey-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  padding-top: 24px;
}

.journey-card {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  min-height: 150px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  background: var(--surface);
  text-align: left;
}

.journey-card:hover {
  border-color: #a9b9b0;
  box-shadow: var(--shadow);
}

.journey-cover {
  width: 100%;
  height: 100%;
  min-height: 150px;
  object-fit: cover;
  background: var(--green-soft);
}

.journey-cover-placeholder {
  display: grid;
  min-height: 150px;
  place-items: center;
  color: var(--green);
  background: var(--green-soft);
  font-size: 14px;
  font-weight: 700;
}

.journey-card-body {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
  padding: 18px;
}

.journey-title {
  display: block;
  margin: 0 0 7px;
  font-size: 21px;
  font-weight: 700;
}

.journey-date,
.journey-stats {
  display: block;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.status-badge {
  align-self: flex-start;
  padding: 3px 7px;
  border-radius: 4px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 12px;
  font-weight: 700;
}

.status-badge.finished {
  color: var(--red);
  background: var(--red-soft);
}

.empty-state {
  grid-column: 1 / -1;
  padding: 64px 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

.trip-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  color: var(--muted);
  font-size: 14px;
}

.icon-button {
  width: 42px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  font-size: 22px;
}

.trip-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}

.trip-header h1 {
  margin-bottom: 8px;
}

.trip-meta {
  margin: 0;
  color: var(--muted);
}

.route-progress {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
  max-width: 420px;
}

.route-chip {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
}

.route-chip.unlocked {
  border-color: #9bc7b6;
  color: var(--green);
  background: var(--green-soft);
}

.memory-timeline {
  display: grid;
  gap: 22px;
  padding-top: 28px;
}

.memory-entry {
  display: grid;
  grid-template-columns: minmax(260px, 42%) minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.memory-entry figure {
  margin: 0;
  min-height: 280px;
  background: var(--green-soft);
}

.memory-entry img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 280px;
  object-fit: cover;
}

.memory-copy {
  padding: 26px;
}

.memory-index {
  margin-bottom: 8px;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
}

.memory-sentence {
  margin: 16px 0;
  color: #324039;
  font-size: 17px;
  line-height: 1.7;
}

.fact-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 16px 0 0;
  border-top: 1px solid var(--line);
  list-style: none;
  color: var(--muted);
  font-size: 14px;
}

.pending-entry {
  padding: 22px 24px;
  border-left: 3px solid var(--gold);
  color: var(--muted);
  background: #fffdf7;
}

.pending-entry strong {
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 13px 16px;
  border: 1px solid #e0b6ab;
  border-radius: 6px;
  color: #7c2e23;
  background: #fff5f2;
  box-shadow: var(--shadow);
}

[hidden] {
  display: none !important;
}

@media (max-width: 780px) {
  .topbar {
    min-height: 58px;
  }

  .brand small {
    display: none;
  }

  .screen {
    padding: 24px 16px 48px;
  }

  .connect-screen {
    grid-template-columns: 1fr;
    gap: 28px;
    align-content: start;
    min-height: auto;
  }

  h1 {
    font-size: 30px;
  }

  .connect-command {
    margin-bottom: 20px;
    font-size: 16px;
  }

  .steps {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    font-size: 12px;
  }

  .steps li {
    align-items: flex-start;
    flex-direction: column;
  }

  .pairing-tool {
    padding: 18px;
  }

  .section-heading,
  .trip-header {
    align-items: flex-start;
    flex-direction: column;
    display: flex;
  }

  .section-summary {
    text-align: left;
  }

  .journey-list {
    grid-template-columns: 1fr;
  }

  .journey-card {
    grid-template-columns: 112px minmax(0, 1fr);
  }

  .route-progress {
    justify-content: flex-start;
  }

  .memory-entry {
    grid-template-columns: 1fr;
  }

  .memory-entry figure,
  .memory-entry img {
    min-height: 220px;
    max-height: 340px;
  }

  .memory-copy {
    padding: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
