:root {
  --pku-red: #8c0012;
  --pku-red-hover: #70000e;
  --pku-red-soft: rgba(140, 0, 18, 0.1);
  --green: #15803d;
  --green-soft: rgba(21, 128, 61, 0.12);
  --amber: #b45309;
  --amber-soft: rgba(180, 83, 9, 0.14);
  --bg: #f4f4f6;
  --card-bg: #ffffff;
  --surface-2: #efeff3;
  --text: #16161a;
  --text-muted: #686873;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 10px 30px rgba(15, 15, 25, 0.07);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.dark {
  --pku-red: #cf293d;
  --pku-red-hover: #e03a4e;
  --pku-red-soft: rgba(207, 41, 61, 0.18);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.18);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.2);
  --bg: #0f1014;
  --card-bg: #1a1c23;
  --surface-2: #252833;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --border: rgba(255, 255, 255, 0.09);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 11px;
  height: 28px;
  border-radius: 6px;
  background: var(--pku-red);
  display: inline-block;
}

.topbar-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.topbar-subtitle {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Auth & PIN Views */
.view-panel {
  padding: 12px 16px 32px;
  flex: 1;
}

.auth-card {
  background: var(--card-bg);
  border-radius: 22px;
  padding: 22px 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.auth-header {
  text-align: center;
  margin-bottom: 18px;
}

.auth-logo {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--pku-red);
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.auth-header h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.auth-header p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-muted);
}

.seg-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 12px;
  margin-bottom: 16px;
}

.seg-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 9px;
  cursor: pointer;
}

.seg-tab.active {
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
}

.field-hint {
  margin: 5px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.text-input {
  width: 100%;
  padding: 11px 13px;
  font-size: 15px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

.text-input:focus {
  border-color: var(--pku-red);
}

.textarea-input {
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.verify-box {
  padding: 12px;
  border-radius: 14px;
  background: var(--pku-red-soft);
  border: 1px solid rgba(140, 0, 18, 0.2);
}

.inline-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.captcha-img {
  height: 42px;
  min-width: 100px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: #fff;
}

.checks-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 2px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.check-row input {
  accent-color: var(--pku-red);
  width: 16px;
  height: 16px;
}

/* Buttons */
.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn {
  border: none;
  border-radius: 13px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

.primary-btn:active,
.secondary-btn:active,
.danger-btn:active,
.ghost-btn:active {
  transform: scale(0.985);
}

.primary-btn:disabled,
.secondary-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.primary-btn {
  background: var(--pku-red);
  color: #ffffff;
  width: 100%;
}

.secondary-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.danger-btn {
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
}

.ghost-btn {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: 13.5px;
  padding: 11px 14px;
}

.nowrap {
  white-space: nowrap;
}

.flex-1 {
  flex: 1;
}

.mt-sm {
  margin-top: 12px;
}

.divider-line {
  display: flex;
  align-items: center;
  margin: 16px 0 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.divider-line::before,
.divider-line::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider-line span {
  padding: 0 10px;
}

.alert {
  padding: 10px 12px;
  border-radius: 11px;
  font-size: 13px;
  line-height: 1.45;
}

.alert-error {
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
}

.alert-info {
  background: var(--green-soft);
  color: var(--green);
}

/* Main Workspace & Tabs */
.view-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(74px + var(--safe-bottom));
}

.tab-panel {
  padding: 4px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Direction & Slot Chips */
.dir-bar {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.dir-bar::-webkit-scrollbar {
  display: none;
}

.dir-chip {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
}

.dir-chip.active {
  background: var(--pku-red);
  color: #fff;
  border-color: var(--pku-red);
}

.slot-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.slot-strip::-webkit-scrollbar {
  display: none;
}

.slot-pill {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 12px;
  padding: 7px 11px;
  min-width: 82px;
  text-align: left;
  cursor: pointer;
  flex-shrink: 0;
}

.slot-pill.active {
  border-color: var(--pku-red);
  background: var(--pku-red-soft);
}

.slot-pill-time {
  font-size: 15px;
  font-weight: 700;
}

.slot-pill-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Hero Ride Card (Marchkov Style) */
.ride-card {
  background: var(--card-bg);
  border-radius: 24px;
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ride-card.is-reserved {
  border-color: rgba(21, 128, 61, 0.35);
}

.ride-card-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  font-size: 13px;
  font-weight: 700;
  background: var(--pku-red-soft);
  color: var(--pku-red);
}

.ride-card.is-reserved .ride-card-banner {
  background: var(--green-soft);
  color: var(--green);
}

.ride-card.is-temp .ride-card-banner {
  background: var(--amber-soft);
  color: var(--amber);
}

.ride-card-body {
  padding: 18px 18px 20px;
  text-align: center;
}

.ride-route-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
  margin: 0 0 4px;
}

.via200-tag {
  display: inline-block;
  margin-top: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--amber-soft);
  color: var(--amber);
}

.ride-big-time {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -1px;
  margin: 6px 0 4px;
  font-variant-numeric: tabular-nums;
}

.ride-meta-line {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* High-brightness pure white QR box even in dark mode */
.qr-stage {
  width: 244px;
  height: 244px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background: #ffffff;
  padding: 14px;
  border: 2px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}

.qr-stage svg {
  width: 100%;
  height: 100%;
  display: block;
}

.qr-tap-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.qr-placeholder {
  width: 220px;
  height: 180px;
  margin: 0 auto 16px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1.5px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  gap: 6px;
}

.qr-placeholder-status {
  font-size: 22px;
  font-weight: 800;
  color: var(--pku-red);
}

.qr-placeholder-sub {
  font-size: 12.5px;
  color: var(--text-muted);
}

.ride-actions-row {
  display: flex;
  gap: 10px;
}

.skeleton-card,
.empty-card {
  background: var(--card-bg);
  border-radius: 22px;
  border: 1px solid var(--border);
  padding: 42px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Upcoming Box */
.upcoming-box {
  background: var(--card-bg);
  border-radius: 18px;
  padding: 14px;
  border: 1px solid var(--border);
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.section-title-row h3 {
  margin: 0;
  font-size: 14.5px;
}

.muted-sm {
  font-size: 12px;
  color: var(--text-muted);
}

.upcoming-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  gap: 10px;
}

.upcoming-item-title {
  font-size: 14px;
  font-weight: 700;
}

.upcoming-item-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Schedule Tab */
.date-strip {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
}

.date-strip::-webkit-scrollbar {
  display: none;
}

.date-btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 13px;
  padding: 8px 12px;
  min-width: 66px;
  text-align: center;
  cursor: pointer;
  flex-shrink: 0;
}

.date-btn.active {
  background: var(--pku-red);
  color: #fff;
  border-color: var(--pku-red);
}

.date-btn-top {
  font-size: 12px;
  font-weight: 600;
}

.date-btn-num {
  font-size: 14px;
  font-weight: 800;
  margin-top: 2px;
}

.schedule-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.schedule-row {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 13px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.schedule-row.is-booked {
  border-color: rgba(21, 128, 61, 0.4);
  background: var(--green-soft);
}

.sched-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.sched-time {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 56px;
}

.sched-info {
  min-width: 0;
}

.sched-route {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.sched-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.mini-btn {
  border: none;
  border-radius: 10px;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.mini-btn-book {
  background: var(--pku-red);
  color: #fff;
}

.mini-btn-qr {
  background: var(--green);
  color: #fff;
}

.mini-btn-temp {
  background: var(--amber-soft);
  color: var(--amber);
}

.mini-btn-disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.pill-amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.pill-green {
  background: var(--green-soft);
  color: var(--green);
}

/* Settings */
.settings-card {
  background: var(--card-bg);
  border-radius: 18px;
  padding: 16px;
  border: 1px solid var(--border);
}

.settings-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.kv-row:last-of-type {
  border-bottom: none;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.toggle-row:last-of-type {
  border-bottom: none;
}

.toggle-title {
  font-size: 14px;
  font-weight: 600;
}

.toggle-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.4;
}

.ios-switch {
  width: 44px;
  height: 24px;
  accent-color: var(--pku-red);
  flex-shrink: 0;
}

.guide-steps {
  margin: 0;
  padding-left: 18px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-muted);
}

.guide-steps strong {
  color: var(--text);
}

/* Bottom Tabbar */
.bottom-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  max-width: 480px;
  margin: 0 auto;
  padding: 6px 8px calc(6px + var(--safe-bottom));
}

.tabbar-item {
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
}

.tabbar-item.active {
  color: var(--pku-red);
}

/* Fullscreen QR Modal (Official PKU Sign-in Style & Bright Pure Mode) */
.qr-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #f5f5f5;
  color: #111111;
  display: flex;
  flex-direction: column;
  padding-top: calc(18px + var(--safe-top));
  padding-bottom: calc(18px + var(--safe-bottom));
}

.qr-modal-inner {
  max-width: 460px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.pku-official-title {
  color: #8c0000;
  font-size: 15px;
  font-weight: 700;
  margin: 6px 0 10px;
}

.pku-official-divider {
  width: 100%;
  height: 1px;
  background: #8c0000;
  margin-bottom: 18px;
}

.pku-official-route {
  font-size: 16px;
  font-weight: 600;
  color: #111;
  text-align: center;
  margin: 0 0 6px;
}

.pku-official-time {
  font-size: 15.5px;
  color: #222;
  margin: 0 0 22px;
  text-align: center;
}

.qr-fullscreen-box {
  width: min(76vw, 290px);
  height: min(76vw, 290px);
  background: #ffffff;
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.08);
}

.qr-fullscreen-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.pku-official-close {
  margin-top: 26px;
  background: #8c0000;
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 9px 34px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 120;
  background: rgba(22, 22, 26, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  max-width: 88vw;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
