:root {
  --hiq-safe-top: 0px;
  --hiq-safe-right: 0px;
  --hiq-safe-bottom: 0px;
  --hiq-safe-left: 0px;

  --lw-cream: #FAF3E3;
  --lw-linen: #F3E6D0;
  --lw-birch: #E7CFA9;
  --lw-birch-edge: #C9A675;
  --lw-walnut: #5C4033;
  --lw-sage: #8DB580;
  --lw-sage-deep: #5E8A52;
  --lw-honey: #F5C45E;
  --lw-coral: #E88B6D;
  --lw-sky: #8FC5E8;
  --lw-font: 'Trebuchet MS', 'Avenir Next Rounded', 'Nunito', 'Rounded Mplus 1c', system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: var(--lw-cream);
  color: var(--lw-walnut);
  font-family: var(--lw-font);
}

body {
  display: flex;
  flex-direction: column;
}

#stage-container {
  position: relative;
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#hiq-safe-probe {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  padding-top: env(safe-area-inset-top, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  visibility: hidden;
  pointer-events: none;
}

/* Strictly hide local-dev QA deck when HearthIQ hosted, Capacitor native, or Electron desktop native */
html[data-hiq-hosted="true"] #qa-deck,
html[data-capacitor-native="true"] #qa-deck,
html[data-desktop-native="true"] #qa-deck {
  display: none !important;
}

html[data-capacitor-native="true"] #hiq-orphan-banner,
html[data-desktop-native="true"] #hiq-orphan-banner {
  display: none !important;
}

/* ==========================================================================
   Local-Dev Collapsible QA Deck (Montessori Wood Strip)
   ========================================================================== */
.qa-deck {
  flex-shrink: 0;
  z-index: 9000;
  background: linear-gradient(180deg, #F8EFE0 0%, #EFE1CA 100%);
  border-bottom: 2px solid #D9BD93;
  color: var(--lw-walnut);
}

.qa-deck-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 12px;
  min-height: 40px;
}

.qa-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.qa-wood-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FFE08A, #E5A93C);
  border: 1.5px solid #B67D24;
  flex-shrink: 0;
}

.qa-brand-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.qa-brand-sub {
  font-size: 12px;
  color: #8A6A52;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 640px) {
  .qa-deck-bar {
    gap: 6px;
    padding: 5px 8px;
  }
  .qa-brand {
    gap: 6px;
    flex-shrink: 0;
  }
  .qa-wood-dot {
    width: 8px;
    height: 8px;
  }
  .qa-brand-sub {
    display: none;
  }
  .qa-brand-title {
    overflow: visible;
    text-overflow: clip;
    max-width: none;
    font-size: 10.5px;
    letter-spacing: 0.01em;
  }
  .qa-quick-pills {
    flex-shrink: 0;
    gap: 4px;
  }
  .qa-status-pill {
    font-size: 10px;
    padding: 2px 7px;
    white-space: nowrap;
  }
  .qa-toggle-btn {
    min-height: 28px;
    padding: 3px 9px;
    font-size: 11px;
  }
}

.qa-quick-pills {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qa-status-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(141, 181, 128, 0.24);
  border: 1.5px solid var(--lw-sage);
  font-size: 12px;
  font-weight: 700;
  color: #3D5B34;
  white-space: nowrap;
}

.qa-toggle-btn {
  min-height: 32px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1.5px solid #C9A675;
  background: #FFF9EE;
  color: var(--lw-walnut);
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.qa-deck-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 8px 12px 10px;
  border-top: 1px solid #DFC9A6;
  background: #F4E8D4;
  max-height: 45vh;
  overflow-y: auto;
}

.qa-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.qa-group-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #856651;
}

.qa-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.qa-chip {
  min-height: 32px;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1.5px solid #D3B88D;
  background: #FFFDF8;
  color: var(--lw-walnut);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.qa-chip.is-active {
  background: var(--lw-sage);
  border-color: var(--lw-sage-deep);
  color: #FFFFFF;
}

.qa-chip-danger {
  border-color: #E09A84;
  background: #FFF2ED;
  color: #9A422B;
}

/* ==========================================================================
   Device Frame Simulator Stage
   ========================================================================== */
.device-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: #EADBC4;
}

html:not([data-device]) .device-stage,
html[data-device="desktop"] .device-stage {
  background: var(--lw-cream);
}

.game-frame {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--lw-cream);
}

html[data-device="iphone"] .device-stage,
html[data-device="ipad"] .device-stage {
  padding: 10px;
}

html[data-device="iphone"] .game-frame {
  width: 390px;
  max-width: 100%;
  height: min(844px, 100%);
  border-radius: 38px;
  border: 6px solid #7C5C47;
  box-shadow: 0 20px 48px rgba(72, 48, 32, 0.28);
}

html[data-device="ipad"] .game-frame {
  width: 820px;
  max-width: 100%;
  height: min(1060px, 100%);
  border-radius: 28px;
  border: 6px solid #7C5C47;
  box-shadow: 0 20px 48px rgba(72, 48, 32, 0.28);
}

/* ==========================================================================
   Warm Montessori Loading & Fallbacks
   ========================================================================== */
#loading-overlay {
  position: fixed;
  inset: 0;
  box-sizing: border-box;
  padding-top: max(var(--hiq-safe-top), env(safe-area-inset-top, 0px));
  padding-right: max(var(--hiq-safe-right), env(safe-area-inset-right, 0px));
  padding-bottom: max(var(--hiq-safe-bottom), env(safe-area-inset-bottom, 0px));
  padding-left: max(var(--hiq-safe-left), env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 42%, #FFFDF8 0%, #FAF3E3 56%, #F1E2C8 100%);
  z-index: 9999;
  transition: opacity 0.42s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.loading-sun {
  font-size: 76px;
  line-height: 1;
  color: var(--lw-honey);
  text-shadow: 0 6px 18px rgba(214, 152, 54, 0.35);
  animation: sunFloat 1.2s ease-in-out infinite;
}

.loading-dots {
  display: flex;
  gap: 12px;
}

.loading-dots span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--lw-coral);
  animation: dotBounce 1.15s ease-in-out infinite;
}

.loading-dots span:nth-child(2) {
  background: var(--lw-sage);
  animation-delay: 0.18s;
}

.loading-dots span:nth-child(3) {
  background: var(--lw-sky);
  animation-delay: 0.36s;
}

@keyframes sunFloat {
  0%, 100% {
    transform: translateY(0) scale(1) rotate(-4deg);
  }
  50% {
    transform: translateY(-12px) scale(1.08) rotate(6deg);
  }
}

@keyframes dotBounce {
  0%, 100% {
    transform: scale(0.82);
    opacity: 0.55;
  }
  50% {
    transform: scale(1.22);
    opacity: 1;
  }
}

/* ==========================================================================
   HearthIQ Orphan Preview Banner & 5s Timeout Fallback Overlay
   ========================================================================== */
.hiq-orphan-banner {
  position: fixed;
  left: max(12px, max(var(--hiq-safe-left), env(safe-area-inset-left, 0px)));
  right: max(12px, max(var(--hiq-safe-right), env(safe-area-inset-right, 0px)));
  bottom: max(12px, max(var(--hiq-safe-bottom), env(safe-area-inset-bottom, 0px)));
  margin: 0 auto;
  max-width: 560px;
  padding: 8px 12px 8px 16px;
  border-radius: 26px;
  border: 2px solid var(--lw-birch-edge);
  background: rgba(255, 251, 243, 0.96);
  box-shadow: 0 10px 26px rgba(92, 64, 51, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--lw-walnut);
  font-size: 13px;
  font-weight: 700;
  z-index: 9500;
}

.hiq-orphan-banner.hidden,
.hiq-fallback-overlay.hidden {
  display: none !important;
}

.hiq-orphan-text {
  flex: 1 1 auto;
}

.hiq-orphan-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 22px;
  background: linear-gradient(135deg, #8DB580 0%, #689459 100%);
  color: #FFFFFF;
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
  touch-action: manipulation;
}

.hiq-orphan-dismiss {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: 2px solid #DEC49D;
  border-radius: 50%;
  background: #FAF3E3;
  color: var(--lw-walnut);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.hiq-fallback-overlay {
  position: fixed;
  inset: 0;
  padding-top: max(16px, max(var(--hiq-safe-top), env(safe-area-inset-top, 0px)));
  padding-right: max(16px, max(var(--hiq-safe-right), env(safe-area-inset-right, 0px)));
  padding-bottom: max(16px, max(var(--hiq-safe-bottom), env(safe-area-inset-bottom, 0px)));
  padding-left: max(16px, max(var(--hiq-safe-left), env(safe-area-inset-left, 0px)));
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 42%, #FFFDF8 0%, #FAF3E3 56%, #EFE1CA 100%);
  z-index: 9998;
}

.hiq-fallback-card {
  width: min(420px, 100%);
  padding: 28px 24px;
  border-radius: 28px;
  border: 3px solid var(--lw-birch-edge);
  background: #FFFDF8;
  box-shadow: 0 16px 38px rgba(92, 64, 51, 0.18);
  text-align: center;
  color: var(--lw-walnut);
}

.hiq-fallback-emblem {
  font-size: 46px;
  color: var(--lw-honey);
  line-height: 1;
  margin-bottom: 10px;
}

.hiq-fallback-title {
  margin: 0 0 10px;
  font-size: 24px;
  color: var(--lw-walnut);
}

.hiq-fallback-desc {
  margin: 0 0 22px;
  font-size: 15px;
  line-height: 1.45;
  color: #7D5E4A;
}

.hiq-fallback-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.hiq-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 124px;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: 24px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.hiq-btn-primary {
  border: 0;
  background: linear-gradient(135deg, #8DB580 0%, #689459 100%);
  color: #FFFFFF;
}

.hiq-btn-secondary {
  border: 2px solid var(--lw-birch-edge);
  background: #FAF3E3;
  color: var(--lw-walnut);
}

/* ==========================================================================
   Companion Account Sync Modal (Strictly behind Parental Gate)
   ========================================================================== */
.lw-companion-modal,
.pw-companion-modal {
  position: fixed;
  inset: 0;
  padding-top: max(16px, max(var(--hiq-safe-top), env(safe-area-inset-top, 0px)));
  padding-right: max(16px, max(var(--hiq-safe-right), env(safe-area-inset-right, 0px)));
  padding-bottom: max(16px, max(var(--hiq-safe-bottom), env(safe-area-inset-bottom, 0px)));
  padding-left: max(16px, max(var(--hiq-safe-left), env(safe-area-inset-left, 0px)));
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(62, 42, 28, 0.56);
  z-index: 9800;
  overflow-y: auto;
}

.lw-companion-card,
.pw-companion-card {
  width: min(440px, 100%);
  padding: 22px;
  border-radius: 26px;
  border: 3px solid var(--lw-birch-edge);
  background: #FFFDF8;
  box-shadow: 0 18px 40px rgba(62, 42, 28, 0.25);
  color: var(--lw-walnut);
}

.lw-companion-header,
.pw-companion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.lw-companion-title,
.pw-companion-title {
  margin: 0;
  font-size: 20px;
}

.lw-companion-close,
.pw-companion-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: 2px solid #DEC49D;
  border-radius: 50%;
  background: #FAF3E3;
  color: var(--lw-walnut);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.lw-companion-status,
.pw-companion-status {
  padding: 10px 12px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: #F4E9D4;
  border: 1.5px solid #DEC49D;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.lw-companion-form,
.pw-companion-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lw-companion-field,
.pw-companion-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lw-companion-label,
.pw-companion-label {
  font-size: 13px;
  font-weight: 800;
  color: #7D5E4A;
}

.lw-companion-input,
.pw-companion-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 2px solid #DEC49D;
  background: #FFFFFF;
  color: var(--lw-walnut);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  user-select: text;
  -webkit-user-select: text;
}

.lw-companion-feedback,
.pw-companion-feedback {
  margin: 0;
  min-height: 18px;
  font-size: 13px;
  font-weight: 700;
  color: #B44D36;
}

.lw-companion-actions,
.pw-companion-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.lw-companion-btn,
.pw-companion-btn {
  min-width: 96px;
}
