:root {
  --bg-deep: #0b1120;
  --bg-card: #162036;
  --bg-surface: #1e293b;
  --border-subtle: rgba(148, 163, 184, 0.18);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --accent-shadow: #0369a1;
  --success: #22c55e;
  --warning: #f59e0b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Thai', sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
  user-select: none;
}

.app-root {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 50% 0%, #1e293b 0%, var(--bg-deep) 68%);
}

/* ===== Launcher / Home Screen ===== */
.launcher-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 20px) calc(var(--safe-left) + 16px);
  overflow-y: auto;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid var(--border-subtle);
  font-size: 13px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

.status-pill.is-installed .status-dot {
  background: var(--success);
}

.icon-btn {
  width: 46px;
  height: 46px;
  min-width: 46px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: rgba(30, 41, 59, 0.85);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

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

.hero-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px 8px;
  gap: 14px;
}

.app-emblem {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  box-shadow: 0 16px 36px rgba(2, 132, 199, 0.32);
  object-fit: cover;
}

.app-title {
  margin: 4px 0 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.app-tagline {
  margin: 0;
  font-size: 15px;
  color: var(--text-muted);
  max-width: 280px;
}

/* Quick URL Box for Phase 1 testing */
.test-url-card {
  width: 100%;
  max-width: 380px;
  margin-top: 8px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(22, 32, 54, 0.9);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.test-url-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.url-input-row {
  display: flex;
  gap: 8px;
}

.url-input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-deep);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  user-select: text;
}

.url-input:focus {
  border-color: var(--accent);
}

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

.mode-chip {
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.mode-chip.is-active {
  border-color: var(--accent);
  color: var(--text-main);
  background: rgba(56, 189, 248, 0.14);
}

.mode-chip:active {
  transform: scale(0.97);
}

/* Thumb Zone Actions */
.bottom-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
}

.btn-hero {
  min-width: 240px;
  height: 54px;
  padding: 0 28px;
  border: none;
  border-radius: 18px;
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
  color: #ffffff;
  font-size: 17px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 5px 0 var(--accent-shadow), 0 12px 24px rgba(2, 132, 199, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-hero:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--accent-shadow), 0 6px 14px rgba(2, 132, 199, 0.25);
}

.secondary-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-ghost {
  height: 46px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.btn-ghost:active {
  transform: scale(0.96);
  opacity: 0.75;
}

.btn-ghost.highlight {
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.08);
}

/* ===== Fullscreen Game Frame View ===== */
.game-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  background: #000000;
}

.game-view.is-open {
  display: flex;
}

.game-iframe {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background: #000000;
}

/* Floating quick pill (safe-area aware) */
.floating-dock {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  right: calc(var(--safe-right) + 12px);
  z-index: 30;
  display: flex;
  gap: 8px;
}

.dock-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(8px);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

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

/* ===== In-App Modals ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.modal-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  border-radius: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform: translateY(10px) scale(0.98);
  transition: transform 0.18s ease;
}

.modal-backdrop.is-open .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.step-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border-subtle);
  font-size: 14px;
  line-height: 1.4;
}

.step-icon {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.contact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.contact-card {
  min-height: 82px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.contact-card:active {
  transform: scale(0.96);
}

.modal-footer {
  display: flex;
  justify-content: center;
}

.btn-pill {
  width: fit-content;
  min-width: 140px;
  height: 46px;
  padding: 0 24px;
  border-radius: 999px;
  border: none;
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

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

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 24px);
  transform: translateX(-50%) translateY(16px);
  z-index: 80;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid var(--border-subtle);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.hidden {
  display: none !important;
}

@media (max-height: 690px) {
  .app-emblem {
    width: 76px;
    height: 76px;
    border-radius: 20px;
  }
  .app-title {
    font-size: 22px;
  }
  .hero-section {
    padding: 10px 8px;
    gap: 10px;
  }
}
