:root {
  --bg: #0b0d12;
  --surface: #161a22;
  --surface-2: #1f2430;
  --pressed: #2c3342;
  --text: #eef1f6;
  --muted: #8a93a6;
  --accent: #4f8cff;
  --ok: #34c759;
  --warn: #ff9f0a;
  --danger: #ff453a;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--surface-2); border-radius: 12px; padding: 12px 14px; width: 100%; -webkit-user-select: text; user-select: text; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.primary { background: var(--accent); color: #fff; border-radius: 12px; padding: 12px 18px; font-weight: 600; }
.primary:active { filter: brightness(.85); }

/* Login */
.login { max-width: 360px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 18vh) 24px 24px; display: grid; gap: 12px; }
.login h1 { margin: 0 0 12px; font-size: 28px; }
.login label { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

/* App frame */
.app { display: flex; flex-direction: column; height: 100%; padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
main { flex: 1; overflow-y: auto; padding: 0 16px 12px; }
.page { display: flex; flex-direction: column; gap: 18px; min-height: 100%; max-width: 460px; margin: 0 auto; }

/* Status */
.status-bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; max-width: 492px; width: 100%; margin: 0 auto; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.offline { background: var(--danger); }
.status-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.status-text span { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.power { position: relative; width: 48px; height: 48px; border-radius: 50%; background: var(--surface); color: var(--danger); display: grid; place-items: center; overflow: hidden; }
.power::before { content: ""; position: absolute; inset: 0; background: var(--danger); opacity: .35; transform: scaleY(0); transform-origin: bottom; }
.power.holding::before { transform: scaleY(1); transition: transform .7s linear; }

/* Favorites */
.favorites { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.favorites:empty { display: none; }
.fav { background: var(--surface); border-radius: 14px; min-height: 52px; padding: 6px; font-size: 13px; font-weight: 600; line-height: 1.15; overflow: hidden; overflow-wrap: anywhere; }
.fav.active { outline: 2px solid var(--accent); }

/* Navigation */
.nav-area { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 6px; }
.side { display: flex; flex-direction: column; gap: 48px; align-items: center; }
.round { width: 58px; height: 58px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; align-content: center; gap: 1px; }
.round span { font-size: 10px; color: var(--muted); }
.round.big { width: 66px; height: 66px; background: var(--surface-2); }
.dpad { position: relative; width: min(62vw, 236px); aspect-ratio: 1; border-radius: 50%; background: var(--surface); }
.dpad .arrow { position: absolute; width: 34%; height: 34%; background: transparent; display: grid; place-items: center; border-radius: 50%; }
.dpad .arrow svg { width: 30px; height: 30px; }
.dpad .up { top: 0; left: 33%; }
.dpad .down { bottom: 0; left: 33%; }
.dpad .left { left: 0; top: 33%; }
.dpad .right { right: 0; top: 33%; }
.dpad .ok { position: absolute; inset: 31%; border-radius: 50%; background: var(--surface-2); font-weight: 700; font-size: 18px; }

/* Lower controls */
.lower { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: stretch; margin-top: auto; }
.rocker { display: flex; flex-direction: column; align-items: center; justify-content: space-between; background: var(--surface); border-radius: 34px; width: 68px; padding: 4px 0; }
.rocker button { width: 60px; height: 64px; border-radius: 30px; background: transparent; display: grid; place-items: center; }
.rocker-label { font-size: 11px; color: var(--muted); font-weight: 600; }
.media { display: flex; flex-direction: column; justify-content: space-between; gap: 14px; }
.media-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.pill { display: flex; align-items: center; justify-content: center; gap: 8px; background: var(--surface); border-radius: 999px; min-height: 52px; padding: 0 18px; }

/* Pressed feedback */
.round:active, .fav:active, .pill:active, .rocker button:active, .dpad .arrow:active, .power:active, .pressed { background: var(--pressed) !important; }
.dpad .ok:active { background: var(--accent) !important; }

/* Apps */
.search { margin-top: 4px; }
.hint { margin: -8px 0 0; color: var(--muted); font-size: 13px; }
.app-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.app-item { display: flex; gap: 8px; }
.app-launch { flex: 1; text-align: left; background: var(--surface); border-radius: 14px; padding: 14px 16px; min-height: 52px; }
.app-launch.active { outline: 2px solid var(--accent); }
.app-star { width: 52px; border-radius: 14px; background: var(--surface); color: var(--muted); font-size: 20px; }
.app-star[aria-pressed="true"] { color: #ffd60a; }
.app-launch:active, .app-star:active { background: var(--pressed); }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* Touch */
.touchpad { flex: 1; min-height: 280px; border-radius: 24px; background: var(--surface); display: grid; place-items: center; text-align: center; color: var(--muted); touch-action: none; }
.touchpad.active { background: var(--surface-2); }
.touch-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.text-form { display: flex; gap: 8px; }

/* Tabs */
.tabs { display: flex; justify-content: center; background: var(--surface); border-top: 1px solid var(--surface-2); padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px); }
.tab { flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: 2px; background: transparent; color: var(--muted); font-size: 11px; padding: 6px 0; min-height: 48px; }
.tab.active { color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translateX(-50%); background: var(--surface-2); padding: 10px 16px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.5); max-width: 90vw; text-align: center; z-index: 10; }

@media (max-height: 700px) {
  .side { gap: 28px; }
  .dpad { width: min(56vw, 200px); }
  .round { width: 52px; height: 52px; }
  .round.big { width: 58px; height: 58px; }
  .rocker button { height: 54px; }
}
