:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --line: #dbe3ee;
  --text: #172033;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-strong: #0b5d57;
  --button-bg: #dbeafe;
  --button-text: #2563eb;
  --button-hover: #bfdbfe;
  --lime: #b7f34d;
  --lime2: #8de62a;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #111827;
  --line: #263244;
  --text: #e5eefb;
  --muted: #9fb0c6;
  --accent: #2dd4bf;
  --accent-strong: #14b8a6;
  --button-bg: #1e3a5f;
  --button-text: #bfdbfe;
  --button-hover: #254b78;
}

* {
  box-sizing: border-box;
}

* {
  scrollbar-width: auto;
  scrollbar-color: #94a3b8 transparent;
}

*::-webkit-scrollbar {
  width: 42px;
  height: 12px;
}

*::-webkit-scrollbar:vertical {
  width: 42px;
}

*::-webkit-scrollbar:horizontal {
  height: 12px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: #94a3b8;
  background-clip: content-box;
  border: 4px solid transparent;
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:vertical {
  border-left-width: 10px;
  border-right-width: 10px;
}

*::-webkit-scrollbar-thumb:horizontal {
  border-top-width: 3px;
  border-bottom-width: 3px;
}

*::-webkit-scrollbar-thumb:hover {
  background: #64748b;
  background-clip: content-box;
}

[data-theme="dark"] * {
  scrollbar-color: #7f8ca3 transparent;
}

[data-theme="dark"] *::-webkit-scrollbar-thumb {
  background: #7f8ca3;
  background-clip: content-box;
}

[data-theme="dark"] *::-webkit-scrollbar-thumb:hover {
  background: #a7b2c4;
  background-clip: content-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", sans-serif;
  position: relative;
  overflow-x: hidden;
}

.mouse-glow {
  position: fixed;
  width: 420px;
  height: 420px;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(120 90 255 / 7%) 0%, rgb(80 160 255 / 3.5%) 35%, transparent 70%);
  filter: blur(35px);
  transform: translate(-50%, -50%);
  z-index: 2;
  opacity: 0;
  transition: opacity 0.2s ease;
  mix-blend-mode: screen;
}

[data-theme="light"] .mouse-glow {
  background: radial-gradient(circle, rgb(37 99 235 / 4%) 0%, rgb(132 204 22 / 2.5%) 35%, transparent 70%);
}

.click-burst-layer {
  position: fixed;
  inset: 0;
  z-index: 9000;
  overflow: hidden;
  pointer-events: none;
}

.click-burst-dot,
.click-burst-ring {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  will-change: opacity, transform;
}

.click-burst-dot {
  width: 11px;
  height: 4px;
  border-radius: 999px;
  background: var(--burst-color, var(--lime));
  box-shadow: 0 0 12px rgb(183 243 77 / 66%), 0 0 24px rgb(141 230 42 / 32%);
  animation: clickBurstDot 560ms cubic-bezier(0.16, 1, 0.3, 1) var(--delay, 0ms) both;
}

.click-burst-ring {
  width: 15px;
  height: 15px;
  border: 2px solid rgb(183 243 77 / 78%);
  border-radius: 999px;
  box-shadow: 0 0 18px rgb(183 243 77 / 38%), 0 0 36px rgb(141 230 42 / 20%);
  animation: clickBurstRing 420ms ease-out both;
}

body.drop-target-active .click-burst-layer {
  display: none;
}

@keyframes clickBurstDot {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--rotation, 0rad)) scaleX(0.5) scaleY(0.8);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rotation, 0rad)) scaleX(0.18) scaleY(0.55);
  }
}

@keyframes clickBurstRing {
  0% {
    opacity: 0.65;
    transform: translate(-50%, -50%) scale(0.45);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.8);
  }
}

@media (prefers-reduced-motion: reduce) {
  .click-burst-dot {
    display: none;
  }
  .click-burst-ring {
    animation: clickBurstRingReduced 200ms ease-out both;
  }
}

@keyframes clickBurstRingReduced {
  from { opacity: .65; transform: translate(-50%, -50%) scale(.6); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(1.8); }
}

.startup-loader {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 42%, rgb(183 243 77 / 13%), transparent 24%),
    rgb(5 12 24 / 86%);
  backdrop-filter: blur(14px);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.startup-loader.startup-loader-closing {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

[data-theme="light"] .startup-loader {
  background:
    radial-gradient(circle at 50% 42%, rgb(122 193 26 / 14%), transparent 24%),
    rgb(247 250 252 / 86%);
}

.startup-loader-card {
  display: grid;
  justify-items: center;
  gap: 18px;
  text-align: center;
}

.startup-loader-mark {
  position: relative;
  width: 164px;
  height: 164px;
  display: grid;
  place-items: center;
}

.startup-loader-outline {
  position: absolute;
  width: 154px;
  height: 154px;
  overflow: visible;
  animation: startupTnsSpin 1.7s linear infinite;
  filter: drop-shadow(0 0 18px rgb(183 243 77 / 45%));
  transform-origin: 50% 50%;
}

.startup-loader-file {
  fill: none;
  stroke: var(--lime);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.startup-loader-file-body {
  stroke-width: 6;
  stroke-dasharray: 165 70;
}

.startup-loader-file-fold {
  stroke-width: 5;
  stroke-dasharray: 34 24;
  opacity: 0.82;
}

.startup-loader-core {
  width: 84px;
  height: 84px;
  border: 2px solid rgb(183 243 77 / 38%);
  border-radius: 26px;
  display: grid;
  place-items: center;
  color: var(--lime);
  background:
    radial-gradient(circle at 50% 40%, rgb(183 243 77 / 14%), transparent 58%),
    rgb(18 43 28 / 78%);
  box-shadow:
    inset 0 0 28px rgb(183 243 77 / 16%),
    0 0 35px rgb(183 243 77 / 28%);
  font-size: 28px;
  font-weight: 950;
  letter-spacing: 0.08em;
}

.startup-loader h2 {
  margin: 0;
  color: var(--lime);
  font-size: clamp(44px, 7vw, 72px);
  letter-spacing: -0.06em;
  line-height: 0.9;
  text-shadow: 0 0 18px rgb(183 243 77 / 48%);
}

.startup-loader-status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.startup-loader[data-state="ready"] .startup-loader-status {
  color: var(--lime);
}

.startup-loader[data-state="error"] .startup-loader-status {
  color: #ff4d4d;
}

@keyframes startupTnsSpin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .startup-loader-outline {
    animation: none;
  }
}

.shell-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 3;
}

.shell-header img {
  width: 52px;
  height: 52px;
}

.brand-copy {
  min-width: 0;
}

.shell-header h1 {
  margin: 0;
  font-size: 30px;
}

.shell-header p {
  margin: 2px 0 0;
  color: var(--muted);
}

.site-stats {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.site-stat {
  flex: 0 0 auto;
  min-width: 148px;
  padding: 10px 16px;
  border: 1px solid rgba(151, 239, 54, 0.35);
  border-radius: 18px;
  background:
    radial-gradient(circle at 20% 10%, rgba(151, 239, 54, 0.14), transparent 55%),
    linear-gradient(145deg, rgba(20, 34, 52, 0.92), rgba(12, 22, 38, 0.88));
  box-shadow: 0 14px 34px rgba(151, 239, 54, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.site-stat strong {
  display: block;
  color: var(--accent);
  font-size: 21px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
}

.site-stat span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.35;
  white-space: nowrap;
}

[data-theme="light"] .site-stat {
  background:
    radial-gradient(circle at 20% 10%, rgba(151, 239, 54, 0.24), transparent 55%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(237, 246, 227, 0.9));
  box-shadow: 0 14px 30px rgba(80, 130, 25, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.status {
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}

.status.ready {
  color: var(--accent);
  border-color: #99d6cd;
}

.header-actions {
  margin-left: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.language-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.language-buttons button {
  width: 46px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: none;
  display: grid;
  place-items: center;
  overflow: hidden;
  line-height: 0;
}

.language-buttons button:hover {
  background: #f8fafc;
}

.language-buttons button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(15 118 110 / 15%);
}

.language-buttons img {
  width: 32px;
  height: 22px;
  object-fit: contain;
  border-radius: 4px;
  display: block;
  margin: auto;
}

[data-theme="dark"] .language-buttons button {
  background: #f8fafc;
}

.about-button {
  width: 100%;
  min-width: 150px;
  padding: 8px 14px;
  background: #172033;
  color: #ffffff;
}

.about-button:hover {
  background: #0f172a;
}

.theme-button {
  width: 46px;
  height: 34px;
  min-width: 46px;
  min-height: 34px;
  flex: 0 0 46px;
  aspect-ratio: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #172033;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  box-shadow: none;
}

.header-actions #theme-btn.theme-button {
  width: 46px !important;
  height: 34px !important;
  min-width: 46px !important;
  min-height: 34px !important;
  flex: 0 0 46px !important;
}

.theme-button:hover {
  background: #f8fafc;
}

[data-theme="dark"] .theme-button {
  background: #f8fafc;
  color: #172033;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 360px;
  gap: 14px;
  padding: 16px;
  align-items: start;
  position: relative;
  z-index: 1;
}

.tools-sidebar {
  grid-column: 1;
  grid-row: 1 / span 5;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  z-index: 3;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 28px rgb(15 23 42 / 6%);
}

[data-theme="dark"] .shell-header,
[data-theme="dark"] .panel,
[data-theme="dark"] .modal {
  background: var(--panel);
}

[data-theme="dark"] .file-button,
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select,
[data-theme="dark"] .code-shell,
[data-theme="dark"] .editor-wrap,
[data-theme="dark"] .lua-code-shell,
[data-theme="dark"] .lua-editor-wrap,
[data-theme="dark"] .summary,
[data-theme="dark"] .problem-table,
[data-theme="dark"] .lua-problem-table {
  background: #0f172a;
  color: var(--text);
  border-color: var(--line);
}

[data-theme="dark"] .code-shell > .line-numbers,
[data-theme="dark"] .lua-code-shell > .line-numbers {
  background: #111827;
  color: #9fb0c6;
}

[data-theme="dark"] .problem-table th,
[data-theme="dark"] .problem-table td,
[data-theme="dark"] .lua-problem-table th,
[data-theme="dark"] .lua-problem-table td,
[data-theme="dark"] .inspector-table th,
[data-theme="dark"] .inspector-table td {
  border-bottom-color: #263244;
}

[data-theme="dark"] .problem-table th,
[data-theme="dark"] .lua-problem-table th,
[data-theme="dark"] .inspector-table th {
  background: #111827;
  color: #e5eefb;
}

[data-theme="dark"] .problem-table tr:hover,
[data-theme="dark"] .lua-problem-table tr:hover,
[data-theme="dark"] .inspector-table tr:hover {
  background: #182338;
  color: #e5eefb;
}

[data-theme="dark"] .problem-table tr.ERROR:hover,
[data-theme="dark"] .lua-problem-table tr.ERROR:hover {
  color: #f87171;
}

[data-theme="dark"] #xml-highlight,
[data-theme="dark"] #py-highlight,
[data-theme="dark"] .lua-highlight,
[data-theme="dark"] .tok-plain {
  color: #e5eefb;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 17px;
}

label {
  display: block;
  margin: 10px 0;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  margin-top: 6px;
}

.hidden {
  display: none !important;
}

textarea {
  min-height: 170px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font: 13px Consolas, monospace;
}

button {
  border: 0;
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--button-text);
  padding: 9px 15px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 1px 0 rgb(37 99 235 / 10%);
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
  white-space: nowrap;
}

button:hover {
  background: var(--button-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgb(37 99 235 / 14%);
}

button:disabled {
  cursor: not-allowed;
  background: #9ca3af;
  color: #ffffff;
  transform: none;
  box-shadow: none;
}

.actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.log-panel {
  grid-column: 1 / -1;
}

.sidebar-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 4px 0;
}

.doctor-launcher,
.module-launcher {
  align-items: flex-start;
  flex-direction: column;
  gap: 12px;
  min-height: 132px;
}

.doctor-launcher button,
.module-launcher button {
  display: none;
}

.home-panel {
  grid-column: 2 / 4;
  grid-row: 1;
  min-height: 520px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 30%, rgb(96 165 250 / 10%), transparent 34%),
    linear-gradient(135deg, rgb(255 255 255 / 95%), rgb(248 250 252 / 96%));
  opacity: 1;
  transform: scale(1);
  transform-origin: center;
  transition: opacity 0.26s ease, transform 0.32s cubic-bezier(0.2, 1.3, 0.4, 1), visibility 0.26s ease;
}

[data-theme="dark"] .home-panel {
  background:
    radial-gradient(circle at 50% 28%, rgb(96 165 250 / 13%), transparent 36%),
    radial-gradient(circle at 62% 46%, rgb(183 243 77 / 8%), transparent 30%),
    #0f172a;
}

.app-active .home-panel {
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
  visibility: hidden;
}

.home-hero {
  width: min(680px, 100%);
  text-align: center;
}

.home-hero img {
  width: 142px;
  height: 142px;
  object-fit: contain;
  filter: drop-shadow(0 14px 24px rgb(15 23 42 / 18%));
}

.home-hero h2 {
  margin: 16px 0 8px;
  font-size: 30px;
}

.home-hero p {
  margin: 0 0 22px;
  color: var(--muted);
}

.drop-zone {
  width: min(520px, 100%);
  margin: 0 auto 22px;
  padding: 28px;
  border: 1px dashed #94a3b8;
  border-radius: 16px;
  color: var(--muted);
  background: rgb(15 23 42 / 3%);
  display: grid;
  gap: 6px;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

[data-theme="dark"] .drop-zone {
  border-color: #334155;
  background: rgb(15 23 42 / 40%);
}

.drop-zone.dragging {
  border-color: var(--lime);
  background: rgb(183 243 77 / 10%);
  transform: translateY(-2px);
}

.drop-zone strong {
  color: var(--text);
}

.home-shortcuts {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tools-sidebar > [hidden],
#home-open-normal[hidden],
#home-open-python[hidden],
#xml-doctor-panel .doctor-toolbar > [hidden] {
  display: none !important;
}

.tools-sidebar .calculator-launcher {
  width: 100%;
  color: var(--text);
  background: var(--panel);
  text-align: left;
  white-space: normal;
}
.tools-sidebar .calculator-launcher:hover {
  background: var(--panel);
}
.calculator-launcher .launcher-icon {
  padding: 6px;
  color: #2dd4bf;
  background: rgb(45 212 191 / 12%);
}
.calculator-launcher .launcher-copy {
  min-width: 0;
  flex: 1;
}
.calculator-launcher .launcher-title {
  display: block;
  margin-bottom: 6px;
  font-size: 16px;
  font-weight: 850;
}
.calculator-launcher .launcher-description {
  display: block;
  color: var(--muted);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.5;
}
@media (max-width: 860px) {
  .layout .tools-sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .layout .tools-sidebar > .doctor-launcher,
  .layout .tools-sidebar > .calculator-launcher {
    aspect-ratio: auto;
    min-height: 116px;
  }
  .tools-sidebar .calculator-launcher .launcher-copy {
    width: 100%;
    flex: 0 1 auto;
  }
  .tools-sidebar .calculator-launcher .launcher-title {
    font-size: clamp(11px, 3.15vw, 13px);
    line-height: 1.16;
    margin: 0;
  }
  .tools-sidebar .calculator-launcher .launcher-description {
    display: none;
  }
}

#xml-doctor-panel,
#normal-module,
#python-module {
  grid-column: 2 / 4;
  grid-row: 1;
  min-width: 0;
}

.doctor-launcher {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  flex-direction: column;
  gap: 0;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.doctor-launcher:hover,
.module-launcher:hover {
  border-color: rgb(183 243 77 / 45%);
  box-shadow: 0 18px 40px rgb(15 23 42 / 10%), 0 0 28px rgb(183 243 77 / 10%);
  transform: translateY(-2px);
}

.launcher-content {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
}

.launcher-icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  object-fit: contain;
  border-radius: 10px;
  margin-top: 2px;
}

.doctor-launcher h2,
.module-launcher h2 {
  margin: 0 0 6px;
}

.doctor-launcher p,
.module-launcher p {
  margin: 0;
  color: var(--muted);
}

.module-launcher {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  flex-direction: column;
  gap: 0;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.module-grid {
  grid-column: 2 / 4;
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 14px;
}

#python-module #py-doctor-panel {
  grid-column: 1 / -1;
  grid-row: auto;
  min-width: 0;
}

.module-grid:not(.collapsed),
.doctor-panel:not(.collapsed) {
  animation: revealPanel 360ms cubic-bezier(0.2, 0.9, 0.2, 1) both;
}

.module-grid.closing,
.doctor-panel.closing {
  animation: hidePanel 260ms ease both;
}

.module-grid.collapsed {
  display: none;
}

.doctor-panel.collapsed {
  display: none;
}

.doctor-panel.drop-target-active {
  border-color: var(--lime);
  box-shadow: 0 0 0 1px rgb(183 243 77 / 55%), 0 0 28px rgb(183 243 77 / 18%);
}

.doctor-panel.drop-target-active .code-shell,
.doctor-panel.drop-target-active .editor-wrap {
  border-color: var(--lime);
  background: rgb(183 243 77 / 8%);
}

body.drop-target-active::after {
  content: "Suelta el archivo para cargarlo";
  position: fixed;
  inset: 16px;
  z-index: 5000;
  display: grid;
  place-items: center;
  border: 2px dashed var(--lime);
  border-radius: 28px;
  background: rgb(15 23 42 / 70%);
  color: var(--lime);
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0.02em;
  pointer-events: none;
  box-shadow: inset 0 0 0 9999px rgb(183 243 77 / 7%), 0 0 44px rgb(183 243 77 / 24%);
  /* Keep this drag UI compositor-safe in Chromium/Brave: a backdrop blur
     on body::after can remain painted after the pseudo-element disappears. */
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.doctor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.doctor-toolbar h2 {
  flex: 0 0 100%;
  margin: 0 0 4px;
}

.doctor-toolbar select {
  min-width: min(320px, 100%);
  max-width: 100%;
  margin-left: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

#xml-line-label {
  color: var(--muted);
  white-space: nowrap;
  margin-left: 0;
}

.file-button {
  width: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--button-text);
  cursor: pointer;
  background: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.tool-menu {
  position: relative;
  display: inline-block;
}

.menu-trigger {
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  background: #1f4775;
  color: #e5eefb;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 10px 26px rgb(15 23 42 / 10%);
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.green-menu-trigger {
  background: linear-gradient(135deg, var(--lime), var(--lime2));
  color: #2d3d17;
  box-shadow: 0 0 20px rgb(183 243 77 / 25%);
}

.menu-trigger:hover {
  transform: translateY(-2px) scale(1.04);
  background: #254f82;
  box-shadow: 0 12px 28px rgb(15 23 42 / 16%);
}

html:not([data-theme="dark"]) .menu-trigger:hover:not(.green-menu-trigger) {
  color: #172033;
}

.green-menu-trigger:hover {
  background: linear-gradient(135deg, var(--lime), var(--lime2));
  box-shadow: 0 0 30px rgb(183 243 77 / 35%), 0 0 80px rgb(183 243 77 / 12%);
}

[data-theme="dark"] .green-menu-trigger:hover {
  color: #ffffff;
}

.menu-trigger:active {
  transform: scale(0.97);
}

.menu-icon {
  color: #22c55e;
  font-size: 18px;
  font-weight: 900;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 12px);
  left: 0;
  width: min(260px, calc(100vw - 36px));
  padding: 12px;
  background: rgb(15 20 28 / 72%);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgb(183 243 77 / 25%);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgb(0 0 0 / 35%), 0 0 25px rgb(183 243 77 / 12%);
  opacity: 0;
  transform: translateY(-18px) scale(0.88);
  transform-origin: top center;
  pointer-events: none;
  z-index: 15;
  transition: opacity 0.25s ease, transform 0.32s cubic-bezier(0.2, 1.3, 0.4, 1);
}

.tool-menu.open > .menu-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.nested-menu {
  display: block;
}

.nested-panel {
  top: 0;
  left: calc(100% + 10px);
  width: min(340px, calc(100vw - 36px));
  transform-origin: top center;
}

.menu-action,
.file-menu-action {
  width: 100%;
  min-height: 40px;
  padding: 10px 16px;
  background: transparent;
  color: #e5e7eb;
  border: none;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
  transition: background 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

.file-menu-action {
  display: block;
}

.menu-panel .menu-action:hover,
.menu-panel .file-menu-action:hover {
  background: rgb(183 243 77 / 18%);
  color: #172033;
  transform: translateX(4px);
  box-shadow: none;
}

.menu-panel .menu-action:disabled {
  opacity: 0.52;
  background: transparent;
  color: #cbd5e1;
  cursor: not-allowed;
  transform: none;
}

.menu-panel .menu-action:disabled:hover {
  background: transparent;
  color: #cbd5e1;
  transform: none;
  box-shadow: none;
}

[data-theme="dark"] .menu-panel .menu-action:hover,
[data-theme="dark"] .menu-panel .file-menu-action:hover {
  background: rgb(183 243 77 / 16%);
  color: #ffffff;
}

[data-theme="dark"] .menu-panel .menu-action:not(:disabled):hover,
[data-theme="dark"] .menu-panel .file-menu-action:hover {
  background: linear-gradient(135deg, var(--lime), var(--lime2));
  color: #172033;
}

[data-theme="dark"] .menu-panel .menu-action:disabled,
[data-theme="dark"] .menu-panel .menu-action:disabled:hover {
  color: #94a3b8;
  background: transparent;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--button-text);
  box-shadow: none;
}

.secondary-button:hover {
  background: #f8fbff;
  box-shadow: 0 8px 20px rgb(37 99 235 / 10%);
}

.success-button {
  background: #d9f99d;
  color: #3f6212;
}

.success-button:hover {
  background: #bef264;
  box-shadow: 0 8px 20px rgb(132 204 22 / 18%);
}

.beige-tool-button {
  border-color: #f4d99f;
  background: #fdecc8;
  color: #9a6a16;
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 45%), 0 1px 0 rgb(154 106 22 / 8%);
}

.beige-tool-button:hover {
  background: #fbdc9a;
  box-shadow: 0 8px 20px rgb(154 106 22 / 16%);
}

.green-tool-button {
  background: #d9f99d;
  color: #3f6212;
  font-weight: 800;
}

.green-tool-button:hover {
  background: #bef264;
  box-shadow: 0 8px 20px rgb(132 204 22 / 18%);
}

/* Keep the Prgm launcher visually aligned with the adjacent Edit menu. */
#xml-prgm-preview-btn:not(:disabled) {
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  background: linear-gradient(135deg, var(--lime), var(--lime2));
  color: #2d3d17;
  font-weight: 800;
  box-shadow: 0 0 20px rgb(183 243 77 / 25%);
}

#xml-prgm-preview-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 0 30px rgb(183 243 77 / 35%), 0 0 80px rgb(183 243 77 / 12%);
}

[data-theme="dark"] #xml-prgm-preview-btn:hover:not(:disabled) {
  color: #ffffff;
}

.yellow-tool-button {
  background: #fde68a;
  color: #854d0e;
  font-weight: 800;
}

.yellow-tool-button:hover {
  background: #facc15;
  box-shadow: 0 8px 20px rgb(202 138 4 / 18%);
}

.lua-toolbar .green-tool-button,
.lua-toolbar #lua-guide {
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--lime), var(--lime2));
  color: #2d3d17;
  font-weight: 900;
  box-shadow: 0 0 20px rgb(183 243 77 / 25%);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.lua-toolbar .green-tool-button:hover,
.lua-toolbar #lua-guide:hover {
  transform: translateY(-2px) scale(1.04);
  background: linear-gradient(135deg, var(--lime), var(--lime2));
  color: #ffffff;
  box-shadow: 0 0 30px rgb(183 243 77 / 35%), 0 0 80px rgb(183 243 77 / 12%);
}

.lua-toolbar .love-preview-tool-button {
  background: linear-gradient(135deg, #e658a0, #ff7dbc);
  color: #fff7fb;
  box-shadow: 0 0 24px rgb(230 88 160 / 36%), 0 0 74px rgb(230 88 160 / 15%);
}

.lua-toolbar .love-preview-tool-button:hover {
  background: linear-gradient(135deg, #ff69ad, #ff9aca);
  color: #ffffff;
  box-shadow: 0 0 30px rgb(230 88 160 / 45%), 0 0 88px rgb(230 88 160 / 18%);
}

.doctor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.75fr);
  gap: 12px;
  min-height: 520px;
}

.doctor-grid.analysis-hidden,
.lua-doctor-grid.analysis-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.code-shell {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  height: 520px;
  min-height: 520px;
  max-height: 520px;
}

.code-shell > .line-numbers,
.lua-code-shell > .line-numbers {
  padding: 10px 6px;
  background: #f8fafc;
  color: #64748b;
  font: 13px/19px Consolas, monospace;
  user-select: none;
  overflow: hidden;
}

.line-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  height: 19px;
  line-height: 19px;
}

.line-row .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
  opacity: 0;
}

.line-row.error .dot {
  background: #ef4444;
  opacity: 1;
}

.line-row.warning .dot {
  background: #f59e0b;
  opacity: 1;
}

#xml-code,
#py-code {
  min-height: 0;
  height: 520px;
  margin: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  line-height: 19px;
  white-space: pre;
  overflow: auto;
}

.editor-wrap {
  position: relative;
  height: 520px;
  overflow: hidden;
  background: #fff;
}

#xml-highlight,
#xml-code,
#py-highlight,
#py-code {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 10px;
  font: 13px/19px Consolas, monospace;
  tab-size: 4;
}

#xml-highlight,
#py-highlight {
  margin: 0;
  color: #111827;
  pointer-events: none;
  overflow: hidden;
  white-space: pre;
}

.code-line {
  height: 19px;
  line-height: 19px;
  min-width: max-content;
}

.code-line.error {
  background: #fee2e2;
}

.code-line.warning {
  background: #fef3c7;
}

[data-theme="dark"] .code-line.error {
  background: #3b121a;
}

[data-theme="dark"] .code-line.warning {
  background: #3a2a10;
}

#xml-code,
#py-code {
  color: transparent;
  caret-color: #0f766e;
  background: transparent;
  resize: none;
}

#xml-code::selection,
#py-code::selection {
  background: rgb(147 197 253 / 55%);
}

.tok-keyword {
  color: #0000ff;
  font-weight: 700;
}

.tok-string {
  color: #008000;
}

.tok-py-string {
  color: #00a000;
}

.tok-op-red {
  color: #ff0000;
  font-weight: 700;
}

.tok-variable {
  color: #000;
  font-style: italic;
}

.tok-plain {
  color: #000;
}

[data-theme="dark"] #xml-highlight,
[data-theme="dark"] #py-highlight,
[data-theme="dark"] .lua-highlight,
[data-theme="dark"] .tok-plain {
  color: #e5eefb;
}

[data-theme="dark"] .tok-keyword {
  color: #7dd3fc;
}

[data-theme="dark"] .tok-string,
[data-theme="dark"] .tok-py-string,
[data-theme="dark"] .tok-lua-string {
  color: #86efac;
}

[data-theme="dark"] .tok-op-red {
  color: #fb7185;
}

[data-theme="dark"] .tok-comment {
  color: #94a3b8;
}

.doctor-side {
  display: flex;
  flex-direction: column;
  min-height: 560px;
}

.doctor-grid.analysis-hidden > .doctor-side,
.lua-doctor-grid.analysis-hidden > .lua-side {
  display: none !important;
}

.doctor-side[hidden],
.lua-side[hidden] {
  display: none !important;
}

.side-log-title,
.doctor-side > .mini-log,
.lua-side > .mini-log {
  display: none !important;
}

.doctor-side h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.summary {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fff;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  column-gap: 8px;
}

.summary strong {
  display: block;
  font-size: 24px;
}

.summary span {
  color: var(--muted);
  font-size: 12px;
  grid-column: 2;
}

.summary img {
  width: 24px;
  height: 24px;
  grid-row: 1 / span 2;
}

.summary.error strong {
  color: #ef4444;
}

.summary.warning strong {
  color: #f59e0b;
}

.summary.info strong {
  color: #3b82f6;
}

.problem-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  display: block;
  max-height: 230px;
  overflow-y: auto;
  margin-bottom: 14px;
}

.problem-table thead,
.problem-table tbody,
.problem-table tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

.problem-table th,
.problem-table td {
  border-bottom: 1px solid #edf2f7;
  padding: 8px;
  font-size: 12px;
  text-align: left;
}

.problem-table th:nth-child(1),
.problem-table td:nth-child(1) {
  width: 70px;
}

.problem-table th:nth-child(2),
.problem-table td:nth-child(2) {
  width: 55px;
}

.problem-table tr {
  cursor: pointer;
}

.problem-table tr:hover {
  background: #f8fafc;
}

.problem-table tr.ERROR {
  color: #dc2626;
  font-weight: 700;
}

[data-theme="dark"] .problem-table tr.ERROR,
[data-theme="dark"] .lua-problem-table tr.ERROR {
  color: #f87171;
  background: #3b121a;
}

.problem-table tr.WARNING {
  color: #ca8a04;
  font-weight: 700;
  background: #fffbeb;
}

.problem-table tr.INFO {
  color: #2563eb;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 48%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  animation: backdropIn 240ms ease both;
}

.modal {
  width: min(720px, calc(100vw - 28px));
  max-height: min(720px, calc(100vh - 28px));
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 80px rgb(15 23 42 / 35%);
  padding: 18px;
  animation: modalSlideIn 320ms cubic-bezier(0.2, 0.95, 0.2, 1) both;
}

.modal-backdrop.closing {
  animation: backdropOut 240ms ease both;
}

.modal-backdrop.closing .modal {
  animation: modalSlideOut 240ms ease both;
}

.modal h2 {
  margin-top: 0;
}

.about-modal {
  width: min(920px, calc(100vw - 28px));
}

.document-modal {
  width: min(640px, calc(100vw - 28px));
}

.inspector-modal {
  width: min(1100px, calc(100vw - 28px));
  overflow-x: hidden;
  overflow-y: auto;
}

.py-doctor-modal {
  width: min(1240px, calc(100vw - 28px));
  max-height: min(92vh, 820px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.py-doctor-modal #py-doctor-modal-slot {
  min-height: 0;
  overflow: auto;
}

.py-doctor-modal #py-doctor-panel {
  margin: 0;
  box-shadow: none;
}

.py-doctor-modal #py-doctor-panel:not(.collapsed) {
  display: block;
}

.py-doctor-modal .doctor-grid {
  min-height: min(58vh, 560px);
}

.py-preview-modal {
  width: min(780px, calc(100vw - 28px));
}

.py-preview-modal .muted-text {
  color: var(--muted);
  margin: -4px 0 14px;
}

.py-preview-label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.py-preview-label textarea {
  min-height: 110px;
  resize: vertical;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
}

.py-preview-terminal-label {
  margin-top: 12px;
}

.py-preview-terminal-label input {
  min-height: 42px;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
}

.py-preview-terminal-label input::placeholder {
  color: var(--muted);
}

.py-preview-output {
  min-height: 220px;
  max-height: 330px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--code-bg);
  color: var(--code-text);
  white-space: pre-wrap;
}

.lua-modal {
  width: min(1240px, calc(100vw - 28px));
}

.lua-preview-modal {
  width: min(470px, calc(100vw - 28px));
  max-height: min(92vh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.love-preview-modal {
  width: min(920px, calc(100vw - 28px));
  max-height: min(92vh, 820px);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
}

.love-project-modal {
  width: min(640px, calc(100vw - 28px));
}

.love-project-picker {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    radial-gradient(circle at 0 0, rgba(255, 105, 173, 0.12), transparent 36%),
    rgba(7, 16, 33, 0.78);
}

.love-project-picker label {
  color: var(--muted);
  font-weight: 800;
}

.love-project-picker input:not([type="file"]) {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(5, 13, 28, 0.92);
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
}

.love-project-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#lua-preview-canvas {
  width: 318px;
  height: 212px;
  image-rendering: auto;
  border: 1px solid #424242;
  border-radius: 0;
  background: #fff;
  display: block;
  margin: 8px auto 12px;
}

.love-preview-stage {
  width: min(320px, 100%);
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  display: block;
  margin: 8px auto 12px;
}

.love-preview-stage.expanded-view {
  width: min(800px, 100%);
  max-width: 800px;
  height: auto;
  aspect-ratio: 4 / 3;
}

.love-preview-calculator-bar {
  height: 26px;
  width: 100%;
  background: #313531;
  color: #edf2ed;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 700 12px Consolas, "Courier New", monospace;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.love-preview-stage.expanded-view .love-preview-calculator-bar {
  display: none;
}

#love-preview-canvas {
  width: 100%;
  height: auto;
  image-rendering: auto;
  border: 0;
  border-radius: 0;
  background: #000;
  display: block;
  margin: 0;
  outline: none;
}

#love-preview-canvas.expanded-view {
  width: 100%;
  height: 100%;
  max-height: none;
}

#love-preview-log {
  flex: 0 0 auto;
  max-height: 160px;
}

.preview-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}

.preview-text-capture {
  width: min(318px, 100%);
  margin: 0 auto 10px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font: 13px Consolas, monospace;
  color: var(--text);
  background: var(--panel);
}

.lua-library-modal {
  width: min(980px, calc(100vw - 28px));
}

.lua-template-builder-modal {
  width: min(1240px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.library-search {
  width: 100%;
  margin: 4px 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 14px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.lua-guide-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -2px 0 14px;
}

.lua-guide-categories button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  color: var(--muted);
  padding: 8px 13px;
  font-weight: 850;
  cursor: pointer;
}

.lua-guide-categories button.active {
  border-color: var(--lime);
  background: linear-gradient(135deg, var(--lime), var(--lime2));
  color: #203900;
  box-shadow: 0 0 18px rgb(183 243 77 / 22%);
}

.lua-guide-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  max-height: min(56vh, 470px);
  overflow: auto;
  padding-right: 4px;
}

.lua-guide-item,
.lua-template-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  padding: 13px;
}

.lua-guide-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.lua-guide-item code {
  color: #2563eb;
  font-weight: 800;
  overflow-wrap: anywhere;
}

[data-theme="dark"] .lua-guide-item code {
  color: #93c5fd;
}

.lua-guide-category {
  border-radius: 999px;
  background: color-mix(in srgb, var(--lime) 18%, transparent);
  color: var(--lime2);
  flex: 0 0 auto;
  font-size: 0.74rem;
  font-weight: 900;
  padding: 4px 8px;
}

.lua-guide-item p,
.lua-template-card p,
.muted-copy {
  color: var(--muted);
  margin: 8px 0 0;
  line-height: 1.45;
}

.lua-template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.lua-template-card {
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.lua-template-card:hover,
.lua-template-card.selected {
  transform: translateY(-2px);
  border-color: #a3e635;
  box-shadow: 0 18px 34px rgb(132 204 22 / 18%);
}

.lua-template-card h3 {
  margin: 0;
}

.template-preview {
  height: 112px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(#d9d9d9, #d9d9d9) 0 0 / 100% 100% no-repeat;
  position: relative;
  overflow: hidden;
}

.template-preview-canvas {
  width: 100%;
  height: 150px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #e0e0e0;
  display: block;
}

.template-preview.form::before {
  content: "";
  position: absolute;
  inset: 18px 18px auto 88px;
  height: 16px;
  box-shadow: 0 26px 0 #fff, 0 52px 0 #fff;
  background: #fff;
  border: 2px solid #8b8b8b;
}

.template-preview.form::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 20px;
  height: 2px;
  background: #8b8b8b;
  box-shadow: 0 12px 0 #fff, 145px 12px 0 #fff;
}

.template-preview.menu::before {
  content: "";
  position: absolute;
  left: 20px;
  top: 20px;
  width: 150px;
  height: 18px;
  border-radius: 2px;
  background: #35a0be;
  box-shadow: 0 24px 0 #f8fafc, 0 48px 0 #f8fafc, 0 72px 0 #f8fafc;
}

.template-preview.popup::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 112px;
  height: 58px;
  transform: translate(-50%, -50%);
  background: #fff;
  box-shadow: 8px 8px 0 rgb(0 0 0 / 10%);
}

.template-preview.popup::after {
  content: "OK";
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translateX(-50%);
  color: #fff;
  background: #2563eb;
  border-radius: 3px;
  padding: 3px 14px;
  font-weight: 800;
  font-size: 11px;
}

.template-preview.details::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 18px;
  width: 138px;
  height: 16px;
  background: #fff;
  border: 2px solid #8b8b8b;
  box-shadow: 0 25px 0 #fff, 0 50px 0 #fff, 0 76px 0 #8b8b8b;
}

.template-preview.details::after {
  content: "Detalles";
  position: absolute;
  right: 12px;
  bottom: 12px;
  color: #111827;
  background: #fff;
  border: 2px solid #8b8b8b;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
}

.lua-template-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.lua-template-options label {
  color: var(--muted);
  font-weight: 800;
}

.lua-template-options input {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  background: var(--panel);
  color: var(--text);
}

.lua-template-options input[type="color"] {
  padding: 3px;
  height: 39px;
}

.lua-template-builder {
  display: grid;
  grid-template-columns: minmax(220px, 0.78fr) minmax(300px, 1fr) minmax(460px, 1.8fr);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(135deg, rgb(15 23 42 / 4%), rgb(15 23 42 / 1%));
  margin-top: 14px;
  min-height: 520px;
  width: 100%;
  box-sizing: border-box;
  flex: 1;
  min-height: 0;
  max-height: calc(100vh - 210px);
}

.template-column {
  padding: 16px;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  box-sizing: border-box;
}

.template-column + .template-column {
  border-left: 1px solid var(--line);
}

.template-column h3,
.generated-code-header h3 {
  margin: 0 0 14px;
  font-size: 14px;
}

.template-type-list {
  display: grid;
  gap: 8px;
}

.lua-template-type {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 14px 12px;
  background: color-mix(in srgb, var(--panel) 86%, #1d4ed8 14%);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  box-sizing: border-box;
  min-width: 0;
}

.lua-template-type > span:last-child {
  min-width: 0;
}

.lua-template-type strong {
  overflow-wrap: anywhere;
}

.lua-template-type.selected,
.lua-template-type:hover {
  border-color: #a3e635;
  box-shadow: inset 4px 0 0 #a3e635;
  background: color-mix(in srgb, var(--panel) 76%, #a3e635 24%);
}

.template-type-icon {
  width: 22px;
  text-align: center;
  color: #d9f99d;
  font-weight: 900;
}

.template-options-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-content: start;
  overflow: auto;
  max-height: none;
  min-width: 0;
}

.template-options-column label {
  color: var(--muted);
  font-weight: 800;
  margin: 0;
}

.template-options-column input,
.template-options-column select {
  width: 100%;
  box-sizing: border-box;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  background: var(--panel);
  color: var(--text);
}

.template-option-grid {
  display: grid;
  gap: 12px;
}

.template-binding-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: end;
  gap: 10px;
  margin-bottom: 10px;
}

.template-binding-row span {
  color: var(--text-strong);
  font-weight: 800;
  padding-bottom: 10px;
}

.template-checks {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
}

.template-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 800;
}

.template-check input {
  width: auto;
  margin: 0;
  accent-color: #a3e635;
}

.menu-route-editor {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, #a3e635 35%, var(--line));
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 90%, #a3e635 10%);
}

.menu-route-editor h4 {
  margin: 0;
  font-size: 13px;
}

.menu-route-row {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.template-options-column input[type="color"] {
  height: 42px;
  padding: 4px;
}

.template-options-column input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.template-preview-stage {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  overflow: hidden;
}

.template-preview-stage .template-preview-canvas {
  display: block;
  width: min(100%, 520px);
  height: auto;
  margin: 0 auto;
}

.generated-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
}

.generated-code-header button {
  color: #84cc16;
  background: transparent;
  padding: 6px 8px;
}

.lua-template-code {
  max-height: 210px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #0f172a;
  color: #c4b5fd;
  font: 12px/1.45 Consolas, monospace;
}

.lua-page-editor-modal {
  width: min(1180px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.lua-page-editor-grid {
  display: grid;
  grid-template-columns: minmax(210px, 0.72fr) minmax(300px, 1fr) minmax(420px, 1.55fr);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin-top: 14px;
  min-height: 430px;
  flex: 1;
  min-height: 0;
  max-height: calc(100vh - 220px);
}

.page-editor-list,
.page-editor-panel,
.page-editor-preview {
  min-width: 0;
}

.page-editor-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  max-height: none;
  overflow: auto;
}

.page-editor-list,
.page-editor-preview {
  overflow: auto;
}

.lua-template-builder-modal > .modal-actions,
.lua-page-editor-modal > .modal-actions {
  display: none;
}

.page-picker {
  width: 100%;
}

.page-picker .menu-trigger {
  width: 100%;
  justify-content: center;
}

.page-picker-panel {
  width: min(300px, calc(100vw - 72px));
  max-height: 320px;
  overflow: auto;
}

.page-picker-panel .file-menu-action.active {
  background: transparent;
  color: #e5e7eb;
  font-weight: 900;
}

[data-theme="dark"] .page-picker-panel .file-menu-action.active {
  background: transparent;
  color: #e5e7eb;
}

.lua-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.lua-toolbar h2 {
  margin: 0 auto 0 0;
}

.lua-edit-menu {
  position: relative;
  display: inline-flex;
}

.lua-edit-menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  min-width: 190px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, #a3e635 35%, var(--line));
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 88%, #0f172a 12%);
  box-shadow: 0 18px 38px rgb(0 0 0 / 28%), 0 0 28px rgb(163 230 53 / 16%);
  z-index: 80;
}

.lua-edit-menu-panel[hidden] {
  display: none;
}

.lua-edit-menu-panel button {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 800;
}

.lua-edit-menu-panel button:hover {
  background: color-mix(in srgb, #a3e635 18%, transparent);
}

#lua-line-label {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.lua-doctor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 12px;
  min-width: 0;
}

.lua-code-shell {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  height: 560px;
}

.lua-editor-wrap {
  position: relative;
  height: 560px;
  overflow: hidden;
  background: #fff;
}

.monaco-code-host {
  position: absolute;
  inset: 0 0 0 10px;
  z-index: 4;
  overflow: hidden;
  background: #fff;
}

.monaco-code-host .monaco-editor,
.monaco-code-host .monaco-editor-background,
.monaco-code-host .monaco-editor .margin {
  background: #fff !important;
}

[data-theme="dark"] .monaco-code-host {
  background: #0f172a;
}

[data-theme="dark"] .monaco-code-host .monaco-editor,
[data-theme="dark"] .monaco-code-host .monaco-editor-background,
[data-theme="dark"] .monaco-code-host .monaco-editor .margin {
  background: #0f172a !important;
}

html:not([data-theme="dark"]) .code-shell,
html:not([data-theme="dark"]) .editor-wrap,
html:not([data-theme="dark"]) .lua-code-shell,
html:not([data-theme="dark"]) .lua-editor-wrap,
html:not([data-theme="dark"]) .monaco-code-host {
  background: #fff !important;
  color: #172033 !important;
}

html:not([data-theme="dark"]) .code-shell > .line-numbers,
html:not([data-theme="dark"]) .lua-code-shell > .line-numbers {
  background: #f8fafc;
  color: #64748b;
}

html:not([data-theme="dark"]) .monaco-code-host .monaco-editor,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor-background,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .margin,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .lines-content,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .view-lines,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .view-overlays {
  background: #fff !important;
}

html:not([data-theme="dark"]) .modal-card .monaco-code-host,
html:not([data-theme="dark"]) .lua-doctor-modal .monaco-code-host,
html:not([data-theme="dark"]) .doctor-card .monaco-code-host {
  background: #fff !important;
  color: #172033 !important;
}

html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .view-line,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .view-line span {
  opacity: 1 !important;
}

html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .mtk1,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .mtk2,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .mtk3,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .mtk4,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .mtk5,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .mtk6,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .mtk7,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .mtk8,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .mtk9,
html:not([data-theme="dark"]) .monaco-code-host .monaco-editor .mtk10 {
  opacity: 1 !important;
}

.monaco-code-host .monaco-editor .glyph-margin,
.monaco-code-host .monaco-editor .margin-view-overlays {
  overflow: visible;
}

.monaco-code-host .monaco-editor .codicon-folding-expanded,
.monaco-code-host .monaco-editor .codicon-folding-collapsed,
.monaco-code-host .monaco-editor .cldr {
  opacity: 1 !important;
}

.monaco-code-host .monaco-scrollable-element > .scrollbar.vertical {
  width: 42px !important;
}

.monaco-code-host .monaco-scrollable-element > .scrollbar.horizontal {
  height: 12px !important;
}

.editor-wrap.monaco-enabled > pre,
.editor-wrap.monaco-enabled > textarea,
.lua-editor-wrap.monaco-enabled > .lua-highlight,
.lua-editor-wrap.monaco-enabled > .lua-editor {
  display: none;
}

.code-shell.monaco-enabled,
.lua-code-shell.monaco-enabled {
  grid-template-columns: minmax(0, 1fr);
}

.code-shell.monaco-enabled > .line-numbers,
.lua-code-shell.monaco-enabled > .line-numbers {
  display: none;
}

.lua-highlight,
.lua-editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 12px;
  border: 0;
  outline: 0;
  font: 13px/19px Consolas, monospace;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  letter-spacing: 0;
}

.lua-highlight {
  color: #111827;
  pointer-events: none;
  overflow: auto;
  scrollbar-width: none;
  user-select: none;
  z-index: 3;
}

.lua-highlight::-webkit-scrollbar {
  display: none;
}

[data-theme="dark"] .lua-code-shell,
[data-theme="dark"] .lua-editor-wrap {
  background:
    radial-gradient(circle at 16px 16px, rgb(147 197 253 / 5%) 0 1px, transparent 1px) 0 0 / 18px 18px,
    linear-gradient(180deg, #0f172a, #111c32);
}

.lua-editor {
  resize: none;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: #0f766e;
  overflow: auto;
  z-index: 2;
}

.lua-editor::selection {
  background: rgb(147 197 253 / 55%);
  color: transparent;
  -webkit-text-fill-color: transparent;
}

[data-theme="dark"] .lua-editor::selection {
  background: rgb(96 165 250 / 45%);
  color: transparent;
  -webkit-text-fill-color: transparent;
}

[data-theme="dark"] #xml-code::selection,
[data-theme="dark"] #py-code::selection {
  background: rgb(96 165 250 / 45%);
  color: #ffffff;
}

.lua-side {
  min-width: 0;
  min-height: 560px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.lua-problem-table {
  display: block;
  max-height: 190px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
}

.lua-problem-table thead,
.lua-problem-table tbody,
.lua-problem-table tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

.lua-problem-table tbody {
  display: block;
}

.lua-problem-table tr.ERROR {
  color: #dc2626;
  font-weight: 700;
  background: #fef2f2;
}

.lua-problem-table tr.WARNING {
  color: #b45309;
  font-weight: 700;
  background: #fffbeb;
}

.tok-comment {
  color: #64748b;
  font-style: italic;
}

.tok-lua-string {
  color: #047857;
  font-weight: 650;
}

.tok-api {
  color: #0284c7;
  font-weight: 800;
}

.tok-member {
  color: #9333ea;
  font-weight: 750;
}

.tok-function {
  color: #c2410c;
  font-weight: 800;
}

.tok-variable {
  color: #be185d;
  font-weight: 750;
}

.tok-number {
  color: #dc2626;
  font-weight: 750;
}

[data-theme="dark"] .tok-api {
  color: #38bdf8;
}

[data-theme="dark"] .tok-member {
  color: #c084fc;
}

[data-theme="dark"] .tok-function {
  color: #fbbf24;
}

[data-theme="dark"] .tok-variable {
  color: #f9a8d4;
}

[data-theme="dark"] .tok-number {
  color: #fca5a5;
}

.inspector-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.inspector-summary span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--text);
  font-weight: 700;
}

[data-theme="dark"] .inspector-summary span {
  background: #1e293b;
  color: #dbeafe;
  border-color: #334155;
}

.inspector-table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  max-height: 430px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.inspector-table {
  min-width: 1120px;
  table-layout: fixed;
}

.inspector-table th:nth-child(1),
.inspector-table td:nth-child(1) {
  width: 150px;
}

.inspector-table th:nth-child(2),
.inspector-table td:nth-child(2) {
  width: 210px;
}

.inspector-table th:nth-child(3),
.inspector-table td:nth-child(3) {
  width: 110px;
}

.inspector-table th:nth-child(4),
.inspector-table td:nth-child(4) {
  width: 150px;
}

.inspector-table th:nth-child(5),
.inspector-table td:nth-child(5) {
  width: 240px;
}

.inspector-table th:nth-child(6),
.inspector-table td:nth-child(6) {
  width: 260px;
}

.inspector-table td {
  overflow-wrap: anywhere;
  vertical-align: top;
}

.mini-action {
  padding: 6px 10px;
  margin: 2px;
  border-radius: 999px;
}

.green-mini-action {
  background: #d9f99d;
  color: #3f6212;
  font-weight: 800;
}

.green-mini-action:hover {
  background: #bef264;
}

@keyframes backdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes backdropOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(54px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modalSlideOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(58px) scale(0.97);
  }
}

@keyframes revealPanel {
  from {
    opacity: 0;
    transform: translateY(26px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes hidePanel {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(28px) scale(0.985);
  }
}

.inspector-code {
  max-height: 560px;
  overflow: auto;
  padding: 12px;
  border-radius: 10px;
  background: #0f172a;
  color: #e2e8f0;
  font: 12px/1.5 Consolas, monospace;
  white-space: pre;
}

.image-resource-preview {
  display: grid;
  place-items: center;
  min-height: 260px;
  max-height: 70vh;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(45deg, rgba(148, 163, 184, 0.12) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(148, 163, 184, 0.12) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(148, 163, 184, 0.12) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(148, 163, 184, 0.12) 75%);
  background-color: var(--panel-2);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.image-resource-meta {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.image-resource-preview img,
.image-resource-preview canvas {
  max-width: 100%;
  max-height: 66vh;
  width: auto;
  height: auto;
  object-fit: contain;
  image-rendering: auto;
}

.image-resource-preview .image-source-preview {
  max-width: none;
  max-height: none;
  width: auto !important;
  height: auto !important;
  aspect-ratio: auto;
}

.image-resource-preview.calculator-mode {
  background: #0b1220;
}

.image-calculator-canvas {
  width: 320px;
  max-width: 100%;
  height: auto;
  border: 1px solid rgba(226, 232, 240, 0.38);
  border-radius: 4px;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.35);
  cursor: grab;
  outline: none;
}

.image-calculator-canvas.dragging {
  cursor: grabbing;
}

.image-source-preview[hidden],
.image-calculator-canvas[hidden] {
  display: none;
}

.image-resource-error {
  padding: 14px 16px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  border-radius: 10px;
  background: rgba(127, 29, 29, 0.28);
  color: #fecaca;
  font: 12px/1.45 Consolas, monospace;
}

.document-form {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 12px 14px;
  align-items: center;
}

.document-form label {
  color: var(--muted);
  font-weight: 700;
}

.document-form input,
.document-form select {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

[data-theme="dark"] .document-form input,
[data-theme="dark"] .document-form select {
  background: #0f172a;
  color: #e5eefb;
  border-color: #334155;
}

[data-theme="dark"] .document-form input::placeholder {
  color: #94a3b8;
}

.about-modal h3 {
  margin: 18px 0 8px;
  color: #0f172a;
}

[data-theme="dark"] .about-modal h3 {
  color: #e5eefb;
}

.about-modal p,
.about-modal li {
  line-height: 1.55;
}

.about-modal ul {
  padding-left: 22px;
}

.about-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.about-links a {
  padding: 8px 12px;
  border-radius: 999px;
  background: #ecfdf5;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.about-disclaimer {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid #fed7aa;
  border-radius: 10px;
  background: #fff7ed;
  color: #7c2d12;
}

[data-theme="dark"] .about-disclaimer {
  background: #24130a;
  border-color: #fdba74;
  color: #fed7aa;
}

.about-disclaimer::selection,
.about-disclaimer *::selection {
  background: #2563eb;
  color: #ffffff;
}

.resolver-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin: 10px 0;
}

.resolver-item strong {
  display: block;
  margin-bottom: 8px;
}

.resolver-option {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  color: var(--text);
}

.resolver-option input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.modal-top-actions {
  position: sticky;
  top: -18px;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: -8px -8px 10px;
  padding: 8px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(10px);
}

.mini-log {
  flex: 1;
  min-height: 150px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  background: #0f172a;
  color: #d1fae5;
  font: 12px Consolas, monospace;
}

#lua-preview-log {
  flex: 0 0 auto;
  height: 180px;
  min-height: 180px;
  max-height: 180px;
  white-space: pre;
}

#log {
  min-height: 180px;
  max-height: 320px;
  overflow: auto;
  padding: 12px;
  background: #0f172a;
  color: #d1fae5;
  border-radius: 8px;
  font: 13px Consolas, monospace;
}

@media (max-width: 1100px) {
  .shell-header {
    flex-wrap: wrap;
  }

  /* Inline submenus have no safe space beside the File menu at this width. */
  .doctor-toolbar .nested-panel {
    position: static;
    width: 100%;
    margin-top: 6px;
  }

  .doctor-toolbar .nested-menu:not(.open) > .nested-panel {
    display: none;
  }

  .doctor-toolbar .nested-menu.open > .nested-panel {
    display: block;
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  .doctor-grid,
  .lua-doctor-grid {
    grid-template-columns: 1fr;
  }

  .doctor-side,
  .lua-side {
    min-width: 0;
  }

  .summary-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  body {
    font-size: 15px;
  }

  .shell-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: flex-start;
    gap: 10px;
    padding: 14px 12px;
  }

  .shell-header img {
    width: 42px;
    height: 42px;
  }

  .shell-header h1 {
    font-size: clamp(24px, 8vw, 34px);
    line-height: 1.05;
  }

  .shell-header p {
    font-size: 15px;
    line-height: 1.25;
  }

  .header-actions {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
  }

  .site-stats {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin-left: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
    gap: 8px;
  }

  .site-stat {
    min-width: 0;
    padding: 8px 10px;
  }

  .site-stat strong {
    font-size: clamp(18px, 7vw, 22px);
  }

  .site-stat span {
    overflow-wrap: anywhere;
    white-space: normal;
    font-size: 10px;
    line-height: 1.15;
  }

  .language-buttons {
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .language-buttons button {
    width: 34px;
    height: 34px;
  }

  .about-button {
    min-width: 116px;
    padding: 8px 10px;
    font-size: 13px;
  }

  .theme-button {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    flex-basis: 34px;
    padding: 0;
    font-size: 18px;
  }

  .header-actions #theme-btn.theme-button {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    min-height: 34px !important;
    flex: 0 0 34px !important;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  .tools-sidebar {
    grid-column: 1;
    grid-row: 1;
  }

  .panel {
    padding: 14px;
    border-radius: 10px;
  }

  .doctor-launcher button,
  .module-launcher button {
    display: none;
  }

  .log-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .home-panel,
  #xml-doctor-panel,
  #normal-module,
  #python-module {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
  }

  .home-panel {
    min-height: 420px;
  }

  .doctor-grid {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .module-grid {
    grid-template-columns: 1fr;
  }

  .doctor-toolbar {
    gap: 8px;
  }

  .doctor-toolbar h2 {
    width: 100%;
  }

  .doctor-toolbar button,
  .doctor-toolbar .file-button {
    flex: 1 1 calc(50% - 8px);
    text-align: center;
    font-size: 13px;
    padding: 9px 10px;
  }

  .doctor-toolbar .tool-menu {
    flex: 1 1 calc(50% - 8px);
  }

  .doctor-toolbar .menu-trigger,
  .doctor-toolbar > #xml-syntax-btn {
    width: 100%;
    justify-content: center;
  }

  .doctor-toolbar .menu-panel button,
  .doctor-toolbar .menu-panel .file-menu-action {
    flex: initial;
    width: 100%;
    text-align: left;
    font-size: 13px;
    padding: 10px 12px;
  }

  .nested-panel {
    position: static;
    width: 100%;
    margin-top: 6px;
    box-shadow: inset 0 0 0 1px rgb(183 243 77 / 12%);
  }

  .nested-menu:not(.open) > .nested-panel {
    display: none;
  }

  .nested-menu.open > .nested-panel {
    display: block;
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  .doctor-toolbar select,
  #xml-line-label,
  #py-line-label,
  #lua-line-label {
    width: 100%;
  }

  .code-shell,
  .editor-wrap,
  #xml-code,
  #py-code {
    height: 420px;
    min-height: 420px;
    max-height: 420px;
  }

  .doctor-side,
  .lua-side {
    min-height: 0;
  }

  .summary-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .modal-backdrop {
    align-items: flex-start;
    padding: 12px;
    overflow: auto;
  }

  .modal {
    width: 100%;
    max-height: none;
    padding: 14px;
  }

  .lua-modal,
  .lua-preview-modal,
  .love-preview-modal,
  .lua-library-modal {
    width: 100%;
    max-height: none;
    overflow: visible;
  }

  .lua-guide-list,
  .lua-template-grid,
  .lua-template-options {
    grid-template-columns: 1fr;
  }

  .lua-template-builder {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .template-column + .template-column {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .template-options-column {
    max-height: none;
    overflow: visible;
  }

  .menu-route-row {
    grid-template-columns: 1fr;
  }

  .lua-page-editor-grid {
    grid-template-columns: 1fr;
  }

  .page-editor-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .lua-guide-list {
    max-height: none;
  }

  .lua-toolbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .lua-toolbar h2 {
    width: 100%;
    font-size: 28px;
    line-height: 1.15;
  }

  .lua-toolbar button {
    flex: 1 1 calc(50% - 8px);
    font-size: 13px;
  }

  .lua-doctor-grid {
    grid-template-columns: 1fr;
  }

  .lua-code-shell,
  .lua-editor-wrap {
    height: 420px;
  }

  #lua-preview-canvas {
    width: min(318px, 100%);
    height: auto;
  }

  .love-preview-stage {
    width: min(320px, 100%);
  }

  .love-preview-stage.expanded-view {
    width: min(800px, 100%);
  }

  #love-preview-canvas.expanded-view {
    max-height: none;
  }

  .preview-controls button {
    flex: 1 1 calc(33.333% - 8px);
    padding: 9px 8px;
  }
}

@media (max-width: 560px) {
  .doctor-toolbar {
    align-items: stretch;
  }

  .doctor-toolbar .tool-menu,
  .doctor-toolbar > #xml-syntax-btn {
    flex: 1 1 100%;
  }

  .menu-trigger {
    min-height: 48px;
  }

  .menu-panel {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    width: 100%;
    max-height: min(70vh, 420px);
    overflow: auto;
    margin-bottom: 0;
  }

  .nested-panel {
    position: static;
    width: 100%;
    margin-top: 6px;
  }

  .nested-menu:not(.open) > .nested-panel {
    display: none;
  }

  .nested-menu.open > .nested-panel {
    display: block;
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }
}


/* Image resource viewer: fixed top controls + TI-Nspire-like default calculator view. */
.image-resource-modal {
  width: min(1180px, calc(100vw - 28px));
  max-height: min(92vh, 860px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.image-resource-modal-header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: relative;
  z-index: 3;
}

.image-resource-heading {
  min-width: 0;
}

.image-resource-modal .image-resource-title {
  margin: 0 0 8px;
}

.image-resource-modal .image-resource-meta {
  margin: 0;
}

.image-resource-top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.image-resource-modal .image-resource-preview {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  margin-top: 14px;
  overflow: auto;
}

.image-resource-preview.calculator-mode {
  min-height: 310px;
}

.image-calculator-canvas {
  width: 320px;
  height: 240px;
  max-width: 100%;
  image-rendering: pixelated;
}

@media (max-width: 700px) {
  .image-resource-modal-header {
    flex-direction: column;
  }
  .image-resource-top-actions {
    width: 100%;
    justify-content: flex-start;
  }
}


/* Document Inspector: +Page menu */
.inspector-modal-actions {
  position: relative;
  align-items: center;
}

.inspector-page-menu {
  position: relative;
}

.inspector-page-menu .menu-panel {
  top: auto;
  bottom: calc(100% + 10px);
  left: auto;
  right: 0;
  transform: translateY(16px) scale(0.9);
  transform-origin: bottom right;
}

.inspector-page-menu.open > .menu-panel {
  transform: translateY(0) scale(1);
}

/* Lists & Spreadsheet preview */
.spreadsheet-modal {
  width: min(980px, calc(100vw - 36px));
  max-height: min(820px, calc(100vh - 36px));
  overflow: auto;
}

.spreadsheet-modal-header {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 14px;
  background: var(--panel);
}

.spreadsheet-modal-header h2 {
  margin: 0 0 4px;
}

.spreadsheet-source-name {
  color: var(--muted);
  font-size: 12px;
}

.spreadsheet-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.spreadsheet-preview-stage {
  min-height: 430px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0f172a;
  display: grid;
  place-items: center;
  overflow: auto;
}

.spreadsheet-calc {
  width: 640px;
  height: 480px;
  flex: 0 0 auto;
  background: #f4f4f4;
  border: 2px solid #1f2937;
  box-shadow: 0 18px 44px rgb(0 0 0 / 28%);
  color: #222;
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr) 46px;
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
}

.spreadsheet-calc-topbar {
  display: grid;
  grid-template-columns: 150px 1fr 145px;
  align-items: center;
  height: 56px;
  background: #2f3737;
  color: #fff;
  border-bottom: 2px solid #8c5b2c;
  font-size: 22px;
}

.spreadsheet-page-tab {
  height: 100%;
  display: grid;
  grid-template-columns: 32px 54px 32px;
  align-items: center;
  justify-content: start;
}

.spreadsheet-page-tab span:nth-child(2) {
  height: 44px;
  display: grid;
  place-items: center;
  background: #f4f4f4;
  color: #111;
  border-right: 1px solid #999;
  border-left: 1px solid #999;
  font-size: 19px;
}

.spreadsheet-tab-arrow {
  text-align: center;
  color: #72b7d5;
  font-size: 17px;
}

.spreadsheet-doc-title {
  text-align: center;
  font-size: 19px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spreadsheet-calc-status {
  text-align: right;
  padding-right: 16px;
  font-size: 16px;
  letter-spacing: 0.02em;
}

.spreadsheet-grid-shell {
  min-height: 0;
  overflow: auto;
  background: #efefef;
}

.spreadsheet-grid {
  --sheet-cols: 8;
  display: grid;
  grid-template-columns: 64px repeat(var(--sheet-cols), 138px);
  grid-auto-rows: 54px;
  min-width: max-content;
  min-height: max-content;
  background: #d9d9d9;
  outline: none;
}

.sheet-corner,
.sheet-col-header,
.sheet-row-header {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e5e5e7;
  color: #6c6c6c;
  border-right: 1px solid #bcbcbc;
  border-bottom: 1px solid #bcbcbc;
  user-select: none;
  font-size: 18px;
}

.sheet-corner::after {
  content: "=";
  color: #777;
  font-weight: 700;
}

.sheet-cell {
  padding: 10px 12px;
  overflow: hidden;
  white-space: nowrap;
  background: #fafafa;
  color: #202020;
  border-right: 1px solid #c9c9c9;
  border-bottom: 1px solid #c9c9c9;
  outline: none;
  font-size: 18px;
}

.sheet-cell.active {
  position: relative;
  box-shadow: inset 0 0 0 4px #2a77d4;
  z-index: 2;
  background: #fff;
}

.spreadsheet-formula-bar {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 95px;
  align-items: center;
  background: #e7e4ea;
  border-top: 1px solid #9a9a9a;
  color: #292929;
  font-size: 17px;
}

.spreadsheet-cell-name {
  height: 100%;
  display: grid;
  place-items: center;
  background: #4b4b50;
  color: #fff;
  font-style: italic;
}

.spreadsheet-formula-value {
  padding: 0 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.spreadsheet-nav-arrows {
  text-align: center;
  font-size: 16px;
}

.spreadsheet-preview-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 760px) {
  .spreadsheet-modal-header {
    align-items: flex-start;
    flex-direction: column;
  }
  .spreadsheet-header-actions {
    justify-content: flex-start;
  }
  .spreadsheet-preview-stage {
    padding: 14px;
    justify-content: start;
  }
}


/* File > +Page: available even with no document loaded. */
.file-page-menu > .nested-trigger {
  color: #d9f99d;
}

[data-theme="dark"] .file-page-menu > .nested-trigger {
  color: #d9f99d;
}

/* Document Inspector +Page: responsive/mobile positioning.
   Keep the menu inside the modal and prevent the generic mobile .menu-panel
   rule from shrinking it to the width of the +Page button. */
.inspector-page-menu .menu-panel {
  width: min(320px, calc(100vw - 48px));
  max-width: min(320px, calc(100vw - 48px));
  overflow-x: hidden;
}

.inspector-page-menu .menu-panel .menu-action {
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

@media (max-width: 700px) {
  .inspector-modal {
    width: calc(100vw - 20px);
    padding: 14px;
  }

  .inspector-modal-actions {
    width: 100%;
    justify-content: flex-end;
    gap: 10px;
  }

  .inspector-page-menu {
    flex: 0 0 auto;
  }

  .inspector-page-menu .menu-panel {
    position: absolute;
    top: auto;
    bottom: calc(100% + 10px);
    left: auto;
    right: 0;
    width: min(320px, calc(100vw - 48px));
    max-width: min(320px, calc(100vw - 48px));
    max-height: min(55vh, 360px);
    overflow-y: auto;
    overflow-x: hidden;
    margin: 0;
    transform-origin: bottom right;
  }

  .inspector-page-menu.open > .menu-panel {
    display: block;
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }
}

@media (max-width: 420px) {
  .inspector-modal-actions {
    align-items: stretch;
  }

  .inspector-page-menu {
    flex: 1 1 auto;
    min-width: 0;
  }

  #inspector-page-trigger {
    width: 100%;
  }

  .inspector-page-menu .menu-panel {
    right: 0;
    width: min(300px, calc(100vw - 36px));
    max-width: min(300px, calc(100vw - 36px));
  }
}



/* TI-Nspire Notes / Graphs +Page previews */
.note-page-modal,
.graph-page-modal {
  width: min(900px, calc(100vw - 28px));
}

.note-calculator-shell,
.graph-calculator-shell {
  width: 320px;
  max-width: 100%;
  margin: 18px auto 8px;
  border: 1px solid #334155;
  background: #ffffff;
  overflow: hidden;
}

.note-calculator-shell .love-preview-calculator-bar,
.graph-calculator-shell .love-preview-calculator-bar {
  /* reuse Preview LÖVE calculator bar without changing its colors/style */
  width: 100%;
}

#note-editor {
  display: block;
  width: 320px;
  max-width: 100%;
  height: 214px;
  min-height: 214px;
  margin: 0;
  padding: 7px 6px;
  border: 0;
  border-radius: 0;
  resize: none;
  outline: none;
  background: #ffffff;
  color: #111111;
  font: 14px Arial, sans-serif;
}

.graph-function-row {
  display: grid;
  grid-template-columns: 22px auto minmax(0, 1fr) 24px;
  align-items: center;
  min-height: 31px;
  border-bottom: 1px solid #2b9fd9;
  background: #f7f7f7;
  color: #111;
  font: 14px Arial, sans-serif;
}

.graph-check { text-align: center; color: #9ca3af; }
.graph-function-name { white-space: nowrap; padding-right: 2px; font-style: italic; }
.graph-list-icon { text-align: center; color: #0089c7; font-size: 20px; }
#graph-formula-input {
  min-width: 0;
  width: 100%;
  margin: 0;
  padding: 3px 2px;
  border: 0;
  border-radius: 0;
  outline: none;
  background: transparent;
  color: #111;
  font: 14px Arial, sans-serif;
}
#graph-native-canvas { display: block; width: 320px; max-width: 100%; height: auto; background: #fff; }

@media (max-width: 420px) {
  .note-page-modal,
  .graph-page-modal { width: calc(100vw - 16px); padding: 12px; }
  .note-calculator-shell,
  .graph-calculator-shell { width: 320px; max-width: 100%; }
}

/* Graph formula controls embedded in Preview LÖVE.
   Intentionally does not modify .love-preview-calculator-bar. */
.love-graph-editor {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  margin: 10px 0 14px;
}

.love-graph-formula-label {
  margin: 0;
  font: 700 14px Consolas, monospace;
  color: var(--text);
  white-space: nowrap;
}

.love-graph-formula-input {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: 14px Consolas, monospace;
}

@media (max-width: 700px) {
  .love-graph-editor {
    grid-template-columns: 1fr 1fr;
  }

  .love-graph-formula-label,
  .love-graph-formula-input {
    grid-column: 1 / -1;
  }
}


/* TI-Nspire Calculator inside Preview LÖVE; existing CALCULATOR VIEW bar unchanged. */
.love-calculator-editor{position:relative;margin:10px 0 14px}.love-calculator-editor-row{display:grid;grid-template-columns:auto minmax(220px,1fr) auto auto auto;gap:9px;align-items:center}.love-calculator-entry{width:100%;min-width:0;padding:9px 11px;border:1px solid var(--line);border-radius:8px;background:var(--panel);color:var(--text);font:15px Consolas,monospace}.love-calculator-template-panel{position:absolute;z-index:20;top:calc(100% + 7px);left:0;width:min(310px,calc(100vw - 48px));padding:7px;display:grid;grid-template-columns:repeat(6,38px);gap:4px;border:1px solid rgba(151,239,54,.4);border-radius:8px;background:#f6f6f6;box-shadow:0 14px 32px rgba(0,0,0,.35)}.love-calculator-template-panel[hidden]{display:none}.love-calculator-template-button{width:38px;height:36px;min-width:38px;padding:5px;border:1px solid #d1d1d1;border-radius:2px;background:#fff}.love-calculator-template-button:hover,.love-calculator-template-button:focus{border-color:#258fe0;background:#e9f5ff}.love-calculator-template-button img{display:block;width:23px;height:23px;margin:auto}@media(max-width:760px){.love-calculator-editor-row{grid-template-columns:1fr 1fr}.love-calculator-entry{grid-column:1/-1}.love-calculator-template-panel{grid-template-columns:repeat(5,38px)}}


/* Calculator v2: direct 2D math entry inside the calculator viewport. */
.love-calculator-toolbar{display:flex!important;grid-template-columns:none!important;align-items:center;gap:10px}.love-calculator-toolbar-spacer{flex:1 1 auto}
.calculator-editor-stage{position:relative;background:#fff}.calculator-editor-stage #love-preview-canvas{background:#fff}
.love-calculator-composer{position:absolute;left:0;right:0;bottom:0;min-height:58px;height:58px;display:flex;align-items:center;padding:4px 9px 5px;background:#fff;border-top:1px solid #d5d5d5;color:#111;overflow-x:auto;overflow-y:hidden;font-family:"Times New Roman",Cambria,serif;font-size:19px;line-height:1.05;z-index:8;cursor:text;outline:none;scrollbar-width:thin}
.love-calculator-composer:focus-within{background:#fff}.love-calculator-composer .calc-visual-slot{display:inline-block;min-width:15px;min-height:18px;padding:1px 2px;outline:none;text-align:center;white-space:pre;color:#111;caret-color:#111;border-radius:1px}
.love-calculator-composer .calc-visual-slot:empty{min-width:18px;background:#fafafa;border:1px solid #b6b6b6;box-shadow:inset 0 0 0 1px #fff}
.love-calculator-composer .calc-visual-slot:focus{background:#c7eaff;border-color:#3199d8;box-shadow:inset 0 -1px 0 #3199d8}
.calc-v-plain{display:flex;align-items:center;min-width:40px}.calc-v-plain-slot{min-width:32px!important;text-align:left!important}
.calc-v-inline,.calc-v-power,.calc-v-root,.calc-v-log,.calc-v-abs,.calc-v-integral,.calc-v-derivative,.calc-v-limit,.calc-v-bigop,.calc-v-matrix,.calc-v-system{display:inline-flex;align-items:center;gap:2px;white-space:nowrap}
.calc-v-power{align-items:flex-start}.calc-v-power sup{font-size:11px;line-height:1;margin-top:-4px}.calc-v-sup-slot{min-width:12px!important;min-height:13px!important;padding:0 1px!important;font-size:12px}.calc-v-italic{font-style:italic}
.calc-v-frac{display:inline-grid;grid-template-rows:auto 1px auto;align-items:center;justify-items:center;vertical-align:middle;min-width:30px;margin:0 2px}.calc-v-frac-num,.calc-v-frac-den{display:flex;align-items:center;justify-content:center;min-width:28px}.calc-v-frac-bar{display:block;width:100%;min-width:30px;height:1px;background:#111}.calc-v-frac .calc-visual-slot{min-width:22px}
.calc-v-root{align-items:flex-end}.calc-v-radical{font-size:31px;line-height:.8;margin-right:-3px}.calc-v-radicand{display:inline-flex;align-items:center;border-top:1px solid #111;padding:2px 2px 0;min-height:26px}.calc-v-nroot{position:relative}.calc-v-index{font-size:10px;align-self:flex-start;margin-right:-5px;margin-top:0;z-index:2}.calc-v-log sub{font-size:10px;align-self:flex-end;margin-left:-2px}.calc-v-sub-slot{font-size:10px;min-width:11px!important;min-height:12px!important;padding:0!important}
.calc-v-abs-bar{display:inline-block;width:1px;height:27px;background:#111;margin:0 2px}.calc-v-bracket{font-size:39px;font-family:serif;font-weight:300;line-height:.9}.calc-v-matrix-grid{display:grid;gap:2px 5px;align-items:center}.calc-v-matrix-grid.cols2{grid-template-columns:repeat(2,minmax(20px,auto))}.calc-v-matrix-grid.cols1{grid-template-columns:minmax(20px,auto)}.calc-v-matrix-grid .calc-visual-slot{min-width:21px}
.calc-v-brace{font-size:54px;line-height:.8;font-family:serif;font-weight:300}.calc-v-system-rows,.calc-v-piece-rows{display:flex;flex-direction:column;gap:2px}.calc-v-system-rows>.calc-visual-slot{min-width:95px;text-align:left}.calc-v-piece-rows>span{display:flex;align-items:center;gap:4px}.calc-v-piece-rows .calc-visual-slot:nth-child(1){min-width:55px}.calc-v-if{margin:0 2px}
.calc-v-bigop{align-items:center}.calc-v-bigop-stack,.calc-v-int-stack,.calc-v-lim-stack{display:grid;grid-template-rows:auto auto auto;justify-items:center;align-items:center}.calc-v-op{font-size:35px;line-height:.75}.calc-v-int{font-size:38px;line-height:.85}.calc-v-upper,.calc-v-lower{font-size:10px;line-height:1;display:flex;align-items:center}.calc-v-upper .calc-visual-slot,.calc-v-lower .calc-visual-slot{font-size:10px;min-width:11px;min-height:12px;padding:0 1px}.calc-v-body{display:flex;align-items:center;margin-left:2px}
.calc-v-derivative{gap:3px}.calc-v-fixed{font-size:16px}.calc-v-order{font-size:9px;min-width:10px!important;min-height:11px!important;padding:0!important}.clone-order{border:0!important;background:transparent!important}.calc-v-var{min-width:12px!important}.calc-v-limit{align-items:center}.calc-v-lim{font-size:17px}.calc-v-lim-stack{grid-template-rows:auto auto}.calc-v-limit>.calc-visual-slot:last-child{min-width:65px;text-align:left}
.love-calculator-template-panel{z-index:30;top:calc(100% + 6px)}
.calculator-editor-stage.expanded-view .love-calculator-composer{height:72px;min-height:72px;font-size:24px;padding-left:14px}.calculator-editor-stage.expanded-view .calc-v-radical{font-size:38px}
@media(max-width:760px){.love-calculator-toolbar{display:flex!important}.love-calculator-composer{font-size:18px}.love-calculator-template-panel{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);max-height:60vh;overflow:auto}.love-calculator-template-panel[hidden]{display:none}}


/* Calculator MathPrint v3: nth-root index, editable boundaries and derivative/dx layout. */
.calc-v-expression{display:inline-flex;align-items:center;white-space:nowrap;min-width:8px}
.calc-v-template{display:inline-flex;align-items:center}
.love-calculator-composer .calc-v-affix{display:inline-block;min-width:3px;min-height:24px;padding:1px 0;outline:none;white-space:pre;caret-color:#111;color:#111;text-align:left}
.love-calculator-composer .calc-v-affix:focus{min-width:7px;background:rgba(199,234,255,.55);box-shadow:inset 0 -1px 0 #3199d8}
.calc-v-nroot{position:relative;display:inline-block!important;padding-left:8px;vertical-align:middle;min-height:34px}
.calc-v-nroot-index{position:absolute;left:0;top:-3px;z-index:3;transform:scale(.78);transform-origin:right bottom;line-height:1}
.calc-v-nroot-index .calc-v-index{min-width:14px!important;min-height:14px!important;font-size:12px!important;padding:0 1px!important}
.calc-v-root-main{display:inline-flex;align-items:flex-end}
.calc-v-nroot .calc-v-radical{font-size:34px;line-height:.82;margin-right:-3px}
.calc-v-nroot .calc-v-radicand{min-height:27px;padding-top:2px}
.calc-v-dfrac{min-width:34px!important;margin-right:3px}
.calc-v-dfrac .calc-v-frac-num,.calc-v-dfrac .calc-v-frac-den{min-width:34px}
.calc-v-dfrac sup{font-size:9px;position:relative;top:-5px}
.calc-v-derivative-body{font-size:20px;line-height:1}
.calc-v-differential{margin-left:4px;font-style:italic}
.calculator-editor-stage.expanded-view .calc-v-nroot{padding-left:10px}.calculator-editor-stage.expanded-view .calc-v-nroot .calc-v-radical{font-size:42px}.calculator-editor-stage.expanded-view .calc-v-nroot-index{top:-5px}

/* Chromium/Brave: all file-import dialogs must avoid fullscreen backdrop
   filters, including when a previously cached script injects old styles. */
.tns-import-progress-overlay,
.tns-import-progress-overlay.visible,
.tns-import-progress-overlay.closing,
.tns-lua-compat-overlay,
.tns-lua-compat-overlay.visible,
.tns-lua-compat-overlay.closing {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Centered document filename: text until clicked, editable in place. */
#xml-doctor-panel > .doctor-toolbar {
  position: relative;
}
#xml-doctor-panel > .doctor-toolbar > h2 {
  flex: 0 0 100%;
  margin: 0 0 4px;
}
#xml-doctor-panel .xml-output-file-name {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 365px));
  min-width: 0;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#xml-doctor-panel .xml-output-file-name [hidden] {
  display: none !important;
}
#xml-doctor-panel #xml-output-filename-display,
#xml-doctor-panel #xml-output-filename-editor {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 5px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 24px;
  text-align: center;
}
#xml-doctor-panel #xml-output-filename-display {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: text;
}
#xml-doctor-panel #xml-output-filename-display:not(:disabled):hover {
  background: color-mix(in srgb, var(--text) 6%, transparent);
}
#xml-doctor-panel #xml-output-filename-display:focus-visible,
#xml-doctor-panel #xml-output-filename-editor:focus-within {
  outline: 2px solid var(--lime2);
  outline-offset: 2px;
}
#xml-doctor-panel #xml-output-filename-editor {
  display: flex;
  align-items: baseline;
  justify-content: center;
  border-color: var(--line);
  background: var(--panel);
  font-weight: 600;
}
#xml-doctor-panel #xml-output-filename-editor:focus-within {
  border-color: var(--lime2);
  box-shadow: 0 0 0 2px rgb(141 230 42 / 15%);
}
#xml-doctor-panel #xml-output-filename {
  field-sizing: content;
  width: auto;
  min-width: 1ch;
  max-width: calc(100% - 4ch);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: right;
}
#xml-doctor-panel #xml-output-filename-suffix {
  flex: 0 0 auto;
  user-select: none;
  pointer-events: none;
}
#xml-doctor-panel #xml-output-filename-display:disabled {
  opacity: 0.6;
  cursor: default;
}
@media (max-width: 850px) {
  #xml-doctor-panel .xml-output-file-name {
    position: static;
    transform: none;
    flex: 0 0 100%;
    width: 100%;
    max-width: 100%;
    min-height: 34px;
  }
}

/* Keep the filename hidden until a document is successfully created or imported. */
#xml-doctor-panel .xml-output-file-name[hidden] { display: none !important; }
#xml-doctor-panel .ndless-project-off-badge {
  display: inline-flex; align-items: center; margin-left: 8px;
  padding: 2px 7px; border-radius: 5px;
  color: #a9b0ba; background: #353c47; border: 1px solid #59616c;
  font-size: 10px; line-height: 1.4; font-weight: 800; letter-spacing: .08em;
}
#xml-doctor-panel #xml-new-ndless-project:disabled {
  cursor: not-allowed; opacity: .74;
}

/* Dedicated rule between regular File menu actions and Save. */
#xml-doctor-panel .ti-file-action-separator {
  height: 1px;
  width: calc(100% - 20px);
  margin: 6px 10px;
  flex: 0 0 auto;
  background: var(--line);
  opacity: .85;
}
.love-calculator-history{position:absolute;top:26px;left:0;right:0;bottom:var(--calc-entry-height,58px);overflow:auto;overscroll-behavior:contain;background:#fff;color:#111;z-index:7;font:16px/1.3 "Times New Roman",Cambria,serif;scrollbar-width:thin}
.calculator-editor-stage.expanded-view .love-calculator-history{top:0;font-size:21px}
.calculator-math-history-row{box-sizing:border-box;min-height:52px;display:flex;align-items:center;justify-content:space-between;gap:16px;padding:10px 8px;border-bottom:1px solid #ddd;max-width:100%}.calculator-math-history-row:nth-child(even){background:#f5f5f5}.calculator-math-history-row.selected{background:#c0e6f3}
.calculator-math-history-entry,.calculator-math-history-result{min-width:0;max-width:100%;overflow-x:auto;overflow-y:hidden;padding:5px 0}.calculator-math-history-result{margin-left:auto;text-align:right}.love-calculator-history math{font-family:"Cambria Math","STIX Two Math",serif;display:inline-block;overflow:visible!important;font-size:1em;vertical-align:middle}.love-calculator-history math mtable{line-height:1.2}
.love-calculator-composer.love-calculator-composer{box-sizing:border-box;max-height:calc(100% - 62px);align-items:center;overflow:auto;scrollbar-width:thin;padding-top:8px;padding-bottom:8px}.love-calculator-composer>.calc-v-expression,.love-calculator-composer>.calc-v-plain{flex-shrink:0}
.preview-window .love-calculator-toolbar{display:flex;flex-wrap:wrap;gap:8px}.preview-window .love-calculator-toolbar #love-calculator-save{flex:1 0 100%;margin-top:4px}
.program-editor-visibility{display:inline-flex;align-items:center;justify-content:center;vertical-align:middle}.program-editor-visibility[aria-pressed="true"]{color:#a5ed32}.program-editor-visibility-note{font:12px/1.5 Arial,sans-serif;color:#a5b7cf;max-width:850px}
/* A declaration belongs to the Program Editor metadata, never its editable model. */
.code-shell.has-program-declaration{grid-template-rows:34px minmax(0,1fr)}
.program-declaration{grid-column:1/-1;min-width:0;padding:7px 14px 7px 64px;border-bottom:1px solid var(--line);font:600 13px/19px Consolas,monospace;white-space:pre;overflow-x:auto;overflow-y:hidden;color:var(--text);background:var(--panel);user-select:text;cursor:default}
.program-declaration[hidden]{display:none}
.inspector-table .inspector-delete-action{opacity:0;pointer-events:none;color:#ff8c9c;border:1px solid #8b3449;min-width:27px;height:27px;padding:0 6px;font:700 21px/23px Arial,sans-serif;vertical-align:middle;background:#421d2b;transition:opacity .12s ease}
.inspector-table tr:hover .inspector-delete-action,.inspector-table tr:focus-within .inspector-delete-action,.inspector-table .inspector-delete-action:focus-visible{visibility:visible;opacity:1;pointer-events:auto}
.inspector-table .inspector-delete-action:disabled{opacity:.4;cursor:wait}
.inspector-delete-dialog{width:min(520px,calc(100vw - 32px));max-height:calc(100dvh - 32px);overflow:auto;border:1px solid #405675;border-radius:16px;padding:24px;background:var(--panel);color:var(--text)}
.inspector-delete-dialog strong,.inspector-delete-dialog code{display:block;overflow-wrap:anywhere;margin:10px 0}.inspector-delete-dialog code{font:12px/1.5 Consolas,monospace;color:var(--muted)}
.inspector-delete-dialog p{font:14px/1.55 Arial,sans-serif}.inspector-delete-dialog .danger-action{background:#b42342;color:#fff;border:1px solid #de516d}.inspector-delete-dialog .danger-action:hover{background:#cc2c4f}
[data-theme=light] .inspector-table .inspector-delete-action{background:#fff0f2;color:#aa1636;border-color:#e5aab7}
@media(hover:none){.inspector-table .inspector-delete-action{visibility:visible;opacity:1;pointer-events:auto}}
.code-shell.has-program-declaration>.editor-wrap{height:100%;min-height:0}
.code-shell.has-program-declaration.monaco-enabled .program-declaration{padding-left:64px}
[data-theme="dark"] .program-declaration{color:#dce8f8;background:#101b2d}
