:root {
  --hiq-safe-top: 0px;
  --hiq-safe-right: 0px;
  --hiq-safe-bottom: 0px;
  --hiq-safe-left: 0px;
  --pw-cream: #FFFBF3;
  --pw-gold: #DFB872;
  --pw-teal: #17464F;
  --pw-ink: #5C3A21;
  --pw-sage: #72C7B0;
  --pw-honey: #E8B563;
}

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: #FFFBF3;
  color: #5C3A21;
  font-family: 'Trebuchet MS', 'Nunito', 'Rounded Mplus 1c', sans-serif;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Optional QA viewport preview framing when toggled via #qa-deck */
html[data-qa-frame="iphone"] body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #231D19;
}

html[data-qa-frame="iphone"] canvas {
  width: 390px !important;
  height: 844px !important;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 32px;
  border: 4px solid #DFB872;
  box-shadow: 0 20px 52px rgba(23, 70, 79, 0.45);
}

html[data-qa-frame="ipad"] body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #231D19;
}

html[data-qa-frame="ipad"] canvas {
  width: 1024px !important;
  height: 768px !important;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 22px;
  border: 4px solid #DFB872;
  box-shadow: 0 20px 52px rgba(23, 70, 79, 0.45);
}

#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;
}

#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%, #FFFBF3 55%, #F6E9CE 100%);
  z-index: 9999;
  transition: opacity 0.45s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 38px;
  border-radius: 28px;
  border: 3px solid #DFB872;
  background: rgba(255, 251, 243, 0.96);
  box-shadow: 0 16px 38px rgba(92, 58, 33, 0.16);
}

.loading-paw {
  font-size: 72px;
  line-height: 1;
  filter: drop-shadow(0 6px 14px rgba(223, 184, 114, 0.65));
  animation: pawBounce 1.15s ease-in-out infinite;
}

.loading-title {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.4px;
  color: #17464F;
}

.loading-dots {
  display: flex;
  gap: 10px;
}

.loading-dots span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #DFB872;
  animation: dotPulse 1.1s ease-in-out infinite;
}

.loading-dots span:nth-child(2) {
  background: #72C7B0;
  animation-delay: 0.18s;
}

.loading-dots span:nth-child(3) {
  background: #17464F;
  animation-delay: 0.36s;
}

.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: 520px;
  box-sizing: border-box;
  padding: 8px 12px 8px 16px;
  border-radius: 28px;
  border: 2px solid #DFB872;
  background: rgba(255, 251, 243, 0.97);
  box-shadow: 0 8px 24px rgba(92, 58, 33, 0.22);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #5C3A21;
  font-size: 14px;
  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 14px;
  border-radius: 22px;
  background: linear-gradient(135deg, #17464F 0%, #2B6D78 100%);
  border: 1.5px solid #DFB872;
  color: #FFFBF3;
  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 #DFB872;
  border-radius: 50%;
  background: #FFFBF3;
  color: #5C3A21;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.hiq-fallback-overlay {
  position: fixed;
  inset: 0;
  box-sizing: border-box;
  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%, #FFFBF3 55%, #F6E9CE 100%);
  z-index: 9998;
}

.hiq-fallback-card {
  width: min(420px, 100%);
  box-sizing: border-box;
  padding: 28px 24px;
  border-radius: 28px;
  border: 3px solid #DFB872;
  background: #FFFBF3;
  box-shadow: 0 14px 36px rgba(92, 58, 33, 0.22);
  text-align: center;
  color: #5C3A21;
}

.hiq-fallback-star {
  font-size: 46px;
  line-height: 1;
  margin-bottom: 10px;
}

.hiq-fallback-title {
  margin: 0 0 10px;
  font-size: 24px;
  color: #17464F;
}

.hiq-fallback-desc {
  margin: 0 0 22px;
  font-size: 15px;
  line-height: 1.45;
  color: #5C3A21;
}

.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: 120px;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, filter 0.12s ease;
}

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

.hiq-btn-primary {
  border: 2px solid #DFB872;
  background: linear-gradient(135deg, #17464F 0%, #246773 100%);
  color: #FFFBF3;
}

.hiq-btn-secondary {
  border: 2px solid #DFB872;
  background: #FFF6E5;
  color: #5C3A21;
}

html[data-capacitor-native="true"] #hiq-orphan-banner,
html[data-capacitor-native="true"] #qa-deck,
html[data-hiq-hosted="true"] #qa-deck {
  display: none !important;
}

/* Warm Parchment Companion & In-App Modal Styles */
.pw-companion-modal,
.pw-dom-modal {
  position: fixed;
  inset: 0;
  box-sizing: border-box;
  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(23, 70, 79, 0.56);
  backdrop-filter: blur(4px);
  z-index: 9800;
  overflow-y: auto;
}

.pw-companion-card,
.pw-dom-card {
  width: min(460px, 100%);
  box-sizing: border-box;
  padding: 22px;
  border-radius: 26px;
  border: 3px solid #DFB872;
  background: #FFFBF3;
  box-shadow: 0 18px 44px rgba(92, 58, 33, 0.34);
  color: #5C3A21;
}

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

.pw-companion-title {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  color: #17464F;
}

.pw-companion-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: 2px solid #DFB872;
  border-radius: 50%;
  background: #FFF6E5;
  color: #5C3A21;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.pw-companion-status {
  padding: 10px 12px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: #F4ECE0;
  border: 1.5px solid #DFB872;
  font-size: 13px;
  font-weight: 700;
  color: #17464F;
  line-height: 1.35;
}

.pw-companion-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pw-companion-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pw-companion-label {
  font-size: 13px;
  font-weight: 800;
  color: #5C3A21;
}

.pw-companion-input {
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 14px;
  border: 2px solid #DFB872;
  background: #FFFFFF;
  color: #5C3A21;
  font-size: 16px;
  font-weight: 600;
  user-select: text;
  -webkit-user-select: text;
}

.pw-companion-input:focus {
  outline: none;
  border-color: #17464F;
  box-shadow: 0 0 0 3px rgba(23, 70, 79, 0.16);
}

.pw-companion-feedback {
  margin: 0;
  min-height: 18px;
  font-size: 13px;
  font-weight: 700;
  color: #17464F;
}

.pw-companion-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.pw-companion-btn {
  min-width: 96px;
}

/* Collapsible QA Deck (hidden automatically in native Capacitor & hosted HearthIQ) */
#qa-deck {
  position: fixed;
  top: auto;
  left: auto;
  right: max(12px, max(var(--hiq-safe-right), env(safe-area-inset-right, 0px)));
  bottom: max(10px, max(var(--hiq-safe-bottom), env(safe-area-inset-bottom, 0px)));
  z-index: 9600;
  width: auto;
  max-width: min(272px, calc(100vw - 24px));
  border-radius: 16px;
  border: 2px solid #DFB872;
  background: rgba(255, 251, 243, 0.96);
  box-shadow: 0 10px 28px rgba(92, 58, 33, 0.25);
  color: #5C3A21;
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  touch-action: manipulation;
}

#qa-deck.collapsed .qa-deck-body {
  display: none;
}

.qa-deck-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: #17464F;
  color: #FFFBF3;
  cursor: pointer;
}

.qa-deck-title {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.3px;
}

.qa-deck-toggle {
  border: 1.5px solid #DFB872;
  border-radius: 10px;
  background: #FFFBF3;
  color: #17464F;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 8px;
  cursor: pointer;
}

.qa-deck-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  max-height: 75vh;
  overflow-y: auto;
}

.qa-deck-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.qa-deck-label {
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #17464F;
}

.qa-deck-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.qa-deck-btn {
  flex: 1 1 auto;
  min-height: 30px;
  padding: 4px 8px;
  border-radius: 10px;
  border: 1.5px solid #DFB872;
  background: #FFF6E5;
  color: #5C3A21;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.qa-deck-btn:hover {
  background: #F7E8C9;
}

.qa-deck-btn.active {
  background: #17464F;
  color: #FFFBF3;
  border-color: #17464F;
}

.qa-deck-btn.danger {
  background: #FFF0ED;
  border-color: #E08A79;
  color: #8A2D1E;
}

@keyframes pawBounce {
  0%, 100% {
    transform: translateY(0) scale(1) rotate(-5deg);
  }
  50% {
    transform: translateY(-12px) scale(1.12) rotate(6deg);
  }
}

@keyframes dotPulse {
  0%, 100% {
    transform: scale(0.8);
    opacity: 0.55;
  }
  50% {
    transform: scale(1.22);
    opacity: 1;
  }
}
