:root {
  --bg: #0d1117;
  --panel: #161b22;
  --line: #283040;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #4dd4ac;
  --warn: #f0883e;
  --bad: #f85149;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

/* ---------- telefon ---------- */

body.phone {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

body.phone #app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  min-height: 100%;
}

#level {
  width: min(88vw, 60vh);
  height: min(88vw, 60vh);
  max-width: 420px;
  max-height: 420px;
  touch-action: none;
}

.readout {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: min(88vw, 420px);
}

/*
 * Fekvő tájolás. iOS Safari nem engedi a tájolás rögzítését, ezért ott a lap
 * oldalra döntéskor átfordul — ilyenkor legalább ne törjön szét az elrendezés:
 * a dőlésjelző balra, a kezelőszervek jobbra kerülnek, és semmi nem csúszik ki
 * a képernyőről.
 */
@media (orientation: landscape) and (max-height: 560px) {
  body.phone #app {
    display: grid;
    grid-template-columns: auto minmax(220px, 1fr);
    align-items: center;
    justify-items: center;
    gap: 10px 20px;
    padding: 8px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left));
  }

  #level {
    grid-row: 1 / 4;
    width: min(46vw, 78vh);
    height: min(46vw, 78vh);
  }

  .readout,
  .detail {
    width: 100%;
    max-width: 420px;
  }

  .bar button {
    width: 54px;
    height: 54px;
  }

  .status {
    font-size: 12px;
  }
}

.readout .cell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 4px;
  text-align: center;
}

.readout b {
  display: block;
  font-variant-numeric: tabular-nums;
  font-size: 18px;
}

.readout span {
  color: var(--muted);
  font-size: 11px;
}

.bar {
  display: flex;
  gap: 12px;
}

.bar button {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--fg);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.bar button svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
  stroke-linecap: round;
}

.bar button.primary {
  background: var(--accent);
  color: #06231b;
  border-color: transparent;
}

.bar button[disabled] {
  opacity: 0.35;
}

.bar button[aria-pressed='true'] {
  border-color: var(--accent);
  color: var(--accent);
}

.status {
  margin: 0;
  min-height: 1.4em;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  max-width: 34em;
}

.status.bad {
  color: var(--bad);
}

.status.warn {
  color: var(--warn);
}

.detail {
  width: min(88vw, 420px);
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.detail dt {
  color: #6e7681;
}

.detail dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ---------- kivetítő ---------- */

body.screen {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
  overflow: hidden;
}

.screen-head {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.screen-head h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.screen-head .spacer {
  flex: 1;
}

.stat {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 14px;
}

.stat b {
  color: var(--fg);
  font-size: 20px;
}

.modes {
  display: flex;
  gap: 6px;
}

.modes button {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.modes button[aria-pressed='true'] {
  color: #06231b;
  background: var(--accent);
  border-color: transparent;
}

.screen-body {
  display: grid;
  grid-template-columns: minmax(280px, 34%) 1fr;
  min-height: 0;
}

#overall {
  border-right: 1px solid var(--line);
  width: 100%;
  height: 100%;
}

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  padding: 14px;
  align-content: start;
  overflow: auto;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  display: grid;
  justify-items: center;
  gap: 4px;
  transition: opacity 0.3s;
}

.tile.stale {
  opacity: 0.3;
}

.tile canvas {
  width: 100%;
  aspect-ratio: 1;
}

.tile .name {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tile .meta {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.empty {
  grid-column: 1 / -1;
  color: var(--muted);
  text-align: center;
  padding: 40px 12px;
}

.empty code {
  color: var(--accent);
  font-size: 20px;
}
