:root {
  --shell: #0b0d0e;
  --panel: #141a1d;
  --panel-2: #1b2327;
  --line: #263035;
  --text: #e9eef1;
  --muted: #8b979d;
  --accent: #ff4d3d;
  --radius: 10px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--shell);
  color: var(--text);
  font: 500 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button,
select {
  font: inherit;
  color: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: color-mix(in srgb, var(--shell) 88%, transparent);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}

.spacer {
  flex: 1;
}

.iconbtn {
  appearance: none;
  border: 0;
  background: var(--panel);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background 120ms ease;
}

.iconbtn:hover,
.iconbtn:focus-visible {
  background: var(--panel-2);
}

.iconbtn[aria-expanded="true"] {
  background: var(--panel-2);
  color: var(--accent);
}

.pageno {
  font-family: ui-monospace, "DejaVu Sans Mono", "Liberation Mono", Menlo, monospace;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #fff;
  min-width: 3.2ch;
  font-variant-numeric: tabular-nums;
}

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.chip:hover {
  color: var(--text);
  border-color: var(--muted);
}

.status {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 22ch;
}

.status.is-offline {
  color: #ffb020;
}

.channel-select {
  min-width: 0;
}

.channel-select select {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 8px 10px;
  cursor: pointer;
  max-width: 9.5em;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  display: grid;
  place-items: center;
  padding: 12px;
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y;
}

.frame {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  background: #000;
  line-height: 0;
}

.frame canvas {
  display: block;
}

.hotlinks {
  position: absolute;
  inset: 0;
}

.hotlinks button {
  position: absolute;
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  border-radius: 2px;
  transition: background 90ms ease;
}

.hotlinks button:hover,
.hotlinks button:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  outline: none;
}

.hotlinks button:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.65);
}

/* ---------- index panel ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 25;
}

.panel {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  width: min(330px, 88vw);
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px 14px calc(24px + env(safe-area-inset-bottom));
  animation: slide-in 160ms ease-out;
}

@keyframes slide-in {
  from {
    transform: translateX(-8px);
    opacity: 0.4;
  }
}

.panel h2 {
  margin: 18px 4px 8px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel h2:first-of-type {
  margin-top: 4px;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tabs button {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
  font-size: 13px;
}

.tabs button[aria-pressed="true"] {
  background: var(--panel-2);
  border-color: var(--muted);
  color: #fff;
}

.tree {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tree button {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.tree button:hover,
.tree button:focus-visible {
  background: var(--panel-2);
}

.tree .num {
  font-family: ui-monospace, "DejaVu Sans Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  min-width: 3ch;
}

.tree .child {
  padding-left: 18px;
}

.tree .section {
  font-weight: 600;
}

/* ---------- keypad ---------- */

.pad {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.padgrid {
  display: grid;
  grid-template-columns: repeat(3, 62px);
  gap: 8px;
}

.padgrid button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  height: 46px;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.padgrid button:active {
  transform: scale(0.97);
}

.padgrid button.go {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  background: #2a1d12;
  border: 1px solid #6b4a1f;
  color: #ffd9a0;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 40;
  max-width: 90vw;
  text-align: center;
}

@media (max-width: 400px) {
  .topbar {
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .iconbtn {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }

  .pageno {
    font-size: 22px;
    min-width: 2.8ch;
  }

  .status {
    display: none;
  }

  .channel-select select {
    padding: 7px 6px;
    font-size: 14px;
    max-width: 7.2em;
  }
}

@media (min-width: 900px) {
  .pageno {
    font-size: 30px;
  }

  .stage {
    padding: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 600px) {
  .stage {
    padding: 6px;
  }
}
