/* Modals + Share + Screenshot Preview */
.controls-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  background: rgba(2, 8, 20, 0.62);
  backdrop-filter: blur(5px);
  padding: 1rem 1.25rem;
  pointer-events: auto;
}

body.modal-open {
  overflow: hidden;
}

body.modal-open .top-nav,
body.modal-open .app-shell,
body.modal-open .mobile-panel-bar,
body.modal-open .mobile-nav-backdrop,
body.modal-open .launcher-overlay {
  pointer-events: none;
}

.controls-modal {
  box-sizing: border-box;
  width: min(560px, calc(100vw - 2.5rem));
  max-height: min(90vh, calc(100vh - 2rem));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: linear-gradient(170deg, rgba(8, 16, 34, 0.97), rgba(7, 20, 39, 0.94));
  box-shadow: 0 20px 48px rgba(2, 9, 24, 0.42);
  color: var(--text-main);
}

.controls-modal-compact {
  width: min(520px, calc(100vw - 2.5rem));
}

.controls-modal-wide {
  width: min(820px, calc(100vw - 2.5rem));
}

.share-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
  align-items: center;
}

.modal-check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line-soft);
  border-radius: 0.75rem;
  background: rgba(8, 16, 32, 0.38);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

.export-preview-wrap {
  border: 1px solid var(--line-soft);
  border-radius: 0.62rem;
  background: rgba(8, 17, 34, 0.62);
  overflow: hidden;
}

.export-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.46rem 0.56rem;
  border-bottom: 1px solid var(--line-soft);
  font: 600 0.66rem/1.1 "Syne", "Space Grotesk", sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.export-preview-frame {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  height: clamp(120px, 34vh, 240px);
  min-height: 120px;
  max-height: 240px;
  overflow: hidden;
}

.export-preview-lines,
.export-preview-code {
  margin: 0;
  font-family: "Consolas", "SFMono-Regular", monospace;
  font-size: 0.7rem;
  line-height: 1.45;
  white-space: pre;
}

.export-preview-lines {
  min-width: 2.1rem;
  height: 100%;
  padding: 0.52rem 0.34rem 0.6rem;
  text-align: right;
  color: var(--text-soft);
  background: rgba(8, 15, 28, 0.58);
  border-right: 1px solid var(--line-soft);
  user-select: none;
  overflow: hidden;
}

.export-preview-code {
  height: 100%;
  padding: 0.52rem 0.6rem 0.6rem;
  color: var(--text-main);
  overflow-x: auto;
  overflow-y: auto;
}

.modal-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.modal-switch-row.form-check {
  padding-left: 0;
}

.modal-switch-row .form-check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  margin-bottom: 0;
}

.modal-switch-row .form-check-label i {
  margin-right: 0.02rem;
}

.modal-switch-row .form-check-input {
  float: none;
  margin-left: auto;
}

.screenshot-preview-card {
  position: relative;
  margin-bottom: 0.85rem;
  border: 1px solid var(--line-soft);
  border-radius: 0.8rem;
  overflow: hidden;
  background-color: rgba(13, 21, 38, 0.88);
  background-image:
    linear-gradient(
      45deg,
      rgba(238, 246, 255, 0.14) 25%,
      transparent 25%,
      transparent 75%,
      rgba(238, 246, 255, 0.14) 75%,
      rgba(238, 246, 255, 0.14)
    ),
    linear-gradient(
      45deg,
      rgba(238, 246, 255, 0.14) 25%,
      transparent 25%,
      transparent 75%,
      rgba(238, 246, 255, 0.14) 75%,
      rgba(238, 246, 255, 0.14)
    );
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}

.screenshot-preview-image {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: transparent;
  transform-origin: 50% 50%;
  transform: translate(0, 0) scale(1);
  transition: transform 60ms linear;
  cursor: zoom-in;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}

.screenshot-zoom-badge {
  position: absolute;
  left: 0.55rem;
  bottom: 0.55rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: rgba(7, 14, 28, 0.72);
  color: #dceaff;
  font: 600 0.7rem/1 "Space Grotesk", "Segoe UI", sans-serif;
  letter-spacing: 0.03em;
  padding: 0.22rem 0.5rem;
  pointer-events: none;
}

.share-link-input {
  width: 100%;
  min-height: 2rem;
  border-radius: 0.52rem;
  border: 1px solid var(--line-soft);
  background: rgba(11, 20, 38, 0.66);
  color: var(--text-main);
  font: 500 0.76rem/1.2 "Space Grotesk", "Segoe UI", sans-serif;
  padding: 0.45rem 0.6rem;
}

.share-link-input:focus-visible {
  outline: 2px solid rgba(90, 164, 255, 0.42);
  outline-offset: 1px;
}

/* Model Equation Cards + About Links */
.controls-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--line-soft);
}

.controls-modal-title {
  display: inline-flex;
  align-items: center;
  gap: 0.48rem;
  margin: 0;
}

.controls-modal-body {
  padding: 0.85rem 0.95rem 0.95rem;
  overflow-y: auto;
  min-height: 0;
}

.equation-card + .equation-card {
  margin-top: 0.8rem;
}

.equation-card {
  border: 1px solid var(--line-soft);
  border-radius: 0.85rem;
  padding: 0.9rem 0.95rem;
  background: rgba(8, 16, 32, 0.48);
}

.equation-card-head {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  margin-bottom: 0.5rem;
}

.equation-card-index {
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.equation-card-title {
  margin: 0;
  font-size: 1rem;
  color: var(--title-color);
}

.equation-card-math {
  padding: 0.35rem 0;
}

.equation-card-math .katex-display {
  margin: 0.2rem 0;
}

.equation-card-math .katex {
  font-size: clamp(0.92rem, 1.5vw, 1.28rem);
}

.equation-card-copy {
  margin: 0.4rem 0 0;
  color: var(--text-main);
  line-height: 1.5;
}

.equation-card-list {
  margin: 0.55rem 0 0;
  padding-left: 1rem;
  color: var(--text-soft);
  line-height: 1.48;
}

.controls-modal-subtitle {
  margin: 0;
  color: var(--title-color);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.controls-list {
  margin: 0.45rem 0 0;
  padding-left: 0;
  list-style-position: inside;
  color: var(--text-main);
  line-height: 1.45;
}

/* Controls Tutorial Table */
.controls-table-wrap {
  margin-top: 0.45rem;
  border: 1px solid var(--line-soft);
  border-radius: 0.75rem;
  overflow-x: auto;
  background: var(--chip-bg);
}

.controls-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
  table-layout: auto;
  font-size: 0.78rem;
  background: transparent;
}

.controls-table thead th {
  padding: 0.5rem 0.58rem;
  text-align: left;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--title-color);
  border-bottom: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--bg-elev) 72%, transparent);
}

.controls-platform-icons {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: 0.32rem;
  color: var(--text-soft);
  font-size: 0.78em;
}

.controls-table tbody th,
.controls-table tbody td {
  padding: 0.46rem 0.58rem;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

.controls-table tbody th {
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}

.controls-table tbody td {
  color: var(--text-main);
  white-space: normal;
  overflow-wrap: anywhere;
}

.keycaps {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.18rem;
}

.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.28rem;
  height: 1.28rem;
  padding: 0 0.35rem;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 0.3rem;
  background: color-mix(in srgb, var(--bg-elev) 68%, transparent);
  color: var(--title-color);
  font: 600 0.68rem/1 "Space Grotesk", "Segoe UI", sans-serif;
  letter-spacing: 0.02em;
  text-transform: none;
  white-space: nowrap;
}

.controls-table tbody tr:nth-child(even) th,
.controls-table tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--bg-elev) 45%, transparent);
}

.controls-table tbody tr:last-child th,
.controls-table tbody tr:last-child td {
  border-bottom: none;
}

@media (max-width: 900px) {
  .controls-table {
    min-width: 520px;
    font-size: 0.74rem;
  }

  .controls-table thead th {
    padding: 0.42rem 0.46rem;
  }

  .controls-table tbody th,
  .controls-table tbody td {
    padding: 0.38rem 0.46rem;
  }

  .controls-table tbody th {
    white-space: normal;
  }

  .keycap {
    min-width: 1.16rem;
    height: 1.16rem;
    padding: 0 0.28rem;
    font-size: 0.64rem;
  }
}

@media (max-width: 640px) {
  .controls-table {
    min-width: 460px;
    font-size: 0.72rem;
  }
}

.about-links a {
  color: var(--accent-2);
  text-decoration: none;
  border-bottom: 1px dashed rgba(90, 164, 255, 0.45);
}

.about-links a:hover,
.about-links a:focus-visible {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Guided Tutorial */
.tutorial-overlay {
  z-index: 1300;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
  align-items: start;
  justify-items: start;
  padding: 0;
}

.tutorial-mask {
  position: fixed;
  z-index: 1300;
  background: rgba(2, 7, 18, 0.66);
  pointer-events: none;
}

.tutorial-card {
  position: fixed;
  width: min(360px, calc(100vw - 2rem));
  max-height: min(78vh, 460px);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: linear-gradient(170deg, rgba(8, 16, 34, 0.97), rgba(7, 20, 39, 0.94));
  box-shadow: 0 20px 48px rgba(2, 9, 24, 0.52);
  color: #dce8ff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1301;
  pointer-events: auto;
}

.tutorial-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--line-soft);
}

.tutorial-title {
  margin: 0;
}

.tutorial-body {
  padding: 0.8rem 0.9rem;
  overflow-y: auto;
  font-size: 0.86rem;
  line-height: 1.45;
}

.tutorial-step-title {
  margin-bottom: 0.4rem;
  color: #e9f2ff;
  font: 700 1rem/1.2 "Syne", "Space Grotesk", sans-serif;
  letter-spacing: 0.02em;
}

.tutorial-body p {
  margin: 0;
  color: #d1def6;
}

.tutorial-body strong {
  color: #f5faff;
}

.tutorial-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.65rem 0.8rem 0.8rem;
  border-top: 1px solid var(--line-soft);
}

.tutorial-counter {
  color: #b8c9e8;
  font: 600 0.72rem/1 "Syne", "Space Grotesk", sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tutorial-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.tutorial-actions .btn-icon-only {
  min-width: 2.1rem;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tutorial-actions .btn-icon-only i {
  font-size: 0.95rem;
}

.tutorial-focus-target {
  outline: none;
  box-shadow: none;
}

body[data-theme="light"] .tutorial-overlay {
  background: transparent;
}

body[data-theme="light"] .tutorial-mask {
  background: rgba(13, 20, 36, 0.48);
}

body[data-theme="light"] .tutorial-card {
  background: linear-gradient(165deg, rgba(246, 251, 255, 0.98), rgba(234, 244, 255, 0.96));
  border-color: rgba(114, 142, 186, 0.35);
  color: #112746;
}

body[data-theme="light"] .tutorial-step-title {
  color: #17345c;
}

body[data-theme="light"] .tutorial-body p {
  color: #274268;
}

body[data-theme="light"] .tutorial-body strong {
  color: #102741;
}

body[data-theme="light"] .tutorial-counter {
  color: #46638a;
}

@media (max-width: 760px) {
  .tutorial-card {
    width: calc(100vw - 1rem);
    max-height: min(74vh, 460px);
  }

  .tutorial-actions .btn {
    padding-left: 0.52rem;
    padding-right: 0.52rem;
  }
}
