:root {
  --green-900: #0f4c3a;
  --green-700: #17694e;
  --green-600: #1c7a5b;
  --green-100: #e6f2ec;
  --gold-500: #c9982f;
  --gold-400: #dcb45a;
  --ink-900: #16211d;
  --ink-600: #4d5b55;
  --ink-300: #9fada6;
  --paper: #fbfaf6;
  --card: #ffffff;
  --line: #e3e0d4;
  --danger: #b3432c;
  --radius-lg: 20px;
  --radius-md: 14px;
  --shadow: 0 10px 30px rgba(15, 76, 58, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink-900);
  overflow: hidden;
}

.screen { display: none; height: 100vh; height: 100dvh; }
.screen.active { display: block; }

/* ---------------------------------- Welcome ---------------------------------- */
#screen-welcome.active { display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; }
.welcome-wrap {
  width: 100%;
  max-width: 460px;
  padding: 28px 20px 60px;
}
.welcome-header { text-align: center; margin-bottom: 22px; }
.brand-mark {
  width: 64px; height: 64px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--green-700), var(--green-900));
  color: var(--gold-400);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.welcome-header h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.01em; color: var(--green-900); }
.tagline { margin: 0; color: var(--ink-600); font-size: 15px; line-height: 1.4; }

.form-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  position: relative;
}
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--green-900); margin-bottom: 6px; }
.ac-wrap { position: relative; }
.ac-wrap input {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper);
  color: var(--ink-900);
  outline: none;
  transition: border-color .15s;
}
.ac-wrap input:focus { border-color: var(--green-600); background: #fff; }

.ac-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0; right: 0;
  max-height: 280px;
  overflow-y: auto;
  margin: 0; padding: 6px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}
.ac-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14.5px;
}
.ac-item:hover, .ac-item:active { background: var(--green-100); }
.ac-icon { font-size: 16px; }
.ac-code { font-weight: 700; color: var(--green-700); margin-right: 4px; }
.ac-empty { padding: 10px; color: var(--ink-300); font-size: 14px; }

.swap-btn {
  display: block;
  margin: -6px auto 8px;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--green-700);
  font-size: 15px;
  cursor: pointer;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  font-size: 15.5px;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-md);
  background: var(--green-700);
  color: #fff;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.primary-btn:disabled { opacity: .45; cursor: not-allowed; }
.primary-btn:not(:disabled):active { background: var(--green-900); }

.ghost-btn {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  border: 1.5px solid var(--green-600);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--green-700);
  cursor: pointer;
}
.ghost-btn.small { width: auto; margin-top: 0; padding: 8px 12px; font-size: 13px; }

.hint { text-align: center; font-size: 12.5px; color: var(--ink-300); margin-top: 16px; }

/* ---------------------------------- Route screen ---------------------------------- */
#screen-route.active { display: block; position: relative; }
.map-container { position: absolute; inset: 0; background: var(--paper); touch-action: none; }
.campus-svg { width: 100%; height: 100%; display: block; }

.zone-rect { fill: var(--green-100); stroke: var(--line); stroke-width: 1.4; }
.zone-label { font-size: 13px; font-weight: 800; fill: var(--green-600); opacity: .55; }
.path-line { stroke: #cfd6ce; stroke-width: 1.6; }
.poi { fill: #b9c3bc; }
.poi-gate { fill: var(--gold-500); }
.poi-landmark { fill: #7c8f88; }
.poi-parking { fill: #d8ddd6; }

.route-shadow { fill: none; stroke: #ffffff; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.route-line { fill: none; stroke: var(--gold-500); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.route-arrow { fill: var(--green-900); }
.marker-dot { fill: var(--green-700); stroke: #fff; stroke-width: 2; }
.marker-dot-inner { fill: #fff; }
.marker-pin { fill: var(--danger); stroke: #fff; stroke-width: 1.5; }
.marker-pin-dot { fill: #fff; }

.map-controls {
  position: absolute;
  right: 14px;
  top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
}
.map-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 18px;
  color: var(--green-900);
  cursor: pointer;
}

.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 52vh;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 30px rgba(0,0,0,.14);
  padding: 10px 18px 18px;
  overflow-y: auto;
  z-index: 4;
}
.sheet-handle { width: 40px; height: 4px; background: var(--line); border-radius: 4px; margin: 0 auto 12px; }
.sheet-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.sheet-top h2 { margin: 0; font-size: 19px; color: var(--green-900); }
.route-subtitle { margin: 2px 0 0; font-size: 13px; color: var(--ink-600); }
.route-summary {
  margin: 10px 0 4px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--gold-500);
  background: #fbf3e1;
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
}

.steps-list { list-style: none; margin: 12px 0 0; padding: 0; }
.step {
  display: flex; gap: 12px;
  padding: 11px 4px;
  border-top: 1px solid var(--line);
  cursor: pointer;
  font-size: 14.5px;
  line-height: 1.4;
}
.step:first-child { border-top: none; }
.step-num {
  flex: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--green-100);
  color: var(--green-700);
  font-size: 12px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.step-final .step-num { background: var(--danger); color: #fff; }
.step-text { padding-top: 2px; }

.offline-badge {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  background: var(--ink-900);
  color: #fff;
  font-size: 12.5px;
  text-align: center;
  padding: 8px 10px;
}

@media (min-width: 720px) {
  .sheet { left: 20px; right: auto; bottom: 20px; width: 380px; max-height: calc(100vh - 40px); border-radius: 20px; }
}
