/* Science Lab — metaphysics terms consent gate */

.stc-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100vw;
  padding:
    max(10px, env(safe-area-inset-top, 0px))
    max(12px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px));
  background:
    radial-gradient(1200px 600px at 20% 0%, rgba(139, 105, 20, 0.18), transparent 55%),
    radial-gradient(900px 500px at 90% 100%, rgba(30, 58, 95, 0.22), transparent 50%),
    rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  box-sizing: border-box;
}

.stc-overlay *,
.stc-overlay *::before,
.stc-overlay *::after {
  box-sizing: border-box;
}

.stc-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.stc-overlay[hidden] {
  display: none !important;
}

.stc-dialog {
  width: min(640px, 100%);
  max-height: min(88vh, 820px);
  max-height: min(88dvh, 820px);
  display: flex;
  flex-direction: column;
  background: var(--qmf-card, #fff);
  color: var(--qmf-text, #1e293b);
  border: 1px solid rgba(139, 105, 20, 0.22);
  border-radius: 18px;
  box-shadow:
    0 24px 64px rgba(15, 23, 42, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  overflow: hidden;
  transform: translateY(14px) scale(0.98);
  transition: transform 0.28s ease;
  min-height: 0;
}

.stc-overlay.is-open .stc-dialog {
  transform: translateY(0) scale(1);
}

.stc-header {
  flex: 0 0 auto;
  padding: 1.15rem 1.35rem 0.9rem;
  background:
    linear-gradient(180deg, rgba(139, 105, 20, 0.1), transparent 80%),
    var(--qmf-card, #fff);
  border-bottom: 1px solid var(--qmf-border, #e2e8f0);
}

.stc-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
}

.stc-kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8b6914;
  margin: 0.15rem 0 0;
}

.stc-lang {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.3rem;
  max-width: min(100%, 280px);
}

.stc-lang-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(139, 105, 20, 0.28);
  background: rgba(255, 255, 255, 0.72);
  color: #6b4f0e;
  border-radius: 999px;
  min-width: 2rem;
  height: 1.85rem;
  padding: 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.stc-lang-btn:hover {
  border-color: rgba(139, 105, 20, 0.55);
  transform: translateY(-1px);
}

.stc-lang-btn.is-active {
  background: linear-gradient(135deg, #8b6914, #6b4f0e);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 12px rgba(139, 105, 20, 0.25);
}

.stc-title {
  margin: 0;
  font-size: clamp(1.15rem, 2.6vw, 1.45rem);
  line-height: 1.3;
  font-weight: 700;
}

.stc-subtitle {
  margin: 0.45rem 0 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--qmf-text-secondary, #64748b);
}

.stc-body-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stc-body {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1rem 1.35rem 1.75rem;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.stc-body h3 {
  margin: 1.1rem 0 0.45rem;
  font-size: 1rem;
  color: #8b6914;
}

.stc-body h3:first-child {
  margin-top: 0;
}

.stc-body p,
.stc-body li {
  font-size: 0.94rem;
  line-height: 1.65;
  color: var(--qmf-text, #1e293b);
}

.stc-body ul {
  margin: 0.35rem 0 0.75rem;
  padding-left: 1.15rem;
}

.stc-body a {
  color: #8b6914;
  font-weight: 600;
}

.stc-fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 40px;
  pointer-events: none;
  background: linear-gradient(180deg, transparent, var(--qmf-card, #fff));
  opacity: 1;
  transition: opacity 0.2s ease;
  z-index: 1;
}

.stc-fade.is-hidden {
  opacity: 0;
}

.stc-scroll-hint {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  color: var(--qmf-text-muted, #94a3b8);
  border-top: 1px dashed var(--qmf-border, #e2e8f0);
  background: rgba(139, 105, 20, 0.04);
  z-index: 2;
}

.stc-scroll-hint.is-done {
  color: #047857;
  background: rgba(16, 185, 129, 0.08);
}

.stc-footer {
  flex: 0 0 auto;
  padding: 0.9rem 1.35rem 1.15rem;
  border-top: 1px solid var(--qmf-border, #e2e8f0);
  background: var(--qmf-card, #fff);
  z-index: 2;
}

.stc-check {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  margin-bottom: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.stc-check input {
  margin-top: 0.25rem;
  width: 1.1rem;
  height: 1.1rem;
  accent-color: #8b6914;
  flex-shrink: 0;
}

.stc-check span {
  font-size: 0.92rem;
  line-height: 1.55;
  font-weight: 500;
}

.stc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
}

.stc-link {
  font-size: 0.85rem;
  color: var(--qmf-text-secondary, #64748b);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stc-agree {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: 999px;
  padding: 0.72rem 1.35rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #8b6914, #6b4f0e);
  box-shadow: 0 8px 20px rgba(139, 105, 20, 0.28);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, filter 0.15s ease;
}

.stc-agree:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.stc-agree:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

body.stc-locked {
  overflow: hidden !important;
  touch-action: none;
}

[data-theme="dark"] .stc-dialog,
[data-theme="dark"] .stc-header,
[data-theme="dark"] .stc-footer {
  background: #0f172a;
}

[data-theme="dark"] .stc-fade {
  background: linear-gradient(180deg, transparent, #0f172a);
}

[data-theme="dark"] .stc-dialog {
  border-color: rgba(212, 175, 55, 0.28);
  color: #e2e8f0;
}

[data-theme="dark"] .stc-kicker,
[data-theme="dark"] .stc-body h3,
[data-theme="dark"] .stc-body a {
  color: #d4af37;
}

[data-theme="dark"] .stc-lang-btn {
  background: rgba(15, 23, 42, 0.85);
  border-color: rgba(212, 175, 55, 0.35);
  color: #e8d39a;
}

[data-theme="dark"] .stc-lang-btn.is-active {
  background: linear-gradient(135deg, #d4af37, #8b6914);
  color: #111827;
}

[data-theme="dark"] .stc-subtitle,
[data-theme="dark"] .stc-link {
  color: #94a3b8;
}

[data-theme="dark"] .stc-body p,
[data-theme="dark"] .stc-body li,
[data-theme="dark"] .stc-check span {
  color: #e2e8f0;
}

/* Mobile: dialog fills safe viewport; body scrolls; footer never overlaps */
@media (max-width: 640px) {
  .stc-overlay {
    align-items: stretch;
    justify-content: stretch;
    padding:
      max(8px, env(safe-area-inset-top, 0px))
      max(8px, env(safe-area-inset-right, 0px))
      max(8px, env(safe-area-inset-bottom, 0px))
      max(8px, env(safe-area-inset-left, 0px));
  }

  .stc-dialog {
    width: 100%;
    max-width: 100%;
    height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
    min-height: 0;
    border-radius: 16px;
  }

  .stc-top {
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
  }

  .stc-lang {
    max-width: none;
    justify-content: flex-start;
  }

  .stc-header {
    padding: 0.85rem 1rem 0.7rem;
  }

  .stc-title {
    font-size: 1.12rem;
  }

  .stc-subtitle {
    font-size: 0.86rem;
  }

  .stc-body {
    padding: 0.85rem 1rem 1.4rem;
  }

  .stc-body p,
  .stc-body li {
    font-size: 0.9rem;
  }

  .stc-scroll-hint {
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
  }

  .stc-footer {
    padding: 0.75rem 1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
  }

  .stc-check {
    margin-bottom: 0.7rem;
  }

  .stc-check span {
    font-size: 0.84rem;
    line-height: 1.45;
  }

  .stc-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .stc-agree {
    width: 100%;
    justify-content: center;
  }
}
