:root {
  --bg-canvas: #0b0f17;
  --bg-surface: #131924;
  --bg-inset: #090d14;
  --border-subtle: #1e293b;
  --btn-ghost: #1b2434;
  --btn-ghost-border: #2d3b52;
  --accent-blue: #0284c7;
  --accent-blue-active: #0369a1;
  --accent-green: #059669;
  --accent-green-active: #047857;
  --accent-red: #dc2626;
  --accent-red-active: #b91c1c;
  --accent-amber: #f59e0b;
  --text-primary: #f1f5f9;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

/* ==================== LOGIN VIEW ==================== */
.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + env(safe-area-inset-top)) 18px calc(20px + env(safe-area-inset-bottom));
  background: radial-gradient(circle at top, #132238 0%, var(--bg-canvas) 62%);
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 22px 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.login-logo {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  flex-shrink: 0;
}

.login-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.login-subtitle {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.text-input {
  width: 100%;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--btn-ghost-border);
  background: var(--bg-inset);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 16px;
  outline: none;
}

.text-input:focus {
  border-color: var(--accent-blue);
}

.form-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(220, 38, 38, 0.14);
  border: 1px solid rgba(220, 38, 38, 0.45);
  color: #fca5a5;
  font-size: 13px;
}

.btn-primary {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--accent-blue);
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary:active {
  background: var(--accent-blue-active);
}

/* ==================== APP SHELL ==================== */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  background: var(--bg-canvas);
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.device-info {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex: 1;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  flex-shrink: 0;
}

.dot-ok {
  background: #10b981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.65);
}

.dot-warn {
  background: var(--accent-amber);
}

.dot-err {
  background: #ef4444;
}

.device-text {
  min-width: 0;
  flex: 1;
}

.emulator-name {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-meta {
  font-size: 10px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.run-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-idle {
  background: rgba(56, 189, 248, 0.1);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.25);
}

.badge-running {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.5);
}

.btn-ghost {
  background: var(--btn-ghost);
  color: var(--text-primary);
  border: 1px solid var(--btn-ghost-border);
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.btn-ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-compact {
  min-height: 28px;
  padding: 0 7px;
  font-size: 11px;
}

.btn-logout {
  color: var(--text-muted);
}

/* ==================== LIVE STAGE ==================== */
.stage-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 4px;
  background: var(--bg-inset);
}

.game-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.game-screen {
  display: block;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 0 0 1px var(--border-subtle);
  background: #000000;
  transform-origin: center center;
  will-change: transform;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.tap-ripple {
  position: fixed;
  width: 30px;
  height: 30px;
  margin-left: -15px;
  margin-top: -15px;
  border-radius: 999px;
  border: 2px solid #38bdf8;
  background: rgba(56, 189, 248, 0.25);
  animation: ripple-out 0.36s ease-out forwards;
}

@keyframes ripple-out {
  from {
    transform: scale(0.45);
    opacity: 0.95;
  }
  to {
    transform: scale(1.45);
    opacity: 0;
  }
}

.stream-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  border-radius: 12px;
  border: 1px dashed var(--btn-ghost-border);
  background: rgba(11, 15, 23, 0.85);
  pointer-events: none;
}

.overlay-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.overlay-sub {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 260px;
  line-height: 1.45;
}

/* HUD Fullscreen */
.stage-hud {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  left: calc(8px + env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 5px;
  z-index: 25;
  pointer-events: none;
}

.stage-hud > * {
  pointer-events: auto;
}

.hud-pill {
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  background: rgba(19, 25, 36, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.3);
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.hud-pill.active-pan {
  background: rgba(2, 132, 199, 0.88);
  border-color: rgba(56, 189, 248, 0.55);
  color: #ffffff;
}

.hud-toggle {
  background: rgba(5, 150, 105, 0.86);
  border-color: rgba(52, 211, 153, 0.45);
  color: #ffffff;
}

.hud-toggle.is-running {
  background: rgba(220, 38, 38, 0.88);
  border-color: rgba(248, 113, 113, 0.55);
  color: #ffffff;
}

.hud-exit {
  background: rgba(2, 132, 199, 0.88);
  border-color: rgba(56, 189, 248, 0.55);
  color: #ffffff;
}

.hud-restore {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  height: 26px;
  padding: 0 9px;
  gap: 5px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 25;
}

.restore-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #38bdf8;
}

.restore-dot.running {
  background: #10b981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.85);
}

.restore-label {
  font-size: 10px;
  font-weight: 700;
  color: #e2e8f0;
}

/* Che do Toan man hinh */
.app-shell.fullscreen .top-bar,
.app-shell.fullscreen .taskbar {
  display: none;
}

.app-shell.fullscreen .stage-wrap {
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background: #000000;
}

.app-shell.fullscreen .game-screen {
  border-radius: 0;
  box-shadow: none;
}

/* ==================== BOTTOM TASKBAR ==================== */
.taskbar {
  flex-shrink: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.app-shell.compact .taskbar-extras {
  display: none;
}

.utility-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.utility-nav,
.utility-right {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.chip-mini {
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-inset);
  border: 1px solid var(--btn-ghost-border);
  cursor: pointer;
}

.chip-nav {
  background: var(--btn-ghost);
  color: #e2e8f0;
}

.chip-nav:active {
  background: var(--accent-blue);
  color: #ffffff;
}

.chip-mini.active-pan {
  background: var(--accent-blue);
  border-color: #38bdf8;
  color: #ffffff;
}

.taskbar-extras {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mode-strip {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 3px;
}

.btn-test {
  min-height: 38px;
  padding: 0 10px;
  font-size: 11.5px;
  flex-shrink: 0;
}

.mode-chip {
  min-height: 32px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 700;
  padding: 0 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-chip.active {
  background: var(--accent-blue);
  color: #ffffff;
}

.mode-chip:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.cta-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-collapse {
  min-height: 42px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.btn-start,
.btn-stop {
  flex: 1;
  min-height: 42px;
  border: 0;
  border-radius: 11px;
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}

.btn-start {
  background: var(--accent-green);
}

.btn-start:active {
  background: var(--accent-green-active);
}

.btn-stop {
  background: var(--accent-red);
}

.btn-stop:active {
  background: var(--accent-red-active);
}

.btn-logs {
  min-height: 42px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  flex-shrink: 0;
}

.log-count {
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bg-inset);
  color: #38bdf8;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ==================== LOG DRAWER ==================== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}

.log-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: min(68dvh, 520px);
  background: var(--bg-surface);
  border-top: 1px solid var(--btn-ghost-border);
  border-radius: 16px 16px 0 0;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  z-index: 50;
  box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.5);
}

.drawer-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--btn-ghost-border);
  margin: 0 auto 8px;
  flex-shrink: 0;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.drawer-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.drawer-actions {
  display: flex;
  gap: 6px;
}

.log-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  color: #cbd5e1;
}

.log-line {
  word-break: break-word;
  padding: 1px 0;
}

/* ==================== TOAST ==================== */
.toast {
  position: fixed;
  left: 50%;
  top: calc(58px + env(safe-area-inset-top));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(19, 25, 36, 0.96);
  border: 1px solid var(--btn-ghost-border);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  z-index: 60;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
