/* ==========================================================================
   Style 1 — responsive, readability & performance fixes
   Loaded after style-core.css and engineering-v2.css on index.html only.
   Fixes layout, sizing and legibility; the visual language is unchanged.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Page never pans sideways on phones
   -------------------------------------------------------------------------- */
html { overflow-x: clip; }
.floating-hud { box-sizing: border-box; }

/* --------------------------------------------------------------------------
   2. Top HUD fits every phone width (320px and up)
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .floating-hud {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .hud-left-group { min-width: 0; flex-shrink: 1; }
  .hud-controls { flex-shrink: 0; gap: 6px; }
  /* Ctrl/⌘K is a keyboard shortcut; on phones the palette stays reachable
     from the Engineering Console's TERMINAL button. */
  .hud-cmd-btn { display: none !important; }
  .mode-btn { white-space: nowrap; }
}

@media (max-width: 380px) {
  .hud-btn {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
  }
  .mode-btn { padding: 7px 10px; }
  .mode-btn .mode-svg { display: none; }
}

@media (max-width: 340px) {
  .hud-controls { gap: 4px; }
  .mode-btn { padding: 7px 8px; font-size: 0.7rem; }
  #modeBtnEngineer .mode-text::after { font-size: 0.7rem; }
}

/* --------------------------------------------------------------------------
   3. Card content: no truncated titles or two-line badges
   -------------------------------------------------------------------------- */
.action-title-row { flex-wrap: wrap; row-gap: 4px; min-width: 0; }
.action-badge { white-space: nowrap; }

@media (max-width: 640px) {
  .action-title {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
  .action-desc {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.35;
  }
  /* Email is the one value people need to read in full */
  .pill-email .pill-val {
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.25;
  }
}

/* Dark theme on phones: keep the isometric pattern as subtle as on desktop
   (desktop multiplies it; phones drew it at full strength and washed the card out). */
@media (max-width: 640px) {
  body.dark-theme .card-geometric-pattern { mix-blend-mode: multiply; }
}

/* --------------------------------------------------------------------------
   4. New: Style switch chip (top-right of the card)
   -------------------------------------------------------------------------- */
.style-switch-chip {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 11px 5px 10px;
  border-radius: var(--radius-pill);
  font-family: var(--font-heading);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(203, 213, 225, 0.85);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  transition: transform var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.style-switch-chip:hover {
  transform: translateY(-2px);
  background: #FFFFFF;
  border-color: rgba(147, 197, 253, 0.95);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.15);
}
.style-switch-chip:active { transform: scale(0.97); }
.style-switch-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #B3361C;
  box-shadow: 0 0 8px rgba(179, 54, 28, 0.45);
  flex-shrink: 0;
}
.style-switch-chip svg { width: 12px; height: 12px; flex-shrink: 0; }
body.dark-theme .style-switch-chip {
  background: rgba(30, 41, 59, 0.85);
  border-color: rgba(148, 163, 184, 0.22);
  color: #E2E8F0;
}
body.dark-theme .style-switch-chip:hover {
  background: rgba(51, 65, 85, 0.95);
  border-color: rgba(56, 189, 248, 0.6);
}
@media (max-width: 640px) {
  .style-switch-chip { top: 12px; right: 12px; }
}
@media (max-width: 400px) {
  .style-switch-chip { top: 10px; right: 10px; padding: 5px 10px 5px 9px; gap: 5px; font-size: 0.7rem; }
  .style-switch-chip svg { display: none; }
  /* Let chip subtitles wrap instead of cutting off */
  .chip-sub { white-space: normal !important; overflow: visible !important; text-overflow: clip !important; line-height: 1.3; }
}

/* --------------------------------------------------------------------------
   5. New: Rate card chip (connect dock) + modal footer button
   -------------------------------------------------------------------------- */
.chip-ratecard {
  text-decoration: none;
  border-color: rgba(167, 243, 208, 0.8);
  background: linear-gradient(135deg, rgba(236, 253, 245, 0.95) 0%, rgba(224, 242, 254, 0.95) 100%);
  box-shadow: 0 10px 25px rgba(5, 150, 105, 0.1), inset 0 1px 1px #FFFFFF;
}
.chip-ratecard:hover {
  border-color: #059669;
  background: linear-gradient(135deg, #FFFFFF 0%, #ECFDF5 100%);
  box-shadow: 0 14px 30px rgba(5, 150, 105, 0.18);
}
.chip-ratecard .chip-icon { background: #059669; box-shadow: 0 6px 14px rgba(5, 150, 105, 0.35); }
.chip-ratecard .chip-label { color: #064E3B; }
.chip-ratecard .chip-badge-highlight { background: #059669; box-shadow: 0 4px 10px rgba(5, 150, 105, 0.3); }

.modal-footer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.modal-secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: #F1F5F9;
  border: 1px solid #CBD5E1;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: all var(--transition-fast);
}
.modal-secondary-btn:hover {
  background: #FFFFFF;
  border-color: #059669;
  color: #059669;
  transform: translateY(-2px);
}
.modal-secondary-btn svg { width: 16px; height: 16px; }
body.dark-theme .modal-secondary-btn {
  background: rgba(30, 41, 59, 0.85);
  border-color: rgba(148, 163, 184, 0.25);
  color: #E2E8F0;
}

/* --------------------------------------------------------------------------
   6. Modals: more room, easier reading (all sizes)
   -------------------------------------------------------------------------- */
.btn-back-gallery,
.nav-page-btn { white-space: nowrap; }
.modal-content-area { padding: 22px 30px 30px; }
.cs-content-body { gap: 20px; }
.project-section-block { gap: 8px; }
.section-heading { font-size: 0.95rem; }
.section-text { font-size: 0.9rem; line-height: 1.62; max-width: 76ch; }
.built-features-grid { gap: 10px 20px; }
.built-features-grid li { font-size: 0.86rem; line-height: 1.5; padding-left: 20px; }
.built-features-grid li::before { top: 4px; }
.callout-desc { font-size: 0.86rem; line-height: 1.58; }
.cap-name { font-size: 1.02rem; }
.cap-desc { font-size: 0.86rem; line-height: 1.5; }
.sim-desc { font-size: 0.84rem; line-height: 1.5; }
.cs-tagline-quote { line-height: 1.4; }
.pgc-subtitle { font-size: 0.8rem; }
.pgc-tagline-bar { font-size: 0.78rem; }

/* Phones: bottom sheet uses its full height, with slimmer chrome */
@media (max-width: 640px) {
  .modal-scroll-area {
    height: 100% !important;
    max-height: none !important;
  }
  .modal-content-area { padding: 16px 16px 24px !important; }

  /* Case-study navigation: one tidy row (project name is already in the header) */
  .detail-nav-middle { display: none; }
  .detail-nav-bar { padding: 4px 16px 10px !important; }

  /* Footer: just the actions */
  .modal-footer {
    gap: 8px !important;
    padding: 10px 16px max(12px, env(safe-area-inset-bottom)) !important;
  }
  .modal-footer-note { display: none; }
  .modal-action-btn { min-height: 46px !important; padding: 11px 16px; }
  .modal-footer-actions {
    display: grid;
    grid-template-columns: auto 1fr;
    width: 100%;
  }
  .modal-footer-actions .modal-action-btn { width: 100%; white-space: nowrap; }
  .modal-secondary-btn { min-height: 46px; border-radius: 12px; padding: 11px 14px; }

  /* Pipelines read left-to-right and wrap, instead of a tall column */
  .pipeline-steps { flex-direction: row; align-items: center; }
  .arrow-sep { transform: none; }

  .section-text { font-size: 0.88rem; }
  .built-features-grid li { font-size: 0.85rem; }
}

@media (max-width: 360px) {
  .modal-secondary-btn span { display: none; }
  .modal-secondary-btn { padding: 11px 12px; }
}

/* --------------------------------------------------------------------------
   7. Smoothness on phones
   Opening a modal used to re-show the corner characters, satellites and
   blurred orbs underneath, then blur them all through the backdrop on every
   frame of the sheet animation. Phones keep them hidden and only dim.
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  body.modal-open .ambient-orb,
  body.modal-open .corner-characters-layer,
  body.modal-open .satellites-layer { display: none !important; }

  .modal-backdrop {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(15, 23, 42, 0.55) !important;
  }
}
html.perf-constrained .modal-backdrop {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  background: rgba(15, 23, 42, 0.5) !important;
}

/* --------------------------------------------------------------------------
   8. Dark theme — finish the modal interiors
   (panels that stayed light, and dark text that sat on dark backgrounds)
   -------------------------------------------------------------------------- */
body.dark-theme .modal-close-btn {
  background: rgba(30, 41, 59, 0.85);
  border-color: rgba(148, 163, 184, 0.25);
  color: #E2E8F0;
}
body.dark-theme .modal-close-btn:hover { background: #F43F5E; border-color: #F43F5E; color: #FFFFFF; }
body.dark-theme .modal-footer-note,
body.dark-theme .meta-status-text { color: #CBD5E1; }
body.dark-theme .meta-hint-tag,
body.dark-theme .detail-project-indicator,
body.dark-theme .pgc-num,
body.dark-theme .cs-num-badge {
  background: rgba(99, 102, 241, 0.16);
  border-color: rgba(129, 140, 248, 0.35);
  color: #C7D2FE;
}
body.dark-theme .filter-tab:not(.is-active) {
  background: rgba(30, 41, 59, 0.85);
  border-color: rgba(148, 163, 184, 0.22);
  color: #CBD5E1;
}
body.dark-theme .pgc-chip,
body.dark-theme .tech-tag,
body.dark-theme .tag {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(148, 163, 184, 0.2);
  color: #CBD5E1;
}
body.dark-theme .btn-inspect-case-study {
  background: rgba(99, 102, 241, 0.16);
  border-color: rgba(129, 140, 248, 0.35);
  color: #C7D2FE;
}

/* Capabilities */
body.dark-theme .capability-card {
  background: rgba(15, 23, 42, 0.85) !important;
  border-color: rgba(148, 163, 184, 0.18) !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35) !important;
}
body.dark-theme .capability-card:hover {
  background: rgba(30, 41, 59, 0.95) !important;
  border-color: rgba(99, 102, 241, 0.6) !important;
}
body.dark-theme .cap-name { color: #F8FAFC; }
body.dark-theme .cap-desc { color: #CBD5E1 !important; }
body.dark-theme .cap-icon-box { background: linear-gradient(135deg, #1E293B 0%, #172554 100%); box-shadow: none; }
body.dark-theme .cap-inquire-btn {
  background: rgba(37, 99, 235, 0.16);
  border-color: rgba(96, 165, 250, 0.4);
  color: #93C5FD;
}
body.dark-theme .cap-inquire-btn:hover { background: var(--color-brand-blue); color: #FFFFFF; }

/* Case study interiors */
body.dark-theme .cs-tagline-quote,
body.dark-theme .pgc-tagline-bar {
  background: rgba(30, 41, 59, 0.75) !important;
  border-color: rgba(99, 102, 241, 0.3) !important;
  color: #C7D2FE !important;
}
body.dark-theme .cs-thumb-box,
body.dark-theme .pgc-thumb-box { box-shadow: none; }
body.dark-theme .arch-pipeline-box {
  background: rgba(15, 23, 42, 0.8);
  border-color: rgba(148, 163, 184, 0.18);
}
body.dark-theme .step-blue { background: rgba(37, 99, 235, 0.16); color: #93C5FD; border-color: rgba(96, 165, 250, 0.35); }
body.dark-theme .step-purple { background: rgba(124, 58, 237, 0.16); color: #C4B5FD; border-color: rgba(167, 139, 250, 0.35); }
body.dark-theme .step-emerald { background: rgba(16, 185, 129, 0.14); color: #6EE7B7; border-color: rgba(52, 211, 153, 0.35); }
body.dark-theme .callout-title { color: #C7D2FE; }
body.dark-theme .callout-title svg { color: #A5B4FC; }
body.dark-theme .callout-desc { color: #CBD5E1; }
body.dark-theme .callout-desc code {
  background: rgba(15, 23, 42, 0.9);
  border-color: rgba(129, 140, 248, 0.35);
  color: #E0E7FF;
}
body.dark-theme .project-card-footer { border-top-color: rgba(148, 163, 184, 0.15); }
body.dark-theme .proj-action-btn.btn-gh,
body.dark-theme .proj-action-btn.btn-private {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(148, 163, 184, 0.25);
  color: #CBD5E1;
}
body.dark-theme .proj-action-btn.btn-gh:hover { background: #F8FAFC; color: #0F172A; }
body.dark-theme .proj-action-btn.btn-inquire {
  background: rgba(37, 99, 235, 0.16);
  border-color: rgba(96, 165, 250, 0.4);
  color: #93C5FD;
}
body.dark-theme .proj-action-btn.btn-inquire:hover { background: var(--color-brand-blue); color: #FFFFFF; }

/* Simulators */
body.dark-theme .interactive-simulator-card {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.9) 0%, rgba(30, 27, 75, 0.55) 100%);
  border-color: rgba(129, 140, 248, 0.3);
  box-shadow: none;
}
body.dark-theme .sim-title,
body.dark-theme .node-name,
body.dark-theme .grade-label { color: #F8FAFC !important; }
body.dark-theme .sim-desc,
body.dark-theme .param-label-row,
body.dark-theme .v2-sim-note { color: #CBD5E1; }
body.dark-theme .sim-live-indicator { background: rgba(15, 23, 42, 0.9); }
body.dark-theme .fsrs-param-box,
body.dark-theme .fsrs-result-card,
body.dark-theme .mesh-stage-box,
body.dark-theme .mesh-reset-btn {
  background: rgba(15, 23, 42, 0.85);
  border-color: rgba(148, 163, 184, 0.2);
}
body.dark-theme .fsrs-grade-btn {
  background: rgba(15, 23, 42, 0.85);
  border-color: rgba(148, 163, 184, 0.22);
}
body.dark-theme .fsrs-grade-btn.is-selected { background: rgba(37, 99, 235, 0.18); }
body.dark-theme .node-avatar-circle { background: linear-gradient(135deg, #1E293B 0%, #1E1B4B 100%); border-color: rgba(129, 140, 248, 0.45); }
body.dark-theme .node-radio-badge { background: rgba(30, 41, 59, 0.9); color: #CBD5E1; }
body.dark-theme .node-status-dot { border-color: #0F172A; }

/* Share + command palette */
body.dark-theme .share-pill-btn:not(.btn-wa-share) {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(148, 163, 184, 0.25);
  color: #E2E8F0;
}
body.dark-theme .cmd-input-bar,
body.dark-theme .cmd-footer-bar {
  background: #0B1120;
  border-color: rgba(148, 163, 184, 0.18);
}
body.dark-theme .cmd-search-input,
body.dark-theme .cmd-text { color: #E2E8F0; }
body.dark-theme .cmd-item:hover,
body.dark-theme .cmd-item.is-focused {
  background: rgba(99, 102, 241, 0.14);
  border-color: rgba(129, 140, 248, 0.3);
}
body.dark-theme .cmd-kbd-badge,
body.dark-theme .cmd-footer-bar kbd {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(148, 163, 184, 0.25);
  color: #CBD5E1;
}
