/* ==================== Responsive ==================== */

@media (max-width: 768px) {
  .hero {
    padding: calc(0.8rem + env(safe-area-inset-top)) 1.2rem 1.6rem;
    margin-bottom: 1rem;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 2.4rem;
    padding-left: 0.9rem;
    padding-right: 0.9rem;
  }

  .panel {
    padding: 1.5rem 1.35rem;
  }

  #about-masel {
    margin: 3.5rem auto 1.8rem;
    padding: 1.5rem 1.35rem;
  }

  .about-card {
    grid-template-columns: 1fr;
    grid-template-areas:
      "intro"
      "title"
      "main"
      "image";
  }

  .about-content {
    max-width: 100%;
  }

  .about-image {
    min-height: 230px;
  }

  .support-strip {
    padding-left: 0.9rem;
    padding-right: 0.9rem;
    margin-bottom: 1.4rem;
  }

  .pdf-export-strip {
    padding-left: 0.9rem;
    padding-right: 0.9rem;
    margin-bottom: 1.35rem;
  }

  .support-strip-inner {
    padding: 0.9rem 0.85rem;
  }

  .pdf-export-inner {
    padding: 0.9rem 0.85rem;
  }

  .support-strip-inner .bmc-button {
    width: 100%;
    justify-content: center;
  }

  .pdf-export-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .pdf-export-actions button {
    width: 100%;
  }

  .pdf-export-status {
    min-width: 0;
    width: 100%;
  }

  .hero-inner {
    flex-direction: column;
    align-items: center;
    gap: 1rem;
  }
}

@media (max-width: 700px) {
  .grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  h1 {
    font-size: 1.55rem;
  }

  h2 {
    font-size: 1.15rem;
  }

  .form-row input,
  .form-row select {
    font-size: 1rem;
    padding: 0.75rem 0.65rem;
  }

  .keystone-layout {
    grid-template-columns: 1fr;
  }

  .keystone-image {
    max-width: 260px;
  }

  .keystone-visual-result {
    padding: 0.75rem 0.7rem 0.8rem;
  }

  .keystone-visual-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }

  .keystone-visual-caption {
    font-size: 0.74rem;
  }
}

/* Mobile Flip-only Styles */
@media (max-width: 768px) {
  /* Tools-Nav mobil ausblenden, Flip benutzen */
  .tools-nav {
    display: none;
  }

  .layout {
    padding-top: 0;
  }

  /* toolsRoot auf Mobile komplett ausblenden — page-flip übernimmt */
  #toolsRoot {
    display: none;
  }

  /* Flip-Container als Karte */
  .page-flip {
    display: block;
    position: relative;
    max-width: 900px;
    margin: 0 auto 1.5rem;
    width: 100%;
    box-sizing: border-box;
    perspective: 1600px;
  }

  /* Karte (Flipper) */
  .page-flip-inner {
    position: relative;
    width: 100%;
    min-height: 520px;
    transition: height 0.3s ease;
  }

  .page-face {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 1rem;
    padding: 1.4rem 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
    transition:
      transform 0.42s cubic-bezier(0.22, 0.61, 0.36, 1),
      opacity 0.26s ease;
  }

  /* Sichtbarkeit/Klicks sauber steuern */
  .page-front {
    pointer-events: auto;
    z-index: 2;
    transform: translateX(0);
    opacity: 1;
  }
  .page-back {
    pointer-events: none;
    z-index: 1;
    transform: translateX(100%);
    opacity: 0;
    background: linear-gradient(135deg, rgba(10, 12, 26, 0.98), rgba(4, 5, 12, 0.98));
    border-radius: 18px;
    border: 1px solid var(--border-subtle);
  }

  .page-flip-inner.is-flipped .page-front {
    pointer-events: none;
    transform: translateX(-28%);
    opacity: 0;
  }

  .page-flip-inner.is-flipped .page-back {
    pointer-events: auto;
    transform: translateX(0);
    opacity: 1;
  }

  .page-header {
    margin-bottom: 1.2rem;
  }

  .page-title {
    font-size: 1.3rem;
    margin: 0 0 0.25rem;
  }

  .page-sub {
    margin: 0;
    font-size: 0.9rem;
    color: var(--muted-soft);
  }

  /* ---------- Mobile Home: Legend ---------- */
  .tool-legend {
    border-top: 1px solid #1c2238;
    padding-top: 0.75rem;
    border-bottom: 1px solid #1c2238;
    padding-bottom: 0.75rem;
    margin-top: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem 1.2rem;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    opacity: 0.8;
  }

  .legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: #aeb6d6;
  }

  .legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: 0 0 6px currentColor;
  }

  .legend-image { color: #00bfff; background: #00bfff; }
  .legend-power { color: #ff8c00; background: #ff8c00; }
  .legend-signal { color: #00f2a9; background: #00f2a9; }
  .legend-light { color: #8e2de2; background: #8e2de2; }
  .legend-audio { color: #ff416c; background: #ff416c; }

  /* ---------- Mobile Home: Icon Grid ---------- */
  .app-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.1rem;
    margin-top: 0.8rem;
    justify-content: center; /* ← zentriert alle Items inkl. letzte Zeile */
  }

  .app-icon-button {
    flex: 0 0 96px;
    width: 96px;
    border: 0;
    background: none;
    padding: 0;
    color: inherit;
    cursor: pointer;
    text-align: center;
  }
  .app-icon-shell {
    width: 72px;
    height: 72px;
    margin: 0 auto 0.4rem;
    border-radius: 16px;
    background: rgba(14, 18, 34, 0.9);
    border: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    position: relative;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  }

  .app-icon-shell svg {
    width: 60%;
    height: 60%;
    stroke: currentColor;
    fill: none;
  }

  .app-icon-shell::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 8px;
    transform: translateX(-50%);
    width: 24px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    opacity: 0.5;
    transition: width 0.2s ease, opacity 0.2s ease;
  }

  .app-icon-shell::after { content: none; }

  .group-image .app-icon-shell  { color: #00bfff; }
  .group-power .app-icon-shell  { color: #ff8c00; }
  .group-signal .app-icon-shell { color: #00f2a9; }
  .group-light .app-icon-shell  { color: #8e2de2; }
  .group-audio .app-icon-shell  { color: #ff416c; }

  .app-icon-label {
    font-size: 0.78rem;
    color: var(--muted);
  }

  .app-icon-button:hover .app-icon-shell {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.2);
  }

  .app-icon-button:hover .app-icon-shell::before {
    width: 32px;
    opacity: 0.9;
  }

  .app-icon-button:focus-visible .app-icon-shell {
    outline: none;
    box-shadow: 0 0 0 2px rgba(58, 228, 255, 0.6);
  }

  .tool-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center; /* Titel in die Mitte */
    gap: 0.7rem;
    min-height: 44px; /* match Touch-Target */
    margin-bottom: 0.9rem;
  }

  .tool-back-btn {
    position: absolute;
    right: 0;
    top: 0%;
    display: inline-flex;
    align-items: center;
    line-height: 1;
    transform: translateY(-50%);
    white-space: nowrap;

    border-radius: 999px;
    border: 1px solid rgba(58, 228, 255, 0.5);
    background: rgba(58, 228, 255, 0.12);
    color: var(--text);
    padding: 0.4rem 0.9rem;
    font-size: 0.8rem;
    cursor: pointer;
  }

  .tool-back-btn:hover {
    background: rgba(58, 228, 255, 0.2);
    border-color: rgba(58, 228, 255, 0.8);
  }

  .tool-back-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(58, 228, 255, 0.5);
  }

  .tool-view {
    margin-top: 0.3rem;
    padding: 0;
    border-radius: 0;
    background: none;
    border: 0;
    box-shadow: none;
  }

  .tool-panel {
    display: none;
  }

  .tool-panel.is-active {
    display: block;
  }

  .tool-view .panel {
    display: block;
  }

  /* ✅ Mobile: Back-to-top ausblenden */
  .back-to-top {
    display: none !important;
  }
}

@media (max-width: 600px) {
  .lang-switch {
    width: auto;
    justify-content: flex-start;
    margin-left: auto;
  }

  .lang-btn {
    flex: 1 1 0;
    max-width: 90px;
  }
}

@media (max-width: 500px) {
  .button-row {
    flex-direction: column;
  }

  .media-button-row {
    flex-direction: column;
  }

  button {
    padding: 0.85rem 1.25rem;
    font-size: 0.9rem;
  }

  .lang-switch .lang-btn {
    padding: 0.4rem 0.55rem;
    font-size: 0.68rem;
  }

  .footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .footer-content {
    flex-direction: column;
    gap: 0.6rem;
  }
}

/* Extra-Abstand zum Footer auf Mobile */
@media (max-width: 768px) {
  main {
    padding-bottom: 6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .page-flip-inner,
  .page-face {
    animation: none !important;
    transition: none !important;
  }
}

/* ==================== Tool-Specific Overrides ==================== */
/* Link Planner – Desktop: Result kompakter (ohne Mobile zu ändern) */
@media (min-width: 769px) {
  /* Result-Box: weniger „luftig“ */
  #lp-result,
  #lp-result p {
    margin: 0;
  }

  /* falls du Absätze als Spacing benutzt: kontrolliertes Spacing */
  #lp-result p + p {
    margin-top: 0.35rem;
  }

  /* falls im Result Container Flex/Space-Between irgendwo greift */
  #lp-result [style*="justify-content"] {
    justify-content: flex-start !important;
    align-content: flex-start !important;
  }

  /* Tabelle noch kompakter */
  #lp-result table th,
  #lp-result table td {
    padding: 0.4rem 0.6rem;
    line-height: 1.25;
  }

  /* Killt Default-Abstände in Table-Cells */
  #lp-result table p,
  #lp-result table ul,
  #lp-result table ol {
    margin: 0;
  }
}

/* Projektor-Auswahl */
.projector-selector {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 1rem 1rem 1.1rem;
  border-radius: 16px;
  background: rgba(8, 10, 20, 0.55);
  border: 1px solid var(--border-subtle);
}

/* Select im gleichen Stil wie deine Number-Inputs */
.select-input {
  width: 100%;
  padding: 0.65rem 0.8rem;     /* etwas mehr Höhe & Luft */
  border-radius: 11px;         /* harmoniert besser mit 16px Panel */
  border: 1px solid rgba(58, 228, 255, 0.22);
  background: linear-gradient(
    135deg,
    rgba(14, 18, 38, 0.95),
    rgba(8, 10, 20, 0.98)
  );
  color: var(--text);
  font-family: var(--font);
  font-size: 0.92rem;
  line-height: 1.3;
  appearance: none;

  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease,
    transform 0.06s ease;
}

/* Hover */
.select-input:hover {
  border-color: rgba(255, 255, 255, 0.28);
  background: linear-gradient(
    135deg,
    rgba(16, 20, 44, 1),
    rgba(10, 12, 24, 1)
  );
}

/* Focus */
.select-input:focus-visible {
  outline: none;
  border-color: rgba(58, 228, 255, 0.85);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 1),
    0 0 14px rgba(58, 228, 255, 0.65);
  background: rgba(12, 15, 28, 1);
  transform: translateY(-1px);
}

/* Disabled */
.select-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: rgba(18, 20, 32, 0.85);
  border-color: var(--border-subtle);
}

/* ==================== Mobile Input Behavior ==================== */
/* verhindert iOS Safari "Auto-Zoom" beim Fokus */
/* Zoom komplett unterbinden */
html {
  touch-action: manipulation;
  -ms-touch-action: manipulation;
}

/* iOS Input-Zoom verhindern (passiert unter 16px) */
input, select, textarea {
  font-size: 16px !important;
}

/* ==================== CTA Button ==================== */
.bmc-button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  background: #FFDD00;
  color: #000;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.16s ease;
  box-shadow: 0 4px 14px rgba(255, 221, 0, 0.3);
}

.bmc-button:hover {
  transform: translateY(-1px);
  background: #ffe94a;
  box-shadow: 0 6px 20px rgba(255, 221, 0, 0.45);
}

.bmc-button:active {
  transform: translateY(0);
}

.bmc-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ==================== Legend & Kategorie-Farben (global) ==================== */

/* Legend-Punkte global verfügbar (Mobile + Desktop) */
.legend-dot   { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 6px currentColor; flex-shrink: 0; }
.legend-item  { display: flex; align-items: center; gap: 0.4rem; color: #aeb6d6; }
.legend-image { color: #00bfff; background: #00bfff; }
.legend-power { color: #ff8c00; background: #ff8c00; }
.legend-signal{ color: #00f2a9; background: #00f2a9; }
.legend-light { color: #8e2de2; background: #8e2de2; }
.legend-audio { color: #ff416c; background: #ff416c; }

/* Nav-Legende: auf Mobile ausgeblendet */
.nav-legend { display: none; }

/* ==================== Desktop Single-Panel-View ==================== */
@media (min-width: 769px) {

  /* ---- Desktop Abstände ---- */

  /* Hero: weniger Abstand nach unten */
  .hero {
    margin-bottom: 0.8rem;
  }

  /* Nav: kein Abstand nach oben/unten — bildet eine Einheit mit der Legende */
  .tools-nav {
    margin-top: 0;
    margin-bottom: 0;
  }

  /* toolsRoot: kein extra bottom-padding (Panels bringen eigenen Abstand) */
  #toolsRoot {
    padding-bottom: 0.5rem;
  }

  /* PDF-Export: Abstand nach oben */
  .pdf-export-strip {
    margin-top: 0;
  }

  /* About: weniger Abstand nach oben */
  #about-masel {
    margin-top: 3rem !important;
  }

  /* Nav-Legende auf Desktop */
  .nav-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.4rem;
    justify-content: center;
    padding: 0.3rem 1rem 1.8rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    max-width: 900px;
    margin: 0 auto !important;
  }

  /* Pill-Borders nach Kategorie */
  .pill-nav.group-image  { border-color: rgba(0, 191, 255, 0.45); }
  .pill-nav.group-power  { border-color: rgba(255, 140,   0, 0.45); }
  .pill-nav.group-signal { border-color: rgba(0, 242, 169, 0.45); }
  .pill-nav.group-light  { border-color: rgba(142, 45, 226, 0.45); }
  .pill-nav.group-audio  { border-color: rgba(255,  65, 108, 0.45); }

  /* Aktive Pill: Kategorie-Farbe als Fill */
  .pill-nav.is-active.group-image  { border-color: #00bfff;  background: #00bfff; }
  .pill-nav.is-active.group-power  { border-color: #ff8c00;  background: #ff8c00; }
  .pill-nav.is-active.group-signal { border-color: #00f2a9;  background: #00f2a9; }
  .pill-nav.is-active.group-light  { border-color: #8e2de2;  background: #8e2de2; }
  .pill-nav.is-active.group-audio  { border-color: #ff416c;  background: #ff416c; }

  /* PDF-Export: nur sichtbar wenn ein Tool aktiv ist */
  .pdf-export-strip {
    display: none;
  }
  #toolsRoot:not(.is-desktop-empty) + .pdf-export-strip {
    display: block;
  }

  /* toolsRoot wenn kein Panel aktiv: kein Platz verbrauchen */
  #toolsRoot.is-desktop-empty {
    display: none;
  }

  /* Kategorie-Überschriften im Single-View ausblenden */
  #toolsRoot .section-title {
    display: none;
  }

  /* Alle Panels versteckt — nur das aktive eingeblendet */
  #toolsRoot .panel {
    display: none;
  }

  /* Tool-Home Panel nie zeigen (kein Homescreen auf Desktop) */
  #tool-home {
    display: none !important;
  }

  #toolsRoot .panel.is-desktop-active {
    display: block;
    animation: desktopPanelFadeIn 0.2s ease;
  }

  @keyframes desktopPanelFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* Homescreen-Panel: Layout */
  #tool-home {
    border: none;
    background: none;
    box-shadow: none;
    padding: 2rem 0;
  }

  .tool-home-header {
    text-align: center;
    margin-bottom: 2rem;
  }

  .tool-home-title {
    margin: 0 0 0.4rem;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
  }

  .tool-home-sub {
    margin: 0 0 1rem;
    color: var(--muted);
    font-size: 0.95rem;
  }

  .tool-home-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.4rem;
    justify-content: center;
  }

  /* App-Icon-Styles für Desktop */
  .app-icon-button {
    flex: 0 0 96px;
    width: 96px;
    border: 0;
    background: none;
    padding: 0;
    color: inherit;
    cursor: pointer;
    text-align: center;
  }

  .app-icon-shell {
    width: 72px;
    height: 72px;
    margin: 0 auto 0.4rem;
    border-radius: 16px;
    background: rgba(14, 18, 34, 0.9);
    border: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.65rem;
    color: var(--text);
    position: relative;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  }

  .app-icon-shell::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 8px;
    transform: translateX(-50%);
    width: 24px;
    height: 2px;
    border-radius: 2px;
    background: var(--muted-soft);
    opacity: 0.5;
    transition: width 0.2s ease, opacity 0.2s ease;
  }

  .app-icon-shell::after { content: none; }

  .group-image .app-icon-shell::before  { background: #00bfff; }
  .group-power .app-icon-shell::before  { background: #ff8c00; }
  .group-signal .app-icon-shell::before { background: #00f2a9; }
  .group-light .app-icon-shell::before  { background: #8e2de2; }
  .group-audio .app-icon-shell::before  { background: #ff416c; }

  .app-icon-label {
    font-size: 0.78rem;
    color: var(--muted);
  }

  .app-icon-button:hover .app-icon-shell {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.2);
  }

  .app-icon-button:hover .app-icon-shell::before {
    width: 32px;
    opacity: 0.9;
  }

  .app-icon-button:focus-visible .app-icon-shell {
    outline: none;
    box-shadow: 0 0 0 2px rgba(58, 228, 255, 0.6);
  }

  /* Legend auf Desktop */
  .tool-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.9rem;
    justify-content: center;
    margin-top: 0.6rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #aeb6d6;
  }

  .tool-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
  }

  .tool-legend .legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }
}
