:root {
  --bg-main: #0a0e17;
  --bg-card: rgba(18, 24, 38, 0.85);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-card-hover: rgba(26, 34, 52, 0.95);
  
  --primary: #3b82f6;
  --primary-glow: rgba(59, 130, 246, 0.4);
  --accent: #06b6d4;
  --success: #10b981;
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.4);
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.08) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  user-select: none;
}

.app-container {
  width: 100%;
  max-width: 480px;
  padding: 16px 14px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sub-target {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: monospace;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--text-dim);
}

.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.btn-icon:active {
  transform: scale(0.94);
}

.btn-icon.power {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.25);
  background: rgba(239, 68, 68, 0.08);
}

.btn-icon.power:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--accent);
  animation: pulse-anim 1.6s infinite;
}

@keyframes pulse-anim {
  0% { transform: scale(0.9); opacity: 1; box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.7); }
  70% { transform: scale(1.1); opacity: 0.8; box-shadow: 0 0 0 8px rgba(6, 182, 212, 0); }
  100% { transform: scale(0.9); opacity: 1; }
}

.preview-controls {
  display: flex;
  gap: 6px;
}

.select-pill, .btn-pill {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 10px;
  cursor: pointer;
  outline: none;
}

.btn-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
}

.btn-pill:hover, .select-pill:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

/* Screen Wrapper */
.screen-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}

.screen-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.2s ease;
}

.screen-loader {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.screen-loader.active {
  opacity: 1;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Active App Bar */
.active-app-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  gap: 10px;
}

.app-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-info .label {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.app-name-wrap strong {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  display: block;
}

.app-name-wrap small {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 0 12px var(--danger-glow);
}

.btn-danger:active {
  transform: scale(0.94);
}

/* Quick Control Row */
.quick-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.btn-ctrl {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  padding: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-ctrl:active {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(0.95);
}

/* D-PAD */
.dpad-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px 0 18px;
}

.dpad {
  position: relative;
  width: 210px;
  height: 210px;
  background: rgba(14, 20, 32, 0.95);
  border: 2px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius-full);
  box-shadow: 
    0 10px 25px rgba(0, 0, 0, 0.6),
    inset 0 2px 10px rgba(255, 255, 255, 0.05);
}

.dpad-btn {
  position: absolute;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.dpad-btn:hover {
  color: #fff;
}

.dpad-btn:active {
  color: var(--accent);
  transform: scale(0.92);
}

.dpad-btn.up {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 50px;
}
.dpad-btn.up:active {
  transform: translateX(-50%) translateY(2px) scale(0.92);
}

.dpad-btn.down {
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 50px;
}
.dpad-btn.down:active {
  transform: translateX(-50%) translateY(-2px) scale(0.92);
}

.dpad-btn.left {
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 60px;
}
.dpad-btn.left:active {
  transform: translateY(-50%) translateX(2px) scale(0.92);
}

.dpad-btn.right {
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 60px;
}
.dpad-btn.right:active {
  transform: translateY(-50%) translateX(-2px) scale(0.92);
}

.dpad-btn.ok {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.05em;
  color: #fff;
}

.dpad-btn.ok:active {
  background: var(--primary);
  border-color: #60a5fa;
  box-shadow: 0 0 20px var(--primary-glow);
  transform: translate(-50%, -50%) scale(0.92);
}

/* Essential Keys */
.essential-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.btn-key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  padding: 12px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-key:active {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.94);
}

.btn-key.home {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.3);
  color: #93c5fd;
}

.btn-key.home:active {
  background: var(--primary);
  color: #fff;
}

/* Playback Row */
.playback-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
}

.btn-play {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-play.primary {
  width: 52px;
  height: 52px;
  background: var(--accent);
  color: #042f2e;
  border: none;
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.35);
}

.btn-play:active {
  transform: scale(0.92);
}

/* Keyboard Text Card */
.card-title-sm {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.text-hint {
  font-size: 0.7rem;
  color: var(--accent);
  background: rgba(6, 182, 212, 0.12);
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

.text-form-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.text-input-row {
  position: relative;
  display: flex;
  align-items: center;
}

.text-input-row input {
  width: 100%;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 12px 38px 12px 14px;
  color: var(--text-main);
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
  transition: all 0.2s ease;
}

.text-input-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 14px var(--primary-glow);
  background: rgba(0, 0, 0, 0.65);
}

.btn-clear-field {
  position: absolute;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.btn-clear-field.visible {
  display: flex;
}

.text-actions-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
}

.btn-action-primary {
  background: linear-gradient(135deg, var(--primary) 0%, #2563eb 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 11px 16px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 14px var(--primary-glow);
  transition: all 0.15s ease;
}

.btn-action-primary:active {
  transform: scale(0.96);
}

.btn-action-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-action-secondary:active {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.96);
}

/* Typing Tools Row */
.typing-tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.btn-tool {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.btn-tool:hover, .btn-tool:active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  transform: translateY(-1px);
}

.btn-tool.danger {
  color: #f87171;
}

.btn-tool.danger:hover, .btn-tool.danger:active {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.4);
}

/* Apps Grid */
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.apps-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 6px;
}

.apps-grid::-webkit-scrollbar {
  width: 4px;
}
.apps-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}

.app-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.app-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(6, 182, 212, 0.4);
}

.app-chip:active {
  transform: scale(0.98);
}

.app-chip-left {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.app-chip-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #1d4ed8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.app-chip-details {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-chip-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-chip-pkg {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: monospace;
}

.app-chip-action {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(6, 182, 212, 0.1);
  padding: 5px 10px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  border: 1px solid rgba(6, 182, 212, 0.2);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: #111726;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.power-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-power-action {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 12px;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-power-action:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-power-action:active {
  transform: scale(0.97);
}

.btn-power-action.danger {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.06);
}

.btn-power-action.danger:hover {
  background: rgba(239, 68, 68, 0.15);
}

.icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-wrap.sleep { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; }
.icon-wrap.wake { background: rgba(6, 182, 212, 0.15); color: var(--accent); }
.icon-wrap.reboot { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.icon-wrap.shutdown { background: rgba(239, 68, 68, 0.2); color: #f87171; }

.action-text strong {
  display: block;
  font-size: 0.9rem;
}

.action-text span {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--accent);
  color: var(--text-main);
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  z-index: 200;
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
}

/* Login Page Styles */
.login-body {
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-card);
  text-align: center;
  margin: 20px;
}

.tv-icon-glow {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-lg);
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #60a5fa;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: 0 0 25px rgba(59, 130, 246, 0.25);
}

.login-header h2 {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.login-header p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.input-group input {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
}

.input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.3);
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:active {
  transform: scale(0.97);
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  margin-bottom: 16px;
  text-align: left;
}

.login-footer {
  margin-top: 24px;
  font-size: 0.75rem;
  color: var(--text-dim);
}
