:root {
  --page: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #eef2f6;
  --text: #172033;
  --text-soft: #5d6878;
  --text-muted: #7a8493;
  --border: #d7dee8;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --accent-strong: #1d4ed8;
  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --shadow: 0 16px 38px rgba(23, 32, 51, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  color-scheme: light;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0;
  background:
    linear-gradient(180deg, #ffffff 0%, var(--page) 42%, #edf1f6 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-shell,
.location-screen,
.finish-screen {
  position: relative;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.location-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.quest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
}

.brand-mark,
.brand-link {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  color: var(--text);
  font-size: 1.08rem;
  font-weight: 800;
}

.header-actions,
.action-row,
.finish-actions,
.admin-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.56fr);
  gap: 20px;
  align-items: stretch;
  margin-bottom: 20px;
}

.hero-copy,
.panel,
.finish-hero {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 330px;
  padding: 40px;
}

.panel {
  padding: 24px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.page-title,
.finish-title {
  margin: 0;
  font-size: 3rem;
  line-height: 1.05;
}

.location-title {
  margin: 0 0 22px;
  font-size: 2.15rem;
  line-height: 1.14;
  text-align: center;
}

.subtitle,
.panel-copy,
.status-text {
  color: var(--text-soft);
  line-height: 1.65;
}

.subtitle {
  max-width: 62ch;
  margin: 18px 0 28px;
  font-size: 1.05rem;
}

.status-panel {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
}

.status-number {
  color: var(--accent-strong);
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
}

.status-label {
  margin-top: 8px;
  color: var(--text-soft);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  transition:
    transform 200ms ease,
    border-color 200ms ease,
    background 200ms ease,
    box-shadow 200ms ease;
}

.button:hover,
.button:focus-visible {
  border-color: var(--accent);
  background: #f8fbff;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.12);
  outline: none;
  transform: translateY(-1px);
}

.button.primary {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.button.primary:hover,
.button.primary:focus-visible {
  background: var(--accent-strong);
}

.button.danger {
  border-color: #fecaca;
  color: var(--danger);
  background: #fff7f7;
}

.button.wide {
  width: 100%;
}

.button[hidden] {
  display: none;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 18px;
}

.section-heading h2,
.panel-title {
  margin: 0;
  font-size: 1.28rem;
}

.location-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.location-tile {
  min-height: 148px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition:
    transform 200ms ease,
    border-color 200ms ease,
    box-shadow 200ms ease,
    background 200ms ease;
}

.location-tile:hover,
.location-tile:focus-visible {
  border-color: var(--accent);
  background: #fbfdff;
  box-shadow: var(--shadow);
  outline: none;
  transform: translateY(-2px);
}

.tile-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 20px;
}

.tile-name {
  margin: 0;
  font-weight: 800;
}

.tile-meta {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.visit-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 800;
}

.location-tile.is-visited .visit-badge {
  border-color: #bbf7d0;
  color: var(--success);
  background: var(--success-soft);
}

.progress-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(23, 32, 51, 0.06);
}

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

.progress-dot {
  width: 12px;
  height: 12px;
  border: 1px solid #b7c1cf;
  border-radius: 50%;
  background: #ffffff;
  transition:
    transform 200ms ease,
    background 200ms ease,
    border-color 200ms ease;
}

.progress-dot.is-visited {
  border-color: var(--accent);
  background: var(--accent);
}

.progress-dot.is-current {
  border-color: var(--text);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
  transform: scale(1.18);
}

.location-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px 0 72px;
}

.flashcard-scene {
  width: min(340px, 88vw);
  height: 220px;
  perspective: 1100px;
  animation: card-enter 400ms ease both;
}

.flashcard {
  position: relative;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: var(--radius);
  transform-style: preserve-3d;
  transition: transform 600ms cubic-bezier(0.22, 0.9, 0.22, 1);
}

.flashcard.is-flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flashcard:hover .card-face,
.flashcard:focus-visible .card-face {
  border-color: var(--accent);
}

.flashcard:focus-visible {
  outline: none;
}

.card-back {
  border-color: #bfdbfe;
  background: #eff6ff;
  transform: rotateY(180deg);
}

.card-kicker {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.card-back .card-kicker {
  color: var(--success);
}

.card-text {
  margin: 0;
  color: var(--text);
  font-size: 1.34rem;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.continue-button {
  margin-top: 24px;
  animation: fade-up 260ms ease both;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 32, 51, 0.48);
  animation: fade-in 200ms ease both;
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  width: min(560px, 100%);
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.modal-panel h2 {
  margin: 0;
  font-size: 1.85rem;
}

.riddle-text {
  margin: 22px 0;
  color: var(--text);
  font-size: 1.22rem;
  font-weight: 700;
  line-height: 1.6;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.55fr);
  gap: 18px;
  align-items: start;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 18px;
}

.tab {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  background: var(--surface);
}

.tab.is-active,
.tab:hover,
.tab:focus-visible {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
  outline: none;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--text-soft);
  font-weight: 700;
}

.input,
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: #ffffff;
  transition:
    border-color 200ms ease,
    box-shadow 200ms ease;
}

.input {
  min-height: 48px;
  padding: 0 14px;
}

.textarea {
  min-height: 104px;
  resize: vertical;
  padding: 12px 14px;
  line-height: 1.45;
}

.input:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
  outline: none;
}

.save-status {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--success);
}

.preview-stack {
  display: grid;
  gap: 18px;
}

.preview-card {
  width: 100%;
  min-height: 220px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.preview-card h3 {
  margin: 0 0 18px;
  font-size: 1.3rem;
}

.preview-card p {
  margin: 0 0 16px;
  color: var(--text-soft);
  line-height: 1.55;
}

.preview-card strong {
  color: var(--text);
}

.route-list {
  display: grid;
  gap: 12px;
  padding: 0;
  margin: 18px 0 0;
  list-style: none;
}

.route-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.route-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: #ffffff;
  background: var(--accent);
}

.route-name {
  display: block;
  font-weight: 800;
}

.route-time {
  display: block;
  margin-top: 3px;
  color: var(--text-soft);
  font-size: 0.92rem;
}

.finish-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
}

.finish-hero {
  min-height: 330px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px;
}

@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (max-width: 860px) {
  .hero,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .hero-copy {
    min-height: auto;
  }
}

@media (max-width: 680px) {
  .app-shell,
  .location-screen,
  .finish-screen {
    width: min(100% - 24px, 1120px);
    padding-top: 18px;
  }

  .quest-header {
    align-items: stretch;
    flex-direction: column;
    margin-bottom: 24px;
  }

  .header-actions,
  .action-row,
  .finish-actions,
  .admin-actions {
    width: 100%;
  }

  .button,
  .action-row .button,
  .finish-actions .button,
  .admin-actions .button {
    flex: 1 1 auto;
  }

  .hero-copy,
  .finish-hero,
  .panel {
    padding: 20px;
  }

  .page-title,
  .finish-title {
    font-size: 2.25rem;
  }

  .location-title {
    font-size: 1.85rem;
  }

  .progress-pill {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 380px) {
  .card-text {
    font-size: 1.16rem;
  }

  .progress-pill {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
