@font-face {
  font-family: Inter;
  src: url("../fonts/inter-200.woff2") format("woff2");
  font-weight: 200;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #000;
  --fg: #fff;
  --dim: #9a9a9a;
  --line: #2a2a2a;
  --gap: 8px;
  --btn-h: 48px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
  font-weight: 200;
  font-style: normal;
  font-size: 14px;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  width: 100dvw;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  display: grid;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 10px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 10px);
  gap: var(--gap);
  background: #000;
}

#app.portrait {
  grid-template-columns: 1fr;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto auto;
  grid-template-areas:
    "top"
    "meters"
    "stage"
    "map"
    "msg"
    "controls"
    "foot";
}

#app.landscape {
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, 0.85fr);
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "stage top"
    "stage meters"
    "stage msg"
    "stage controls"
    "map   foot";
  align-items: stretch;
}

#topbar {
  grid-area: top;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-rows: auto auto;
  column-gap: 8px;
  row-gap: 2px;
  align-items: center;
  min-height: 0;
}

#title {
  grid-column: 1;
  grid-row: 1;
  font-size: clamp(13px, 3.6vw, 18px);
  white-space: nowrap;
  line-height: 1.2;
}

#phase {
  grid-column: 1;
  grid-row: 2;
  color: var(--dim);
  font-size: clamp(11px, 2.6vw, 13px);
  line-height: 1.2;
  white-space: nowrap;
}

#clock {
  grid-column: 2;
  grid-row: 1 / span 2;
  font-size: clamp(16px, 4.2vw, 22px);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  white-space: nowrap;
  justify-self: end;
  align-self: center;
}

#btn-mute {
  grid-column: 3;
  grid-row: 1 / span 2;
  width: 52px;
  min-width: 52px;
  height: 44px;
  min-height: 44px;
}

#meters {
  grid-area: meters;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  min-height: 0;
}

.meter {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  column-gap: 6px;
  row-gap: 3px;
  align-items: center;
}

.meter span {
  grid-column: 1 / -1;
  color: var(--dim);
  font-size: clamp(10px, 2.4vw, 12px);
  line-height: 1.1;
}

.meter .track {
  grid-column: 1 / 3;
  height: 8px;
  border: 1px solid #fff;
  background: #000;
  position: relative;
  min-width: 0;
}

.meter .track i {
  display: block;
  height: 100%;
  width: 0%;
  background: #fff;
  pointer-events: none;
}

#hr-val {
  grid-column: 3;
  font-style: normal;
  font-size: clamp(11px, 2.6vw, 13px);
  font-variant-numeric: tabular-nums;
  min-width: 2.2em;
  text-align: right;
}

#stage {
  grid-area: stage;
  min-height: 0;
  min-width: 0;
  position: relative;
  border: 1px solid #fff;
  overflow: hidden;
  background: #000;
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#maprow {
  grid-area: map;
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 8px;
  height: clamp(72px, 16vh, 128px);
  min-height: 72px;
  max-height: 128px;
}

#app.landscape #maprow {
  height: 92px;
  min-height: 92px;
  max-height: 92px;
  grid-template-columns: 1fr 1.15fr;
  grid-template-rows: minmax(0, 1fr);
}

#app.landscape #footer {
  min-height: 92px;
  align-items: flex-end;
  justify-content: flex-end;
}

#app.landscape #message {
  min-height: 2.2em;
  max-height: 2.6em;
}

#map, #elev {
  display: block;
  width: 100%;
  height: 100%;
  border: 1px solid #fff;
  background: #000;
  min-width: 0;
  min-height: 0;
}

#message {
  grid-area: msg;
  margin: 0;
  min-height: 2.3em;
  max-height: 2.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: clamp(12px, 3vw, 15px);
  line-height: 1.25;
  color: var(--fg);
  overflow: hidden;
}

#controls {
  grid-area: controls;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-height: var(--btn-h);
  touch-action: manipulation;
}

#controls.wide4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

#controls.wide2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#controls.wide1 {
  grid-template-columns: 1fr;
}

#footer {
  grid-area: foot;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 16px;
  font-size: clamp(11px, 2.5vw, 13px);
  letter-spacing: 0.04em;
  color: var(--fg);
}

button {
  font-family: inherit;
  font-weight: 200;
  font-size: clamp(12px, 3vw, 15px);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  color: #fff;
  background: #000;
  border: 1px solid #fff;
  border-radius: 0;
  min-height: var(--btn-h);
  height: var(--btn-h);
  padding: 0 8px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
  overflow: hidden;
}

button:focus-visible {
  outline: 1px solid #fff;
  outline-offset: 2px;
}

button[aria-pressed="true"],
button.held {
  background: #fff;
  color: #000;
}

button:disabled {
  color: #666;
  border-color: #444;
}

/* compact landscape phones */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --gap: 5px; --btn-h: 44px; }
  #message { font-size: 12px; }
  #app.landscape #maprow,
  #app.landscape #footer { height: 80px; min-height: 80px; max-height: 80px; }
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}
