:root {
  --bg: #0c1218;
  --bg-elev: #15202b;
  --bg-btn: #1c2a38;
  --bg-btn-hover: #243547;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #3dd6c6;
  --accent-dim: #2a9f93;
  --danger: #f07178;
  --online: #5fd68a;
  --offline: #9aa7b8;
  --warning: #e8c547;
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #1a3344 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #12261f 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  min-height: 100dvh;
}

.app {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: 1.25rem 1.1rem calc(2.5rem + env(safe-area-inset-bottom, 0px));
  padding-left: max(1.1rem, env(safe-area-inset-left, 0px));
  padding-right: max(1.1rem, env(safe-area-inset-right, 0px));
  padding-top: max(1.25rem, env(safe-area-inset-top, 0px));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.pill {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: var(--bg-elev);
}

.pill.online {
  color: var(--online);
}

.pill.offline {
  color: var(--offline);
}

.feedback {
  margin: -0.35rem 0 0.85rem;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid #2a3b4d;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
}

.feedback.error {
  border-color: rgba(240, 113, 120, 0.5);
  color: var(--danger);
}

.feedback.ok {
  border-color: rgba(61, 214, 198, 0.45);
  color: var(--accent);
}

.offline-banner {
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  background: #261a0a;
  border: 1px solid rgba(232, 197, 71, 0.45);
  color: var(--warning);
  font-size: 0.88rem;
  line-height: 1.4;
}

.volume-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.panel h1 {
  margin: 0 0 0.5rem;
  font-size: 1.65rem;
  letter-spacing: -0.03em;
}

.lead {
  margin: 0 0 1.5rem;
  color: var(--muted);
  line-height: 1.45;
}

.pair-form label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.pair-form input {
  width: 100%;
  padding: 1rem;
  border: 1px solid #2a3b4d;
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text);
  font-family: var(--mono);
  font-size: 1.75rem;
  letter-spacing: 0.35em;
  text-align: center;
}

.pair-form button,
.cmd {
  border: 0;
  border-radius: var(--radius);
  background: var(--bg-btn);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.pair-form button {
  width: 100%;
  margin-top: 1rem;
  padding: 0.95rem;
  background: var(--accent);
  color: #06221f;
  font-size: 1rem;
}

.pair-form button:hover,
.cmd:hover:not(:disabled) {
  filter: brightness(1.05);
}

.pair-form button:active,
.cmd:active:not(:disabled),
.cmd.is-pressed:not(:disabled) {
  transform: scale(0.96);
  background: var(--bg-btn-hover);
}

.cmd.is-pressed:not(:disabled) {
  outline: 2px solid rgba(61, 214, 198, 0.55);
  outline-offset: 1px;
}

.cmd:disabled {
  opacity: 0.4;
  cursor: default;
  filter: none;
}

.device-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.add-tv {
  margin-bottom: 1.1rem;
  border-radius: var(--radius);
  border: 1px solid #2a3b4d;
  background: transparent;
}

.add-tv-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.8rem;
  padding: 0.65rem 0.85rem;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.add-tv-summary::-webkit-details-marker {
  display: none;
}

.add-tv-summary svg {
  width: 1.1rem;
  height: 1.1rem;
}

.add-tv[open] .add-tv-summary {
  border-bottom: 1px solid #2a3b4d;
  color: var(--text);
}

.add-tv-body {
  padding: 0.85rem;
}

.invite-box {
  margin-top: 0.85rem;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1px solid #2a3b4d;
}

.invite-lead {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.invite-pin {
  font-family: var(--mono);
  font-size: 2rem;
  letter-spacing: 0.35em;
  text-align: center;
  color: var(--accent);
  font-weight: 600;
}

.invite-actions {
  margin-top: 0.75rem;
}

.invite-actions .cmd {
  width: 100%;
  min-height: 2.8rem;
}

.invite-meta {
  margin: 0.5rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.device-row select {
  flex: 1;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid #2a3b4d;
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
}

.ghost {
  border: 1px solid #2a3b4d;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  padding: 0 0.85rem;
  font: inherit;
  cursor: pointer;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.6rem;
  padding: 0;
}

.icon-btn svg {
  width: 1.1rem;
  height: 1.1rem;
}

.cmd {
  min-height: 3.4rem;
  padding: 0.75rem;
  font-size: 0.95rem;
  background: var(--bg-btn);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.cmd svg {
  width: 1.15rem;
  height: 1.15rem;
  flex-shrink: 0;
}

.row.playback .cmd span {
  display: none;
}

.row.playback .cmd svg {
  width: 1.35rem;
  height: 1.35rem;
}

.pad {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1.5rem;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 3.4rem);
  grid-template-areas:
    ". up ."
    "left ok right"
    ". down .";
  gap: 0.55rem;
  margin: 0.25rem 0 0.35rem;
}

.dpad-btn {
  min-height: 3.4rem;
  width: 100%;
}

.dpad-btn.ok {
  background: var(--accent);
  color: #06221f;
  font-size: 1rem;
  font-weight: 700;
}

.dpad-btn.ok.is-pressed:not(:disabled) {
  background: var(--accent-dim);
}

.row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.row:has(.cmd:nth-child(4)) {
  grid-template-columns: repeat(4, 1fr);
}

.cmd:hover:not(:disabled) {
  background: var(--bg-btn-hover);
}

.cmd.wide {
  width: 100%;
}

.cmd.subtle {
  background: transparent;
  border: 1px solid #2a3b4d;
  color: var(--muted);
}

.apps-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
}

.apps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.app-btn {
  text-align: left;
  padding: 0.85rem 0.9rem;
  border: 0;
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.app-btn:hover:not(:disabled) {
  background: var(--bg-btn-hover);
}

.app-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.hint-keys {
  margin: 1rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.error {
  margin-top: 1rem;
  color: var(--danger);
  font-size: 0.9rem;
}

.empty {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  grid-column: 1 / -1;
}
