:root {
  color-scheme: light dark;
  --bg: #f4f1ea;
  --surface: #faf8f2;
  --line: #d7d0c3;
  --line-strong: #b9af9b;
  --text: #181714;
  --muted: #6f695d;
  --primary: #7f6a2b;
  --accent: #8c6c2f;
  --ok: #2f8f4e;
}

[data-theme="dark"] {
  --bg: #0f0f0e;
  --surface: #181716;
  --line: #2c2a26;
  --line-strong: #3f3c36;
  --text: #e8e4df;
  --muted: #a19b91;
  --primary: #d4c08d;
  --accent: #e2b35c;
  --ok: #4cc37a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f0e;
    --surface: #181716;
    --line: #2c2a26;
    --line-strong: #3f3c36;
    --text: #e8e4df;
    --muted: #a19b91;
    --primary: #d4c08d;
    --accent: #e2b35c;
    --ok: #4cc37a;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Instrument Sans", sans-serif;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 1rem;
  padding: 1rem 1rem 1.25rem;
  justify-content: center;
}

.topline,
.calibration-popover,
.permission-banner,
.instrument-panel,
.seo-copy-block,
.footer-note,
.faq-hero,
.faq-group,
.faq-footer {
  width: 100%;
  max-width: 33rem;
  margin: 0 auto;
}

.topline {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding-top: max(0.2rem, env(safe-area-inset-top));
}

.topline-meta {
  display: grid;
  justify-items: end;
  gap: 0.4rem;
}

.topline-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.language-selector {
  position: relative;
}

.brand {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
}

.brand-icon {
  font-size: 1.28rem;
  line-height: 1;
  color: var(--accent);
}

.top-control {
  appearance: none;
  min-height: 2.1rem;
  padding: 0.15rem 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.38rem;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1;
  transition: color 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}

.help-button {
  background: transparent;
  padding: 0;
}

.top-control:hover {
  color: var(--text);
  background: transparent;
}

.topline-controls > * + * {
  position: relative;
  margin-left: 0.35rem;
}

.topline-controls > * + *::before {
  content: "";
  position: absolute;
  left: -0.38rem;
  top: 50%;
  width: 1px;
  height: 0.9rem;
  transform: translateY(-50%);
  background: var(--line);
}

.top-control:focus,
.top-control:focus-visible,
.top-control:active {
  background: transparent;
  outline: none;
  box-shadow: none;
}

.top-control-icon {
  font-size: 1rem;
  line-height: 1;
}

.top-control-label {
  letter-spacing: 0.02em;
  border-bottom: 1px solid transparent;
}

.current-flag {
  font-size: 0.95rem;
}

.theme-toggle {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 0.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover {
  color: var(--text);
}

.theme-toggle:focus,
.theme-toggle:focus-visible,
.theme-toggle:active {
  background: transparent;
  outline: none;
  box-shadow: none;
}

.theme-toggle .top-control-icon {
  font-size: 1.35rem;
}

.language-selector-trigger {
  min-width: 0;
  gap: 0.24rem;
}

.language-options {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  list-style: none;
  padding: 0.5rem 0;
  margin: 0.25rem 0 0;
  min-width: 100px;
  z-index: 10;
  border-radius: 0.5rem;
}

.language-options[hidden] {
  display: none;
}

.language-options li {
  margin: 0;
}

.language-options .flag {
  margin-right: 0.5rem;
}

[data-theme="dark"] .language-options,
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .language-options {
    background: var(--surface);
    border-color: var(--line);
  }
}

[data-theme="dark"] .language-button,
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .language-button {
    color: var(--muted);
  }
}

[data-theme="dark"] .language-button:hover,
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .language-button:hover {
    background-color: var(--line);
    color: var(--text);
  }
}

[data-theme="dark"] .language-button[aria-selected="true"],
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .language-button[aria-selected="true"] {
    color: var(--text);
  }
}

[data-theme="dark"] .theme-toggle,
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle {
    background: transparent;
  }
}

[data-theme="dark"] .top-control,
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .top-control {
    background: transparent;
  }
}

.help-button[aria-expanded="true"] {
  color: var(--text);
}

.help-button[aria-expanded="true"] .top-control-label {
  border-bottom-color: var(--line-strong);
}

.help-button[data-state="low"] {
  color: var(--text);
}

.help-button[data-state="low"] .top-control-label {
  border-bottom-color: var(--accent);
}

.language-button {
  appearance: none;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 0.8rem;
  font: inherit;
  font-size: 0.84rem;
  text-align: left;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.language-button.is-active {
  color: var(--text);
  font-weight: 600;
}

.language-button[aria-selected="true"] {
  color: var(--text);
  font-weight: 600;
}

.language-button:hover {
  background: var(--line);
  color: var(--text);
}

.readout-label,
.footer-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.permission-banner {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  width: calc(100% - 2rem);
  max-width: 31rem;
}

.permission-toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.6rem 0.6rem 0.6rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .permission-toast,
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .permission-toast {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

.permission-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.permission-close {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.permission-close:hover {
  color: var(--text);
}

.calibration-popover {
  border: 1px solid var(--line);
  background: rgba(250, 248, 242, 0.96);
  padding: 0.85rem 1rem;
}

[data-theme="dark"] .calibration-popover {
  border-color: var(--line-strong);
  background: rgba(20, 19, 18, 0.98);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .calibration-popover {
    border-color: var(--line-strong);
    background: rgba(20, 19, 18, 0.98);
  }
}

.calibration-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.calibration-text {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--muted);
}

.calibration-graphic,
.faq-graphic {
  margin-top: 0.75rem;
  display: flex;
  justify-content: center;
}

.instructions-img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  mix-blend-mode: multiply;
  opacity: 0.9;
}

[data-theme="dark"] .instructions-img {
  mix-blend-mode: normal;
  filter: invert(1) hue-rotate(180deg) contrast(0.92) brightness(0.92);
  opacity: 0.86;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .instructions-img {
    mix-blend-mode: normal;
    filter: invert(1) hue-rotate(180deg) contrast(0.92) brightness(0.92);
    opacity: 0.86;
  }
}

.permission-copy {
  margin: 0;
  color: var(--text);
  line-height: 1.35;
  font-size: 0.88rem;
}

.permission-button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  appearance: none;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text);
  border-radius: 0;
  padding: 0.52rem 0.75rem;
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
}

.permission-icon {
  font-size: 0.9rem;
  line-height: 1;
  color: var(--accent);
}

.permission-button-text {
  line-height: 1;
}

.location-block {
  display: grid;
  gap: 0.18rem;
}

.location-coordinates {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.01em;
}

.instrument-panel {
  display: grid;
  align-content: center;
  gap: 1.5rem;
  background: #baacac14;
  padding: 16px;
  box-shadow: 0 0 10px #e8dede;
}

[data-theme="dark"] .instrument-panel {
  background: rgba(232, 228, 223, 0.035);
  box-shadow: 0 0 10px rgba(24, 23, 20, 0.8);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .instrument-panel {
    background: rgba(232, 228, 223, 0.035);
    box-shadow: 0 0 10px rgba(24, 23, 20, 0.8);
  }
}

.readout,
.altitude-block {
  padding: 0;
  background: transparent;
  border: 0;
}

.readout {
  display: grid;
  gap: 0.15rem;
}

.readout-value,
.altitude-value {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  line-height: 0.92;
  color: var(--text);
}

.readout-value {
  font-size: clamp(1.55rem, 6.8vw, 2.45rem);
  letter-spacing: 0.005em;
  display: block;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.altitude-value {
  font-size: clamp(1.8rem, 8vw, 2.6rem);
}

.altitude-main,
.municipality-row {
  display: grid;
  gap: 0.18rem;
}

.municipality-value {
  margin: 0;
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.1;
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
}

.municipality-value::before {
  content: "location_on";
  font-family: "Material Symbols Sharp";
  font-size: 1rem;
  line-height: 1;
  color: var(--accent);
  font-weight: 400;
  font-style: normal;
}

.heading-strip-mask {
  position: relative;
  display: block;
  width: 100%;
  overflow: hidden;
  mask-image: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, 0.6) 14%, #000 32%, #000 68%, rgba(0, 0, 0, 0.6) 86%, transparent 100%);
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, 0.6) 14%, #000 32%, #000 68%, rgba(0, 0, 0, 0.6) 86%, transparent 100%);
}

.heading-strip-mask.is-idle {
  opacity: 0.48;
}

.heading-strip-track {
  display: flex;
  align-items: center;
  will-change: transform;
}

.heading-strip-item {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-family: "Instrument Sans", sans-serif;
  font-weight: 800;
  white-space: nowrap;
  text-align: center;
  padding: 0 0.12em;
  text-transform: uppercase;
  font-feature-settings: "case" 1;
}

.heading-strip-item-cardinal {
  font-size: clamp(1.55rem, 6.2vw, 2.3rem);
  letter-spacing: 0.015em;
}

.heading-strip-item-ordinal {
  font-size: clamp(1.15rem, 4.7vw, 1.65rem);
  letter-spacing: 0.02em;
}

.direction-copy {
  margin: 0.1rem 0 0;
  color: var(--muted);
  line-height: 1.2;
  font-size: 1.1rem;
  min-height: 1.4rem;
}

.direction-degrees {
  display: inline-block;
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
  font-weight: 500;
}

.compass-wrap {
  display: grid;
  place-items: center;
  padding: 0.25rem 0;
}

.compass {
  position: relative;
  width: min(78vw, 25rem);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line-strong);
}

.phone-marker-orbit {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  will-change: transform;
  z-index: 4;
}

.phone-marker {
  position: absolute;
  left: 50%;
  top: -2rem;
  transform: translateX(-50%);
}

.phone-marker-arrow {
  width: 0;
  height: 0;
  border-left: 0.55rem solid transparent;
  border-right: 0.55rem solid transparent;
  border-top: 0.9rem solid var(--accent);
}

.compass-ring,
.compass::before,
.compass::after {
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  content: "";
}

.compass-ring {
  border: 1px solid var(--line);
}

.compass::before {
  inset: 15%;
  border: 1px solid rgba(185, 175, 155, 0.55);
}

.compass::after {
  inset: 0.65rem;
  background: conic-gradient(from 0deg, rgba(111, 105, 93, 0.7) 0deg 1deg, transparent 1deg 14deg, rgba(111, 105, 93, 0.35) 14deg 15deg, transparent 15deg 30deg);
  mask: radial-gradient(circle, transparent 69%, black 69%);
}

.tick,
.cardinal,
.ordinal,
.compass-core,
.compass-rose,
.compass-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.tick {
  width: 1px;
  height: calc(50% - 1.95rem);
  transform-origin: center bottom;
  transform: translate(-50%, -100%);
  background: linear-gradient(180deg, rgba(111, 105, 93, 0.9), transparent 45%);
}

.tick-e { transform: translate(-50%, -100%) rotate(90deg); }
.tick-ne { transform: translate(-50%, -100%) rotate(45deg); }
.tick-se { transform: translate(-50%, -100%) rotate(135deg); }
.tick-s { transform: translate(-50%, -100%) rotate(180deg); }
.tick-sw { transform: translate(-50%, -100%) rotate(225deg); }
.tick-w { transform: translate(-50%, -100%) rotate(270deg); }
.tick-nw { transform: translate(-50%, -100%) rotate(315deg); }

.cardinal,
.ordinal {
  font-family: "Archivo Black", "Space Grotesk", sans-serif;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--text);
  white-space: nowrap;
  text-align: center;
}

.cardinal { font-size: clamp(0.95rem, 4vw, 1.2rem); }
.ordinal { font-size: clamp(0.68rem, 3vw, 0.82rem); color: var(--muted); }

.north {
  transform: translate(-50%, -50%) rotate(0deg) translateY(calc(var(--cardinal-radius) * -1)) rotate(var(--counter-rotation, 0deg));
}

.east {
  transform: translate(-50%, -50%) rotate(90deg) translateY(calc(var(--cardinal-radius) * -1)) rotate(calc(var(--counter-rotation, 0deg) - 90deg));
}

.south {
  transform: translate(-50%, -50%) rotate(180deg) translateY(calc(var(--cardinal-radius) * -1)) rotate(calc(var(--counter-rotation, 0deg) - 180deg));
}

.west {
  transform: translate(-50%, -50%) rotate(270deg) translateY(calc(var(--cardinal-radius) * -1)) rotate(calc(var(--counter-rotation, 0deg) - 270deg));
}

.north-east {
  transform: translate(-50%, -50%) rotate(45deg) translateY(calc(var(--ordinal-radius) * -1)) rotate(calc(var(--counter-rotation, 0deg) - 45deg));
}

.south-east {
  transform: translate(-50%, -50%) rotate(135deg) translateY(calc(var(--ordinal-radius) * -1)) rotate(calc(var(--counter-rotation, 0deg) - 135deg));
}

.south-west {
  transform: translate(-50%, -50%) rotate(225deg) translateY(calc(var(--ordinal-radius) * -1)) rotate(calc(var(--counter-rotation, 0deg) - 225deg));
}

.north-west {
  transform: translate(-50%, -50%) rotate(315deg) translateY(calc(var(--ordinal-radius) * -1)) rotate(calc(var(--counter-rotation, 0deg) - 315deg));
}

.compass-rose {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  --counter-rotation: 0deg;
  --cardinal-radius: 8.5rem;
  --ordinal-radius: 8.5rem;
  transform: translate(-50%, -50%) rotate(0deg);
}

.compass-core {
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(250, 248, 242, 0.96);
  border: 1px solid rgba(185, 175, 155, 0.65);
  z-index: 3;
}

.compass-core-value {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.altitude-block {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 0.95rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.seo-copy-block {
  display: grid;
  gap: 0;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.seo-heading {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
  font-variant-caps: all-petite-caps;
}

.seo-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
  line-height: 1.55;
  max-width: 32rem;
}

.seo-copy::before {
  content: "- ";
}

.seo-note {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
  max-width: 32rem;
}

.material-symbols-sharp {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.footer-link,
.brand-link,
.calibration-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid rgba(111, 105, 93, 0.35);
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  border-bottom: 0;
}

.footer-link:hover, .brand-link:hover, .calibration-link:hover {
  border-bottom-color: rgba(111, 105, 93, 0.7);
}

/* FAQ Styles */
.faq-hero, .faq-group, .faq-footer {
  width: 100%;
  max-width: 33rem;
  margin: 0 auto;
}

.faq-hero { padding: 1rem 0 2rem; }
.faq-title {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
}
.faq-title-icon {
  font-size: 1.55rem;
  line-height: 1;
  color: var(--muted);
}
.faq-lead { margin: 0.75rem 0 0; color: var(--muted); line-height: 1.5; font-size: 1.05rem; }

.faq-group { margin-bottom: 2.5rem; }
.faq-group-title { margin: 0 0 1rem; font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 0.5rem; display: flex; align-items: center; gap: 0.4rem; }
.faq-icon { font-size: 1.1em; color: var(--muted); }

.faq-item { padding: 0.85rem 0; }
.faq-item + .faq-item { border-top: 1px solid rgba(215, 208, 195, 0.4); }
.faq-item summary { cursor: pointer; color: var(--text); font-weight: 500; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 1rem; font-size: 1.05rem; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: ""; flex: 0 0 auto; width: 0.8rem; height: 0.8rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236f695d' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-size: contain; background-repeat: no-repeat; transition: transform 0.2s ease; }
.faq-item[open] summary::after { transform: rotate(180deg); }

.faq-answer { margin-top: 0.75rem; color: var(--muted); line-height: 1.6; font-size: 0.95rem; }
.faq-answer p { margin: 0; }
.faq-answer p + p { margin-top: 0.75rem; }
.faq-answer ul { margin: 0.5rem 0 0; padding-left: 1.25rem; }
.faq-answer li { margin: 0.4rem 0; }
.faq-footer { margin: 1rem auto 3rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }

@media (prefers-reduced-motion: reduce) { .compass-rose { transition: none; } }
@media (max-width: 480px) {
  .app-shell { padding: 0.9rem 0.9rem calc(1rem + env(safe-area-inset-bottom)); gap: 0.9rem; }
  .calibration-popover { padding: 0.8rem 0.9rem; }
  .direction-copy { font-size: 0.96rem; }
  .altitude-block { grid-template-columns: 1fr; }
}
@media (min-width: 720px) {
  .app-shell { padding: 1.5rem; }
  .topline, .instrument-panel, .footer-note, .faq-hero, .faq-group, .faq-footer { max-width: 36rem; }
}
