:root {
  --bg: #0e1116;
  --card: #171b22;
  --key: #222833;
  --key-hi: #2b3342;
  --text: #e8ecf3;
  --muted: #8a94a6;
  --accent: #3b82f6;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.app { max-width: 430px; margin: 0 auto; padding: 14px 14px 40px; }
button, input, summary { touch-action: manipulation; font: inherit; color: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.top h1 { font-size: 20px; margin: 0; letter-spacing: .2px; }
.top-right { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 12px; background: var(--card); cursor: pointer; }

.status { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); background: var(--card); padding: 7px 11px; border-radius: 999px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); display: inline-block; }
.status[data-state="connecting"] .dot, .status[data-state="waiting_auth"] .dot { background: var(--warn); animation: pulse 1s infinite; }
.status[data-state="connected"] .dot { background: var(--ok); }
.status[data-state="connected"] { color: var(--text); }
@keyframes pulse { 50% { opacity: .35; } }

.panel { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.panel[hidden] { display: none; }
.panel label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.row { display: flex; gap: 8px; }
input:not([type=checkbox]) { flex: 1; min-width: 0; background: var(--key); border: 1px solid transparent; border-radius: 12px; padding: 12px 14px; outline: none; }
input:not([type=checkbox]):focus { border-color: var(--accent); }
button.primary { background: var(--accent); border: 0; border-radius: 12px; padding: 0 18px; font-weight: 600; cursor: pointer; min-height: 46px; }
button.primary:disabled { opacity: .6; }
button.ghost { margin-top: 12px; background: transparent; border: 1px solid var(--key-hi); border-radius: 12px; padding: 10px 12px; color: var(--muted); cursor: pointer; }
.hint { font-size: 12.5px; color: var(--muted); margin: 8px 2px 0; }
.adv { margin-top: 12px; }
.adv summary, .numpad-wrap summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 0; }
.adv label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 8px 0 12px; }
.adv input[type=checkbox] { width: 18px; height: 18px; }
.cert { margin-top: 12px; background: #1c2230; border-radius: 12px; padding: 12px; font-size: 14px; }
.cert[hidden] { display: none; }
.cert p { margin: 0 0 6px; }
.cert ol { margin: 6px 0 10px; padding-left: 20px; color: var(--muted); }
.btn-link { display: inline-block; background: var(--key-hi); padding: 10px 14px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600; }

/* Control remoto */
.remote { background: var(--card); border-radius: 28px; padding: 16px 14px 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; transition: opacity .2s; }
.remote[data-enabled="false"] { opacity: .45; }
.remote[data-enabled="false"] .key { cursor: not-allowed; }
.key { background: var(--key); border: 0; border-radius: 14px; min-height: 48px; font-size: 18px; display: grid; place-items: center; cursor: pointer; user-select: none; -webkit-user-select: none; transition: transform .06s, background .1s; }
.key:active, .key.pressed { transform: scale(.94); background: var(--key-hi); }
.key.txt { font-size: 14px; font-weight: 600; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.row4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.power { background: var(--danger); }
.power:active { background: #c53030; }

.mid { display: grid; grid-template-columns: 62px minmax(0, 1fr) 62px; align-items: center; gap: 8px; }
.rocker { display: grid; grid-template-rows: 1fr auto 1fr; background: var(--key); border-radius: 31px; padding: 4px; height: 168px; }
.rocker .key { background: transparent; font-size: 24px; min-height: 0; border-radius: 27px; }
.rocker .key:active { background: var(--key-hi); }
.rocker .lbl { text-align: center; font-size: 11px; color: var(--muted); letter-spacing: 1px; }

.dpad { width: min(100%, 210px); aspect-ratio: 1; margin: 0 auto; border-radius: 50%; background: var(--key); display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 6px; }
.dpad .key { background: transparent; border-radius: 50%; min-height: 0; font-size: 17px; color: var(--muted); }
.dpad .key:active { background: var(--key-hi); color: var(--text); }
.dpad .up { grid-area: 1 / 2; } .dpad .left { grid-area: 2 / 1; } .dpad .right { grid-area: 2 / 3; } .dpad .down { grid-area: 3 / 2; }
.dpad .ok { grid-area: 2 / 2; background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; }
.dpad .ok:active { background: #2563eb; color: #fff; }

.colors { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.colors .key { min-height: 18px; height: 18px; border-radius: 999px; }
.c-red { background: #dc2626; } .c-green { background: #16a34a; } .c-yellow { background: #eab308; } .c-blue { background: #2563eb; }
.colors .key:active { filter: brightness(1.3); background: inherit; }

.media { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.media .key { font-size: 16px; }

.numpad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 8px; }
.sec { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; margin: 6px 2px -4px; }
.apps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.app-tile { background: var(--key); border: 0; border-radius: 14px; padding: 14px 6px; font-weight: 700; font-size: 14px; cursor: pointer; }
.app-tile:active { background: var(--key-hi); transform: scale(.96); }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(92vw, 400px); background: #2a1215; color: #fecaca; border: 1px solid #7f1d1d; padding: 12px 16px; border-radius: 12px; font-size: 14px; z-index: 10; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.toast[hidden] { display: none; }
.toast.info { background: #12202a; color: #bfe3ff; border-color: #1e4a6b; }

@media (max-width: 350px) {
  .app { padding-left: 10px; padding-right: 10px; }
  .remote { padding-left: 10px; padding-right: 10px; }
  .mid { grid-template-columns: 50px minmax(0, 1fr) 50px; gap: 6px; }
  .key.txt { font-size: 13px; }
}
