:root {
  color-scheme: light dark;
  --bg: #f3f0ea;
  --fg: #1b1a17;
  --muted: #6a6560;
  --line: #ddd6cb;
  --face: #fffdf8;
  --btn: #1b1a17;
  --btn-fg: #f3f0ea;
  --danger: #8a2f2f;
  --accent: #c24d1c;
  --here: #f6e6d4;
  --pad: clamp(1rem, 4.5vw, 2.25rem);
  --max: min(26rem, 100%);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12110f;
    --fg: #ece8e1;
    --muted: #9a948a;
    --line: #2c2a26;
    --face: #1c1a17;
    --btn: #ece8e1;
    --btn-fg: #12110f;
    --danger: #e08a8a;
    --accent: #e08a58;
    --here: #3d2e22;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.4;
}

.app {
  min-height: 100dvh;
  width: var(--max);
  margin: 0 auto;
  padding: calc(var(--pad) + env(safe-area-inset-top))
    calc(var(--pad) + env(safe-area-inset-right))
    calc(var(--pad) + env(safe-area-inset-bottom))
    calc(var(--pad) + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(0.85rem, 2.2vh, 1.35rem);
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.ident h1,
.place {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
}

.place {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.flag {
  font-size: 1.25rem;
  line-height: 1;
}

.clocks {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.clocks p {
  margin: 0;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.4rem;
  font-size: 0.92rem;
}

.clocks .unit {
  color: var(--muted);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.status.is-error {
  color: var(--danger);
}

.status[hidden],
.result[hidden],
.place[hidden],
#title[hidden] {
  display: none;
}

.result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}

.stage {
  position: relative;
  width: min(100%, 24rem, 78vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
}

.compass {
  width: 100%;
  aspect-ratio: 1;
  touch-action: none;
}

.instrument {
  width: 100%;
  height: 100%;
  display: block;
  font-family: var(--font);
  user-select: none;
}

.slide {
  will-change: transform;
}

.face {
  fill: var(--face);
}

.rim {
  stroke: var(--line);
  stroke-width: 1.35;
}

.rim-inner {
  stroke: var(--line);
  stroke-width: 0.7;
  opacity: 0.7;
}

.tick-major {
  stroke: var(--accent);
  stroke-width: 1.85;
  stroke-linecap: round;
}

.tick-mid {
  stroke: var(--fg);
  stroke-width: 1.15;
  opacity: 0.45;
  stroke-linecap: round;
}

.tick-minor {
  stroke: var(--muted);
  stroke-width: 0.8;
  opacity: 0.35;
}

.card,
.card-n {
  font-size: 7.4px;
  font-weight: 700;
  letter-spacing: 0.7px;
}

.card { fill: var(--muted); }
.card-n { fill: var(--accent); }

.sq {
  fill: var(--bg);
  stroke: var(--line);
  stroke-width: 0.7;
}

.sq-you {
  fill: var(--here);
}

.sq-sel {
  stroke: var(--accent);
  stroke-width: 1.8;
  filter: url(#selglow);
}

.sq-label {
  fill: var(--muted);
  font-size: 6.5px;
  font-weight: 650;
  letter-spacing: 0.35px;
}

.sq-you-label {
  fill: var(--fg);
  font-size: 5.7px;
  letter-spacing: 0.5px;
}

.sq-you-sub {
  fill: var(--fg);
  font-size: 7.6px;
  font-weight: 700;
  letter-spacing: 0.85px;
}

.acc {
  fill: var(--accent);
  opacity: 0.2;
  animation: acc-pulse 2.4s ease-out infinite;
}

.you {
  fill: var(--accent);
  stroke: var(--face);
  stroke-width: 0.9;
}

.beam {
  stroke: var(--accent);
  stroke-width: 1.25;
  stroke-dasharray: 2.6 2;
  stroke-linecap: round;
  animation: beam-run 0.9s linear infinite;
}

.needle-g.is-off { display: none; }
.needle-head { fill: var(--accent); }
.needle-hub { fill: var(--accent); }

.sq-label,
.you,
.acc,
.beam,
.you-mark {
  pointer-events: none;
}

.hud {
  display: flex;
  width: min(100%, 15.5rem);
  justify-content: space-between;
  align-items: center;
}

.seg {
  display: flex;
  gap: 0.15rem;
  padding: 0.18rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--face) 88%, transparent);
  backdrop-filter: blur(10px);
}

.me {
  border-radius: 999px;
  background: color-mix(in srgb, var(--face) 88%, transparent);
  backdrop-filter: blur(10px);
}

.readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  width: 100%;
  background: transparent;
  color: inherit;
  min-height: 0;
  padding: 0;
  border-radius: 0;
}

.sel-grid {
  font-size: clamp(1.55rem, 7vw, 2rem);
  font-weight: 650;
  letter-spacing: 0.1em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}

.sel-meta {
  color: var(--muted);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
}

.readout.is-flash .sel-grid {
  animation: readout-in 0.32s ease;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem 1rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.meta-line strong {
  color: var(--fg);
  font-weight: 650;
}

#locate {
  appearance: none;
  width: 100%;
  min-height: 2.9rem;
  border: 0;
  border-radius: 999px;
  background: var(--btn);
  color: var(--btn-fg);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.app.is-live #locate {
  background: transparent;
  color: var(--muted);
  min-height: 2.25rem;
  font-size: 0.84rem;
  font-weight: 500;
}

.seg button,
.me,
.readout {
  appearance: none;
  width: auto;
  min-height: 1.85rem;
  border: 0;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--muted);
  cursor: pointer;
  padding: 0.28rem 0.62rem;
}

.seg button.is-on,
.me:active {
  background: var(--fg);
  color: var(--bg);
  border-radius: 999px;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}

@keyframes acc-pulse {
  0% { opacity: 0.28; }
  100% { opacity: 0.05; }
}

@keyframes beam-run {
  to { stroke-dashoffset: -9; }
}

@keyframes readout-in {
  from {
    opacity: 0.35;
    transform: translateY(4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .slide { will-change: auto; }
  .acc,
  .beam,
  .readout.is-flash .sel-grid {
    animation: none;
  }
}

@media (min-width: 720px) {
  :root {
    --max: min(34rem, 100%);
  }

  .stage {
    width: min(100%, 28rem);
  }
}

@media (max-width: 360px) {
  .header {
    flex-direction: column;
    gap: 0.5rem;
  }

  .clocks,
  .clocks p {
    text-align: left;
    justify-content: flex-start;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .app {
    justify-content: flex-start;
    gap: 0.55rem;
    padding-top: calc(0.6rem + env(safe-area-inset-top));
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
  }

  .stage {
    width: min(100%, 46vh);
  }

  .sel-grid {
    font-size: 1.35rem;
  }
}

@media (orientation: landscape) and (min-width: 860px) and (max-height: 640px) {
  .app {
    width: min(56rem, 100%);
    display: grid;
    grid-template-columns: min(46vh, 26rem) minmax(12rem, 1fr);
    grid-template-rows: auto auto 1fr auto;
    align-items: center;
    column-gap: 2rem;
  }

  .header {
    grid-column: 1 / -1;
  }

  .status {
    grid-column: 1 / -1;
  }

  .result {
    display: contents;
  }

  .stage {
    grid-row: 3;
    width: min(46vh, 26rem);
  }

  .readout,
  .meta-line,
  #locate {
    grid-column: 2;
    text-align: left;
    align-items: flex-start;
  }

  .readout {
    grid-row: 3;
    align-self: center;
  }

  .meta-line {
    justify-content: flex-start;
    grid-row: 3;
    align-self: end;
    margin-bottom: 3rem;
  }

  #locate {
    grid-row: 4;
    width: auto;
    justify-self: start;
  }
}
