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

:root {
  --bg: #0a0a0f;
  --bg2: #111118;
  --bg3: #1a1a28;
  --accent: #6c63ff;
  --accent2: #5a52d5;
  --text: #e0e0e0;
  --text2: #666;
  --danger: #e74c3c;
  --warn: #f39c12;
  --success: #2ecc71;
  --border: #222233;
  --radius: 12px;
  --nav-h: 56px;
}

html, body {
  height: 100%; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}

.hidden { display: none !important; }
.screen { height: 100%; width: 100%; position: absolute; inset: 0; }

/* ===== PAIRING ===== */
.pairing-container {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; padding: 20px; gap: 16px;
}
.pairing-icon { font-size: 56px; }
.pairing-container h1 { font-size: 26px; font-weight: 700; color: var(--accent); }
.pairing-container p { color: var(--text2); font-size: 14px; }
.pairing-input-group { width: 100%; max-width: 240px; }
#pairingInput {
  width: 100%; padding: 14px; font-size: 30px; text-align: center;
  letter-spacing: 10px; background: var(--bg2); border: 2px solid var(--border);
  border-radius: var(--radius); color: var(--text); outline: none; font-weight: 700;
}
#pairingInput:focus { border-color: var(--accent); }
.error-msg { color: var(--danger) !important; min-height: 18px; font-size: 13px !important; }

/* ===== BUTTONS ===== */
.btn-primary {
  padding: 14px 40px; font-size: 16px; font-weight: 600;
  background: var(--accent); color: white; border: none;
  border-radius: var(--radius); width: 100%; max-width: 240px;
}
.btn-primary:active { background: var(--accent2); }
.btn-secondary {
  padding: 12px 24px; background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); font-size: 15px;
}
.btn-danger {
  padding: 12px 24px; background: var(--danger); color: white;
  border: none; border-radius: var(--radius); font-size: 15px;
}
.btn-cancel {
  width: 100%; padding: 14px; background: var(--warn); color: #000;
  border: none; border-radius: var(--radius); font-size: 15px;
  font-weight: 600; margin-top: 12px;
}
.btn-mute {
  padding: 10px 20px; background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 15px; margin-top: 12px;
}

/* ===== TABS ===== */
#mainApp {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-pane {
  display: none;
  height: 100%;
  flex-direction: column;
  overflow-y: auto;
}
.tab-pane.active { display: flex; }

/* Screen tab doesn't scroll - split layout */
#tabScreen { overflow: hidden; }

.bottom-nav {
  height: var(--nav-h);
  display: flex;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--text2);
  font-size: 20px; padding: 4px;
}
.nav-btn span { font-size: 10px; }
.nav-btn.active { color: var(--accent); }

/* ===== SCREEN TAB - PORTRAIT LAYOUT ===== */

/* Top half: PC screen */
.viewer-container {
  flex: 1;
  position: relative;
  background: #000;
  touch-action: none;
  min-height: 0;
}

#screenCanvas {
  width: 100%; height: 100%;
  object-fit: contain; display: block;
}

.viewer-topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: rgba(0,0,0,0.6);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  z-index: 5;
}

.viewer-title {
  font-size: 13px; font-weight: 700; color: var(--accent); flex: 1;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }

.quality-select {
  padding: 3px 6px; background: rgba(255,255,255,0.1);
  color: #fff; border: none; border-radius: 6px; font-size: 11px;
  -webkit-appearance: none;
}

.topbar-btn {
  padding: 4px 8px; background: rgba(255,255,255,0.1);
  border: none; border-radius: 6px; font-size: 16px; color: #fff;
}

/* Bottom half: Controls */
.controls-panel {
  flex-shrink: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  position: relative;
}

.controls-row {
  display: flex;
  gap: 14px;
  align-items: center;
}

/* Joystick */
.joystick-area {
  width: 120px; height: 120px;
  position: relative; touch-action: none; flex-shrink: 0;
}

.joystick-base {
  position: absolute; inset: 0; border-radius: 50%;
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.1);
}

.joystick-thumb {
  position: absolute; top: 50%; left: 50%;
  width: 50px; height: 50px; border-radius: 50%;
  background: radial-gradient(circle, rgba(108,99,255,0.85), rgba(108,99,255,0.4));
  border: 2px solid rgba(255,255,255,0.25);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 12px rgba(108,99,255,0.3);
}

/* Action buttons */
.action-col {
  flex: 1; display: flex; flex-direction: column; gap: 6px;
}

.action-row {
  display: flex; gap: 6px;
}

.ctrl-btn {
  flex: 1; padding: 12px 4px;
  border-radius: 10px; border: 1px solid rgba(255,255,255,0.12);
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  color: #fff; touch-action: manipulation;
}
.ctrl-btn:active { transform: scale(0.95); filter: brightness(1.3); }

.ctrl-a { background: rgba(46,204,113,0.35); border-color: rgba(46,204,113,0.5); }
.ctrl-b { background: rgba(231,76,60,0.35); border-color: rgba(231,76,60,0.5); }
.ctrl-x { background: rgba(52,152,219,0.35); border-color: rgba(52,152,219,0.5); }
.ctrl-y { background: rgba(241,196,15,0.35); border-color: rgba(241,196,15,0.5); font-size: 18px; }
.ctrl-scroll { background: rgba(255,255,255,0.06); font-size: 12px; }

/* ===== KEYBOARD PANEL ===== */
.keyboard-panel {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 0 10px 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateY(100%);
  transition: transform 0.2s ease;
  max-height: 70vh;
  overflow-y: auto;
}
.keyboard-panel.visible { transform: translateY(0); }

.kb-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0 8px; position: sticky; top: 0;
  background: var(--bg2); z-index: 1;
}
.kb-title { flex: 1; font-size: 14px; font-weight: 600; color: var(--text2); }

.kb-close {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  background: var(--danger); color: #fff; border: none;
  border-radius: 8px; font-size: 16px; font-weight: 700;
}

.kb-voice {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  background: var(--bg3); color: #fff; border: 1px solid var(--border);
  border-radius: 8px; font-size: 16px;
}
.kb-voice.voice-active {
  background: var(--danger); border-color: var(--danger);
  animation: pulse-voice 1s infinite;
}
@keyframes pulse-voice { 0%,100% { opacity:1; } 50% { opacity:0.5; } }

.kb-input-row { display: flex; gap: 6px; margin-bottom: 8px; }
.kb-input-row input {
  flex: 1; padding: 10px; background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font-size: 15px; outline: none;
}
.kb-input-row input:focus { border-color: var(--accent); }

.kb-send {
  padding: 10px 14px; background: var(--accent); color: #fff;
  border: none; border-radius: 8px; font-size: 16px; font-weight: 700;
}

.kb-shortcuts { display: flex; flex-wrap: wrap; gap: 5px; }
.kb-key {
  padding: 9px 11px; background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; font-weight: 500;
}
.kb-key:active, .kb-key.pressed { background: var(--accent); border-color: var(--accent); }

/* ===== TAB HEADER (for non-screen tabs) ===== */
.tab-header {
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tab-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

/* ===== MEDIA TAB ===== */
.media-section, .volume-section { padding: 20px; text-align: center; }
.media-section h3, .volume-section h3 { font-size: 14px; color: var(--text2); margin-bottom: 16px; }

.media-controls { display: flex; align-items: center; justify-content: center; gap: 16px; }
.media-btn {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); font-size: 24px;
  display: flex; align-items: center; justify-content: center;
}
.media-btn-main { width: 72px; height: 72px; font-size: 32px; background: var(--accent); border: none; }
.media-btn:active { opacity: 0.7; }

.volume-controls { display: flex; align-items: center; gap: 12px; }
.vol-btn { font-size: 24px; background: none; border: none; padding: 8px; }
#volumeSlider {
  flex: 1; height: 6px; -webkit-appearance: none; appearance: none;
  background: var(--bg3); border-radius: 3px; outline: none;
}
#volumeSlider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 24px; height: 24px;
  border-radius: 50%; background: var(--accent);
}

/* ===== FILES TAB ===== */
.files-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg2); flex-shrink: 0; flex-wrap: wrap;
}
.files-nav-btn {
  padding: 6px 12px; background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}
.files-nav-btn:active { background: var(--accent); }
.current-path { font-size: 12px; color: var(--text2); word-break: break-all; flex: 1; min-width: 100%; }
.files-list { flex: 1; overflow-y: auto; }

.file-item {
  display: flex; align-items: center; padding: 12px 16px; gap: 12px;
  border-bottom: 1px solid var(--border);
}
.file-item:active { background: var(--bg3); }
.file-icon { font-size: 24px; flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 11px; color: var(--text2); margin-top: 2px; }
.file-download {
  padding: 6px 10px; background: var(--accent); color: white;
  border: none; border-radius: 6px; font-size: 12px; flex-shrink: 0;
}

/* ===== SYSTEM TAB ===== */
.system-info { padding: 16px; overflow-y: auto; flex: 1; }
.info-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.info-card h4 { font-size: 11px; color: var(--text2); text-transform: uppercase; margin-bottom: 6px; }
.info-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.info-row span:last-child { color: var(--text2); }

.progress-bar { width: 100%; height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; }

.system-actions { padding: 16px; flex-shrink: 0; }
.system-actions h3 { font-size: 14px; color: var(--text2); margin-bottom: 10px; }
.sys-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sys-btn {
  padding: 14px; background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px;
}
.sys-btn:active { opacity: 0.7; }
.sys-btn-warn { border-color: var(--warn); color: var(--warn); }
.sys-btn-danger { border-color: var(--danger); color: var(--danger); }

/* ===== MODAL ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-content {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; max-width: 320px;
  width: 100%; text-align: center;
}
.modal-content p { margin-bottom: 20px; font-size: 16px; }
.modal-actions { display: flex; gap: 12px; justify-content: center; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { display: none; }
* { scrollbar-width: none; }
