/* ============================================
   RESPONSIVE — Mobile & Tablet Overrides
   All rules scoped to max-width ≤1023px.
   Desktop (≥1024px) is NEVER affected.
   ============================================ */

/* ============================================
   OVERFLOW SAFETY — Prevent horizontal scroll
   ============================================ */
@media (max-width: 1023px) {
  html, body {
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
}

/* ============================================
   TABLET — ≤1023px
   ============================================ */
@media (max-width: 1023px) {
  /* Disable VanillaTilt glare artifact on touch */
  .js-tilt-glare {
    display: none !important;
  }
}

/* ============================================
   SMALL TABLET / LARGE PHONE — ≤768px
   ============================================ */
@media (max-width: 768px) {

  /* --- Page Overlay --- */
  #page-content {
    width: 95vw;
    padding: var(--space-xl) var(--space-lg);
    max-height: 92vh;
    border-radius: var(--radius-md);
  }

  /* Hide map legend — tooltips are always visible at this breakpoint */
  .map-legend {
    display: none;
  }

  /* Reduce ornamental inner border on mobile */
  #page-content::before {
    inset: 5px;
  }

  /* --- Back to Map — ensure minimum 44px tap target --- */
  #back-to-map {
    min-width: 44px;
    min-height: 44px;
    padding: 10px 16px;
    font-size: 0.8rem;
  }

  /* --- Hotspot Touch Improvements --- */
  .hotspot {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  /* Expand click area for easier tapping */
  .hotspot-click-area {
    inset: -15px;
  }

  /* Hide tooltips on mobile since the background image already contains the labels */
  .hotspot-tooltip {
    display: none !important;
  }

  /* --- Experience Page — wrap header on narrow screens --- */
  .experience-header {
    flex-wrap: wrap;
  }

  .experience-title {
    font-size: clamp(1.1rem, 3.5vw, 1.4rem);
  }

  .experience-company {
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  }

  /* --- Contact Page — stack label/value vertically --- */
  .contact-links li {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .contact-label {
    font-size: 0.95rem;
  }

  .contact-value {
    font-size: 0.9rem;
    word-break: break-all;
  }

  /* --- Certificates Grid — smaller min for narrow screens --- */
  .certificates-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
  }

  /* --- About: Cyber Card — scale down --- */
  .cyber-container {
    width: 200px;
    height: 280px;
  }

  .title {
    font-size: 22px;
    letter-spacing: 2px;
  }

  #prompt {
    font-size: 13px;
    bottom: 80px;
  }

  .subtitle {
    font-size: 10px;
    bottom: 30px;
  }

  /* --- Mobile Nav Bar --- */
  .mobile-nav {
    display: flex;
  }

  .mobile-nav-toggle {
    display: flex;
  }
}

/* ============================================
   STANDARD PHONE — ≤480px
   ============================================ */
@media (max-width: 480px) {

  /* --- Page Overlay --- */
  #page-content {
    width: 98vw;
    padding: var(--space-lg) var(--space-md);
    max-height: 95vh;
    border-radius: var(--radius-sm);
  }

  /* Hide ornamental border on very small screens — save space */
  #page-content::before {
    display: none;
  }

  /* --- Page Header --- */
  .page-header {
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
  }

  .page-header::after {
    font-size: 0.9rem;
    bottom: -9px;
    padding: 0 8px;
  }

  /* --- Back to Map — compact but tappable --- */
  #back-to-map {
    top: 8px;
    left: 8px;
    padding: 8px 12px;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
  }

  /* Hide text, keep icon only */
  #back-to-map span:not(.back-icon) {
    display: none;
  }

  .back-icon {
    font-size: 1.3em;
  }

  /* --- Experience Page --- */
  .experience-card {
    padding: var(--space-lg);
  }

  .experience-icon {
    font-size: 2rem;
  }

  .experience-body p {
    font-size: 0.95rem;
    line-height: 1.65;
  }

  .experience-footer .cert-btn {
    width: 100%;
    justify-content: center;
    padding: 10px 14px;
    font-size: 0.85rem;
  }

  /* --- Certificates --- */
  .certificates-grid {
    grid-template-columns: 1fr;
  }

  .certificate-card {
    padding: var(--space-lg) var(--space-md);
  }

  .cert-icon {
    font-size: 2.5rem;
  }

  .cert-name {
    font-size: 1.05rem;
  }

  .cert-btn {
    width: 100%;
    font-size: 0.85rem;
    padding: 10px 14px;
  }

  /* --- Contact --- */
  .contact-form-container {
    padding: var(--space-lg);
  }

  .contact-input,
  .contact-textarea {
    font-size: 16px; /* Prevent iOS auto-zoom */
  }

  /* --- About: Cyber Card — scale further --- */
  .cyber-container {
    width: 180px;
    height: 252px;
  }

  .cyber-card-section {
    padding: var(--space-md) 0 var(--space-lg);
  }

  .title {
    font-size: 18px;
    letter-spacing: 1px;
    padding-top: 14px;
  }

  #prompt {
    font-size: 11px;
    bottom: 65px;
  }

  .subtitle {
    font-size: 9px;
    bottom: 22px;
  }

  /* --- About: Profile Stats --- */
  .profile-stat {
    padding: var(--space-sm) var(--space-md);
  }

  /* --- About: Story Journal --- */
  .story-journal {
    padding: var(--space-md);
    padding-left: calc(var(--space-md) + 6px);
  }

  .story-journal p {
    font-size: 0.88rem;
    line-height: 1.75;
  }

  .story-journal p:first-child::first-letter {
    font-size: 1.8em;
  }

  /* --- About: Quest Items --- */
  .quest-board {
    padding: var(--space-md);
  }

  .quest-item {
    padding: 8px 6px;
    gap: 8px;
  }

  .quest-text {
    font-size: 0.8rem;
  }


}

/* ============================================
   SMALL PHONE — ≤414px
   ============================================ */
@media (max-width: 414px) {
  /* Fine-tune section headings */
  .section-heading h2 {
    font-size: clamp(1rem, 4.5vw, 1.5rem);
  }

  /* Traits badges — smaller on narrow screens */
  .trait-badge {
    padding: 5px 10px;
    font-size: 0.68rem;
  }
}

/* ============================================
   VERY SMALL PHONE — ≤375px
   ============================================ */
@media (max-width: 375px) {
  #page-content {
    padding: var(--space-md) var(--space-sm);
  }

  .page-title {
    font-size: clamp(1.2rem, 5vw, 1.5rem);
  }

  .page-subtitle {
    font-size: 0.8rem;
  }

  /* Cyber card — minimum viable size */
  .cyber-container {
    width: 160px;
    height: 224px;
  }

  .title {
    font-size: 15px;
    padding-top: 10px;
  }

  #prompt {
    font-size: 10px;
    bottom: 55px;
  }

  .subtitle {
    font-size: 8px;
    bottom: 18px;
  }

  /* Experience title tighter */
  .experience-title {
    font-size: 1rem;
  }

  .experience-company {
    font-size: 0.85rem;
  }
}

/* ============================================
   MINIMUM WIDTH — ≤320px
   ============================================ */
@media (max-width: 320px) {
  #page-content {
    width: 100vw;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: var(--space-md) var(--space-xs);
  }

  .page-title {
    font-size: 1.1rem;
  }

  .page-subtitle {
    font-size: 0.75rem;
  }

  /* Stack experience header vertically */
  .experience-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .experience-icon {
    font-size: 1.5rem;
  }

  /* Hotspots — minimum size with good tap area */
  .hotspot {
    width: 45px;
    height: 45px;
  }

  .hotspot-click-area {
    inset: -18px;
  }

  /* Contact form full-bleed */
  .contact-form-container {
    padding: var(--space-md);
    border-radius: var(--radius-sm);
  }
}

/* ============================================
   MOBILE NAVIGATION BAR
   Hidden on desktop, shown ≤768px
   ============================================ */

/* Toggle button — bottom-right compass */
.mobile-nav-toggle {
  display: none; /* Hidden on desktop */
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 80;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(42, 26, 10, 0.95), rgba(58, 42, 26, 0.95));
  border: 2px solid var(--gold);
  color: var(--gold);
  font-size: 1.4rem;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), 0 0 15px rgba(201, 168, 76, 0.2);
  transition: transform var(--duration-fast) var(--ease-smooth),
              box-shadow var(--duration-fast) var(--ease-smooth);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.mobile-nav-toggle:active {
  transform: scale(0.92);
}

.mobile-nav-toggle.active {
  transform: rotate(45deg);
  background: linear-gradient(135deg, rgba(58, 42, 26, 0.95), rgba(74, 58, 42, 0.95));
}

/* Navigation bar — bottom of screen */
.mobile-nav {
  display: none; /* Hidden on desktop */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 75;
  background: linear-gradient(180deg, rgba(42, 26, 10, 0.97), rgba(13, 8, 0, 0.99));
  border-top: 1px solid rgba(201, 168, 76, 0.4);
  padding: 8px 4px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform var(--duration-normal) var(--ease-smooth);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav.open {
  transform: translateY(0);
}

.mobile-nav-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  min-width: 50px;
  min-height: 44px;
  cursor: pointer;
  color: var(--parchment-dark);
  font-family: var(--font-heading);
  font-size: 0.55rem;
  letter-spacing: 0.03em;
  text-align: center;
  border-radius: var(--radius-sm);
  transition: color var(--duration-fast) var(--ease-smooth),
              background var(--duration-fast) var(--ease-smooth);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  border: none;
  background: none;
}

.mobile-nav-item:active {
  background: rgba(201, 168, 76, 0.15);
  color: var(--gold-bright);
}

.mobile-nav-item-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.mobile-nav-item-label {
  white-space: nowrap;
  opacity: 0.8;
}

/* ============================================
   LANDSCAPE PHONE
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
  #page-content {
    max-height: 90vh;
    padding: var(--space-md) var(--space-lg);
  }

  #back-to-map {
    top: 6px;
    left: 6px;
  }

  .mobile-nav {
    padding: 4px 4px;
  }

  .mobile-nav-item {
    min-height: 38px;
    font-size: 0.5rem;
  }

  .mobile-nav-item-icon {
    font-size: 1.1rem;
  }
}

/* ============================================
   TOUCH DEVICE ACTIVE STATES
   Applied via .touch-device class on <html>
   ============================================ */
.touch-device .btn-medieval:active {
  opacity: 0.85;
  transform: scale(0.97);
}

.touch-device .experience-card:active {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2), 0 0 10px rgba(201, 168, 76, 0.15);
  transform: scale(0.99);
}

.touch-device .certificate-card:active {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), 0 0 10px rgba(201, 168, 76, 0.2);
  transform: scale(0.99);
}

.touch-device .trait-badge:active {
  transform: scale(0.95);
  opacity: 0.85;
}

.touch-device .profile-stat:active {
  transform: scale(0.98);
}

.touch-device .quest-item:active {
  background: rgba(201, 168, 76, 0.08);
}

/* On touch devices, don't rely on hover for trait-badge glow */
.touch-device .trait-badge:hover::after {
  opacity: 0;
}
