:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --ink: #241f1a;
  --ink-muted: #6b6255;
  --border: #e6e0d4;
  --accent: #c65a2e;
  --accent-ink: #ffffff;
  --slate: #3d4a52;
  --danger: #b3382c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(36, 31, 26, 0.06), 0 8px 24px rgba(36, 31, 26, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191512;
    --surface: #221d19;
    --ink: #f2ece2;
    --ink-muted: #a89c8a;
    --border: #382f28;
    --accent: #e07c4c;
    --accent-ink: #1a1310;
    --slate: #8fa3ad;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px;
}

/* --- Top bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  position: relative;
  flex-shrink: 0;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--accent-ink);
}

/* --- Hero / empty landing --- */
.hero {
  padding: 64px 20px;
  text-align: center;
}

.hero h1 {
  font-size: 1.6rem;
  margin: 0 0 8px;
}

.hero p {
  color: var(--ink-muted);
  margin: 0;
}

/* --- Route detail --- */
.route-photo-wrap {
  padding: 0 20px 40px;
}

.route-photo {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  background: var(--border);
  display: block;
}

.route-header {
  padding: 20px 20px 0;
}

.route-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.route-title-row h1 {
  font-size: 1.5rem;
  margin: 0;
  letter-spacing: -0.01em;
}

.route-meta {
  color: var(--ink-muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

.route-stars {
  color: var(--accent);
  font-size: 1rem;
  margin-top: 6px;
  letter-spacing: 2px;
}

.grade-badge {
  flex-shrink: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 1.05rem;
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
  margin: 24px 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.stat-card .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

.stat-card .value {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 2px;
}

.route-description {
  padding: 0 20px 40px;
  white-space: pre-line;
}

.route-description h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

/* --- Forms --- */
.form-page {
  padding: 32px 20px 60px;
}

.form-page h1 {
  font-size: 1.4rem;
  margin-bottom: 24px;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="file"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-field input { width: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.error-banner {
  background: rgba(179, 56, 44, 0.1);
  color: var(--danger);
  border: 1px solid rgba(179, 56, 44, 0.3);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 18px;
  font-size: 0.9rem;
}

/* --- Login --- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card h1 {
  font-size: 1.2rem;
  margin: 0 0 20px;
  text-align: center;
}

/* --- Admin dashboard --- */
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.route-list {
  padding: 0 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.route-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.route-row .thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--border);
  flex-shrink: 0;
}

.route-row .info {
  flex: 1;
  min-width: 0;
}

.route-row .info .name {
  font-weight: 600;
}

.route-row .info .sub {
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.route-row .info .deployed-link {
  font-size: 0.8rem;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-row .info .deployed-link a {
  color: var(--accent);
  text-decoration: none;
}

.route-row .info .deployed-link a:hover {
  text-decoration: underline;
}

.route-row .actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.status-badges {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.badge-status {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 999px;
}

.badge-status.is-on {
  background: var(--accent);
  color: var(--accent-ink);
}

.badge-status.is-off {
  background: var(--border);
  color: var(--ink-muted);
}

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--ink-muted);
}

.qr-preview {
  padding: 20px;
  text-align: center;
}

.qr-preview img {
  width: 220px;
  height: 220px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
}

@media (max-width: 480px) {
  .field-row { grid-template-columns: 1fr; }
}
