:root {
  color-scheme: dark;
  --bg: #050607;
  --surface: #111315;
  --surface-2: #181b1e;
  --line: rgba(255, 255, 255, 0.11);
  --muted: #92989f;
  --text: #f4f5f6;
  --accent: #f2c35d;
  --active-quality: #6ea8ff;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% -10%, rgba(255, 255, 255, 0.08), transparent 34rem),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 18px calc(36px + var(--safe-bottom));
}

.topbar, .section-heading-row, .dialog-heading, .profile-strip, .control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar { margin-bottom: 16px; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 1.6rem; letter-spacing: -0.04em; }
h2 { margin-bottom: 0; font-size: 1.25rem; letter-spacing: -0.025em; }
h3 { margin: 18px 0 10px; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

.eyebrow {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.icon-button, .small-button, .secondary-button, .primary-button {
  border: 0;
  cursor: pointer;
  color: var(--text);
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 1.35rem;
}

.profile-strip {
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(17, 19, 21, 0.76);
  backdrop-filter: blur(16px);
}

.profile-strip span { display: block; color: var(--muted); font-size: 0.78rem; }
.profile-strip strong { display: block; margin-top: 2px; font-size: 0.98rem; }

.privacy-chip {
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(46, 229, 141, 0.1);
  color: #7ceab3;
  font-size: 0.67rem;
  font-weight: 700;
}

.compass-section {
  padding-top: 4px;
  text-align: center;
}

.compass-wrap {
  position: relative;
  width: min(88vw, 390px);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 50%;
  background: #0b0d0f;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.14),
    0 24px 70px rgba(0, 0, 0, 0.58),
    inset 0 0 60px rgba(255, 255, 255, 0.025);
  overflow: hidden;
}

.compass-wrap::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.09);
  pointer-events: none;
}

.top-bearing {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 2px;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 0;
  border-bottom: 15px solid var(--accent);
  filter: drop-shadow(0 0 8px rgba(242, 195, 93, 0.55));
}

.compass-dial {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transform: rotate(var(--dial-rotation, 0deg));
  transition: transform 110ms linear;
  will-change: transform;
}

.sector-wheel {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  opacity: 0.52;
  filter: saturate(0.92);
  -webkit-mask: radial-gradient(circle, transparent 0 44%, #000 45% 100%);
  mask: radial-gradient(circle, transparent 0 44%, #000 45% 100%);
}

.tick-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.cardinal-labels {
  position: absolute;
  inset: 0;
}

.cardinal-label {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42px;
  margin-left: -21px;
  margin-top: -12px;
  font-size: 0.78rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.82);
  text-align: center;
  transform-origin: 50% 12px;
}

.cardinal-label.north { color: #ff6575; }

.center-readout {
  position: absolute;
  z-index: 4;
  inset: 25%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(20, 23, 26, 0.96), rgba(8, 10, 11, 0.98));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.09), 0 8px 38px rgba(0, 0, 0, 0.42);
  padding: 18px;
}

.heading-value {
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.35rem, 11vw, 3.45rem);
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.07em;
}

.active-direction { margin-top: 8px; font-size: 1rem; font-weight: 750; }
.active-quality { margin-top: 5px; color: var(--active-quality); font-size: 0.75rem; font-weight: 650; line-height: 1.25; }

.sensor-status {
  min-height: 39px;
  margin: 16px 6px 10px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.control-row { justify-content: center; }

.primary-button, .secondary-button, .small-button {
  min-height: 44px;
  border-radius: 13px;
  padding: 0 16px;
  font-weight: 720;
}

.primary-button {
  background: var(--text);
  color: #08090a;
}

.secondary-button, .small-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.secondary-button[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--active-quality) 70%, white 10%);
  background: color-mix(in srgb, var(--active-quality) 18%, var(--surface-2));
}

.small-button { min-height: 36px; border-radius: 11px; padding: 0 12px; font-size: 0.78rem; }
.full-width { width: 100%; }

.demo-controls {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
}

.demo-controls label { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.76rem; }
.demo-controls input { width: 100%; margin-top: 12px; accent-color: var(--active-quality); }

.target-card, .guidance-card, .direction-overview {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(17, 19, 21, 0.84);
}

.target-content { margin-top: 15px; font-size: 0.88rem; line-height: 1.55; }
.target-content.muted { color: var(--muted); }

.target-route {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  margin: 14px 0 10px;
}

.target-direction {
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.target-direction span { display: block; color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; }
.target-direction strong { display: block; margin-top: 4px; }
.target-arrow { color: var(--muted); }
.target-turn { color: var(--active-quality); font-weight: 750; }
.target-note { margin-bottom: 0; color: var(--muted); }

.guidance-card {
  position: relative;
  overflow: hidden;
}
.guidance-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--active-quality);
}

.guidance-heading { display: flex; align-items: center; gap: 12px; }
.quality-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--active-quality); box-shadow: 0 0 20px var(--active-quality); }
.hanzi { margin-bottom: 2px; color: var(--active-quality); font-size: 0.9rem; font-weight: 800; }
.traditional-copy, .practical-copy, .caution-copy { line-height: 1.6; }
.traditional-copy { margin-top: 18px; color: #d6d9dc; }
.practical-copy { color: var(--text); font-weight: 620; }
.caution-copy { margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.8rem; }

.chip-list { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 7px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--active-quality) 12%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--active-quality) 30%, transparent);
  font-size: 0.72rem;
}

.direction-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 15px;
}

.direction-tile {
  position: relative;
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  overflow: hidden;
}
.direction-tile::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 3px;
  background: var(--tile-color);
}
.direction-tile.active { outline: 1px solid var(--tile-color); }
.direction-tile .tile-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.direction-tile strong { font-size: 0.9rem; }
.direction-tile .tile-dir { color: var(--muted); font-size: 0.72rem; }
.direction-tile .tile-quality { margin-top: 8px; color: var(--tile-color); font-size: 0.75rem; font-weight: 760; }

.sheet-dialog {
  width: min(100% - 22px, 500px);
  max-height: min(88vh, 780px);
  margin: auto auto max(8px, var(--safe-bottom));
  padding: 0;
  border: 0;
  border-radius: 24px 24px 18px 18px;
  background: transparent;
  color: var(--text);
}
.sheet-dialog::backdrop { background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(8px); }

.dialog-card {
  max-height: min(88vh, 780px);
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: inherit;
  background: #101214;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}

.dialog-close { font-size: 1.45rem; flex: 0 0 auto; }
.field { display: block; margin-top: 18px; }
.field > span, .field legend { display: block; margin-bottom: 8px; color: #d7dadd; font-size: 0.8rem; font-weight: 700; }
.field small { color: var(--muted); font-weight: 500; }
.field input[type="text"], .field input[type="date"], .field input[type="number"], .field select {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
  background: var(--surface-2);
  color: var(--text);
}
.field input:focus, .field select:focus { border-color: rgba(110, 168, 255, 0.8); box-shadow: 0 0 0 3px rgba(110, 168, 255, 0.12); }

.radio-field { padding: 0; border: 0; }
.radio-field label { display: flex; align-items: center; gap: 9px; min-height: 42px; }
.radio-field input { accent-color: #6ea8ff; }
.field-help, .privacy-note { margin: 6px 0 0; color: var(--muted); font-size: 0.72rem; line-height: 1.5; }

.advanced-settings { margin: 18px 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,0.02); }
.advanced-settings summary { cursor: pointer; color: #d7dadd; font-size: 0.8rem; font-weight: 700; }
.compact-field { margin-top: 14px; }
.notice { margin: 14px 0; padding: 11px 12px; border-radius: 12px; background: rgba(242, 195, 93, 0.1); color: #f3d896; font-size: 0.76rem; line-height: 1.5; }
.form-error { min-height: 22px; margin: 8px 0; color: #ff8b97; font-size: 0.78rem; }
.privacy-note { text-align: center; }

.sticky-heading { position: sticky; top: -20px; z-index: 2; padding: 20px 0 12px; background: #101214; }
.activity-group + .activity-group { margin-top: 22px; }
.activity-group h3 { margin-top: 0; }
.activity-option {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.activity-option + .activity-option { margin-top: 8px; }
.activity-option strong { display: block; font-size: 0.88rem; }
.activity-option span { display: block; margin-top: 5px; color: var(--muted); font-size: 0.72rem; line-height: 1.4; }
.activity-option.selected { border-color: var(--active-quality); }

.about-card p { color: #d3d6d9; line-height: 1.6; }
.about-card strong { color: var(--text); }
.version-copy { color: var(--muted) !important; font-size: 0.74rem; }

@media (max-width: 370px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .control-row { gap: 7px; }
  .primary-button, .secondary-button { padding-left: 12px; padding-right: 12px; }
  .center-readout { inset: 24%; }
}

@media (min-width: 700px) {
  .sheet-dialog { margin: auto; border-radius: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .compass-dial { transition: none; }
}
