:root {
  --bg: #eef6ff;
  --bg-2: #f8fbff;
  --card: rgba(255, 255, 255, 0.92);
  --solid-card: #ffffff;
  --text: #17324d;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #f59e0b;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --line: #d7e3f3;
  --line-strong: #bfdbfe;
  --editor-bg: #ffffff;
  --editor-gutter: #f1f5f9;
  --editor-text: #0f172a;
  --editor-line: #64748b;
  --shadow: 0 18px 45px rgba(37, 99, 235, 0.14);
  --shadow-strong: 0 24px 70px rgba(15, 23, 42, 0.24);
  --radius: 22px;
}

[data-theme="dark"] {
  --bg: #07111f;
  --bg-2: #0f172a;
  --card: rgba(15, 23, 42, 0.9);
  --solid-card: #111827;
  --text: #e5edf7;
  --muted: #a7b4c7;
  --primary: #60a5fa;
  --primary-dark: #93c5fd;
  --primary-soft: rgba(37, 99, 235, 0.22);
  --success: #4ade80;
  --success-soft: rgba(22, 163, 74, 0.18);
  --warning: #fbbf24;
  --danger: #fb7185;
  --danger-soft: rgba(220, 38, 38, 0.15);
  --line: #243247;
  --line-strong: #334155;
  --editor-bg: #020617;
  --editor-gutter: #030712;
  --editor-text: #f8fafc;
  --editor-line: #94a3b8;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  --shadow-strong: 0 24px 80px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(96, 165, 250, 0.34), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(34, 197, 94, 0.14), transparent 28rem),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 54%, var(--bg) 100%);
}

button,
textarea,
input,
select {
  font: inherit;
}

button {
  user-select: none;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 34px;
}

.topbar,
.activity-card,
.panel,
.help-card {
  border: 1px solid rgba(215, 227, 243, 0.86);
  border-color: var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-mark {
  display: grid;
  place-items: center;
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  border-radius: 20px;
  color: white;
  background: linear-gradient(135deg, var(--primary), #06b6d4 54%, var(--success));
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.28);
  font-size: 1.1rem;
  font-weight: 1000;
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.9rem, 4vw, 3.2rem);
  line-height: 1.02;
}

h2 {
  margin-bottom: 6px;
}

h3 {
  margin-bottom: 8px;
}

.subtitle,
.panel-header p,
.muted-text {
  margin-bottom: 0;
  color: var(--muted);
}

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

.primary-btn,
.success-btn,
.ghost-btn,
.icon-btn {
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  padding: 0 18px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border 0.15s ease;
}

.primary-btn {
  color: white;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.28);
}

.success-btn {
  color: white;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  box-shadow: 0 10px 22px rgba(22, 163, 74, 0.22);
}

.ghost-btn,
.icon-btn {
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--solid-card);
}

.ghost-btn.danger {
  color: var(--danger);
}

.primary-btn:hover,
.success-btn:hover,
.ghost-btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
}

.activity-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 20px;
  padding: 20px 22px;
}

.activity-stats {
  display: flex;
  gap: 12px;
}

.activity-stats > div {
  min-width: 112px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  text-align: center;
  background: var(--solid-card);
}

.stat-number {
  display: block;
  color: var(--primary);
  font-size: 1.65rem;
  font-weight: 1000;
  line-height: 1;
}

.stat-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.07fr) minmax(380px, 0.93fr);
  gap: 20px;
  margin-top: 20px;
}

.panel,
.help-card {
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin-bottom: 4px;
  font-size: 1.1rem;
}

.compact-header {
  padding: 16px 18px;
}

.status-badge {
  flex: none;
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.82rem;
  font-weight: 900;
}

.language-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 18px 0;
  background: color-mix(in srgb, var(--solid-card) 92%, var(--primary-soft));
}

.tab-btn {
  border: 1px solid var(--line);
  border-bottom-color: transparent;
  border-radius: 14px 14px 0 0;
  padding: 11px 18px;
  color: var(--muted);
  background: var(--solid-card);
  font-weight: 1000;
  cursor: pointer;
}

.tab-btn.active {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
}

.editor-info {
  padding: 10px 18px 14px;
  color: var(--muted);
  background: color-mix(in srgb, var(--solid-card) 92%, var(--primary-soft));
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

.editor-wrap {
  position: relative;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  min-height: max(560px, 72vh);
  background: var(--editor-bg);
}

.line-numbers {
  min-height: max(560px, 72vh);
  padding: 18px 10px;
  color: var(--editor-line);
  border-right: 1px solid rgba(148, 163, 184, 0.18);
  background: var(--editor-gutter);
  font: var(--editor-font-size, 15px)/1.65 Consolas, Monaco, Courier New, monospace;
  text-align: right;
  white-space: pre;
  user-select: none;
  overflow: hidden;
}

.editor-stack {
  position: relative;
  min-width: 0;
  min-height: max(560px, 72vh);
  background: var(--editor-bg);
}

#codeEditor,
.code-match-layer {
  width: 100%;
  min-height: max(560px, 72vh);
  padding: 18px;
  font: var(--editor-font-size, 15px)/1.65 Consolas, Monaco, Courier New, monospace;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

#codeEditor {
  position: relative;
  z-index: 2;
  display: block;
  resize: none;
  overflow: hidden;
  border: 0;
  outline: none;
  color: var(--editor-text);
  background: transparent;
}

.code-match-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  color: transparent;
  pointer-events: none;
  overflow: hidden;
  scrollbar-width: none;
}

.code-match-layer::-webkit-scrollbar {
  display: none;
}

.code-match-layer .tag-match {
  border-radius: 5px;
  color: transparent;
  text-decoration-line: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
}

.code-match-layer .tag-match-pair {
  background: rgba(37, 99, 235, 0.14);
  text-decoration-color: #2563eb;
}

.code-match-layer .tag-match-missing {
  background: rgba(239, 68, 68, 0.14);
  text-decoration-color: #ef4444;
  text-decoration-style: wavy;
}

.code-match-layer .tag-match-self {
  background: rgba(22, 163, 74, 0.14);
  text-decoration-color: #16a34a;
}

#codeEditor::selection {
  background: rgba(96, 165, 250, 0.35);
}

/* Theme-aware editor surface */
:root #codeEditor {
  caret-color: #0f172a;
}

[data-theme="dark"] #codeEditor {
  caret-color: #f8fafc;
}

:root .editor-wrap,
:root .editor-stack {
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.16);
}

[data-theme="dark"] .editor-wrap,
[data-theme="dark"] .editor-stack {
  box-shadow: none;
}

.tips-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--solid-card);
  font-size: 0.9rem;
}

kbd {
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 6px;
  color: var(--text);
  background: var(--solid-card);
  font-size: 0.78rem;
  font-weight: 900;
}

.suggestion-box {
  position: absolute;
  z-index: 10;
  left: 18px;
  top: 54px;
  width: min(390px, calc(100% - 36px));
  max-height: 270px;
  overflow-y: auto;
  border: 1px solid rgba(147, 197, 253, 0.6);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 20px 35px rgba(15, 23, 42, 0.22);
}

.suggestion-box.hidden,
.hidden {
  display: none !important;
}

.suggestion-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  width: 100%;
  padding: 11px 13px;
  border-bottom: 1px solid #e2e8f0;
  color: #172554;
  cursor: pointer;
}

.suggestion-item:last-child {
  border-bottom: 0;
}

.suggestion-item:hover,
.suggestion-item.active {
  background: #eff6ff;
}

.suggestion-label {
  font-weight: 1000;
}

.suggestion-desc {
  color: #64748b;
  font-size: 0.82rem;
}

.suggestion-type {
  align-self: start;
  border-radius: 999px;
  padding: 3px 8px;
  color: #1d4ed8;
  background: #dbeafe;
  font-size: 0.72rem;
  font-weight: 1000;
}

.right-column {
  display: grid;
  gap: 20px;
  align-content: start;
}

.preview-panel {
  min-height: 100%;
}

#previewFrame {
  display: block;
  width: 100%;
  min-height: 390px;
  border: 0;
  background: white;
}

.result-content {
  padding: 18px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 250px;
  text-align: center;
  color: var(--muted);
}

.empty-state h3 {
  color: var(--text);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 8px;
  border-radius: 20px;
  color: var(--success);
  background: var(--success-soft);
  font-size: 1.5rem;
  font-weight: 1000;
}

.score-card {
  display: grid;
  gap: 14px;
}

.score-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  background: var(--solid-card);
}

.score-number {
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1;
  font-weight: 1000;
  color: var(--primary);
}

.score-number small {
  color: var(--muted);
  font-size: 1rem;
}

.score-pill {
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 1000;
  color: #166534;
  background: #dcfce7;
}

.score-pill.needs-work {
  color: #991b1b;
  background: #fee2e2;
}

.score-pill.almost {
  color: #92400e;
  background: #fef3c7;
}

.feedback-box {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  color: var(--text);
  background: color-mix(in srgb, var(--solid-card) 86%, var(--primary-soft));
}

.rubric-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rubric-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: var(--solid-card);
}

.rubric-check {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  color: white;
  background: var(--success);
  font-weight: 1000;
}

.rubric-check.fail {
  background: var(--danger);
}

.rubric-title {
  margin: 0;
  font-weight: 900;
}

.rubric-rule {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.84rem;
}

.rubric-points {
  font-weight: 1000;
  color: var(--primary);
  white-space: nowrap;
}

.help-card {
  margin-top: 20px;
  padding: 18px 20px;
}

.help-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.help-grid > div {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  color: var(--muted);
  background: var(--solid-card);
}

code {
  border-radius: 6px;
  padding: 2px 5px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-family: Consolas, Monaco, Courier New, monospace;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.66);
}

.admin-modal {
  width: min(980px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--solid-card);
  box-shadow: var(--shadow-strong);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1.6rem;
}

.pin-screen,
.admin-form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.pin-row {
  display: flex;
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-weight: 900;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 12px 13px;
  color: var(--text);
  background: var(--solid-card);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.helper-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.6fr;
  gap: 14px;
}

.rubric-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.criteria-editor {
  display: grid;
  gap: 12px;
}

.criterion-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: color-mix(in srgb, var(--solid-card) 92%, var(--primary-soft));
}

.criterion-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.4fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}

.remove-criterion {
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

@media (max-width: 1100px) {
  .topbar,
  .activity-card,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .activity-stats {
    width: 100%;
    justify-content: flex-start;
  }

  .workspace,
  .help-grid {
    grid-template-columns: 1fr;
  }

  #previewFrame {
    min-height: 430px;
  }
}

@media (max-width: 760px) {
  .brand-block {
    align-items: flex-start;
  }

  .top-actions > button {
    flex: 1 1 150px;
  }

  .activity-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .form-grid,
  .criterion-grid {
    grid-template-columns: 1fr;
  }

  .pin-row {
    flex-direction: column;
  }

  .score-main {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 1480px);
    padding-top: 10px;
  }

  .topbar,
  .activity-card,
  .panel,
  .help-card,
  .admin-modal {
    border-radius: 18px;
  }

  .logo-mark {
    display: none;
  }

  .editor-wrap {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .line-numbers {
    padding-left: 6px;
    padding-right: 7px;
  }

  #codeEditor,
  .code-match-layer {
    padding: 14px;
    font-size: var(--editor-font-size, 15px);
  }

  .suggestion-box {
    left: 14px;
    width: calc(100% - 28px);
  }

  .tab-btn {
    flex: 1 1 auto;
    padding-inline: 10px;
  }

  .rubric-item {
    grid-template-columns: auto 1fr;
  }

  .rubric-points {
    grid-column: 2;
  }
}

/* Version 2 additions: full HTML checker, richer suggestions, and flexible preview layouts */
.structure-alert {
  border-bottom: 1px solid var(--line);
  padding: 12px 18px;
  background: var(--solid-card);
}

.structure-alert.good {
  background: color-mix(in srgb, var(--success-soft) 68%, var(--solid-card));
}

.structure-alert.warning {
  background: color-mix(in srgb, var(--danger-soft) 58%, var(--solid-card));
}

.structure-message {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  margin-bottom: 10px;
  color: var(--text);
}

.structure-message span {
  color: var(--muted);
  font-size: 0.9rem;
}

.structure-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.structure-chip {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.78rem;
  font-weight: 1000;
}

.structure-chip.pass {
  color: #166534;
  background: #dcfce7;
}

.structure-chip.missing {
  color: #991b1b;
  background: #fee2e2;
}

.preview-header {
  align-items: flex-start;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.layout-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  color: var(--muted);
  background: var(--solid-card);
  font-size: 0.8rem;
  font-weight: 1000;
  cursor: pointer;
}

.layout-btn:hover,
.layout-btn.active {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), #06b6d4);
}

.layout-btn.strong {
  color: #14532d;
  border-color: #bbf7d0;
  background: #dcfce7;
}

.layout-btn.danger {
  color: #991b1b;
  border-color: #fecaca;
  background: #fee2e2;
}

.workspace[data-layout="stacked"] {
  grid-template-columns: 1fr;
}

.workspace[data-layout="stacked"] #previewFrame {
  min-height: 640px;
}

.workspace[data-layout="preview-focus"] {
  grid-template-columns: minmax(340px, 0.72fr) minmax(520px, 1.28fr);
}

.workspace[data-layout="preview-focus"] #previewFrame {
  min-height: 700px;
}

.workspace[data-layout="preview-focus"] .result-panel {
  display: none;
}

.preview-fullscreen-active {
  overflow: hidden;
}

.preview-fullscreen-active .preview-panel {
  position: fixed;
  z-index: 3000;
  inset: 14px;
  display: flex;
  flex-direction: column;
  border-radius: 22px;
  background: var(--solid-card);
  box-shadow: var(--shadow-strong);
}

.preview-fullscreen-active .preview-panel #previewFrame {
  flex: 1;
  min-height: 0;
  height: 100%;
}

.preview-fullscreen-active .preview-panel .panel-header {
  flex: none;
}

.suggestion-item.has-closing {
  border-left: 4px solid #ef4444;
}

.suggestion-type.closing {
  color: #991b1b;
  background: #fee2e2;
}

.suggestion-type.self-closing {
  color: #166534;
  background: #dcfce7;
}

.suggestion-type.template {
  color: #7c2d12;
  background: #ffedd5;
}

[data-theme="dark"] .suggestion-box {
  background: #0f172a;
  border-color: #334155;
}

[data-theme="dark"] .suggestion-item {
  color: #e5edf7;
  border-bottom-color: #243247;
}

[data-theme="dark"] .suggestion-item:hover,
[data-theme="dark"] .suggestion-item.active {
  background: #1e293b;
}

[data-theme="dark"] .suggestion-desc {
  color: #a7b4c7;
}

[data-theme="dark"] .structure-chip.pass {
  color: #bbf7d0;
  background: rgba(22, 163, 74, 0.28);
}

[data-theme="dark"] .structure-chip.missing {
  color: #fecaca;
  background: rgba(220, 38, 38, 0.28);
}

@media (max-width: 1100px) {
  .preview-actions {
    justify-content: flex-start;
  }

  .workspace[data-layout="preview-focus"] {
    grid-template-columns: 1fr;
  }

  .workspace[data-layout="preview-focus"] .result-panel {
    display: block;
  }
}

@media (max-width: 560px) {
  .structure-alert {
    padding: 10px 12px;
  }

  .layout-btn {
    flex: 1 1 auto;
  }

  .preview-fullscreen-active .preview-panel {
    inset: 6px;
    border-radius: 16px;
  }
}

/* Multiple activity selector and teacher activity manager */
.activity-main {
  display: grid;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.activity-select-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(240px, 2fr) auto;
  align-items: end;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(135deg, var(--solid-card), var(--bg-2));
}

.activity-select-row label {
  align-self: center;
  color: var(--primary);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.activity-select-row select {
  min-height: 46px;
  font-weight: 800;
}

.activity-select-row .ghost-btn {
  white-space: nowrap;
}

.admin-activity-manager {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg-2);
}

.admin-activity-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.admin-activity-actions button {
  flex: 1 1 140px;
}

@media (max-width: 900px) {
  .activity-select-row {
    grid-template-columns: 1fr;
  }

  .activity-select-row .ghost-btn {
    width: 100%;
  }
}

/* Version 4: friendlier student flow and keyboard shortcut polish */
.simplified-topbar {
  position: relative;
  overflow: hidden;
}

.simplified-topbar::after {
  content: "";
  position: absolute;
  right: -120px;
  top: -140px;
  width: 310px;
  height: 310px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.16), transparent 66%);
  pointer-events: none;
}

.simplified-topbar .brand-block,
.simplified-topbar .top-actions {
  position: relative;
  z-index: 1;
}

.student-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.step-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: var(--solid-card);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.07);
}

.step-card.active-step {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary-soft) 42%, var(--solid-card)), var(--solid-card));
}

.step-number {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  color: white;
  background: linear-gradient(135deg, var(--primary), #06b6d4);
  font-weight: 1000;
}

.step-card strong {
  display: block;
  margin-bottom: 4px;
}

.step-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.teacher-btn {
  border-color: color-mix(in srgb, var(--primary) 28%, var(--line));
}

.quiet-action {
  opacity: 0.82;
}

.shortcut-strip {
  justify-content: flex-start;
  gap: 8px 14px;
}

.shortcut-strip span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: color-mix(in srgb, var(--solid-card) 88%, var(--primary-soft));
}

.activity-card {
  align-items: stretch;
}

.activity-select-row {
  grid-template-columns: 140px minmax(230px, 1fr) auto;
}

.panel-header .section-kicker {
  margin-bottom: 4px;
}

.editor-heading {
  background: linear-gradient(135deg, color-mix(in srgb, var(--solid-card) 88%, var(--primary-soft)), var(--solid-card));
}

.language-tabs {
  position: sticky;
  top: 0;
  z-index: 3;
}

.tab-btn::after {
  display: inline-block;
  margin-left: 8px;
  color: inherit;
  opacity: 0.75;
  font-size: 0.78rem;
}

.tab-btn[data-language="html"]::after { content: "Ctrl+1"; }
.tab-btn[data-language="css"]::after { content: "Ctrl+2"; }
.tab-btn[data-language="js"]::after { content: "Ctrl+3"; }

#saveBtn {
  border-color: color-mix(in srgb, var(--success) 38%, var(--line));
}

.friendly-help .help-grid > div {
  min-height: 102px;
}

@media (max-width: 1120px) {
  .student-steps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .activity-select-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .student-steps {
    grid-template-columns: 1fr;
  }

  .step-card {
    padding: 12px;
  }

  .shortcut-strip span {
    flex: 1 1 150px;
    justify-content: center;
  }

  .top-actions > button {
    flex: 1 1 130px;
  }
}


/* Version 5: matching HTML tag helper and editor zoom */
.editor-toolbar {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px;
  background: color-mix(in srgb, var(--solid-card) 82%, var(--primary-soft));
}

.mini-tool-btn {
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--text);
  background: var(--solid-card);
  font-weight: 1000;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
}

.mini-tool-btn:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}

.zoom-level {
  min-width: 48px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 1000;
}

.tag-match-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: color-mix(in srgb, var(--solid-card) 88%, var(--primary-soft));
  font-size: 0.92rem;
  line-height: 1.35;
}

.tag-match-info::before {
  content: "⌁";
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: white;
  background: var(--primary);
  font-weight: 1000;
}

.tag-match-info.good::before {
  content: "✓";
  background: #16a34a;
}

.tag-match-info.warning::before {
  content: "!";
  background: #f97316;
}

.tag-match-info.error::before {
  content: "×";
  background: #ef4444;
}

[data-theme="dark"] .code-match-layer .tag-match-pair {
  background: rgba(96, 165, 250, 0.16);
  text-decoration-color: #60a5fa;
}

[data-theme="dark"] .code-match-layer .tag-match-missing {
  background: rgba(248, 113, 113, 0.18);
  text-decoration-color: #f87171;
}

[data-theme="dark"] .code-match-layer .tag-match-self {
  background: rgba(74, 222, 128, 0.16);
  text-decoration-color: #4ade80;
}

@media (max-width: 700px) {
  .editor-toolbar {
    align-items: stretch;
    width: 100%;
  }

  .zoom-controls {
    justify-content: space-between;
  }
}

/* Version 6: cleaner guided flow, collapsible activity chooser, sticky editor actions */
.step-button {
  width: 100%;
  text-align: left;
  color: var(--text);
  cursor: pointer;
}

.step-button:focus-visible {
  outline: 4px solid var(--primary-soft);
  outline-offset: 3px;
}

.step-card.needs-attention,
.activity-card.needs-attention {
  border-color: var(--danger);
  background: linear-gradient(135deg, color-mix(in srgb, var(--danger-soft) 72%, var(--solid-card)), var(--solid-card));
  box-shadow: 0 18px 40px rgba(220, 38, 38, 0.18);
}

.step-card.needs-attention .step-number {
  background: linear-gradient(135deg, var(--danger), #f97316);
}

.collapsed-card {
  display: none !important;
}

.activity-warning {
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--line));
  border-radius: 14px;
  padding: 12px 14px;
  color: #991b1b;
  background: #fee2e2;
  font-weight: 800;
  line-height: 1.45;
}

[data-theme="dark"] .activity-warning {
  color: #fecaca;
  background: rgba(220, 38, 38, 0.2);
}

.editor-panel {
  overflow: visible;
}

.editor-sticky-actions {
  position: sticky;
  top: 10px;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--solid-card) 94%, var(--primary-soft));
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
}

.editor-sticky-actions strong {
  display: block;
  margin-bottom: 2px;
}

.editor-sticky-actions span {
  color: var(--muted);
  font-size: 0.85rem;
}

.editor-sticky-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.editor-sticky-buttons .primary-btn,
.editor-sticky-buttons .success-btn {
  min-height: 40px;
  padding-inline: 16px;
}

.language-tabs {
  top: 76px;
}

@media (max-width: 760px) {
  .editor-sticky-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .editor-sticky-buttons > button {
    flex: 1 1 150px;
  }

  .language-tabs {
    top: 128px;
  }
}

/* Version 7: less intrusive suggestions + full editor mode */
.strong-tool {
  color: #14532d;
  background: #dcfce7;
}

.danger-tool {
  color: #991b1b;
  background: #fee2e2;
}

[data-theme="dark"] .strong-tool {
  color: #bbf7d0;
  background: rgba(22, 163, 74, 0.28);
}

[data-theme="dark"] .danger-tool {
  color: #fecaca;
  background: rgba(220, 38, 38, 0.28);
}

.suggestion-box {
  left: auto;
  right: 16px;
  top: auto;
  bottom: 16px;
  width: min(320px, calc(100% - 32px));
  max-height: 220px;
  border-radius: 14px;
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.18);
  overflow-y: auto;
}

.suggestion-mini-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  color: #475569;
  background: #f8fafc;
  font-size: 0.78rem;
  font-weight: 1000;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.suggestion-close {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  color: #64748b;
  background: #e2e8f0;
  font-size: 1rem;
  font-weight: 1000;
  cursor: pointer;
}

.suggestion-close:hover {
  color: #991b1b;
  background: #fee2e2;
}

.suggestion-item {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 9px 10px;
}

.suggestion-label {
  font-size: 0.95rem;
}

.suggestion-desc {
  display: -webkit-box;
  margin-top: 2px;
  overflow: hidden;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  font-size: 0.78rem;
}

.suggestion-type {
  padding: 3px 7px;
  font-size: 0.68rem;
}

[data-theme="dark"] .suggestion-mini-header {
  color: #cbd5e1;
  border-bottom-color: #243247;
  background: #111827;
}

[data-theme="dark"] .suggestion-close {
  color: #cbd5e1;
  background: #1e293b;
}

.editor-fullscreen-active {
  overflow: hidden;
}

.editor-fullscreen-active .editor-panel,
#editorPanel:fullscreen {
  position: fixed;
  z-index: 4200;
  inset: 0;
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  overflow: hidden;
  border-radius: 0;
  background: var(--solid-card);
  box-shadow: none;
}

.editor-fullscreen-active .editor-sticky-actions,
.editor-fullscreen-active .language-tabs {
  flex: none;
}

.editor-fullscreen-active .editor-panel .panel-header,
.editor-fullscreen-active .editor-info,
.editor-fullscreen-active .structure-alert,
.editor-fullscreen-active .tag-match-info,
.editor-fullscreen-active .tips-row {
  display: none;
}

.editor-fullscreen-active .editor-wrap {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}

.editor-fullscreen-active .line-numbers,
.editor-fullscreen-active .editor-stack,
.editor-fullscreen-active #codeEditor,
.editor-fullscreen-active .code-match-layer {
  min-height: 0;
  height: 100%;
}

.editor-fullscreen-active .line-numbers {
  overflow: hidden;
}

.editor-fullscreen-active .code-match-layer {
  overflow: hidden;
}

.editor-fullscreen-active #codeEditor {
  resize: none;
  overflow: auto;
}

.editor-fullscreen-active .language-tabs {
  top: 0;
}

.editor-fullscreen-active .editor-sticky-actions {
  top: 0;
  box-shadow: none;
  padding-block: 10px;
}

.editor-fullscreen-active .suggestion-box {
  bottom: 76px;
}

@media (max-width: 700px) {
  .suggestion-box {
    right: 10px;
    bottom: 10px;
    width: calc(100% - 20px);
  }

  .editor-fullscreen-active .editor-panel,
  #editorPanel:fullscreen {
    inset: 0;
    border-radius: 0;
  }

  .editor-fullscreen-active .tag-match-info,
  .editor-fullscreen-active .structure-alert,
  .editor-fullscreen-active .editor-info {
    display: none;
  }
}


/* Version 8: cleaner editor surface and no native resize limiter */
#codeEditor::-webkit-resizer {
  display: none;
}

.editor-wrap,
.editor-stack,
#codeEditor {
  max-width: 100%;
}

.editor-fullscreen-active .editor-wrap {
  height: 100%;
  min-height: 0 !important;
}

.editor-fullscreen-active .editor-stack {
  min-height: 0 !important;
}

.editor-fullscreen-active .suggestion-box {
  right: 20px;
  bottom: 20px;
}


/* Version 9: true full-screen editor and stronger undo/redo support */
.editor-fullscreen-active .editor-panel {
  border: 0;
}

.editor-fullscreen-active .editor-wrap,
#editorPanel:fullscreen .editor-wrap {
  flex: 1 1 auto;
  height: auto !important;
  min-height: 0 !important;
}

.editor-fullscreen-active .editor-stack,
.editor-fullscreen-active #codeEditor,
.editor-fullscreen-active .line-numbers,
.editor-fullscreen-active .code-match-layer,
#editorPanel:fullscreen .editor-stack,
#editorPanel:fullscreen #codeEditor,
#editorPanel:fullscreen .line-numbers,
#editorPanel:fullscreen .code-match-layer {
  height: 100% !important;
  min-height: 0 !important;
}

.editor-fullscreen-active #codeEditor,
#editorPanel:fullscreen #codeEditor {
  overflow: auto;
}

.save-zip-btn {
  font-weight: 800;
  border-color: rgba(14, 165, 233, 0.35) !important;
}

.editor-sticky-buttons .save-zip-btn {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.12), rgba(34, 197, 94, 0.12));
}


/* Version 9: editor-first layout; less reading before coding */
.app-shell {
  width: min(1560px, calc(100% - 20px));
  padding: 12px 0 24px;
}

.topbar {
  padding: 12px 16px;
  gap: 14px;
  margin-bottom: 12px;
}

.logo-mark {
  flex-basis: 44px;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 0.95rem;
}

.eyebrow,
.section-kicker {
  margin-bottom: 3px;
}

h1 {
  margin-bottom: 2px;
  font-size: clamp(1.25rem, 2vw, 1.8rem);
}

.subtitle {
  font-size: 0.88rem;
}

.top-actions {
  gap: 8px;
}

.top-actions .ghost-btn {
  min-height: 38px;
  padding-inline: 13px;
}

.workspace {
  margin-top: 0;
}

.panel-header {
  padding: 12px 16px;
}

.panel-header h2 {
  margin-bottom: 0;
}

.editor-heading {
  gap: 10px;
}

.editor-info {
  display: none;
}

.structure-alert:empty,
.tag-match-info {
  display: none;
}

.tag-match-info.good,
.tag-match-info.error {
  display: block;
  margin: 10px 16px 0;
}

.editor-sticky-actions {
  padding: 10px 14px;
}

.editor-sticky-actions span {
  font-size: 0.82rem;
}

.language-tabs {
  padding: 10px 14px 0;
}

.editor-wrap,
.line-numbers,
.editor-stack,
#codeEditor,
.code-match-layer {
  min-height: max(620px, 76vh);
}

.quick-after-editor {
  margin-top: 12px;
}

.compact-section-title {
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  padding: 11px 14px;
  color: var(--muted);
  background: color-mix(in srgb, var(--solid-card) 84%, var(--primary-soft));
  font-size: 0.92rem;
}

.activity-card {
  margin-top: 12px;
}

.activity-launch-btn.needs-attention,
.ghost-btn.needs-attention {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
  box-shadow: 0 14px 30px rgba(220, 38, 38, 0.16);
}

.compact-help {
  margin-top: 12px;
  padding: 0;
}

.compact-help > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 18px;
  color: var(--primary-dark);
  font-weight: 1000;
}

.compact-help > summary::-webkit-details-marker {
  display: none;
}

.compact-help > summary::after {
  content: ' +';
}

.compact-help[open] > summary::after {
  content: ' −';
}

.compact-help .help-header,
.compact-help .help-grid {
  padding-inline: 18px;
}

.compact-help .help-grid {
  padding-bottom: 18px;
}

.step-card.needs-attention .step-number {
  background: linear-gradient(135deg, var(--danger), #f97316);
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
  }
  .brand-block {
    align-items: flex-start;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 12px, 1560px);
    padding-top: 8px;
  }
  .topbar {
    padding: 10px;
  }
  .subtitle {
    display: none;
  }
  .top-actions .ghost-btn {
    flex: 1 1 130px;
  }
}

/* Version 10: true editor-first screen. Nothing bulky appears before the code area. */
.app-shell {
  width: min(1640px, calc(100% - 12px));
  padding: 6px 0 18px;
}

.topbar {
  position: sticky;
  top: 6px;
  z-index: 100;
  min-height: auto;
  margin-bottom: 8px;
  padding: 9px 12px;
  border-radius: 18px;
}

.logo-mark {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  font-size: 0.82rem;
}

.brand-block {
  gap: 10px;
  min-width: 210px;
}

.eyebrow {
  margin-bottom: 0;
  font-size: 0.62rem;
  letter-spacing: 0.11em;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.05rem, 1.4vw, 1.45rem);
  line-height: 1;
}

.subtitle {
  display: none;
}

.top-actions {
  align-items: center;
  gap: 6px;
}

.top-actions .ghost-btn,
.top-actions .primary-btn,
.top-actions .success-btn {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  white-space: nowrap;
}

.top-run-btn,
.top-result-btn {
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.workspace {
  margin-top: 0 !important;
  align-items: start;
}

.editor-panel {
  position: relative;
  min-height: calc(100vh - 102px);
  border-radius: 18px;
}

/* Remove all reading panels above the editor. */
.editor-heading,
.editor-sticky-actions,
.editor-info,
.structure-alert,
.tag-match-info,
.shortcut-strip,
.quick-after-editor,
.student-steps {
  display: none !important;
}

/* Show only the tabs, then the actual editor immediately. */
.language-tabs {
  display: flex;
  align-items: end;
  gap: 5px;
  min-height: 38px;
  padding: 5px 8px 0 !important;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--solid-card) 94%, var(--primary-soft));
}

.tab-btn {
  min-height: 32px;
  padding: 7px 16px;
  border-radius: 12px 12px 0 0;
  font-size: 0.92rem;
}

.editor-wrap {
  border-radius: 0 0 18px 18px;
  border-top: 0;
}

.editor-wrap,
.line-numbers,
.editor-stack,
#codeEditor,
.code-match-layer {
  min-height: calc(100vh - 150px) !important;
}

#codeEditor {
  padding-top: 16px;
}

.line-numbers {
  padding-top: 16px;
}

.fullscreen-exit-btn {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 4305;
  min-height: 38px;
  border: 0;
  border-radius: 999px;
  padding: 0 16px;
  color: white;
  background: linear-gradient(135deg, #dc2626, #fb7185);
  box-shadow: 0 16px 34px rgba(220, 38, 38, 0.22);
  font-weight: 900;
  cursor: pointer;
}

.fullscreen-exit-btn.hidden {
  display: none;
}

.editor-fullscreen-active .fullscreen-exit-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

.editor-fullscreen-active .editor-panel,
#editorPanel:fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  border-radius: 0 !important;
  border: 0 !important;
}

.editor-fullscreen-active .language-tabs,
#editorPanel:fullscreen .language-tabs {
  min-height: 42px;
  padding-right: 112px !important;
  border-radius: 0;
}

.editor-fullscreen-active .editor-wrap,
#editorPanel:fullscreen .editor-wrap {
  flex: 1 1 auto;
  height: calc(100vh - 42px) !important;
  min-height: 0 !important;
  border-radius: 0 !important;
}

.editor-fullscreen-active .line-numbers,
.editor-fullscreen-active .editor-stack,
.editor-fullscreen-active #codeEditor,
.editor-fullscreen-active .code-match-layer,
#editorPanel:fullscreen .line-numbers,
#editorPanel:fullscreen .editor-stack,
#editorPanel:fullscreen #codeEditor,
#editorPanel:fullscreen .code-match-layer {
  height: 100% !important;
  min-height: 0 !important;
}

.activity-card.collapsed-card {
  display: none !important;
}

.activity-card:not(.collapsed-card) {
  display: flex !important;
  margin-top: 8px;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .top-actions .ghost-btn,
  .top-actions .primary-btn,
  .top-actions .success-btn {
    min-height: 32px;
    padding-inline: 10px;
    font-size: 0.82rem;
  }

  .editor-panel {
    min-height: calc(100vh - 150px);
  }

  .editor-wrap,
  .line-numbers,
  .editor-stack,
  #codeEditor,
  .code-match-layer {
    min-height: calc(100vh - 190px) !important;
  }
}

/* Scale-based rubric builder */
.scale-criterion-card {
  display: grid;
  gap: 14px;
}

.criterion-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.criterion-title-big {
  margin-top: 6px;
  font-size: 1.02rem;
  font-weight: 800;
}

.compact-criterion-grid {
  grid-template-columns: 0.6fr 1.2fr 1fr;
}

.scale-rubric-table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--solid-card);
}

.scale-rubric-head,
.scale-level-row {
  display: grid;
  grid-template-columns: 170px 110px 1fr;
  gap: 10px;
  align-items: center;
}

.scale-rubric-head {
  padding: 10px 12px;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: color-mix(in srgb, var(--solid-card) 78%, var(--primary-soft));
}

.scale-level-row {
  padding: 12px;
  border-top: 1px solid var(--line);
}

.scale-level-name {
  font-weight: 900;
  color: var(--text);
}

.scale-level-row label {
  gap: 5px;
}

.level-description-label textarea {
  resize: vertical;
  min-height: 54px;
}

.scale-result-item.excellent {
  border-left: 5px solid #22c55e;
}

.scale-result-item.good {
  border-left: 5px solid #38bdf8;
}

.scale-result-item.fair {
  border-left: 5px solid #f59e0b;
}

.scale-result-item.needsImprovement {
  border-left: 5px solid #ef4444;
}

@media (max-width: 820px) {
  .criterion-header-row,
  .rubric-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .compact-criterion-grid,
  .scale-rubric-head,
  .scale-level-row {
    grid-template-columns: 1fr;
  }

  .scale-rubric-head {
    display: none;
  }
}


/* Version 12: teacher rubric table input */
.rubric-table-note {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--solid-card) 82%, var(--primary-soft));
  color: var(--text);
  font-size: 0.95rem;
}

.rubric-table-scroll {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--solid-card);
  box-shadow: var(--shadow-soft);
}

.teacher-rubric-table {
  width: 100%;
  min-width: 1120px;
  border-collapse: separate;
  border-spacing: 0;
}

.teacher-rubric-table th,
.teacher-rubric-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.teacher-rubric-table th:last-child,
.teacher-rubric-table td:last-child {
  border-right: 0;
}

.teacher-rubric-table tr:last-child td {
  border-bottom: 0;
}

.teacher-rubric-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 14px 12px;
  text-align: left;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: color-mix(in srgb, var(--solid-card) 78%, var(--primary-soft));
}

.teacher-rubric-table thead th:first-child {
  z-index: 3;
}

.rubric-criterion-cell {
  width: 320px;
  min-width: 320px;
  padding: 14px;
  background: color-mix(in srgb, var(--solid-card) 92%, var(--primary-soft));
}

.rubric-level-cell {
  min-width: 190px;
  padding: 12px;
}

.criterion-title-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.criterion-number {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 900;
}

.criterion-mini-grid {
  display: grid;
  grid-template-columns: 0.55fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.criterion-mini-grid label:last-child {
  grid-column: 1 / -1;
}

.criterion-mini-grid input,
.criterion-mini-grid select,
.rubric-level-cell input,
.rubric-level-cell textarea {
  font-size: 0.9rem;
}

.rubric-score-label {
  display: grid;
  grid-template-columns: auto 86px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 900;
  color: var(--muted);
}

.rubric-level-cell textarea {
  min-height: 104px;
  resize: vertical;
}

.rubric-criterion-cell .remove-criterion {
  width: auto;
  height: auto;
  min-height: 0;
  margin-top: 10px;
  padding: 8px 12px;
}

@media (max-width: 820px) {
  .teacher-rubric-table,
  .teacher-rubric-table thead,
  .teacher-rubric-table tbody,
  .teacher-rubric-table th,
  .teacher-rubric-table td,
  .teacher-rubric-table tr {
    display: block;
    min-width: 0;
    width: 100%;
  }

  .teacher-rubric-table thead {
    display: none;
  }

  .rubric-table-row {
    border-bottom: 2px solid var(--line);
  }

  .teacher-rubric-table td {
    border-right: 0;
  }

  .teacher-rubric-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 8px;
    font-size: 0.76rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
  }

  .rubric-criterion-cell,
  .rubric-level-cell {
    width: 100%;
    min-width: 0;
  }
}

/* Admin modal width fix: make Teacher/Admin workspace wider without stretching the PIN form */
#adminOverlay {
  padding: 8px;
}

#adminOverlay .admin-modal {
  width: min(1560px, calc(100vw - 16px));
  max-height: calc(100dvh - 16px);
  border-radius: 22px;
}

#adminOverlay .modal-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--solid-card);
}

#adminOverlay .admin-form {
  padding: 22px 28px 26px;
}

#adminOverlay .pin-screen {
  width: min(560px, 100%);
  min-height: 0;
  margin: 0 auto;
  padding: 34px 20px;
}

#adminOverlay .pin-row {
  align-items: center;
}

#adminOverlay .pin-row input {
  min-height: 52px;
}

#adminOverlay .pin-row .primary-btn {
  min-height: 52px;
  padding-inline: 24px;
}

#adminOverlay .rubric-table-scroll {
  max-height: 58vh;
}

@media (max-width: 760px) {
  #adminOverlay {
    padding: 6px;
  }

  #adminOverlay .admin-modal {
    width: calc(100vw - 12px);
    max-height: calc(100dvh - 12px);
    border-radius: 16px;
  }

  #adminOverlay .admin-form {
    padding: 16px 12px 18px;
  }

  #adminOverlay .pin-screen {
    padding: 22px 12px;
  }
}

/* Latest admin panel fix: admin view covers the screen and hides the sticky student topbar */
body.admin-open {
  overflow: hidden;
}

body.admin-open .topbar {
  display: none !important;
}

body.admin-open #adminOverlay {
  z-index: 9000 !important;
  padding: 6px !important;
  place-items: stretch !important;
}

body.admin-open #adminOverlay .admin-modal {
  width: 100% !important;
  height: calc(100dvh - 12px) !important;
  max-height: none !important;
  border-radius: 18px !important;
}

body.admin-open #adminOverlay .modal-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--solid-card);
}

body.admin-open #closeAdminBtn {
  position: sticky;
  top: 14px;
  z-index: 70;
  flex: 0 0 auto;
}

body.admin-open #adminOverlay .admin-form {
  padding: 22px 30px 28px !important;
}

@media (max-width: 760px) {
  body.admin-open #adminOverlay {
    padding: 4px !important;
  }

  body.admin-open #adminOverlay .admin-modal {
    height: calc(100dvh - 8px) !important;
    border-radius: 14px !important;
  }

  body.admin-open #adminOverlay .admin-form {
    padding: 16px 12px 18px !important;
  }
}

/* Latest update: Notepad++-style syntax colors for HTML, CSS, and JavaScript */
.editor-stack {
  isolation: isolate;
}

.code-match-layer {
  color: var(--editor-text) !important;
  background: transparent;
  user-select: none;
}

#codeEditor {
  color: transparent !important;
  -webkit-text-fill-color: transparent;
  caret-color: var(--editor-text);
}

#codeEditor::selection {
  color: transparent;
  -webkit-text-fill-color: transparent;
  background: rgba(96, 165, 250, 0.35);
}

.code-match-layer .tag-match {
  color: inherit !important;
  border-radius: 4px;
  text-decoration-line: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
}

.code-match-layer .syn-doctype {
  color: #334155;
  font-weight: 900;
}

.code-match-layer .syn-html-tag,
.code-match-layer .syn-html-bracket {
  color: #0000cc;
  font-weight: 900;
}

.code-match-layer .syn-html-attr {
  color: #7952b3;
}

.code-match-layer .syn-html-equals,
.code-match-layer .syn-punctuation {
  color: #64748b;
}

.code-match-layer .syn-string {
  color: #b91c1c;
}

.code-match-layer .syn-comment {
  color: #64748b;
  font-style: italic;
}

.code-match-layer .syn-css-selector {
  color: #7c3aed;
  font-weight: 900;
}

.code-match-layer .syn-css-property {
  color: #0369a1;
  font-weight: 800;
}

.code-match-layer .syn-number {
  color: #c2410c;
}

.code-match-layer .syn-js-keyword {
  color: #9333ea;
  font-weight: 900;
}

.code-match-layer .syn-js-function {
  color: #0f766e;
  font-weight: 800;
}

[data-theme="dark"] .code-match-layer .syn-doctype {
  color: #cbd5e1;
}

[data-theme="dark"] .code-match-layer .syn-html-tag,
[data-theme="dark"] .code-match-layer .syn-html-bracket {
  color: #60a5fa;
}

[data-theme="dark"] .code-match-layer .syn-html-attr {
  color: #c084fc;
}

[data-theme="dark"] .code-match-layer .syn-html-equals,
[data-theme="dark"] .code-match-layer .syn-punctuation {
  color: #94a3b8;
}

[data-theme="dark"] .code-match-layer .syn-string {
  color: #fca5a5;
}

[data-theme="dark"] .code-match-layer .syn-comment {
  color: #94a3b8;
}

[data-theme="dark"] .code-match-layer .syn-css-selector {
  color: #c084fc;
}

[data-theme="dark"] .code-match-layer .syn-css-property {
  color: #38bdf8;
}

[data-theme="dark"] .code-match-layer .syn-number {
  color: #fdba74;
}

[data-theme="dark"] .code-match-layer .syn-js-keyword {
  color: #c084fc;
}

[data-theme="dark"] .code-match-layer .syn-js-function {
  color: #5eead4;
}

/* Firebase Auth teacher login update */
.teacher-login-screen {
  justify-content: center;
  align-items: center;
  min-height: min(520px, 70vh);
}

.teacher-login-card {
  display: grid;
  gap: 14px;
  width: min(520px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 24px;
  background: color-mix(in srgb, var(--solid-card) 88%, var(--primary-soft));
  box-shadow: var(--shadow);
}

.teacher-login-card h3 {
  margin-bottom: 4px;
  font-size: 1.35rem;
}

.teacher-login-actions {
  display: flex;
  gap: 10px;
}

.teacher-login-actions button {
  flex: 1;
}

.admin-open .topbar {
  visibility: hidden;
}

/* Improved Firebase Auth login layout */
body.admin-open #adminOverlay .pin-screen.teacher-login-screen {
  width: 100% !important;
  min-height: calc(100dvh - 150px) !important;
  margin: 0 !important;
  padding: 28px clamp(16px, 4vw, 56px) !important;
  display: grid !important;
  place-items: center !important;
  background:
    radial-gradient(circle at 18% 16%, rgba(37, 99, 235, 0.16), transparent 28rem),
    radial-gradient(circle at 88% 80%, rgba(6, 182, 212, 0.12), transparent 26rem),
    linear-gradient(135deg, color-mix(in srgb, var(--solid-card) 88%, var(--primary-soft)), var(--solid-card));
}

.teacher-login-layout {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  align-items: stretch;
  gap: 18px;
}

.teacher-login-intro,
.teacher-login-card {
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: clamp(22px, 3vw, 34px);
  background: color-mix(in srgb, var(--solid-card) 92%, var(--primary-soft));
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.14);
}

.teacher-login-intro {
  display: grid;
  align-content: center;
  gap: 12px;
  color: var(--text);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(6, 182, 212, 0.1)), var(--solid-card);
}

.teacher-login-icon {
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  border-radius: 24px;
  color: white;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  box-shadow: 0 18px 40px rgba(37, 99, 235, 0.25);
  font-size: 2rem;
}

.teacher-login-intro h3 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.65rem);
  line-height: 1.03;
}

.teacher-login-intro p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}

.login-checklist {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.login-checklist span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 12px;
  color: var(--text);
  background: var(--solid-card);
  font-size: 0.9rem;
  font-weight: 800;
}

.teacher-login-card {
  display: grid;
  align-content: center;
  gap: 14px;
  width: 100% !important;
  margin: 0 !important;
}

.teacher-login-card label {
  font-size: 0.95rem;
}

.teacher-login-card input {
  min-height: 56px;
  border-radius: 18px;
  padding-inline: 18px;
  font-size: 1rem;
  font-weight: 700;
  background: var(--solid-card);
}

.teacher-login-actions {
  display: grid !important;
  grid-template-columns: 1fr auto;
  gap: 10px !important;
  margin-top: 4px;
}

.teacher-login-actions .primary-btn,
.teacher-login-actions .ghost-btn {
  min-height: 54px !important;
  padding-inline: 22px !important;
  border-radius: 18px !important;
}

.teacher-login-actions .primary-btn:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
}

.login-error {
  margin: 0;
  border: 1px solid color-mix(in srgb, var(--danger) 48%, var(--line));
  border-radius: 16px;
  padding: 12px 14px;
  color: #991b1b;
  background: #fee2e2;
  font-weight: 800;
  line-height: 1.45;
}

[data-theme="dark"] .login-error {
  color: #fecaca;
  background: rgba(220, 38, 38, 0.18);
}

@media (max-width: 840px) {
  .teacher-login-layout {
    grid-template-columns: 1fr;
  }

  .teacher-login-intro h3 {
    font-size: 1.75rem;
  }

  .teacher-login-actions {
    grid-template-columns: 1fr;
  }
}

/* Mobile-first upgrade: phone/tablet responsive layout */
@media (max-width: 820px) {
  html,
  body {
    width: 100%;
    overflow-x: hidden;
  }

  body {
    padding-bottom: calc(88px + env(safe-area-inset-bottom));
    background: var(--bg);
  }

  .app-shell {
    width: 100%;
    padding: 0 0 calc(18px + env(safe-area-inset-bottom));
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 120;
    width: 100%;
    margin: 0;
    border-radius: 0 0 18px 18px;
    padding: 10px 12px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
  }

  .brand-block {
    width: 100%;
    gap: 10px;
  }

  .logo-mark {
    display: grid;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 13px;
  }

  .eyebrow {
    font-size: 0.58rem;
    letter-spacing: 0.1em;
  }

  h1 {
    max-width: calc(100vw - 76px);
    font-size: clamp(1rem, 5.4vw, 1.35rem);
    line-height: 1.08;
  }

  .subtitle {
    display: block;
    font-size: 0.76rem;
    line-height: 1.2;
  }

  /* Phone action bar: keep the editor visible and put controls at the thumb area. */
  .top-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4100;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    overflow-x: auto;
    overflow-y: hidden;
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--solid-card) 94%, var(--primary-soft));
    box-shadow: 0 -14px 32px rgba(15, 23, 42, 0.16);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .top-actions::-webkit-scrollbar {
    display: none;
  }

  .top-actions .status-badge {
    display: none;
  }

  .top-actions .primary-btn,
  .top-actions .success-btn,
  .top-actions .ghost-btn {
    flex: 0 0 auto;
    min-width: max-content;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 999px;
    font-size: 0.9rem;
    box-shadow: none;
  }

  .top-run-btn { order: 1; }
  .top-result-btn { order: 2; }
  .activity-launch-btn { order: 3; }
  .save-zip-btn { order: 4; }
  .full-editor-top { order: 5; }
  .teacher-btn { order: 6; }
  #themeToggle { order: 7; }
  #resetBtn { order: 8; }
  #clearBtn { order: 9; }
  #exitEditorBtn { order: 10; }

  .workspace,
  .workspace[data-layout="split"],
  .workspace[data-layout="stacked"],
  .workspace[data-layout="preview-focus"] {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    margin: 8px 0 0 !important;
  }

  .panel,
  .activity-card,
  .help-card {
    width: calc(100% - 12px);
    margin-left: auto;
    margin-right: auto;
    border-radius: 16px;
  }

  .editor-panel {
    min-height: auto;
    overflow: hidden;
  }

  .language-tabs {
    position: sticky;
    top: 62px;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 6px 6px 0 !important;
    min-height: 40px;
  }

  .tab-btn {
    width: 100%;
    min-height: 38px;
    padding: 8px 4px;
    border-radius: 12px 12px 0 0;
    font-size: 0.86rem;
    text-align: center;
  }

  .tab-btn::after {
    display: none;
  }

  .editor-wrap {
    grid-template-columns: 38px minmax(0, 1fr);
    min-height: 62vh !important;
    border-radius: 0 0 16px 16px;
  }

  .line-numbers,
  .editor-stack,
  #codeEditor,
  .code-match-layer {
    height: 62vh !important;
    min-height: 420px !important;
  }

  .line-numbers {
    padding: 12px 6px;
    font-size: var(--editor-font-size, 16px);
    line-height: 1.62;
  }

  #codeEditor,
  .code-match-layer {
    padding: 12px;
    font-size: var(--editor-font-size, 16px);
    line-height: 1.62;
    white-space: pre;
    overflow-wrap: normal;
  }

  #codeEditor {
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .code-match-layer {
    overflow: hidden !important;
  }

  .suggestion-box {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    top: auto;
    width: auto;
    max-height: 42vh;
    border-radius: 16px;
  }

  .suggestion-item {
    min-height: 48px;
    padding: 10px 12px;
  }

  .right-column {
    display: grid;
    gap: 12px;
    width: 100%;
  }

  .panel-header,
  .compact-header,
  .preview-header {
    display: grid;
    gap: 10px;
    padding: 12px;
  }

  .panel-header h2 {
    font-size: 1rem;
  }

  .panel-header p,
  .muted-text {
    font-size: 0.86rem;
    line-height: 1.35;
  }

  .preview-actions {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .preview-actions::-webkit-scrollbar {
    display: none;
  }

  .layout-btn {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 11px;
    font-size: 0.78rem;
  }

  #previewFrame {
    min-height: 48vh !important;
    height: 48vh;
  }

  .result-content {
    padding: 12px;
  }

  .score-main,
  .rubric-item {
    border-radius: 16px;
  }

  .score-main {
    display: grid;
    gap: 12px;
  }

  .score-number {
    font-size: clamp(2rem, 13vw, 3rem);
  }

  .rubric-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .rubric-points {
    grid-column: 2;
    justify-self: start;
  }

  .activity-card:not(.collapsed-card) {
    display: grid !important;
    gap: 14px;
    padding: 12px;
  }

  .activity-select-row,
  .activity-stats {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .activity-stats > div {
    min-width: 0;
  }

  .compact-help > summary {
    padding: 13px 14px;
  }

  .compact-help .help-header,
  .compact-help .help-grid {
    padding-inline: 14px;
  }

  .help-grid {
    grid-template-columns: 1fr !important;
  }

  .help-grid > div {
    min-height: 0;
    padding: 12px;
    font-size: 0.88rem;
  }
}

@media (max-width: 820px) and (orientation: landscape) {
  body {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .topbar {
    padding: 7px 10px;
  }

  .subtitle {
    display: none;
  }

  .language-tabs {
    top: 52px;
  }

  .editor-wrap,
  .line-numbers,
  .editor-stack,
  #codeEditor,
  .code-match-layer {
    height: 70vh !important;
    min-height: 300px !important;
  }
}

/* Phone-friendly Teacher/Admin screen */
@media (max-width: 820px) {
  .modal-overlay {
    place-items: stretch;
    padding: 0;
    background: rgba(2, 6, 23, 0.78);
  }

  .admin-modal {
    width: 100vw !important;
    height: 100dvh !important;
    max-height: none !important;
    border: 0;
    border-radius: 0;
  }

  .modal-header {
    position: sticky;
    top: 0;
    z-index: 30;
    align-items: center;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 12px;
    background: var(--solid-card);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  }

  .modal-header h2 {
    font-size: 1.05rem;
    line-height: 1.1;
  }

  .modal-header .muted-text {
    display: none;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 999px;
  }

  body.admin-open #adminOverlay .pin-screen.teacher-login-screen {
    min-height: calc(100dvh - 72px) !important;
    padding: 14px 12px calc(20px + env(safe-area-inset-bottom)) !important;
  }

  .teacher-login-layout {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .teacher-login-intro {
    padding: 16px;
    border-radius: 20px;
    align-content: start;
  }

  .teacher-login-icon {
    width: 52px;
    height: 52px;
    border-radius: 18px;
    font-size: 1.5rem;
  }

  .teacher-login-intro h3 {
    font-size: 1.45rem;
  }

  .teacher-login-intro p {
    font-size: 0.9rem;
  }

  .login-checklist {
    gap: 6px;
  }

  .login-checklist span {
    border-radius: 12px;
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .teacher-login-card {
    padding: 16px;
    border-radius: 20px;
  }

  .teacher-login-card input,
  .pin-screen input,
  .admin-form input,
  .admin-form select,
  .admin-form textarea {
    min-height: 48px;
    border-radius: 14px;
    font-size: 16px;
  }

  .teacher-login-actions {
    grid-template-columns: 1fr !important;
  }

  .teacher-login-actions .primary-btn,
  .teacher-login-actions .ghost-btn {
    min-height: 50px !important;
    border-radius: 16px !important;
  }

  .admin-form {
    gap: 12px;
    padding: 12px 12px calc(96px + env(safe-area-inset-bottom));
  }

  .admin-activity-manager,
  .criterion-card,
  .rubric-table-note,
  .rubric-table-scroll {
    border-radius: 16px;
  }

  .form-grid,
  .admin-activity-actions,
  .criterion-mini-grid {
    display: grid;
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .rubric-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    padding-top: 12px;
  }

  .teacher-rubric-table,
  .teacher-rubric-table thead,
  .teacher-rubric-table tbody,
  .teacher-rubric-table th,
  .teacher-rubric-table td,
  .teacher-rubric-table tr {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .teacher-rubric-table thead {
    display: none;
  }

  .rubric-table-row {
    margin-bottom: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--solid-card);
  }

  .rubric-criterion-cell,
  .rubric-level-cell {
    width: 100%;
    min-width: 0;
    border-right: 0 !important;
    padding: 12px;
  }

  .teacher-rubric-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 8px;
    color: var(--primary);
    font-size: 0.72rem;
    font-weight: 1000;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .rubric-score-label {
    grid-template-columns: 1fr 104px;
  }

  .rubric-level-cell textarea {
    min-height: 96px;
  }

  .admin-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--solid-card) 96%, var(--primary-soft));
    box-shadow: 0 -14px 30px rgba(15, 23, 42, 0.14);
  }

  .admin-actions button {
    min-height: 48px;
    padding: 0 10px;
    border-radius: 14px;
    font-size: 0.86rem;
  }

  .admin-open .topbar,
  .admin-open .top-actions {
    visibility: hidden;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 1rem;
  }

  .logo-mark {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
  }

  .top-actions .primary-btn,
  .top-actions .success-btn,
  .top-actions .ghost-btn {
    min-height: 42px;
    padding: 0 12px;
    font-size: 0.84rem;
  }

  .editor-wrap {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .line-numbers {
    padding-left: 4px;
    padding-right: 4px;
  }

  #codeEditor,
  .code-match-layer {
    padding-left: 10px;
    padding-right: 10px;
  }
}

/* FINAL MOBILE FIX: tabs must never cover the code editor */
@media (max-width: 820px) {
  html,
  body {
    overflow-x: hidden !important;
  }

  body {
    padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
  }

  .app-shell {
    width: 100% !important;
    padding: 0 0 18px !important;
  }

  .topbar {
    position: relative !important;
    top: auto !important;
    z-index: 40 !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    width: 100% !important;
    margin: 0 0 10px !important;
    padding: 12px !important;
    border-radius: 0 0 18px 18px !important;
  }

  .brand-block {
    width: 100% !important;
    min-width: 0 !important;
  }

  .brand-block > div:last-child {
    min-width: 0 !important;
  }

  h1 {
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
  }

  .top-actions {
    position: static !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    z-index: auto !important;
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 8px !important;
    width: 100% !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .top-actions .status-badge,
  .full-editor-top {
    display: none !important;
  }

  .top-actions .primary-btn,
  .top-actions .success-btn,
  .top-actions .ghost-btn {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 42px !important;
    padding: 0 8px !important;
    border-radius: 14px !important;
    font-size: clamp(0.72rem, 3.2vw, 0.86rem) !important;
    line-height: 1.1 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .top-run-btn { order: 1 !important; }
  .top-result-btn { order: 2 !important; }
  .activity-launch-btn { order: 3 !important; }
  .save-zip-btn { order: 4 !important; }
  .teacher-btn { order: 5 !important; }
  #themeToggle { order: 6 !important; }
  #resetBtn { order: 7 !important; }
  #clearBtn { order: 8 !important; }

  .workspace,
  .workspace[data-layout="split"],
  .workspace[data-layout="stacked"],
  .workspace[data-layout="preview-focus"] {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    width: 100% !important;
    margin: 0 !important;
  }

  .panel,
  .activity-card,
  .help-card {
    width: calc(100% - 12px) !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .editor-panel {
    display: block !important;
    overflow: hidden !important;
    min-height: 0 !important;
  }

  .language-tabs {
    position: static !important;
    top: auto !important;
    z-index: 1 !important;
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 4px !important;
    width: 100% !important;
    min-height: 0 !important;
    padding: 6px 6px 0 !important;
    border-bottom: 1px solid var(--line) !important;
    background: color-mix(in srgb, var(--solid-card) 94%, var(--primary-soft)) !important;
  }

  .tab-btn {
    min-width: 0 !important;
    width: 100% !important;
    min-height: 42px !important;
    padding: 8px 4px !important;
    font-size: clamp(0.78rem, 4vw, 0.95rem) !important;
    border-radius: 13px 13px 0 0 !important;
  }

  .tab-btn::after {
    display: none !important;
  }

  .editor-wrap {
    display: grid !important;
    grid-template-columns: 38px minmax(0, 1fr) !important;
    width: 100% !important;
    margin-top: 0 !important;
    border-radius: 0 0 16px 16px !important;
    min-height: 64vh !important;
    overflow: hidden !important;
  }

  .line-numbers,
  .editor-stack,
  #codeEditor,
  .code-match-layer {
    height: 64vh !important;
    min-height: 440px !important;
  }

  .line-numbers {
    padding: 12px 5px !important;
    font-size: clamp(14px, 4.4vw, 16px) !important;
    line-height: 1.62 !important;
  }

  #codeEditor,
  .code-match-layer {
    padding: 12px !important;
    font-size: clamp(14px, 4.4vw, 16px) !important;
    line-height: 1.62 !important;
    white-space: pre !important;
    overflow-wrap: normal !important;
  }

  #codeEditor {
    overflow: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .code-match-layer {
    overflow: hidden !important;
  }

  .right-column {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    width: 100% !important;
  }

  .suggestion-box {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    bottom: 12px !important;
    top: auto !important;
    width: auto !important;
    max-height: 42vh !important;
  }
}

@media (max-width: 420px) {
  .top-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .top-actions .primary-btn,
  .top-actions .success-btn,
  .top-actions .ghost-btn {
    font-size: 0.82rem !important;
  }

  .editor-wrap {
    grid-template-columns: 34px minmax(0, 1fr) !important;
  }

  #codeEditor,
  .code-match-layer {
    padding: 10px !important;
  }
}

/* FINAL PHONE EDITOR REPAIR: real phone-friendly editor and fullscreen */
@media (max-width: 820px) {
  :root {
    --mobile-editor-font-size: 12.5px;
    --mobile-editor-line-height: 1.48;
  }

  /* Do not let the language tabs stick/float over the code. */
  .editor-panel .language-tabs,
  body:not(.editor-fullscreen-active) .editor-panel .language-tabs {
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    z-index: 2 !important;
    transform: none !important;
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 3px !important;
    min-height: 34px !important;
    height: 34px !important;
    padding: 4px 4px 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  .editor-panel .tab-btn {
    min-height: 30px !important;
    height: 30px !important;
    padding: 0 3px !important;
    border-radius: 10px 10px 0 0 !important;
    font-size: 0.72rem !important;
    line-height: 1 !important;
  }

  .editor-panel .editor-wrap {
    position: relative !important;
    display: grid !important;
    grid-template-columns: 30px minmax(0, 1fr) !important;
    min-height: 58vh !important;
    height: 58vh !important;
    margin: 0 !important;
    overflow: hidden !important;
    border-radius: 0 0 14px 14px !important;
  }

  .editor-panel .line-numbers,
  .editor-panel .editor-stack,
  .editor-panel #codeEditor,
  .editor-panel .code-match-layer {
    height: 58vh !important;
    min-height: 58vh !important;
    max-height: 58vh !important;
    font-size: var(--mobile-editor-font-size) !important;
    line-height: var(--mobile-editor-line-height) !important;
  }

  .editor-panel .line-numbers {
    padding: 8px 3px !important;
    text-align: right !important;
    overflow: hidden !important;
  }

  .editor-panel #codeEditor,
  .editor-panel .code-match-layer {
    padding: 8px 8px !important;
    white-space: pre !important;
    overflow-wrap: normal !important;
    word-break: normal !important;
    tab-size: 2 !important;
  }

  .editor-panel #codeEditor {
    overflow: auto !important;
    resize: none !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .editor-panel .code-match-layer {
    overflow: hidden !important;
  }

  /* Keep header actions readable without forcing side scroll. */
  .top-actions {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 7px !important;
  }

  .top-actions .primary-btn,
  .top-actions .success-btn,
  .top-actions .ghost-btn {
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 6px !important;
    font-size: 0.72rem !important;
    border-radius: 12px !important;
  }

  .preview-actions {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 7px !important;
    overflow: visible !important;
  }

  .preview-actions .layout-btn {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 38px !important;
    font-size: 0.76rem !important;
    white-space: nowrap !important;
  }
}

@media (max-width: 420px) {
  .top-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }

  .top-actions .primary-btn,
  .top-actions .success-btn,
  .top-actions .ghost-btn {
    font-size: 0.68rem !important;
    min-height: 36px !important;
    height: 36px !important;
    padding: 0 4px !important;
  }

  .teacher-btn::before { content: ''; }
  .teacher-btn { font-size: 0 !important; }
  .teacher-btn::after { content: 'Admin'; font-size: 0.68rem; }

  #themeToggle { font-size: 0 !important; }
  #themeToggle::after { content: 'Theme'; font-size: 0.68rem; }

  #clearBtn { font-size: 0 !important; }
  #clearBtn::after { content: 'Clear'; font-size: 0.68rem; }
}

/* Mobile full editor must be clean: no giant text, no overlapping exit button. */
@media (max-width: 820px) {
  body.editor-fullscreen-active {
    overflow: hidden !important;
    padding: 0 !important;
  }

  body.editor-fullscreen-active .editor-panel,
  #editorPanel:fullscreen {
    position: fixed !important;
    inset: 0 !important;
    z-index: 5000 !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    background: var(--editor-bg) !important;
  }

  body.editor-fullscreen-active .editor-panel .language-tabs,
  #editorPanel:fullscreen .language-tabs {
    position: relative !important;
    flex: 0 0 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    padding: 4px 4px 0 !important;
    padding-right: 4px !important;
    border-radius: 0 !important;
    z-index: 2 !important;
  }

  body.editor-fullscreen-active .editor-panel .tab-btn,
  #editorPanel:fullscreen .tab-btn {
    height: 32px !important;
    min-height: 32px !important;
    font-size: 0.72rem !important;
    border-radius: 9px 9px 0 0 !important;
  }

  body.editor-fullscreen-active .editor-wrap,
  #editorPanel:fullscreen .editor-wrap {
    flex: 1 1 auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    grid-template-columns: 30px minmax(0, 1fr) !important;
    border-radius: 0 !important;
  }

  body.editor-fullscreen-active .line-numbers,
  body.editor-fullscreen-active .editor-stack,
  body.editor-fullscreen-active #codeEditor,
  body.editor-fullscreen-active .code-match-layer,
  #editorPanel:fullscreen .line-numbers,
  #editorPanel:fullscreen .editor-stack,
  #editorPanel:fullscreen #codeEditor,
  #editorPanel:fullscreen .code-match-layer {
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    font-size: var(--mobile-editor-font-size) !important;
    line-height: var(--mobile-editor-line-height) !important;
  }

  body.editor-fullscreen-active #codeEditor,
  #editorPanel:fullscreen #codeEditor {
    overflow: auto !important;
    padding: 8px !important;
  }

  body.editor-fullscreen-active .code-match-layer,
  #editorPanel:fullscreen .code-match-layer {
    padding: 8px !important;
  }

  body.editor-fullscreen-active .fullscreen-exit-btn {
    position: fixed !important;
    right: 12px !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
    top: auto !important;
    z-index: 5200 !important;
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 14px !important;
    border-radius: 999px !important;
    font-size: 0.78rem !important;
    opacity: 0.92 !important;
  }
}

/* Error Checker Panel */
.error-checker-panel {
  overflow: hidden;
}

.error-checker-header {
  align-items: center;
}

.error-checker-content {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.checker-empty {
  display: grid;
  gap: 4px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  padding: 14px;
  color: var(--muted);
  background: color-mix(in srgb, var(--solid-card) 86%, var(--primary-soft));
}

.checker-empty strong {
  color: var(--text);
}

.checker-summary {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: var(--solid-card);
}

.checker-summary strong {
  display: block;
  margin-bottom: 3px;
  color: var(--text);
  font-size: 1rem;
}

.checker-summary span {
  color: var(--muted);
  font-size: 0.88rem;
}

.checker-summary.pass {
  border-color: color-mix(in srgb, var(--success) 42%, var(--line));
  background: color-mix(in srgb, var(--success-soft) 64%, var(--solid-card));
}

.checker-summary.warning {
  border-color: color-mix(in srgb, var(--warning) 42%, var(--line));
  background: color-mix(in srgb, #fef3c7 56%, var(--solid-card));
}

.checker-summary.error {
  border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
  background: color-mix(in srgb, var(--danger-soft) 56%, var(--solid-card));
}

.checker-list {
  display: grid;
  gap: 9px;
}

.checker-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: var(--solid-card);
}

.checker-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  color: white;
  background: var(--primary);
  font-size: 0.9rem;
  font-weight: 1000;
}

.checker-item.pass .checker-icon {
  background: var(--success);
}

.checker-item.error .checker-icon {
  background: var(--danger);
}

.checker-item.warning .checker-icon {
  color: #78350f;
  background: #fbbf24;
}

.checker-item.tip .checker-icon {
  background: #0ea5e9;
}

.checker-item h3 {
  margin: 0 0 3px;
  font-size: 0.95rem;
}

.checker-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.checker-item small {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-weight: 800;
  line-height: 1.35;
}

.checker-item.pass {
  border-left: 5px solid var(--success);
}

.checker-item.warning {
  border-left: 5px solid var(--warning);
}

.checker-item.error {
  border-left: 5px solid var(--danger);
}

.checker-item.tip {
  border-left: 5px solid #0ea5e9;
}

[data-theme="dark"] .checker-summary.warning {
  background: rgba(245, 158, 11, 0.16);
}

[data-theme="dark"] .checker-summary.pass {
  background: rgba(22, 163, 74, 0.16);
}

[data-theme="dark"] .checker-summary.error {
  background: rgba(220, 38, 38, 0.16);
}

@media (max-width: 760px) {
  .error-checker-content {
    padding: 12px;
  }

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

  .checker-item h3 {
    font-size: 0.9rem;
  }

  .checker-item p,
  .checker-item small {
    font-size: 0.82rem;
  }
}


/* AI Review Panel additions */
.ai-review-panel {
  border-color: color-mix(in srgb, var(--primary) 34%, var(--line));
}

.ai-review-header {
  background: linear-gradient(135deg, color-mix(in srgb, var(--solid-card) 88%, var(--primary-soft)), var(--solid-card));
}

.ai-review-content {
  padding: 18px;
}

.empty-ai-review {
  display: grid;
  place-items: center;
  min-height: 220px;
  text-align: center;
  color: var(--muted);
}

.ai-empty-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 8px;
  border-radius: 20px;
  color: #7c3aed;
  background: color-mix(in srgb, #ede9fe 80%, var(--solid-card));
  font-size: 1.45rem;
  font-weight: 1000;
}

.ai-small-note {
  max-width: 520px;
  margin: 6px auto 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.ai-review-card {
  display: grid;
  gap: 14px;
}

.ai-review-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--solid-card) 82%, var(--primary-soft)), var(--solid-card));
}

.ai-review-main h3 {
  margin-bottom: 6px;
  line-height: 1.25;
}

.ai-badge {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 16px;
  color: white;
  background: linear-gradient(135deg, #7c3aed, #06b6d4);
  font-weight: 1000;
  box-shadow: 0 12px 28px rgba(124, 58, 237, 0.24);
}

.ai-review-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.ai-review-block {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: var(--solid-card);
}

.ai-review-block h4 {
  margin: 0 0 10px;
  color: var(--text);
}

.ai-review-block ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.4;
}

.ai-review-block.good {
  border-left: 5px solid #22c55e;
}

.ai-review-block.improve {
  border-left: 5px solid #f59e0b;
}

.ai-review-block.steps {
  border-left: 5px solid #06b6d4;
}

.ai-note {
  border: 1px dashed color-mix(in srgb, var(--primary) 45%, var(--line));
  border-radius: 16px;
  padding: 12px 14px;
  color: var(--muted);
  background: color-mix(in srgb, var(--solid-card) 85%, var(--primary-soft));
}

.ai-loading-box {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  background: var(--solid-card);
}

.ai-spinner {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border: 4px solid color-mix(in srgb, var(--primary) 18%, var(--line));
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: aiSpin 0.8s linear infinite;
}

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

.ai-review-top-btn {
  border-color: color-mix(in srgb, #7c3aed 36%, var(--line)) !important;
  color: color-mix(in srgb, #7c3aed 70%, var(--text));
}

[data-theme="dark"] .ai-empty-icon {
  color: #ddd6fe;
  background: rgba(124, 58, 237, 0.22);
}

@media (max-width: 900px) {
  .ai-review-grid {
    grid-template-columns: 1fr;
  }

  .ai-review-main,
  .ai-loading-box {
    align-items: stretch;
    flex-direction: column;
  }

  .ai-badge {
    align-self: flex-start;
  }
}


/* Rubric image import for Teacher/Admin */
.rubric-image-import-card {
  display: grid;
  gap: 14px;
  border: 1px solid color-mix(in srgb, var(--primary) 32%, var(--line));
  border-radius: 22px;
  padding: 16px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--solid-card) 86%, var(--primary-soft)), var(--solid-card));
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.08);
}

.rubric-import-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.rubric-import-header h3 {
  margin-bottom: 4px;
}

.rubric-import-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.78rem;
  font-weight: 1000;
}

.rubric-import-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(260px, 1.1fr);
  gap: 14px;
  align-items: stretch;
}

.rubric-file-drop {
  display: grid;
  place-items: center;
  min-height: 154px;
  border: 2px dashed color-mix(in srgb, var(--primary) 40%, var(--line));
  border-radius: 20px;
  padding: 18px;
  text-align: center;
  background: color-mix(in srgb, var(--solid-card) 90%, var(--primary-soft));
  cursor: pointer;
}

.rubric-file-drop:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.rubric-file-drop input {
  max-width: 100%;
  margin-top: 10px;
  cursor: pointer;
}

.rubric-file-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), #06b6d4);
  color: white;
  font-size: 1.3rem;
}

.rubric-file-drop small {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.35;
}

.rubric-import-actions {
  display: grid;
  align-content: center;
  gap: 10px;
}

.rubric-import-status {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: var(--solid-card);
}

.rubric-import-status.ready {
  border-color: color-mix(in srgb, var(--primary) 36%, var(--line));
  color: var(--primary-dark);
}

.rubric-import-status.loading {
  border-color: color-mix(in srgb, var(--warning) 55%, var(--line));
  color: #92400e;
  background: #fef3c7;
}

.rubric-import-status.success {
  border-color: color-mix(in srgb, var(--success) 55%, var(--line));
  color: #166534;
  background: #dcfce7;
}

.rubric-import-status.error {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--line));
  color: #991b1b;
  background: #fee2e2;
}

.rubric-image-preview-wrap {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px;
  background: var(--solid-card);
}

.rubric-image-preview-wrap img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 12px;
  background: white;
}

[data-theme="dark"] .rubric-import-status.loading {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.18);
}

[data-theme="dark"] .rubric-import-status.success {
  color: #bbf7d0;
  background: rgba(22, 163, 74, 0.18);
}

[data-theme="dark"] .rubric-import-status.error {
  color: #fecaca;
  background: rgba(220, 38, 38, 0.18);
}

@media (max-width: 820px) {
  .rubric-import-header,
  .rubric-import-grid {
    grid-template-columns: 1fr;
  }

  .rubric-import-header {
    flex-direction: column;
  }
}


.rubric-extracted-text-wrap {
  display: grid;
  gap: 8px;
  font-weight: 900;
}

.rubric-extracted-text-wrap textarea {
  width: 100%;
  min-height: 130px;
  resize: vertical;
}

/* Rubric parser expects fixed 5-column rubric format: Criteria, Excellent, Good, Fair, Needs Improvement. */


/* Manual 5-column rubric input */
.manual-rubric-card {
  margin: 1rem 0 1.2rem;
  padding: 1rem;
  border: 1px solid var(--border, #cfe0f7);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(239, 246, 255, 0.9), rgba(255, 255, 255, 0.95));
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

.manual-rubric-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.manual-rubric-header h3 {
  margin: 0 0 0.35rem;
}

.manual-score-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.manual-score-row label {
  font-weight: 700;
}

.manual-score-row input {
  margin-top: 0.35rem;
  width: 100%;
}

.manual-rubric-scroll {
  overflow-x: auto;
  border: 1px solid var(--border, #cfe0f7);
  border-radius: 16px;
  background: #ffffff;
}

.manual-rubric-input-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: fixed;
}

.manual-rubric-input-table th,
.manual-rubric-input-table td {
  border: 1px solid var(--border, #cfe0f7);
  vertical-align: top;
  padding: 0.65rem;
}

.manual-rubric-input-table th {
  text-align: center;
  font-weight: 800;
  background: rgba(37, 99, 235, 0.08);
}

.manual-rubric-input-table th:first-child,
.manual-rubric-input-table td:first-child {
  width: 18%;
}

.manual-rubric-input-table th:last-child,
.manual-rubric-input-table td:last-child {
  width: 95px;
  text-align: center;
}

.manual-rubric-input-table textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  border: 1px solid transparent;
  background: rgba(248, 250, 252, 0.92);
  border-radius: 10px;
  padding: 0.65rem;
  font: inherit;
  line-height: 1.35;
}

.manual-rubric-input-table textarea:focus {
  border-color: #60a5fa;
  outline: none;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18);
}

.manual-rubric-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0.9rem;
}

.manual-rubric-status {
  margin-top: 0.8rem;
}

.manual-rubric-status.success {
  color: #15803d;
}

.manual-rubric-status.error {
  color: #b91c1c;
}

@media (max-width: 900px) {
  .manual-score-row {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 560px) {
  .manual-score-row {
    grid-template-columns: 1fr;
  }

  .manual-rubric-actions > * {
    flex: 1 1 100%;
  }
}


/* App-styled dialog boxes: replaces browser alert/confirm so it feels part of the app. */
.app-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 950000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.46);
  backdrop-filter: blur(8px);
}

.app-dialog-overlay.hidden {
  display: none !important;
}

.app-dialog-card {
  width: min(520px, 94vw);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  padding: 1.2rem;
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  color: var(--text);
  background: linear-gradient(145deg, var(--solid-card), var(--bg-2));
  box-shadow: var(--shadow-strong);
  transform: translateY(0);
  animation: appDialogPop 0.18s ease-out;
}

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

.app-dialog-icon {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.25);
}

.app-dialog-card.danger .app-dialog-icon {
  background: var(--danger);
  box-shadow: 0 10px 24px rgba(220, 38, 38, 0.24);
}

.app-dialog-content {
  min-width: 0;
}

.app-dialog-kicker {
  margin: 0 0 0.2rem;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-dialog-card.danger .app-dialog-kicker {
  color: var(--danger);
}

.app-dialog-content h3 {
  margin: 0;
  font-size: clamp(1.1rem, 2.8vw, 1.35rem);
}

.app-dialog-content p:last-child {
  margin: 0.5rem 0 0;
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-line;
}

.app-dialog-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  flex-wrap: wrap;
  padding-top: 0.25rem;
}

.app-dialog-actions button {
  min-width: 98px;
}

.app-dialog-card.alert .app-dialog-cancel {
  display: none;
}

.app-dialog-card.danger .app-dialog-ok {
  background: var(--danger);
  border-color: var(--danger);
}

@media (max-width: 560px) {
  .app-dialog-card {
    grid-template-columns: 1fr;
    text-align: left;
  }

  .app-dialog-actions {
    justify-content: stretch;
  }

  .app-dialog-actions button {
    flex: 1 1 120px;
  }
}


/* Floating Code Helper modal */
.code-helper-float-btn {
  position: fixed;
  right: 22px;
  bottom: 24px;
  z-index: 4100;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--line));
  border-radius: 999px;
  color: var(--primary-strong);
  background: color-mix(in srgb, var(--solid-card) 88%, var(--primary-soft));
  box-shadow: 0 18px 36px rgba(37, 99, 235, 0.22);
  font-weight: 900;
  cursor: pointer;
}

.code-helper-float-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 22px 44px rgba(37, 99, 235, 0.28);
}

.code-helper-modal.hidden {
  display: none !important;
}

.error-checker-panel.code-helper-modal {
  position: fixed;
  top: 92px;
  right: 18px;
  bottom: 18px;
  width: min(480px, calc(100vw - 32px));
  z-index: 5600;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--primary) 26%, var(--line));
  border-radius: 24px;
  background: var(--solid-card);
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.28);
}

.error-checker-panel.code-helper-modal::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(2px);
}

.code-helper-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: nowrap;
}

.code-helper-close {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--solid-card);
  font-size: 1.45rem;
  line-height: 1;
  font-weight: 900;
  cursor: pointer;
}

.code-helper-close:hover {
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.35);
  background: rgba(254, 226, 226, 0.55);
}

.error-checker-panel.code-helper-modal .error-checker-content {
  overflow: auto;
  min-height: 0;
  padding-bottom: 18px;
}

body.editor-fullscreen-active .code-helper-float-btn,
#editorPanel:fullscreen .code-helper-float-btn {
  top: 12px;
  right: 118px;
  bottom: auto;
  z-index: 4310;
  min-height: 38px;
  height: 38px;
  padding: 0 14px;
  font-size: 0.82rem;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.24);
}

body.editor-fullscreen-active .error-checker-panel.code-helper-modal,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal {
  top: 62px;
  right: 14px;
  bottom: 14px;
  width: min(480px, calc(100vw - 28px));
  z-index: 4320;
}

@media (max-width: 760px) {
  .code-helper-float-btn {
    right: 14px;
    bottom: 16px;
    min-height: 42px;
    padding: 0 14px;
    font-size: 0.86rem;
  }

  .error-checker-panel.code-helper-modal {
    inset: auto 10px 10px 10px;
    top: 72px;
    width: auto;
    border-radius: 20px;
  }

  body.editor-fullscreen-active .code-helper-float-btn,
  #editorPanel:fullscreen .code-helper-float-btn {
    right: 104px;
    top: 12px;
    max-width: calc(100vw - 210px);
    overflow: hidden;
    white-space: nowrap;
  }
}


/* Stable top toolbar: prevents header height jumps when status text changes. */
.topbar.simplified-topbar,
.topbar {
  align-items: center !important;
  min-height: 66px !important;
  overflow: visible !important;
}

.top-actions {
  align-items: center !important;
  flex-wrap: nowrap !important;
  min-height: 42px !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scrollbar-width: none !important;
}

.top-actions::-webkit-scrollbar {
  display: none !important;
}

.top-actions > *,
.top-actions .ghost-btn,
.top-actions .primary-btn,
.top-actions .success-btn,
#clearBtn {
  flex: 0 0 auto !important;
  align-self: center !important;
  white-space: nowrap !important;
}

#statusBadge,
.status-badge.compact-status {
  flex: 0 0 96px !important;
  width: 96px !important;
  max-width: 96px !important;
  min-width: 96px !important;
  height: 34px !important;
  min-height: 34px !important;
  max-height: 34px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 10px !important;
  overflow: hidden !important;
  white-space: nowrap !important;
  text-overflow: ellipsis !important;
  line-height: 1 !important;
  text-align: center !important;
  box-sizing: border-box !important;
}

#statusBadge::before {
  content: '';
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  margin-right: 6px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.6;
}

body.editor-fullscreen-active .topbar,
#editorPanel:fullscreen ~ .topbar {
  min-height: 56px !important;
}

@media (min-width: 761px) {
  .top-actions {
    justify-content: flex-end !important;
  }
}

@media (max-width: 760px) {
  .topbar.simplified-topbar,
  .topbar {
    min-height: 58px !important;
  }

  #statusBadge,
  .status-badge.compact-status {
    display: none !important;
  }
}

/* Mobile polish + installable app adjustments */
.install-app-btn {
  color: var(--primary-strong);
  border-color: color-mix(in srgb, var(--primary) 30%, var(--line));
  background: color-mix(in srgb, var(--primary-soft) 72%, var(--solid-card));
}

@media (max-width: 820px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .app-shell {
    padding: 0 0 14px !important;
  }

  .topbar.simplified-topbar,
  .topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 3500 !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    min-height: auto !important;
    padding: calc(8px + env(safe-area-inset-top)) 8px 8px !important;
    border-radius: 0 0 18px 18px !important;
    border-left: 0 !important;
    border-right: 0 !important;
    background: color-mix(in srgb, var(--solid-card) 96%, var(--primary-soft)) !important;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.10) !important;
  }

  .brand-block {
    min-width: 0 !important;
    width: 100% !important;
    gap: 8px !important;
  }

  .brand-block .logo-mark {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    border-radius: 12px !important;
    font-size: 0.86rem !important;
  }

  .brand-block h1 {
    max-width: calc(100vw - 72px) !important;
    overflow: hidden !important;
    white-space: nowrap !important;
    text-overflow: ellipsis !important;
    font-size: 1rem !important;
    line-height: 1.12 !important;
  }

  .brand-block .eyebrow,
  .brand-block .subtitle {
    font-size: 0.68rem !important;
    line-height: 1 !important;
  }

  .top-actions {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 6px !important;
    min-height: 0 !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  .top-actions .primary-btn,
  .top-actions .success-btn,
  .top-actions .ghost-btn,
  .top-actions > button {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 6px !important;
    border-radius: 12px !important;
    font-size: 0.70rem !important;
    line-height: 1.05 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    justify-content: center !important;
  }

  #themeToggle,
  #downloadZipBtn,
  #resetBtn,
  #clearBtn {
    font-size: 0.68rem !important;
  }

  .workspace {
    padding: 8px !important;
  }

  .editor-panel,
  .preview-panel,
  .ai-review-panel,
  .activity-card,
  .result-card {
    border-radius: 18px !important;
  }
}

@media (max-width: 440px) {
  .top-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .top-actions .primary-btn,
  .top-actions .success-btn,
  .top-actions .ghost-btn,
  .top-actions > button {
    font-size: 0.66rem !important;
    height: 36px !important;
    min-height: 36px !important;
    border-radius: 11px !important;
  }
}

/* Phone-friendly admin builder */
@media (max-width: 820px) {
  body.admin-open {
    overflow: hidden !important;
  }

  #adminOverlay {
    z-index: 7000 !important;
    padding: 0 !important;
    align-items: stretch !important;
    justify-items: stretch !important;
    background: rgba(2, 6, 23, 0.72) !important;
  }

  #adminOverlay .admin-modal,
  .admin-modal {
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    border: 0 !important;
    border-radius: 0 !important;
  }

  #adminOverlay .modal-header,
  .modal-header {
    flex: 0 0 auto !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 20 !important;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px !important;
    background: color-mix(in srgb, var(--solid-card) 97%, var(--primary-soft)) !important;
  }

  #adminOverlay .modal-header h2 {
    font-size: 1.05rem !important;
  }

  #adminOverlay .modal-header .section-kicker,
  #adminOverlay .modal-header .muted-text {
    display: none !important;
  }

  #adminOverlay .pin-screen,
  #adminOverlay .admin-form {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 12px 12px calc(96px + env(safe-area-inset-bottom)) !important;
  }

  .admin-activity-manager,
  .manual-rubric-card,
  .rubric-table-note,
  .rubric-table-scroll,
  .teacher-login-card,
  .teacher-login-intro {
    border-radius: 18px !important;
  }

  .manual-rubric-card {
    padding: 12px !important;
  }

  .manual-rubric-header {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .manual-rubric-header .muted-text {
    font-size: 0.84rem !important;
    line-height: 1.35 !important;
  }

  .manual-score-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .manual-rubric-scroll {
    overflow: visible !important;
    border: 0 !important;
    background: transparent !important;
  }

  .manual-rubric-input-table,
  .manual-rubric-input-table thead,
  .manual-rubric-input-table tbody,
  .manual-rubric-input-table tr,
  .manual-rubric-input-table th,
  .manual-rubric-input-table td {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .manual-rubric-input-table thead {
    display: none !important;
  }

  .manual-rubric-input-row {
    margin: 0 0 12px !important;
    padding: 10px !important;
    border: 1px solid var(--line) !important;
    border-radius: 18px !important;
    background: var(--solid-card) !important;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06) !important;
  }

  .manual-rubric-input-table td {
    border: 0 !important;
    padding: 8px 0 !important;
    text-align: left !important;
  }

  .manual-rubric-input-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    color: var(--primary);
    font-size: 0.72rem;
    font-weight: 1000;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .manual-rubric-input-table textarea {
    min-height: 88px !important;
    border: 1px solid var(--line) !important;
    background: color-mix(in srgb, var(--solid-card) 90%, var(--primary-soft)) !important;
  }

  .manual-rubric-actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .manual-rubric-actions button,
  .admin-activity-actions button,
  .admin-actions button,
  .remove-manual-rubric-row {
    width: 100% !important;
    min-height: 46px !important;
    border-radius: 14px !important;
  }

  .rubric-toolbar h3,
  .manual-rubric-header h3 {
    font-size: 1.05rem !important;
  }

  .rubric-toolbar .muted-text {
    font-size: 0.84rem !important;
  }
}

@media (max-width: 420px) {
  .manual-score-row {
    grid-template-columns: 1fr !important;
  }
}

/* Phone-friendly Code Helper */
@media (max-width: 820px) {
  body.code-helper-open {
    overflow: hidden !important;
  }

  .code-helper-float-btn {
    right: 12px !important;
    bottom: calc(14px + env(safe-area-inset-bottom)) !important;
    z-index: 5300 !important;
    min-height: 44px !important;
    max-width: calc(100vw - 24px) !important;
    padding: 0 15px !important;
    border-radius: 999px !important;
    font-size: 0.82rem !important;
    background: linear-gradient(135deg, var(--primary), #7c3aed) !important;
    color: #fff !important;
    box-shadow: 0 18px 40px rgba(37, 99, 235, 0.32) !important;
  }

  .error-checker-panel.code-helper-modal {
    position: fixed !important;
    inset: auto 8px 8px 8px !important;
    top: calc(78px + env(safe-area-inset-top)) !important;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    max-height: calc(100dvh - 94px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    z-index: 7600 !important;
    border-radius: 22px !important;
    overflow: hidden !important;
    background: var(--solid-card) !important;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.34) !important;
  }

  .error-checker-panel.code-helper-modal .error-checker-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 2 !important;
    display: grid !important;
    grid-template-columns: 1fr auto !important;
    gap: 10px !important;
    padding: 12px !important;
    background: color-mix(in srgb, var(--solid-card) 96%, var(--primary-soft)) !important;
  }

  .error-checker-panel.code-helper-modal .error-checker-header h2 {
    font-size: 1.05rem !important;
  }

  .error-checker-panel.code-helper-modal .error-checker-header p:not(.section-kicker) {
    display: none !important;
  }

  .code-helper-header-actions {
    gap: 6px !important;
  }

  .code-helper-header-actions .layout-btn,
  .code-helper-close {
    min-height: 40px !important;
    height: 40px !important;
    border-radius: 999px !important;
  }

  .error-checker-panel.code-helper-modal .error-checker-content {
    max-height: calc(100dvh - 170px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 10px 12px calc(14px + env(safe-area-inset-bottom)) !important;
  }

  body.editor-fullscreen-active .code-helper-float-btn,
  #editorPanel:fullscreen .code-helper-float-btn {
    top: auto !important;
    left: 12px !important;
    right: auto !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
    height: 38px !important;
    min-height: 38px !important;
    max-width: calc(100vw - 132px) !important;
    padding: 0 12px !important;
    font-size: 0.74rem !important;
  }

  body.editor-fullscreen-active .error-checker-panel.code-helper-modal,
  #editorPanel:fullscreen .error-checker-panel.code-helper-modal {
    top: 10px !important;
    bottom: calc(58px + env(safe-area-inset-bottom)) !important;
    left: 8px !important;
    right: 8px !important;
    max-height: none !important;
    width: auto !important;
  }
}

/* Desktop header repair: keep the title and action buttons from colliding. */
@media (min-width: 821px) {
  .app-shell {
    width: min(1560px, calc(100% - 28px)) !important;
  }

  .topbar.simplified-topbar,
  .topbar {
    display: grid !important;
    grid-template-columns: minmax(300px, 460px) minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 18px !important;
    padding: 16px 18px !important;
    min-height: 86px !important;
    overflow: visible !important;
  }

  .brand-block {
    min-width: 0 !important;
    width: 100% !important;
  }

  .brand-block .logo-mark {
    flex: 0 0 48px !important;
    width: 48px !important;
    height: 48px !important;
    border-radius: 16px !important;
  }

  .brand-block h1 {
    max-width: 100% !important;
    margin: 0 !important;
    font-size: clamp(1.35rem, 1.55vw, 1.85rem) !important;
    line-height: 1.02 !important;
  }

  .brand-block .eyebrow {
    margin-bottom: 2px !important;
    font-size: 0.68rem !important;
    line-height: 1 !important;
  }

  .brand-block .subtitle {
    display: none !important;
  }

  .top-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-end !important;
    align-items: center !important;
    align-content: center !important;
    gap: 8px !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    min-height: 44px !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  .top-actions > *,
  .top-actions .ghost-btn,
  .top-actions .primary-btn,
  .top-actions .success-btn,
  #clearBtn {
    flex: 0 0 auto !important;
    min-height: 40px !important;
    height: 40px !important;
    padding: 0 14px !important;
    font-size: 0.92rem !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }

  #statusBadge,
  .status-badge.compact-status {
    flex: 0 0 90px !important;
    width: 90px !important;
    min-width: 90px !important;
    max-width: 90px !important;
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 8px !important;
  }
}

@media (min-width: 821px) and (max-width: 1180px) {
  .topbar.simplified-topbar,
  .topbar {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .brand-block h1 {
    font-size: 1.35rem !important;
  }

  .top-actions {
    justify-content: flex-start !important;
  }
}


/* FINAL FIX: slim desktop header + safe output scroll offset.
   Keeps mobile rules below 820px, but prevents the desktop toolbar from becoming a tall block. */
@media (min-width: 821px) {
  :root {
    --desktop-topbar-safe-height: 70px;
  }

  .app-shell {
    width: min(1680px, calc(100% - 16px)) !important;
    padding-top: 6px !important;
  }

  .topbar.simplified-topbar,
  .topbar {
    position: sticky !important;
    top: 4px !important;
    z-index: 1200 !important;
    display: grid !important;
    grid-template-columns: minmax(260px, 420px) minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 10px !important;
    min-height: 58px !important;
    max-height: 74px !important;
    padding: 7px 10px !important;
    margin-bottom: 8px !important;
    border-radius: 16px !important;
    overflow: visible !important;
  }

  .brand-block {
    min-width: 0 !important;
    width: 100% !important;
    gap: 8px !important;
  }

  .brand-block .logo-mark,
  .logo-mark {
    flex: 0 0 40px !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: 13px !important;
    font-size: 0.8rem !important;
  }

  .brand-block h1 {
    max-width: 100% !important;
    margin: 0 !important;
    font-size: clamp(1.05rem, 1.22vw, 1.42rem) !important;
    line-height: 1.04 !important;
    letter-spacing: -0.035em !important;
    white-space: normal !important;
  }

  .brand-block .eyebrow {
    margin: 0 0 1px !important;
    font-size: 0.58rem !important;
    line-height: 1 !important;
    letter-spacing: 0.13em !important;
  }

  .brand-block .subtitle {
    display: none !important;
  }

  .top-actions {
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: flex-end !important;
    align-items: center !important;
    gap: 6px !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    min-height: 38px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 0 2px !important;
    scrollbar-width: thin !important;
  }

  .top-actions > *,
  .top-actions .ghost-btn,
  .top-actions .primary-btn,
  .top-actions .success-btn,
  #clearBtn {
    flex: 0 0 auto !important;
    min-height: 36px !important;
    height: 36px !important;
    padding: 0 10px !important;
    border-radius: 999px !important;
    font-size: 0.82rem !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }

  #statusBadge,
  .status-badge.compact-status {
    flex: 0 0 78px !important;
    width: 78px !important;
    min-width: 78px !important;
    max-width: 78px !important;
    height: 32px !important;
    min-height: 32px !important;
    padding: 0 7px !important;
    font-size: 0.78rem !important;
  }

  #previewPanel,
  #resultPanel,
  #aiReviewPanel,
  #activityCard,
  #editorPanel {
    scroll-margin-top: calc(var(--desktop-topbar-safe-height) + 14px) !important;
  }
}

@media (min-width: 821px) and (max-width: 1180px) {
  .topbar.simplified-topbar,
  .topbar {
    grid-template-columns: minmax(220px, 330px) minmax(0, 1fr) !important;
  }

  .brand-block h1 {
    font-size: 1rem !important;
  }

  .top-actions > *,
  .top-actions .ghost-btn,
  .top-actions .primary-btn,
  .top-actions .success-btn,
  #clearBtn {
    font-size: 0.76rem !important;
    padding: 0 8px !important;
  }
}

/* Status badge anti-cutoff fix */
#status,
.status,
.status-pill,
.header-status,
.top-status,
#statusText {
  box-sizing: border-box;
  min-width: 96px !important;
  width: auto !important;
  max-width: 140px !important;
  flex: 0 0 auto !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  white-space: nowrap !important;
  overflow: visible !important;
  text-overflow: clip !important;
  padding-left: 14px !important;
  padding-right: 14px !important;
}

.app-header,
.top-header,
header {
  overflow: visible !important;
}

@media (max-width: 768px) {
  #status,
  .status,
  .status-pill,
  .header-status,
  .top-status,
  #statusText {
    min-width: 84px !important;
    max-width: 118px !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
    font-size: 0.86rem !important;
  }
}


/* Safe Rename Files modal */
.rename-files-btn {
  min-height: 32px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px 12px 0 0;
  padding: 7px 14px;
  color: var(--primary-dark);
  background: color-mix(in srgb, var(--solid-card) 82%, var(--primary-soft));
  font-size: 0.9rem;
  font-weight: 1000;
  cursor: pointer;
  white-space: nowrap;
}

.rename-files-btn:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.1);
}

.file-name-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 9400;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 6, 23, 0.64);
  backdrop-filter: blur(6px);
}

.file-name-dialog-card {
  width: min(620px, 100%);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--solid-card);
  box-shadow: var(--shadow-strong);
  overflow: hidden;
}

.file-name-dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--solid-card) 90%, var(--primary-soft));
}

.file-name-dialog-header h3 {
  margin: 0 0 6px;
  font-size: 1.35rem;
}

.file-name-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 18px 20px 10px;
}

.file-name-dialog-card .helper-note {
  padding: 0 20px 14px;
}

.file-name-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
}

@media (max-width: 720px) {
  .rename-files-btn {
    flex: 1 1 100%;
    border-radius: 12px;
    margin-top: 4px;
  }

  .file-name-grid {
    grid-template-columns: 1fr;
  }

  .file-name-dialog-actions button {
    flex: 1 1 150px;
  }
}

/* Full Editor Rename Files visibility fix */
body.editor-fullscreen-active .editor-panel .language-tabs,
#editorPanel:fullscreen .language-tabs {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  align-items: end !important;
  gap: 4px !important;
  flex: 0 0 40px !important;
  height: 40px !important;
  min-height: 40px !important;
  max-height: 40px !important;
  padding: 4px 118px 0 4px !important;
  overflow: visible !important;
  border-radius: 0 !important;
  z-index: 5100 !important;
}

body.editor-fullscreen-active .editor-panel .tab-btn,
body.editor-fullscreen-active .editor-panel .rename-files-btn,
#editorPanel:fullscreen .tab-btn,
#editorPanel:fullscreen .rename-files-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  min-width: 0 !important;
  height: 34px !important;
  min-height: 34px !important;
  padding: 0 6px !important;
  border-radius: 10px 10px 0 0 !important;
  font-size: 0.78rem !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

body.editor-fullscreen-active .editor-panel .tab-btn::after,
#editorPanel:fullscreen .tab-btn::after {
  display: none !important;
  content: none !important;
}

body.editor-fullscreen-active .editor-panel .rename-files-btn,
#editorPanel:fullscreen .rename-files-btn {
  border: 1px dashed var(--line-strong) !important;
  background: color-mix(in srgb, var(--solid-card) 82%, var(--primary-soft)) !important;
  color: var(--primary-dark) !important;
  font-size: 0 !important;
}

body.editor-fullscreen-active .editor-panel .rename-files-btn::before,
#editorPanel:fullscreen .rename-files-btn::before {
  content: 'Rename';
  font-size: 0.78rem;
  font-weight: 1000;
}

body.editor-fullscreen-active .editor-wrap,
#editorPanel:fullscreen .editor-wrap {
  height: calc(100vh - 40px) !important;
  height: calc(100dvh - 40px) !important;
}

@media (max-width: 820px) {
  body.editor-fullscreen-active .editor-panel .language-tabs,
  #editorPanel:fullscreen .language-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    flex-basis: 38px !important;
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    padding: 4px 4px 0 !important;
  }

  body.editor-fullscreen-active .editor-panel .tab-btn,
  body.editor-fullscreen-active .editor-panel .rename-files-btn,
  #editorPanel:fullscreen .tab-btn,
  #editorPanel:fullscreen .rename-files-btn {
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 3px !important;
    font-size: 0.68rem !important;
  }

  body.editor-fullscreen-active .editor-panel .tab-btn[data-language='js'],
  #editorPanel:fullscreen .tab-btn[data-language='js'] {
    font-size: 0 !important;
  }

  body.editor-fullscreen-active .editor-panel .tab-btn[data-language='js']::before,
  #editorPanel:fullscreen .tab-btn[data-language='js']::before {
    content: 'JS';
    font-size: 0.68rem;
    font-weight: 1000;
  }

  body.editor-fullscreen-active .editor-panel .rename-files-btn::before,
  #editorPanel:fullscreen .rename-files-btn::before {
    content: 'Rename';
    font-size: 0.68rem;
  }

  body.editor-fullscreen-active .editor-wrap,
  #editorPanel:fullscreen .editor-wrap {
    height: calc(100dvh - 38px) !important;
  }
}


/* Rename dialog must appear inside browser fullscreen editor */
body.editor-fullscreen-active #fileNameDialogOverlay,
#editorPanel:fullscreen #fileNameDialogOverlay,
.file-name-dialog-overlay.inside-editor-fullscreen {
  z-index: 9999 !important;
  position: fixed !important;
  inset: 0 !important;
  display: grid;
}

body.editor-fullscreen-active #fileNameDialogOverlay.hidden,
#editorPanel:fullscreen #fileNameDialogOverlay.hidden,
.file-name-dialog-overlay.inside-editor-fullscreen.hidden {
  display: none !important;
}

.file-name-dialog-overlay.inside-editor-fullscreen .file-name-dialog-card {
  max-height: calc(100dvh - 28px);
  overflow: auto;
}

/* FINAL RESTORE: Full Editor should look like normal editor tabs, not stretched blocks */
body.editor-fullscreen-active .editor-panel .language-tabs,
#editorPanel:fullscreen .language-tabs {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: flex-end !important;
  justify-content: flex-start !important;
  gap: 5px !important;
  flex: 0 0 44px !important;
  height: 44px !important;
  min-height: 44px !important;
  max-height: 44px !important;
  padding: 4px 128px 0 0 !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  border-radius: 0 !important;
  border-bottom: 1px solid var(--line) !important;
  background: color-mix(in srgb, var(--solid-card) 94%, var(--primary-soft)) !important;
  z-index: 5200 !important;
  scrollbar-width: none !important;
}

body.editor-fullscreen-active .editor-panel .language-tabs::-webkit-scrollbar,
#editorPanel:fullscreen .language-tabs::-webkit-scrollbar {
  display: none !important;
}

body.editor-fullscreen-active .editor-panel .tab-btn,
body.editor-fullscreen-active .editor-panel .rename-files-btn,
#editorPanel:fullscreen .tab-btn,
#editorPanel:fullscreen .rename-files-btn {
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: 0 !important;
  height: 40px !important;
  min-height: 40px !important;
  max-height: 40px !important;
  padding: 0 22px !important;
  border-radius: 13px 13px 0 0 !important;
  font-size: 0.92rem !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  overflow: visible !important;
  text-overflow: clip !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

body.editor-fullscreen-active .editor-panel .tab-btn::after,
#editorPanel:fullscreen .tab-btn::after {
  display: inline-block !important;
  margin-left: 8px !important;
  font-size: 0.78rem !important;
  opacity: 0.75 !important;
}

body.editor-fullscreen-active .editor-panel .tab-btn[data-language='html']::after,
#editorPanel:fullscreen .tab-btn[data-language='html']::after { content: 'Ctrl+1' !important; }
body.editor-fullscreen-active .editor-panel .tab-btn[data-language='css']::after,
#editorPanel:fullscreen .tab-btn[data-language='css']::after { content: 'Ctrl+2' !important; }
body.editor-fullscreen-active .editor-panel .tab-btn[data-language='js']::after,
#editorPanel:fullscreen .tab-btn[data-language='js']::after { content: 'Ctrl+3' !important; }

body.editor-fullscreen-active .editor-panel .tab-btn[data-language='js'],
#editorPanel:fullscreen .tab-btn[data-language='js'] {
  font-size: 0.92rem !important;
}

body.editor-fullscreen-active .editor-panel .tab-btn[data-language='js']::before,
#editorPanel:fullscreen .tab-btn[data-language='js']::before,
body.editor-fullscreen-active .editor-panel .rename-files-btn::before,
#editorPanel:fullscreen .rename-files-btn::before {
  content: none !important;
  display: none !important;
}

body.editor-fullscreen-active .editor-panel .rename-files-btn,
#editorPanel:fullscreen .rename-files-btn {
  color: var(--primary-dark) !important;
  background: color-mix(in srgb, var(--solid-card) 82%, var(--primary-soft)) !important;
  border: 1px dashed var(--line-strong) !important;
  min-width: 154px !important;
}

body.editor-fullscreen-active .editor-wrap,
#editorPanel:fullscreen .editor-wrap {
  height: calc(100vh - 44px) !important;
  height: calc(100dvh - 44px) !important;
  min-height: 0 !important;
  border-radius: 0 !important;
}

body.editor-fullscreen-active .line-numbers,
body.editor-fullscreen-active .editor-stack,
body.editor-fullscreen-active #codeEditor,
body.editor-fullscreen-active .code-match-layer,
#editorPanel:fullscreen .line-numbers,
#editorPanel:fullscreen .editor-stack,
#editorPanel:fullscreen #codeEditor,
#editorPanel:fullscreen .code-match-layer {
  height: 100% !important;
  min-height: 0 !important;
}

/* Keep Code Helper visible in Full Editor */
body.editor-fullscreen-active .code-helper-float-btn,
#editorPanel:fullscreen .code-helper-float-btn {
  position: fixed !important;
  left: auto !important;
  right: 24px !important;
  top: auto !important;
  bottom: 28px !important;
  z-index: 6200 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  height: 48px !important;
  min-height: 48px !important;
  max-height: 48px !important;
  max-width: none !important;
  padding: 0 24px !important;
  border-radius: 999px !important;
  font-size: 1rem !important;
  white-space: nowrap !important;
  box-shadow: 0 18px 42px rgba(37, 99, 235, 0.28) !important;
}

body.editor-fullscreen-active .error-checker-panel.code-helper-modal,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal {
  z-index: 6300 !important;
}

/* Rename modal must appear over Full Editor without changing the tab layout */
.file-name-dialog-overlay.inside-editor-fullscreen {
  position: absolute !important;
  inset: 0 !important;
  z-index: 7000 !important;
  display: grid !important;
  place-items: center !important;
  padding: 18px !important;
  background: rgba(2, 6, 23, 0.64) !important;
  backdrop-filter: blur(6px) !important;
}

.file-name-dialog-overlay.inside-editor-fullscreen.hidden {
  display: none !important;
}

.file-name-dialog-overlay.inside-editor-fullscreen .file-name-dialog-card {
  width: min(620px, calc(100vw - 28px)) !important;
  max-height: calc(100dvh - 32px) !important;
  overflow: auto !important;
}

@media (max-width: 760px) {
  body.editor-fullscreen-active .editor-panel .language-tabs,
  #editorPanel:fullscreen .language-tabs {
    height: 42px !important;
    min-height: 42px !important;
    max-height: 42px !important;
    flex-basis: 42px !important;
    padding: 4px 8px 0 4px !important;
  }

  body.editor-fullscreen-active .editor-panel .tab-btn,
  body.editor-fullscreen-active .editor-panel .rename-files-btn,
  #editorPanel:fullscreen .tab-btn,
  #editorPanel:fullscreen .rename-files-btn {
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    padding: 0 14px !important;
    font-size: 0.84rem !important;
  }

  body.editor-fullscreen-active .editor-panel .tab-btn::after,
  #editorPanel:fullscreen .tab-btn::after {
    display: none !important;
  }

  body.editor-fullscreen-active .editor-panel .rename-files-btn,
  #editorPanel:fullscreen .rename-files-btn {
    min-width: 132px !important;
  }

  body.editor-fullscreen-active .editor-wrap,
  #editorPanel:fullscreen .editor-wrap {
    height: calc(100dvh - 42px) !important;
  }

  body.editor-fullscreen-active .code-helper-float-btn,
  #editorPanel:fullscreen .code-helper-float-btn {
    right: 12px !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
    height: 42px !important;
    min-height: 42px !important;
    padding: 0 15px !important;
    font-size: 0.86rem !important;
  }
}

/* FINAL FIX: Full Editor controls, Code Helper header, and modal layering */
body.editor-fullscreen-active #editorPanel,
#editorPanel:fullscreen {
  overflow: hidden !important;
}

/* Keep the fullscreen exit button above the tabs so it is not half-covered. */
body.editor-fullscreen-active .fullscreen-exit-btn,
#editorPanel:fullscreen .fullscreen-exit-btn,
body.editor-fullscreen-active #exitEditorStickyBtn,
#editorPanel:fullscreen #exitEditorStickyBtn {
  position: fixed !important;
  top: 7px !important;
  right: 12px !important;
  z-index: 9800 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: auto !important;
  min-width: 96px !important;
  height: 34px !important;
  min-height: 34px !important;
  max-height: 34px !important;
  padding: 0 15px !important;
  border-radius: 999px !important;
  border: 0 !important;
  color: #fff !important;
  background: linear-gradient(135deg, #dc2626, #fb7185) !important;
  box-shadow: 0 14px 30px rgba(220, 38, 38, 0.26) !important;
  font-size: 0.84rem !important;
  font-weight: 1000 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

/* Reserve clean space for the Exit Full button while keeping the tab style like normal view. */
body.editor-fullscreen-active .editor-panel .language-tabs,
#editorPanel:fullscreen .language-tabs {
  padding-right: 124px !important;
  z-index: 5400 !important;
}

/* Keep Code Helper button visible and away from the exit button. */
body.editor-fullscreen-active .code-helper-float-btn,
#editorPanel:fullscreen .code-helper-float-btn {
  position: fixed !important;
  left: auto !important;
  right: 22px !important;
  top: auto !important;
  bottom: calc(22px + env(safe-area-inset-bottom)) !important;
  z-index: 7600 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  height: 46px !important;
  min-height: 46px !important;
  max-height: 46px !important;
  max-width: none !important;
  padding: 0 22px !important;
  border-radius: 999px !important;
  font-size: 0.96rem !important;
  white-space: nowrap !important;
  color: var(--primary-strong, var(--primary-dark)) !important;
  background: color-mix(in srgb, var(--solid-card) 88%, var(--primary-soft)) !important;
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--line)) !important;
  box-shadow: 0 18px 42px rgba(37, 99, 235, 0.28) !important;
}

/* The old fullscreen rule hides all .panel-header. Re-show only Code Helper's header so the X is available. */
body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal {
  position: fixed !important;
  top: 56px !important;
  right: 14px !important;
  bottom: 14px !important;
  left: auto !important;
  width: min(500px, calc(100vw - 28px)) !important;
  max-width: min(500px, calc(100vw - 28px)) !important;
  height: auto !important;
  max-height: none !important;
  z-index: 9000 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  border-radius: 22px !important;
  background: var(--solid-card) !important;
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.30) !important;
}

body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal.hidden,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal.hidden {
  display: none !important;
}

body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal .error-checker-header,
body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal .panel-header,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal .error-checker-header,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal .panel-header {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  flex: 0 0 auto !important;
  gap: 12px !important;
  min-height: 72px !important;
  padding: 12px 14px !important;
  border-bottom: 1px solid var(--line) !important;
  background: color-mix(in srgb, var(--solid-card) 96%, var(--primary-soft)) !important;
  position: sticky !important;
  top: 0 !important;
  z-index: 3 !important;
}

body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal .error-checker-header .section-kicker,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal .error-checker-header .section-kicker {
  display: block !important;
  margin: 0 0 2px !important;
}

body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal .error-checker-header h2,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal .error-checker-header h2 {
  display: block !important;
  margin: 0 !important;
  font-size: 1rem !important;
}

body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal .error-checker-header p:not(.section-kicker),
#editorPanel:fullscreen .error-checker-panel.code-helper-modal .error-checker-header p:not(.section-kicker) {
  display: none !important;
}

body.editor-fullscreen-active #editorPanel .code-helper-header-actions,
#editorPanel:fullscreen .code-helper-header-actions {
  display: inline-flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex: 0 0 auto !important;
}

body.editor-fullscreen-active #editorPanel .code-helper-close,
#editorPanel:fullscreen .code-helper-close {
  display: inline-grid !important;
  place-items: center !important;
  width: 40px !important;
  min-width: 40px !important;
  height: 40px !important;
  min-height: 40px !important;
  padding: 0 !important;
  border-radius: 999px !important;
  font-size: 1.35rem !important;
  line-height: 1 !important;
  z-index: 4 !important;
}

body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal .error-checker-content,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal .error-checker-content {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow-y: auto !important;
  padding: 12px 14px 16px !important;
}

/* Rename modal should float above fullscreen editor without affecting the tabs. */
.file-name-dialog-overlay.inside-editor-fullscreen {
  position: absolute !important;
  inset: 0 !important;
  z-index: 9600 !important;
  display: grid !important;
  place-items: center !important;
  padding: 18px !important;
  background: rgba(2, 6, 23, 0.64) !important;
  backdrop-filter: blur(6px) !important;
}

.file-name-dialog-overlay.inside-editor-fullscreen.hidden {
  display: none !important;
}

@media (max-width: 760px) {
  body.editor-fullscreen-active .editor-panel .language-tabs,
  #editorPanel:fullscreen .language-tabs {
    padding-right: 100px !important;
  }

  body.editor-fullscreen-active .fullscreen-exit-btn,
  #editorPanel:fullscreen .fullscreen-exit-btn,
  body.editor-fullscreen-active #exitEditorStickyBtn,
  #editorPanel:fullscreen #exitEditorStickyBtn {
    top: 6px !important;
    right: 8px !important;
    min-width: 86px !important;
    height: 32px !important;
    min-height: 32px !important;
    padding: 0 10px !important;
    font-size: 0.74rem !important;
  }

  body.editor-fullscreen-active .code-helper-float-btn,
  #editorPanel:fullscreen .code-helper-float-btn {
    right: 10px !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 13px !important;
    font-size: 0.78rem !important;
  }

  body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal,
  #editorPanel:fullscreen .error-checker-panel.code-helper-modal {
    top: 50px !important;
    left: 8px !important;
    right: 8px !important;
    bottom: calc(58px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    max-width: none !important;
    border-radius: 18px !important;
  }

  body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal .error-checker-header,
  body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal .panel-header,
  #editorPanel:fullscreen .error-checker-panel.code-helper-modal .error-checker-header,
  #editorPanel:fullscreen .error-checker-panel.code-helper-modal .panel-header {
    min-height: 62px !important;
    padding: 10px 12px !important;
  }
}


/* FINAL PATCH: Fullscreen Run + Result beside Exit Full */
.fullscreen-editor-actions {
  display: none !important;
}

body.editor-fullscreen-active .fullscreen-editor-actions,
#editorPanel:fullscreen .fullscreen-editor-actions {
  position: fixed !important;
  top: 7px !important;
  right: 12px !important;
  z-index: 10050 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 8px !important;
  width: auto !important;
  max-width: calc(100vw - 24px) !important;
  padding: 0 !important;
  margin: 0 !important;
  pointer-events: auto !important;
}

body.editor-fullscreen-active .fullscreen-editor-actions.hidden,
#editorPanel:fullscreen .fullscreen-editor-actions.hidden {
  display: none !important;
}

body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-run-btn,
body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-auto-run-btn,
body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-result-btn,
body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-exit-btn,
#editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-run-btn,
#editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-auto-run-btn,
#editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-result-btn,
#editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-exit-btn {
  position: static !important;
  inset: auto !important;
  transform: none !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: 74px !important;
  height: 34px !important;
  min-height: 34px !important;
  max-height: 34px !important;
  padding: 0 13px !important;
  border-radius: 999px !important;
  font-size: 0.84rem !important;
  font-weight: 1000 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18) !important;
}

body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-exit-btn,
#editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-exit-btn {
  min-width: 96px !important;
  border: 0 !important;
  color: #fff !important;
  background: linear-gradient(135deg, #dc2626, #fb7185) !important;
  box-shadow: 0 14px 30px rgba(220, 38, 38, 0.26) !important;
}

body.editor-fullscreen-active .editor-panel .language-tabs,
#editorPanel:fullscreen .language-tabs {
  padding-right: 330px !important;
}

body.editor-fullscreen-active .code-helper-float-btn,
#editorPanel:fullscreen .code-helper-float-btn {
  z-index: 9300 !important;
}

@media (max-width: 900px) {
  body.editor-fullscreen-active .fullscreen-editor-actions,
  #editorPanel:fullscreen .fullscreen-editor-actions {
    top: auto !important;
    right: 10px !important;
    bottom: calc(58px + env(safe-area-inset-bottom)) !important;
    gap: 6px !important;
  }

  body.editor-fullscreen-active .editor-panel .language-tabs,
  #editorPanel:fullscreen .language-tabs {
    padding-right: 8px !important;
  }

  body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-run-btn,
  body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-result-btn,
  body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-exit-btn,
  #editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-run-btn,
  #editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-result-btn,
  #editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-exit-btn {
    height: 38px !important;
    min-height: 38px !important;
    min-width: 68px !important;
    padding: 0 10px !important;
    font-size: 0.78rem !important;
  }

  body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-exit-btn,
  #editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-exit-btn {
    min-width: 82px !important;
  }

  body.editor-fullscreen-active .code-helper-float-btn,
  #editorPanel:fullscreen .code-helper-float-btn {
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
  }
}

@media (max-width: 430px) {
  body.editor-fullscreen-active .fullscreen-editor-actions,
  #editorPanel:fullscreen .fullscreen-editor-actions {
    left: 8px !important;
    right: 8px !important;
    justify-content: center !important;
  }

  body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-run-btn,
  body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-result-btn,
  body.editor-fullscreen-active .fullscreen-editor-actions .fullscreen-exit-btn,
  #editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-run-btn,
  #editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-result-btn,
  #editorPanel:fullscreen .fullscreen-editor-actions .fullscreen-exit-btn {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    padding: 0 6px !important;
  }
}

/* FINAL FIX: clean Full Editor toolbar with visible Run, Result, Exit Full */
body.editor-fullscreen-active #editorPanel,
#editorPanel:fullscreen {
  overflow: hidden !important;
}

body.editor-fullscreen-active #editorPanel .language-tabs,
#editorPanel:fullscreen .language-tabs {
  position: relative !important;
  top: 0 !important;
  z-index: 120 !important;
  display: flex !important;
  align-items: end !important;
  justify-content: flex-start !important;
  flex-wrap: nowrap !important;
  gap: 5px !important;
  height: 48px !important;
  min-height: 48px !important;
  max-height: 48px !important;
  padding: 5px 360px 0 0 !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  background: color-mix(in srgb, var(--solid-card) 96%, var(--primary-soft)) !important;
  border-bottom: 1px solid var(--line) !important;
  box-shadow: 0 1px 0 rgba(148, 163, 184, 0.28) !important;
  scrollbar-width: none !important;
}

body.editor-fullscreen-active #editorPanel .language-tabs::-webkit-scrollbar,
#editorPanel:fullscreen .language-tabs::-webkit-scrollbar {
  display: none !important;
}

body.editor-fullscreen-active #editorPanel .tab-btn,
body.editor-fullscreen-active #editorPanel .rename-files-btn,
#editorPanel:fullscreen .tab-btn,
#editorPanel:fullscreen .rename-files-btn {
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: 130px !important;
  max-width: none !important;
  height: 43px !important;
  min-height: 43px !important;
  max-height: 43px !important;
  padding: 0 22px !important;
  border-radius: 14px 14px 0 0 !important;
  font-size: 0.92rem !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

body.editor-fullscreen-active #editorPanel .tab-btn::after,
#editorPanel:fullscreen .tab-btn::after {
  display: inline-block !important;
}

body.editor-fullscreen-active #fullscreenEditorActions,
#editorPanel:fullscreen #fullscreenEditorActions,
body.editor-fullscreen-active .fullscreen-editor-actions,
#editorPanel:fullscreen .fullscreen-editor-actions {
  position: fixed !important;
  top: 7px !important;
  right: 10px !important;
  z-index: 30000 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 6px !important;
  width: auto !important;
  max-width: 355px !important;
  height: 38px !important;
  padding: 3px !important;
  margin: 0 !important;
  border: 1px solid rgba(147, 197, 253, 0.52) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, 0.86) !important;
  backdrop-filter: blur(8px) !important;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.16) !important;
  pointer-events: auto !important;
  overflow: visible !important;
}

[data-theme="dark"] body.editor-fullscreen-active #fullscreenEditorActions,
[data-theme="dark"] #editorPanel:fullscreen #fullscreenEditorActions,
[data-theme="dark"] body.editor-fullscreen-active .fullscreen-editor-actions,
[data-theme="dark"] #editorPanel:fullscreen .fullscreen-editor-actions {
  background: rgba(15, 23, 42, 0.88) !important;
  border-color: rgba(96, 165, 250, 0.42) !important;
}

body.editor-fullscreen-active #fullscreenEditorActions.hidden,
#editorPanel:fullscreen #fullscreenEditorActions.hidden,
body.editor-fullscreen-active .fullscreen-editor-actions.hidden,
#editorPanel:fullscreen .fullscreen-editor-actions.hidden {
  display: none !important;
}

body.editor-fullscreen-active #fullscreenRunBtn,
body.editor-fullscreen-active #fullscreenResultBtn,
body.editor-fullscreen-active #exitEditorStickyBtn,
#editorPanel:fullscreen #fullscreenRunBtn,
#editorPanel:fullscreen #fullscreenResultBtn,
#editorPanel:fullscreen #exitEditorStickyBtn {
  position: static !important;
  inset: auto !important;
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  align-items: center !important;
  justify-content: center !important;
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: 76px !important;
  height: 32px !important;
  min-height: 32px !important;
  max-height: 32px !important;
  padding: 0 12px !important;
  margin: 0 !important;
  border-radius: 999px !important;
  border: 0 !important;
  font-size: 0.82rem !important;
  font-weight: 1000 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  transform: none !important;
  box-shadow: none !important;
}

body.editor-fullscreen-active #fullscreenResultBtn,
#editorPanel:fullscreen #fullscreenResultBtn {
  min-width: 86px !important;
  color: #fff !important;
  background: linear-gradient(135deg, #16a34a, #22c55e) !important;
}

body.editor-fullscreen-active #exitEditorStickyBtn,
#editorPanel:fullscreen #exitEditorStickyBtn {
  min-width: 88px !important;
  color: #fff !important;
  background: linear-gradient(135deg, #dc2626, #fb7185) !important;
}

body.editor-fullscreen-active #exitEditorBtn,
#editorPanel:fullscreen #exitEditorBtn {
  display: none !important;
}

body.editor-fullscreen-active #editorPanel .editor-wrap,
#editorPanel:fullscreen .editor-wrap {
  height: calc(100vh - 48px) !important;
  height: calc(100dvh - 48px) !important;
  min-height: 0 !important;
  border-radius: 0 !important;
}

body.editor-fullscreen-active .code-helper-float-btn,
#editorPanel:fullscreen .code-helper-float-btn {
  position: fixed !important;
  right: 16px !important;
  bottom: calc(16px + env(safe-area-inset-bottom)) !important;
  z-index: 29000 !important;
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal {
  z-index: 29500 !important;
}

body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal .panel-header,
body.editor-fullscreen-active #editorPanel .error-checker-panel.code-helper-modal .error-checker-header,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal .panel-header,
#editorPanel:fullscreen .error-checker-panel.code-helper-modal .error-checker-header {
  display: flex !important;
}

@media (max-width: 760px) {
  body.editor-fullscreen-active #editorPanel .language-tabs,
  #editorPanel:fullscreen .language-tabs {
    height: 50px !important;
    min-height: 50px !important;
    max-height: 50px !important;
    padding: 5px 8px 0 0 !important;
  }

  body.editor-fullscreen-active #editorPanel .tab-btn,
  body.editor-fullscreen-active #editorPanel .rename-files-btn,
  #editorPanel:fullscreen .tab-btn,
  #editorPanel:fullscreen .rename-files-btn {
    min-width: 94px !important;
    height: 45px !important;
    min-height: 45px !important;
    max-height: 45px !important;
    padding: 0 12px !important;
    font-size: 0.8rem !important;
  }

  body.editor-fullscreen-active #fullscreenEditorActions,
  #editorPanel:fullscreen #fullscreenEditorActions,
  body.editor-fullscreen-active .fullscreen-editor-actions,
  #editorPanel:fullscreen .fullscreen-editor-actions {
    top: auto !important;
    left: 10px !important;
    right: 10px !important;
    bottom: calc(62px + env(safe-area-inset-bottom)) !important;
    justify-content: center !important;
    max-width: none !important;
    width: auto !important;
    height: 44px !important;
  }

  body.editor-fullscreen-active #fullscreenRunBtn,
  body.editor-fullscreen-active #fullscreenResultBtn,
  body.editor-fullscreen-active #exitEditorStickyBtn,
  #editorPanel:fullscreen #fullscreenRunBtn,
  #editorPanel:fullscreen #fullscreenResultBtn,
  #editorPanel:fullscreen #exitEditorStickyBtn {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    padding: 0 8px !important;
    font-size: 0.76rem !important;
  }

  body.editor-fullscreen-active .code-helper-float-btn,
  #editorPanel:fullscreen .code-helper-float-btn {
    right: 10px !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
  }

  body.editor-fullscreen-active #editorPanel .editor-wrap,
  #editorPanel:fullscreen .editor-wrap {
    height: calc(100dvh - 50px) !important;
  }
}

/* FINAL FIX: keep Suggestions and Code Helper from covering each other */
#suggestionBox {
  z-index: 28000 !important;
}

/* Suggestions appear above the Code Helper button instead of under it. */
body.suggestions-open #suggestionBox:not(.hidden) {
  bottom: calc(92px + env(safe-area-inset-bottom)) !important;
  right: 16px !important;
  max-height: min(260px, calc(100dvh - 150px)) !important;
}

/* In Full Editor, keep Code Helper at the bottom and place Suggestions above it. */
body.editor-fullscreen-active.suggestions-open #editorPanel #suggestionBox:not(.hidden),
#editorPanel:fullscreen #suggestionBox:not(.hidden) {
  position: absolute !important;
  right: 16px !important;
  bottom: calc(94px + env(safe-area-inset-bottom)) !important;
  width: min(390px, calc(100vw - 32px)) !important;
  max-height: min(270px, calc(100dvh - 160px)) !important;
  z-index: 28000 !important;
}

body.editor-fullscreen-active .code-helper-float-btn,
#editorPanel:fullscreen .code-helper-float-btn {
  right: 16px !important;
  bottom: calc(16px + env(safe-area-inset-bottom)) !important;
  z-index: 29000 !important;
}

/* When Code Helper panel is open, hide suggestions so the panel is not cluttered. */
body.code-helper-open #suggestionBox {
  display: none !important;
}

@media (max-width: 760px) {
  body.suggestions-open #suggestionBox:not(.hidden),
  body.editor-fullscreen-active.suggestions-open #editorPanel #suggestionBox:not(.hidden),
  #editorPanel:fullscreen #suggestionBox:not(.hidden) {
    left: 10px !important;
    right: 10px !important;
    bottom: calc(118px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    max-height: min(230px, calc(100dvh - 180px)) !important;
  }
}

/* Full Editor Run behavior: Output Preview takes over cleanly after Run. */
body.preview-fullscreen-active .preview-panel {
  z-index: 50000 !important;
  inset: 8px !important;
  border-radius: 18px !important;
}

body.preview-fullscreen-active .preview-panel .panel-header,
body.preview-fullscreen-active .preview-panel .preview-header {
  display: flex !important;
  position: relative !important;
  z-index: 50001 !important;
  background: var(--solid-card) !important;
}

body.preview-fullscreen-active #exitPreviewBtn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

body.preview-fullscreen-active #previewFrame {
  width: 100% !important;
  min-height: 0 !important;
  height: 100% !important;
}

@media (max-width: 760px) {
  body.preview-fullscreen-active .preview-panel {
    inset: 4px !important;
    border-radius: 14px !important;
  }

  body.preview-fullscreen-active .preview-panel .panel-header,
  body.preview-fullscreen-active .preview-panel .preview-header {
    padding: 10px !important;
  }
}


/* Smooth fullscreen output preview after running from Full Editor */
body.preview-fullscreen-active.preview-has-back-editor #backToEditorPreviewBtn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

.back-editor-preview-btn {
  color: #0f3b1d !important;
  border-color: #86efac !important;
  background: #dcfce7 !important;
  box-shadow: 0 10px 24px rgba(22, 163, 74, 0.16);
}

body.preview-fullscreen-active .preview-panel {
  animation: previewFadeIn 0.24s ease both;
}

body.fullscreen-run-transition::before {
  content: "Opening Output Preview...";
  position: fixed;
  inset: 0;
  z-index: 99998;
  display: grid;
  place-items: center;
  color: #0f3b64;
  background: rgba(248, 251, 255, 0.78);
  backdrop-filter: blur(4px);
  font-weight: 1000;
  letter-spacing: 0.02em;
  pointer-events: none;
}

[data-theme="dark"] body.fullscreen-run-transition::before {
  color: #e5edf7;
  background: rgba(2, 6, 23, 0.78);
}

@keyframes previewFadeIn {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 760px) {
  body.preview-fullscreen-active .preview-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  body.preview-fullscreen-active #backToEditorPreviewBtn,
  body.preview-fullscreen-active #exitPreviewBtn {
    min-height: 42px;
  }
}


/* Book / slide page transition between Full Editor and Full Output Preview */
body.fullscreen-run-transition::before {
  content: none !important;
}

body.book-page-transitioning {
  overflow: hidden !important;
}

body.book-page-transitioning::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 120000;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(37, 99, 235, 0.18), rgba(255, 255, 255, 0.96) 36%, rgba(219, 234, 254, 0.98) 66%, rgba(14, 165, 233, 0.2)),
    radial-gradient(circle at 18% 50%, rgba(37, 99, 235, 0.18), transparent 34rem),
    var(--solid-card);
  box-shadow:
    -32px 0 80px rgba(15, 23, 42, 0.22),
    32px 0 80px rgba(37, 99, 235, 0.2),
    inset 18px 0 34px rgba(255, 255, 255, 0.7),
    inset -16px 0 34px rgba(37, 99, 235, 0.15);
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

body.book-page-transitioning::after {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 120001;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: min(360px, calc(100vw - 48px));
  border: 1px solid rgba(147, 197, 253, 0.9);
  border-radius: 999px;
  padding: 16px 24px;
  color: #0f2f5f;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 24px 70px rgba(37, 99, 235, 0.22);
  font-weight: 1000;
  letter-spacing: 0.02em;
  pointer-events: none;
}

body.book-to-preview::after {
  content: "Opening Output Preview";
  animation: bookCaptionForward 0.78s ease both;
}

body.book-to-editor::after {
  content: "Back to Editor";
  animation: bookCaptionBack 0.78s ease both;
}

body.book-to-preview::before {
  transform-origin: left center;
  animation: bookPageForward 0.78s cubic-bezier(0.2, 0.76, 0.22, 1) both;
}

body.book-to-editor::before {
  transform-origin: right center;
  animation: bookPageBack 0.78s cubic-bezier(0.2, 0.76, 0.22, 1) both;
}

body.book-to-preview .editor-panel,
body.book-to-editor .preview-panel {
  animation: pageSlideAway 0.45s ease both;
}

body.preview-fullscreen-active.preview-has-back-editor .preview-panel {
  animation: outputBookArrive 0.5s cubic-bezier(0.2, 0.76, 0.22, 1) both !important;
}

body.editor-fullscreen-active .editor-panel {
  animation: editorBookArrive 0.42s cubic-bezier(0.2, 0.76, 0.22, 1) both;
}

@keyframes bookPageForward {
  0% {
    opacity: 0;
    transform: translateX(100%) skewX(-4deg) scaleX(0.94);
  }
  16% {
    opacity: 1;
  }
  48% {
    opacity: 1;
    transform: translateX(0) skewX(-1deg) scaleX(1);
  }
  100% {
    opacity: 0;
    transform: translateX(-105%) skewX(5deg) scaleX(0.92);
  }
}

@keyframes bookPageBack {
  0% {
    opacity: 0;
    transform: translateX(-100%) skewX(4deg) scaleX(0.94);
  }
  16% {
    opacity: 1;
  }
  48% {
    opacity: 1;
    transform: translateX(0) skewX(1deg) scaleX(1);
  }
  100% {
    opacity: 0;
    transform: translateX(105%) skewX(-5deg) scaleX(0.92);
  }
}

@keyframes bookCaptionForward {
  0%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
  28%, 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes bookCaptionBack {
  0%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
  28%, 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes pageSlideAway {
  from { filter: blur(0); transform: scale(1); opacity: 1; }
  to { filter: blur(1px); transform: scale(0.992); opacity: 0.88; }
}

@keyframes outputBookArrive {
  from { opacity: 0; transform: translateX(36px) scale(0.985); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes editorBookArrive {
  from { opacity: 0.04; transform: translateX(-28px) scale(0.99); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

[data-theme="dark"] body.book-page-transitioning::before {
  background:
    linear-gradient(90deg, rgba(96, 165, 250, 0.2), rgba(15, 23, 42, 0.96) 36%, rgba(30, 41, 59, 0.98) 66%, rgba(14, 165, 233, 0.18)),
    radial-gradient(circle at 18% 50%, rgba(96, 165, 250, 0.18), transparent 34rem),
    #0f172a;
  box-shadow:
    -32px 0 80px rgba(0, 0, 0, 0.42),
    32px 0 80px rgba(96, 165, 250, 0.18),
    inset 18px 0 34px rgba(255, 255, 255, 0.06),
    inset -16px 0 34px rgba(96, 165, 250, 0.12);
}

[data-theme="dark"] body.book-page-transitioning::after {
  color: #e5edf7;
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(15, 23, 42, 0.92);
}

@media (prefers-reduced-motion: reduce) {
  body.book-page-transitioning::before,
  body.book-page-transitioning::after,
  body.book-to-preview .editor-panel,
  body.book-to-editor .preview-panel,
  body.preview-fullscreen-active.preview-has-back-editor .preview-panel,
  body.editor-fullscreen-active .editor-panel {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (max-width: 760px) {
  body.book-page-transitioning::after {
    min-width: min(300px, calc(100vw - 32px));
    padding: 13px 18px;
    font-size: 0.9rem;
  }

  body.book-to-preview::before,
  body.book-to-editor::before {
    animation-duration: 0.62s;
  }
}


/* True browser fullscreen Output Preview: same feel as Full Editor */
#previewPanel:fullscreen,
#previewPanel:-webkit-full-screen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  display: flex !important;
  flex-direction: column !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: var(--solid-card) !important;
  box-shadow: none !important;
  overflow: hidden !important;
}

#previewPanel:fullscreen .panel-header,
#previewPanel:fullscreen .preview-header,
#previewPanel:-webkit-full-screen .panel-header,
#previewPanel:-webkit-full-screen .preview-header {
  flex: 0 0 auto !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 12px !important;
  min-height: 58px !important;
  padding: 10px 14px !important;
  border-bottom: 1px solid var(--line) !important;
  border-radius: 0 !important;
  background: color-mix(in srgb, var(--solid-card) 94%, var(--primary-soft)) !important;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08) !important;
}

#previewPanel:fullscreen .preview-header h2,
#previewPanel:-webkit-full-screen .preview-header h2 {
  margin: 0 !important;
  font-size: 1rem !important;
}

#previewPanel:fullscreen .preview-header p,
#previewPanel:-webkit-full-screen .preview-header p {
  display: none !important;
}

#previewPanel:fullscreen .preview-actions,
#previewPanel:-webkit-full-screen .preview-actions {
  display: flex !important;
  flex-wrap: wrap !important;
  justify-content: flex-end !important;
  align-items: center !important;
  gap: 8px !important;
}

#previewPanel:fullscreen #previewFrame,
#previewPanel:-webkit-full-screen #previewFrame {
  flex: 1 1 auto !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  border: 0 !important;
  background: #ffffff !important;
}

#previewPanel:fullscreen #backToEditorPreviewBtn,
#previewPanel:fullscreen #exitPreviewBtn,
#previewPanel:-webkit-full-screen #backToEditorPreviewBtn,
#previewPanel:-webkit-full-screen #exitPreviewBtn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 40px !important;
  padding: 0 14px !important;
  white-space: nowrap !important;
}

#previewPanel:fullscreen #fullPreviewBtn,
#previewPanel:-webkit-full-screen #fullPreviewBtn {
  display: none !important;
}

body.preview-fullscreen-active .preview-panel {
  /* CSS fallback when browser native fullscreen is blocked */
  width: auto;
  height: auto;
}

@media (max-width: 760px) {
  #previewPanel:fullscreen .panel-header,
  #previewPanel:fullscreen .preview-header,
  #previewPanel:-webkit-full-screen .panel-header,
  #previewPanel:-webkit-full-screen .preview-header {
    align-items: stretch !important;
    flex-direction: column !important;
    min-height: 0 !important;
    padding: 9px !important;
  }

  #previewPanel:fullscreen .preview-actions,
  #previewPanel:-webkit-full-screen .preview-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    width: 100% !important;
  }
}

/* Smooth no-blink book transition: keep one fullscreen container and swap pages inside it. */
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel {
  perspective: 1400px !important;
  transform-style: preserve-3d !important;
  overflow: hidden !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel {
  position: absolute !important;
  inset: 0 !important;
  z-index: 7600 !important;
  display: flex !important;
  flex-direction: column !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: var(--solid-card) !important;
  box-shadow: none !important;
  overflow: hidden !important;
  transform-origin: left center !important;
  backface-visibility: hidden !important;
  animation: previewBookPageIn 720ms cubic-bezier(0.18, 0.86, 0.25, 1) both !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen.preview-closing-to-editor #editorPanel .preview-panel {
  transform-origin: right center !important;
  animation: previewBookPageOut 720ms cubic-bezier(0.18, 0.86, 0.25, 1) both !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
  flex: 0 0 auto !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 12px !important;
  min-height: 58px !important;
  padding: 10px 14px !important;
  border-bottom: 1px solid var(--line) !important;
  border-radius: 0 !important;
  background: color-mix(in srgb, var(--solid-card) 94%, var(--primary-soft)) !important;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08) !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header h2 {
  margin: 0 !important;
  font-size: 1rem !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header p {
  display: none !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
  display: flex !important;
  flex-wrap: wrap !important;
  justify-content: flex-end !important;
  align-items: center !important;
  gap: 8px !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewFrame {
  flex: 1 1 auto !important;
  display: block !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  border: 0 !important;
  background: #ffffff !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #backToEditorPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #exitPreviewBtn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 40px !important;
  padding: 0 14px !important;
  white-space: nowrap !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #fullPreviewBtn {
  display: none !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #codeHelperFloatingBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #fullscreenEditorActions,
body.editor-fullscreen-active.preview-inside-editor-fullscreen .language-tabs,
body.editor-fullscreen-active.preview-inside-editor-fullscreen .editor-wrap {
  pointer-events: none !important;
}

body.editor-fullscreen-active.book-page-transitioning #editorPanel::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 8800;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(37, 99, 235, 0.18), rgba(255, 255, 255, 0.97) 35%, rgba(219, 234, 254, 0.98) 67%, rgba(14, 165, 233, 0.2)),
    radial-gradient(circle at 18% 50%, rgba(37, 99, 235, 0.2), transparent 34rem),
    var(--solid-card);
  box-shadow:
    -32px 0 80px rgba(15, 23, 42, 0.22),
    32px 0 80px rgba(37, 99, 235, 0.2),
    inset 18px 0 34px rgba(255, 255, 255, 0.7),
    inset -16px 0 34px rgba(37, 99, 235, 0.15);
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

body.editor-fullscreen-active.book-page-transitioning #editorPanel::after {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 8801;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: min(360px, calc(100vw - 48px));
  border: 1px solid rgba(147, 197, 253, 0.9);
  border-radius: 999px;
  padding: 16px 24px;
  color: #0f2f5f;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 24px 70px rgba(37, 99, 235, 0.22);
  font-weight: 1000;
  letter-spacing: 0.02em;
  pointer-events: none;
}

body.editor-fullscreen-active.book-to-preview #editorPanel::after {
  content: "Opening Output Preview";
  animation: bookCaptionForward 720ms ease both;
}

body.editor-fullscreen-active.book-to-editor #editorPanel::after {
  content: "Back to Editor";
  animation: bookCaptionBack 720ms ease both;
}

body.editor-fullscreen-active.book-to-preview #editorPanel::before {
  transform-origin: left center;
  animation: editorBookPageForward 720ms cubic-bezier(0.18, 0.86, 0.25, 1) both;
}

body.editor-fullscreen-active.book-to-editor #editorPanel::before {
  transform-origin: right center;
  animation: editorBookPageBack 720ms cubic-bezier(0.18, 0.86, 0.25, 1) both;
}

@keyframes previewBookPageIn {
  0% {
    opacity: 0;
    transform: translateX(70px) rotateY(-16deg) scale(0.985);
    filter: blur(2px);
  }
  42% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: translateX(0) rotateY(0deg) scale(1);
    filter: blur(0);
  }
}

@keyframes previewBookPageOut {
  0% {
    opacity: 1;
    transform: translateX(0) rotateY(0deg) scale(1);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translateX(78px) rotateY(14deg) scale(0.985);
    filter: blur(2px);
  }
}

@keyframes editorBookPageForward {
  0% {
    opacity: 0;
    transform: translateX(100%) skewX(-4deg) scaleX(0.94);
  }
  16% { opacity: 1; }
  48% {
    opacity: 1;
    transform: translateX(0) skewX(-1deg) scaleX(1);
  }
  100% {
    opacity: 0;
    transform: translateX(-105%) skewX(5deg) scaleX(0.92);
  }
}

@keyframes editorBookPageBack {
  0% {
    opacity: 0;
    transform: translateX(-100%) skewX(4deg) scaleX(0.94);
  }
  16% { opacity: 1; }
  48% {
    opacity: 1;
    transform: translateX(0) skewX(1deg) scaleX(1);
  }
  100% {
    opacity: 0;
    transform: translateX(105%) skewX(-5deg) scaleX(0.92);
  }
}

[data-theme="dark"] body.editor-fullscreen-active.book-page-transitioning #editorPanel::before {
  background:
    linear-gradient(90deg, rgba(96, 165, 250, 0.2), rgba(15, 23, 42, 0.96) 36%, rgba(30, 41, 59, 0.98) 66%, rgba(14, 165, 233, 0.18)),
    radial-gradient(circle at 18% 50%, rgba(96, 165, 250, 0.18), transparent 34rem),
    #0f172a;
  box-shadow:
    -32px 0 80px rgba(0, 0, 0, 0.42),
    32px 0 80px rgba(96, 165, 250, 0.18),
    inset 18px 0 34px rgba(255, 255, 255, 0.06),
    inset -16px 0 34px rgba(96, 165, 250, 0.12);
}

[data-theme="dark"] body.editor-fullscreen-active.book-page-transitioning #editorPanel::after {
  color: #e5edf7;
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(15, 23, 42, 0.92);
}

@media (max-width: 760px) {
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
    align-items: stretch !important;
    flex-direction: column !important;
    min-height: 0 !important;
    padding: 9px !important;
  }

  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    width: 100% !important;
  }

  body.editor-fullscreen-active.book-page-transitioning #editorPanel::after {
    min-width: min(300px, calc(100vw - 32px));
    padding: 13px 18px;
    font-size: 0.9rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel,
  body.editor-fullscreen-active.book-page-transitioning #editorPanel::before,
  body.editor-fullscreen-active.book-page-transitioning #editorPanel::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}


/* Clean fullscreen preview UI: output should look like true output, not another editor panel. */
body.preview-fullscreen-active .preview-panel .panel-header,
body.preview-fullscreen-active .preview-panel .preview-header,
#previewPanel:fullscreen .panel-header,
#previewPanel:fullscreen .preview-header,
#previewPanel:-webkit-full-screen .panel-header,
#previewPanel:-webkit-full-screen .preview-header,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
  position: absolute !important;
  top: 12px !important;
  right: 12px !important;
  left: auto !important;
  z-index: 90020 !important;
  display: flex !important;
  justify-content: flex-end !important;
  align-items: center !important;
  width: auto !important;
  min-height: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 999px !important;
  background: transparent !important;
  box-shadow: none !important;
  pointer-events: none !important;
}

body.preview-fullscreen-active .preview-panel .preview-header > div:first-child,
#previewPanel:fullscreen .preview-header > div:first-child,
#previewPanel:-webkit-full-screen .preview-header > div:first-child,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header > div:first-child {
  display: none !important;
}

body.preview-fullscreen-active .preview-actions,
#previewPanel:fullscreen .preview-actions,
#previewPanel:-webkit-full-screen .preview-actions,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 8px !important;
  width: auto !important;
  padding: 8px !important;
  border: 1px solid rgba(191, 219, 254, 0.92) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, 0.9) !important;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.16) !important;
  backdrop-filter: blur(12px) !important;
  pointer-events: auto !important;
}

[data-theme="dark"] body.preview-fullscreen-active .preview-actions,
[data-theme="dark"] #previewPanel:fullscreen .preview-actions,
[data-theme="dark"] #previewPanel:-webkit-full-screen .preview-actions,
[data-theme="dark"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
  border-color: rgba(51, 65, 85, 0.92) !important;
  background: rgba(15, 23, 42, 0.9) !important;
}

body.preview-fullscreen-active .preview-actions .layout-btn[data-layout],
body.preview-fullscreen-active .preview-actions #fullPreviewBtn,
#previewPanel:fullscreen .preview-actions .layout-btn[data-layout],
#previewPanel:fullscreen .preview-actions #fullPreviewBtn,
#previewPanel:-webkit-full-screen .preview-actions .layout-btn[data-layout],
#previewPanel:-webkit-full-screen .preview-actions #fullPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions .layout-btn[data-layout],
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions #fullPreviewBtn {
  display: none !important;
}

body.preview-fullscreen-active #backToEditorPreviewBtn,
body.preview-fullscreen-active #exitPreviewBtn,
#previewPanel:fullscreen #backToEditorPreviewBtn,
#previewPanel:fullscreen #exitPreviewBtn,
#previewPanel:-webkit-full-screen #backToEditorPreviewBtn,
#previewPanel:-webkit-full-screen #exitPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #backToEditorPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #exitPreviewBtn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 38px !important;
  padding: 0 14px !important;
  border-radius: 999px !important;
  white-space: nowrap !important;
}

body.preview-fullscreen-active .preview-panel,
#previewPanel:fullscreen,
#previewPanel:-webkit-full-screen,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel {
  padding: 0 !important;
  background: #ffffff !important;
}

body.preview-fullscreen-active #previewFrame,
#previewPanel:fullscreen #previewFrame,
#previewPanel:-webkit-full-screen #previewFrame,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewFrame {
  flex: 1 1 auto !important;
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  min-height: 100% !important;
  border: 0 !important;
  background: #ffffff !important;
}

@media (max-width: 760px) {
  body.preview-fullscreen-active .preview-panel .panel-header,
  body.preview-fullscreen-active .preview-panel .preview-header,
  #previewPanel:fullscreen .panel-header,
  #previewPanel:fullscreen .preview-header,
  #previewPanel:-webkit-full-screen .panel-header,
  #previewPanel:-webkit-full-screen .preview-header,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
    top: auto !important;
    right: 10px !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
  }

  body.preview-fullscreen-active .preview-actions,
  #previewPanel:fullscreen .preview-actions,
  #previewPanel:-webkit-full-screen .preview-actions,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
    display: grid !important;
    grid-template-columns: 1fr auto !important;
    width: min(440px, calc(100vw - 20px)) !important;
  }
}

/* Final clean output preview mode: hide editor-only controls while preview is active inside Full Editor. */
body.editor-fullscreen-active.preview-inside-editor-fullscreen #fullscreenEditorActions,
body.editor-fullscreen-active.preview-inside-editor-fullscreen .fullscreen-editor-actions,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #fullscreenRunBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #fullscreenResultBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #exitEditorStickyBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #exitEditorBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #codeHelperFloatingBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen .code-helper-float-btn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #errorCheckerPanel,
body.editor-fullscreen-active.preview-inside-editor-fullscreen .language-tabs,
body.editor-fullscreen-active.preview-inside-editor-fullscreen .editor-wrap,
body.editor-fullscreen-active.preview-inside-editor-fullscreen .suggestion-box {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel {
  z-index: 9900 !important;
  isolation: isolate !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
  position: absolute !important;
  top: 12px !important;
  right: 12px !important;
  left: auto !important;
  z-index: 9950 !important;
  display: block !important;
  width: auto !important;
  min-height: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  pointer-events: none !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header > div,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header h2,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header p {
  display: none !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 8px !important;
  width: auto !important;
  max-width: calc(100vw - 24px) !important;
  padding: 6px !important;
  border: 1px solid rgba(147, 197, 253, 0.55) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, 0.72) !important;
  backdrop-filter: blur(12px) !important;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14) !important;
  pointer-events: auto !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions .layout-btn[data-layout],
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #fullPreviewBtn {
  display: none !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #backToEditorPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #exitPreviewBtn {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 40px !important;
  padding: 0 16px !important;
  border-radius: 999px !important;
  white-space: nowrap !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewFrame {
  position: absolute !important;
  inset: 0 !important;
  z-index: 1 !important;
  width: 100% !important;
  height: 100% !important;
  min-height: 100% !important;
}

[data-theme="dark"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
  background: rgba(15, 23, 42, 0.76) !important;
  border-color: rgba(96, 165, 250, 0.42) !important;
}

@media (max-width: 620px) {
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
    top: 8px !important;
    right: 8px !important;
  }

  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
    gap: 6px !important;
    padding: 5px !important;
  }

  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #backToEditorPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #exitPreviewBtn {
    min-height: 36px !important;
    padding: 0 11px !important;
    font-size: 0.82rem !important;
  }
}

/* Fix: keep only Back to Editor and Exit visible in fullscreen output launched from Full Editor. */
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header > div:first-child,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header h2,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header p {
  display: none !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header {
  position: absolute !important;
  top: 12px !important;
  right: 12px !important;
  left: auto !important;
  z-index: 99999 !important;
  display: block !important;
  width: auto !important;
  min-height: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  pointer-events: none !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header > .preview-actions,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 8px !important;
  width: auto !important;
  max-width: calc(100vw - 24px) !important;
  padding: 6px !important;
  border: 1px solid rgba(147, 197, 253, 0.55) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, 0.78) !important;
  backdrop-filter: blur(12px) !important;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14) !important;
  pointer-events: auto !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions .layout-btn[data-layout],
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #fullPreviewBtn {
  display: none !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #backToEditorPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #exitPreviewBtn {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 40px !important;
  padding: 0 16px !important;
  border-radius: 999px !important;
  white-space: nowrap !important;
  pointer-events: auto !important;
}

@media (max-width: 760px) {
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header {
    top: auto !important;
    right: 10px !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
  }

  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
    width: min(440px, calc(100vw - 20px)) !important;
    display: grid !important;
    grid-template-columns: 1fr auto !important;
  }
}

/* Fullscreen Output Preview: add Result button beside Back to Editor and Exit. */
body.preview-fullscreen-active.preview-has-back-editor #resultFromPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #resultFromPreviewBtn {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 40px !important;
  padding: 0 16px !important;
  border-radius: 999px !important;
  white-space: nowrap !important;
  color: #ffffff !important;
  border-color: transparent !important;
  background: linear-gradient(135deg, #16a34a, #22c55e) !important;
  box-shadow: 0 10px 22px rgba(22, 163, 74, 0.18) !important;
}

body.preview-fullscreen-active:not(.preview-has-back-editor) #resultFromPreviewBtn,
body:not(.preview-fullscreen-active) #resultFromPreviewBtn {
  display: none !important;
}

@media (max-width: 620px) {
  body.preview-fullscreen-active.preview-has-back-editor #resultFromPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #resultFromPreviewBtn {
    min-height: 36px !important;
    padding: 0 11px !important;
    font-size: 0.82rem !important;
  }
}


/* Smarter Code Helper verification */
.smart-check-btn {
  color: #075985 !important;
  border-color: #bae6fd !important;
  background: #e0f2fe !important;
}

.advanced-checker-card {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--line));
  border-radius: 18px;
  padding: 14px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary-soft) 64%, var(--solid-card)), var(--solid-card));
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.10);
}

.advanced-checker-head { display: grid; gap: 4px; }
.advanced-checker-head strong { color: var(--text); font-size: 1rem; }
.advanced-checker-head span { color: var(--muted); line-height: 1.4; }

.advanced-checker-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: var(--solid-card);
}

.advanced-checker-block h4 { margin: 0 0 6px; font-size: 0.92rem; }
.advanced-checker-block ul { margin: 0; padding-left: 18px; color: var(--muted); }
.advanced-checker-block.error { border-color: #fecaca; background: #fff7f7; }
.advanced-checker-block.warning { border-color: #fde68a; background: #fffbeb; }
.advanced-checker-block.tip { border-color: #bfdbfe; background: #eff6ff; }

[data-theme="dark"] .smart-check-btn {
  color: #bae6fd !important;
  border-color: #164e63 !important;
  background: rgba(14, 165, 233, 0.18) !important;
}

[data-theme="dark"] .advanced-checker-block.error,
[data-theme="dark"] .advanced-checker-block.warning,
[data-theme="dark"] .advanced-checker-block.tip { background: rgba(15, 23, 42, 0.72); }


/* Hidden teacher/admin access: Sir JR's text opens admin, no visible header button. */
.hidden-admin-trigger {
  display: inline-block;
  cursor: default;
  user-select: none;
}

.hidden-admin-trigger:focus-visible {
  outline: 3px solid var(--primary-soft);
  outline-offset: 3px;
  border-radius: 8px;
}

/* FINAL STATE FIX: Full Editor controls must always return after Output Preview. */
body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) #fullscreenEditorActions,
body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) .fullscreen-editor-actions {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) #fullscreenEditorActions.hidden,
body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) .fullscreen-editor-actions.hidden {
  display: flex !important;
}

body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) #fullscreenRunBtn,
body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) #fullscreenResultBtn,
body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) #exitEditorStickyBtn {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) #codeHelperFloatingBtn,
body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) .code-helper-float-btn {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) #editorPanel .language-tabs,
body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) #editorPanel .editor-wrap {
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) #editorPanel .language-tabs {
  display: flex !important;
}

body.editor-fullscreen-active:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen) #editorPanel .editor-wrap {
  display: grid !important;
}

/* Multi-page Website Mode */
.html-page-manager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--solid-card) 92%, var(--primary-soft));
}

.html-page-manager.hidden {
  display: none !important;
}

.page-manager-left,
.page-manager-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.page-manager-label {
  flex: 0 0 auto;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 1000;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#htmlPageSelect {
  min-width: 180px;
  min-height: 34px;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.86rem;
  font-weight: 900;
}

.page-manager-btn {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 11px;
  color: var(--text);
  background: var(--solid-card);
  font-size: 0.82rem;
  font-weight: 1000;
  cursor: pointer;
}

.page-manager-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.1);
}

.page-manager-btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--line));
}

.page-manager-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.page-dialog-card {
  width: min(520px, calc(100vw - 24px));
}

.page-dialog-label {
  padding: 16px 18px 0;
}

.editor-fullscreen-active .html-page-manager,
#editorPanel:fullscreen .html-page-manager {
  flex: 0 0 auto;
  padding-right: 290px;
}

.preview-inside-editor-fullscreen .html-page-manager {
  display: none !important;
}

@media (max-width: 760px) {
  .html-page-manager {
    align-items: stretch;
    flex-direction: column;
  }
  .page-manager-left,
  .page-manager-actions {
    width: 100%;
  }
  #htmlPageSelect {
    min-width: 0;
    flex: 1 1 auto;
  }
  .page-manager-actions .page-manager-btn {
    flex: 1 1 auto;
  }
  .editor-fullscreen-active .html-page-manager,
  #editorPanel:fullscreen .html-page-manager {
    padding-right: 10px;
  }
}


/* Tabs/Pages manager: cleaner multi-file controls for HTML, CSS, and JavaScript */
.html-page-manager {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 8px !important;
  flex-wrap: nowrap !important;
}

.html-page-manager[data-language="css"] .page-manager-label::after,
.html-page-manager[data-language="js"] .page-manager-label::after,
.html-page-manager[data-language="html"] .page-manager-label::after {
  content: '';
}

.page-manager-left {
  flex: 1 1 auto !important;
  min-width: 0 !important;
}

#htmlPageSelect {
  flex: 1 1 auto !important;
  min-width: 130px !important;
  max-width: 360px !important;
}

.page-manager-actions {
  flex: 0 0 auto !important;
  white-space: nowrap !important;
}

.page-dialog-overlay.inside-editor-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  z-index: 900000 !important;
  display: grid !important;
  place-items: center !important;
  padding: 18px !important;
  background: rgba(2, 6, 23, 0.64) !important;
}

.page-dialog-overlay.inside-editor-fullscreen.hidden {
  display: none !important;
}

.editor-fullscreen-active .html-page-manager,
#editorPanel:fullscreen .html-page-manager {
  padding-right: 300px !important;
}

@media (max-width: 760px) {
  .language-tabs {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    scrollbar-width: none !important;
  }
  .language-tabs::-webkit-scrollbar { display: none !important; }
  .language-tabs .tab-btn,
  .language-tabs .rename-files-btn {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
  }

  .html-page-manager {
    display: grid !important;
    grid-template-columns: 1fr !important;
    align-items: stretch !important;
    gap: 7px !important;
    padding: 7px !important;
  }
  .page-manager-left,
  .page-manager-actions {
    width: 100% !important;
  }
  .page-manager-label {
    font-size: 0.68rem !important;
  }
  #htmlPageSelect {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
  }
  .page-manager-actions {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }
  .page-manager-btn {
    min-width: 0 !important;
    padding: 0 8px !important;
    font-size: 0.76rem !important;
  }
  .editor-fullscreen-active .html-page-manager,
  #editorPanel:fullscreen .html-page-manager {
    padding-right: 8px !important;
  }
}

@media (max-width: 420px) {
  .page-manager-actions {
    grid-template-columns: 1fr 1fr !important;
  }
  .page-manager-actions .danger {
    grid-column: 1 / -1 !important;
  }
}

/* Enhanced cinematic book transition between Full Editor and Fullscreen Preview. */
body.editor-fullscreen-active.book-page-transitioning #editorPanel {
  perspective: 2200px !important;
  transform-style: preserve-3d !important;
  isolation: isolate !important;
  background: var(--solid-card) !important;
}

/* The turning sheet. It stays inside one fullscreen container, so there is no browser blink. */
body.editor-fullscreen-active.book-page-transitioning #editorPanel::before {
  content: "" !important;
  position: absolute !important;
  inset: 0 !important;
  z-index: 12000 !important;
  pointer-events: none !important;
  border: 0 !important;
  border-radius: 0 !important;
  transform-style: preserve-3d !important;
  backface-visibility: hidden !important;
  will-change: transform, opacity, filter !important;
  background:
    linear-gradient(90deg,
      rgba(15, 23, 42, 0.10) 0%,
      rgba(255, 255, 255, 0.96) 5%,
      rgba(255, 255, 255, 1) 46%,
      rgba(219, 234, 254, 0.98) 73%,
      rgba(37, 99, 235, 0.20) 100%),
    repeating-linear-gradient(0deg,
      rgba(37, 99, 235, 0.018) 0,
      rgba(37, 99, 235, 0.018) 1px,
      transparent 1px,
      transparent 5px),
    var(--solid-card) !important;
  box-shadow:
    -18px 0 44px rgba(15, 23, 42, 0.22),
    38px 0 86px rgba(37, 99, 235, 0.24),
    inset 22px 0 38px rgba(255, 255, 255, 0.72),
    inset -28px 0 46px rgba(37, 99, 235, 0.18) !important;
}

/* A subtle page-edge caption, not a blocking overlay. */
body.editor-fullscreen-active.book-page-transitioning #editorPanel::after {
  position: absolute !important;
  left: 50% !important;
  top: auto !important;
  bottom: calc(22px + env(safe-area-inset-bottom)) !important;
  z-index: 12010 !important;
  transform: translateX(-50%) !important;
  min-width: 0 !important;
  padding: 9px 16px !important;
  border: 1px solid rgba(147, 197, 253, 0.68) !important;
  border-radius: 999px !important;
  color: #17324d !important;
  background: rgba(255, 255, 255, 0.82) !important;
  backdrop-filter: blur(12px) !important;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.16) !important;
  font-size: 0.86rem !important;
  font-weight: 900 !important;
  letter-spacing: 0.02em !important;
  pointer-events: none !important;
  will-change: opacity, transform !important;
}

body.editor-fullscreen-active.book-to-preview #editorPanel::before {
  transform-origin: left center !important;
  animation: cinematicPageTurnForward 980ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

body.editor-fullscreen-active.book-to-editor #editorPanel::before {
  transform-origin: right center !important;
  animation: cinematicPageTurnBack 980ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

body.editor-fullscreen-active.book-to-preview #editorPanel::after {
  content: "Opening preview" !important;
  animation: cinematicCaption 980ms ease both !important;
}

body.editor-fullscreen-active.book-to-editor #editorPanel::after {
  content: "Returning to editor" !important;
  animation: cinematicCaption 980ms ease both !important;
}

/* Preview arrives only after the page reaches its edge. */
body.editor-fullscreen-active.preview-inside-editor-fullscreen.book-preview-revealing #editorPanel .preview-panel {
  animation: cinematicPreviewReveal 550ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
  transform-origin: right center !important;
  will-change: transform, opacity, filter !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen.book-preview-leaving #editorPanel .preview-panel {
  animation: cinematicPreviewLeave 470ms cubic-bezier(0.55, 0.02, 0.78, 0.28) both !important;
  transform-origin: left center !important;
  will-change: transform, opacity, filter !important;
}

body.editor-fullscreen-active.book-editor-revealing #editorPanel .language-tabs,
body.editor-fullscreen-active.book-editor-revealing #editorPanel .html-page-manager,
body.editor-fullscreen-active.book-editor-revealing #editorPanel .editor-wrap,
body.editor-fullscreen-active.book-editor-revealing #fullscreenEditorActions,
body.editor-fullscreen-active.book-editor-revealing #codeHelperFloatingBtn {
  animation: cinematicEditorReveal 560ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
  will-change: transform, opacity, filter !important;
}

@keyframes cinematicPageTurnForward {
  0% {
    opacity: 0;
    transform: translateX(0) rotateY(0deg) scale(1);
    filter: brightness(1);
  }
  7% { opacity: 1; }
  42% {
    opacity: 1;
    transform: translateX(-1.5%) rotateY(-76deg) scale(0.995);
    filter: brightness(0.97);
  }
  55% {
    opacity: 0.98;
    transform: translateX(-3%) rotateY(-102deg) scale(0.992);
    filter: brightness(0.92);
  }
  100% {
    opacity: 0;
    transform: translateX(-10%) rotateY(-178deg) scale(0.985);
    filter: brightness(0.88);
  }
}

@keyframes cinematicPageTurnBack {
  0% {
    opacity: 0;
    transform: translateX(0) rotateY(0deg) scale(1);
    filter: brightness(1);
  }
  7% { opacity: 1; }
  42% {
    opacity: 1;
    transform: translateX(1.5%) rotateY(76deg) scale(0.995);
    filter: brightness(0.97);
  }
  55% {
    opacity: 0.98;
    transform: translateX(3%) rotateY(102deg) scale(0.992);
    filter: brightness(0.92);
  }
  100% {
    opacity: 0;
    transform: translateX(10%) rotateY(178deg) scale(0.985);
    filter: brightness(0.88);
  }
}

@keyframes cinematicPreviewReveal {
  0% {
    opacity: 0;
    transform: translateX(7%) rotateY(-12deg) scale(0.985);
    filter: blur(5px) brightness(0.92);
  }
  45% { opacity: 1; }
  100% {
    opacity: 1;
    transform: translateX(0) rotateY(0deg) scale(1);
    filter: blur(0) brightness(1);
  }
}

@keyframes cinematicPreviewLeave {
  0% {
    opacity: 1;
    transform: translateX(0) rotateY(0deg) scale(1);
    filter: blur(0) brightness(1);
  }
  100% {
    opacity: 0;
    transform: translateX(-6%) rotateY(11deg) scale(0.986);
    filter: blur(4px) brightness(0.93);
  }
}

@keyframes cinematicEditorReveal {
  0% {
    opacity: 0;
    transform: translateX(-3%) scale(0.99);
    filter: blur(4px);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
    filter: blur(0);
  }
}

@keyframes cinematicCaption {
  0%, 10% { opacity: 0; transform: translate(-50%, 10px) scale(0.97); }
  24%, 72% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -8px) scale(0.98); }
}

[data-theme="dark"] body.editor-fullscreen-active.book-page-transitioning #editorPanel::before {
  background:
    linear-gradient(90deg,
      rgba(0, 0, 0, 0.32) 0%,
      rgba(15, 23, 42, 0.98) 7%,
      rgba(17, 24, 39, 1) 46%,
      rgba(30, 41, 59, 0.98) 73%,
      rgba(96, 165, 250, 0.22) 100%),
    repeating-linear-gradient(0deg,
      rgba(96, 165, 250, 0.025) 0,
      rgba(96, 165, 250, 0.025) 1px,
      transparent 1px,
      transparent 5px),
    #0f172a !important;
  box-shadow:
    -18px 0 50px rgba(0, 0, 0, 0.50),
    38px 0 90px rgba(96, 165, 250, 0.20),
    inset 22px 0 38px rgba(255, 255, 255, 0.045),
    inset -28px 0 46px rgba(96, 165, 250, 0.14) !important;
}

[data-theme="dark"] body.editor-fullscreen-active.book-page-transitioning #editorPanel::after {
  color: #e5edf7 !important;
  border-color: rgba(96, 165, 250, 0.45) !important;
  background: rgba(15, 23, 42, 0.82) !important;
}

@media (max-width: 760px) {
  body.editor-fullscreen-active.book-page-transitioning #editorPanel::after {
    bottom: calc(14px + env(safe-area-inset-bottom)) !important;
    padding: 8px 13px !important;
    font-size: 0.78rem !important;
  }

  body.editor-fullscreen-active.book-to-preview #editorPanel::before,
  body.editor-fullscreen-active.book-to-editor #editorPanel::before {
    animation-duration: 820ms !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.editor-fullscreen-active.book-page-transitioning #editorPanel::before,
  body.editor-fullscreen-active.book-page-transitioning #editorPanel::after,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen.book-preview-revealing #editorPanel .preview-panel,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen.book-preview-leaving #editorPanel .preview-panel,
  body.editor-fullscreen-active.book-editor-revealing #editorPanel .language-tabs,
  body.editor-fullscreen-active.book-editor-revealing #editorPanel .html-page-manager,
  body.editor-fullscreen-active.book-editor-revealing #editorPanel .editor-wrap,
  body.editor-fullscreen-active.book-editor-revealing #fullscreenEditorActions,
  body.editor-fullscreen-active.book-editor-revealing #codeHelperFloatingBtn {
    animation-duration: 1ms !important;
  }
}


/* Final smooth book transition fix: one overlay handles the movement, so no blink/repeat. */
body.editor-fullscreen-active.book-page-transitioning #editorPanel::before,
body.editor-fullscreen-active.book-page-transitioning #editorPanel::after {
  content: none !important;
  display: none !important;
  animation: none !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel,
body.editor-fullscreen-active.preview-inside-editor-fullscreen.preview-closing-to-editor #editorPanel .preview-panel {
  animation: none !important;
  transform: none !important;
  opacity: 1 !important;
  filter: none !important;
}

.fullscreen-book-transition-layer {
  position: absolute;
  inset: 0;
  z-index: 120000;
  overflow: hidden;
  pointer-events: none;
  perspective: 1800px;
  transform-style: preserve-3d;
  background: rgba(2, 6, 23, 0.08);
  opacity: 1;
}

.fullscreen-book-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 48%, rgba(255, 255, 255, 0.10), transparent 38%),
    radial-gradient(circle at 18% 50%, rgba(37, 99, 235, 0.18), transparent 34rem),
    linear-gradient(90deg, rgba(15, 23, 42, 0.10), transparent 26%, transparent 74%, rgba(15, 23, 42, 0.14));
  animation: bookVignettePulse 1040ms cubic-bezier(0.2, 0.78, 0.24, 1) both;
}

.fullscreen-book-stage {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  perspective: 1800px;
}

.fullscreen-book-fixed-page,
.fullscreen-book-turn-page {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 58%;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.98), rgba(239, 246, 255, 0.98) 52%, rgba(219, 234, 254, 0.96)),
    var(--solid-card);
  box-shadow:
    0 34px 90px rgba(15, 23, 42, 0.24),
    inset 18px 0 28px rgba(255, 255, 255, 0.56),
    inset -22px 0 36px rgba(37, 99, 235, 0.13);
  backface-visibility: hidden;
  will-change: transform, opacity, filter;
}

.fullscreen-book-fixed-page {
  right: 0;
  opacity: 0.48;
  transform: translateX(8%) scaleX(0.985);
  filter: blur(0.4px);
}

.fullscreen-book-turn-page {
  left: 50%;
  transform-origin: left center;
  border-left: 1px solid rgba(147, 197, 253, 0.8);
}

.fullscreen-book-spine {
  position: absolute;
  inset: 0 auto 0 0;
  width: 18px;
  background: linear-gradient(90deg, rgba(15, 23, 42, 0.25), rgba(255, 255, 255, 0.35), transparent);
  opacity: 0.8;
}

.fullscreen-book-highlight {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(105deg, transparent 0%, rgba(255, 255, 255, 0.72) 43%, rgba(255, 255, 255, 0.12) 50%, transparent 63%),
    repeating-linear-gradient(0deg, rgba(37, 99, 235, 0.025) 0 2px, transparent 2px 14px);
  mix-blend-mode: screen;
  opacity: 0.72;
}

.fullscreen-book-edge {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, rgba(15, 23, 42, 0.2), transparent);
  opacity: 0;
  animation: bookEdgePass 1040ms cubic-bezier(0.2, 0.78, 0.24, 1) both;
}

.fullscreen-book-caption {
  position: absolute;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  border: 1px solid rgba(147, 197, 253, 0.55);
  border-radius: 999px;
  padding: 10px 16px;
  color: #12305f;
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 52px rgba(15, 23, 42, 0.14);
  font-size: 0.86rem;
  font-weight: 1000;
  letter-spacing: 0.02em;
  opacity: 0;
  animation: bookCaptionSmooth 1040ms ease both;
}

.fullscreen-book-transition-layer.to-preview .fullscreen-book-turn-page {
  animation: bookTurnToPreview 1040ms cubic-bezier(0.18, 0.88, 0.2, 1) both;
}

.fullscreen-book-transition-layer.to-preview .fullscreen-book-fixed-page {
  animation: bookFixedToPreview 1040ms cubic-bezier(0.18, 0.88, 0.2, 1) both;
}

.fullscreen-book-transition-layer.to-editor .fullscreen-book-turn-page {
  left: auto;
  right: 50%;
  transform-origin: right center;
  border-left: 0;
  border-right: 1px solid rgba(147, 197, 253, 0.8);
  animation: bookTurnToEditor 1040ms cubic-bezier(0.18, 0.88, 0.2, 1) both;
}

.fullscreen-book-transition-layer.to-editor .fullscreen-book-fixed-page {
  left: 0;
  right: auto;
  animation: bookFixedToEditor 1040ms cubic-bezier(0.18, 0.88, 0.2, 1) both;
}

.fullscreen-book-transition-layer.is-done {
  opacity: 0;
  transition: opacity 90ms ease;
}

@keyframes bookTurnToPreview {
  0% { opacity: 0; transform: translateX(58%) rotateY(-68deg) scaleX(0.96); filter: blur(1.8px); }
  12% { opacity: 1; }
  45% { opacity: 1; transform: translateX(-2%) rotateY(-8deg) scaleX(1); filter: blur(0); }
  56% { opacity: 1; transform: translateX(-18%) rotateY(11deg) scaleX(1.02); filter: blur(0); }
  100% { opacity: 0; transform: translateX(-112%) rotateY(58deg) scaleX(0.96); filter: blur(1.4px); }
}

@keyframes bookTurnToEditor {
  0% { opacity: 0; transform: translateX(-58%) rotateY(68deg) scaleX(0.96); filter: blur(1.8px); }
  12% { opacity: 1; }
  45% { opacity: 1; transform: translateX(2%) rotateY(8deg) scaleX(1); filter: blur(0); }
  56% { opacity: 1; transform: translateX(18%) rotateY(-11deg) scaleX(1.02); filter: blur(0); }
  100% { opacity: 0; transform: translateX(112%) rotateY(-58deg) scaleX(0.96); filter: blur(1.4px); }
}

@keyframes bookFixedToPreview {
  0% { opacity: 0.22; transform: translateX(10%) scale(0.985); }
  44% { opacity: 0.42; transform: translateX(2%) scale(0.995); }
  55% { opacity: 0.58; transform: translateX(0) scale(1); }
  100% { opacity: 0; transform: translateX(-4%) scale(1.01); }
}

@keyframes bookFixedToEditor {
  0% { opacity: 0.22; transform: translateX(-10%) scale(0.985); }
  44% { opacity: 0.42; transform: translateX(-2%) scale(0.995); }
  55% { opacity: 0.58; transform: translateX(0) scale(1); }
  100% { opacity: 0; transform: translateX(4%) scale(1.01); }
}

@keyframes bookEdgePass {
  0%, 100% { opacity: 0; transform: translateX(-50%) scaleX(0.6); }
  42%, 58% { opacity: 0.58; transform: translateX(-50%) scaleX(1.8); }
}

@keyframes bookVignettePulse {
  0% { opacity: 0; }
  18%, 72% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes bookCaptionSmooth {
  0%, 100% { opacity: 0; transform: translate(-50%, 8px); }
  18%, 76% { opacity: 1; transform: translate(-50%, 0); }
}

[data-theme="dark"] .fullscreen-book-vignette {
  background:
    radial-gradient(circle at 50% 48%, rgba(96, 165, 250, 0.12), transparent 38%),
    radial-gradient(circle at 18% 50%, rgba(96, 165, 250, 0.20), transparent 34rem),
    linear-gradient(90deg, rgba(0, 0, 0, 0.42), transparent 26%, transparent 74%, rgba(0, 0, 0, 0.46));
}

[data-theme="dark"] .fullscreen-book-fixed-page,
[data-theme="dark"] .fullscreen-book-turn-page {
  background:
    linear-gradient(90deg, rgba(15, 23, 42, 0.98), rgba(30, 41, 59, 0.98) 52%, rgba(37, 99, 235, 0.40)),
    #0f172a;
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.5),
    inset 18px 0 28px rgba(255, 255, 255, 0.06),
    inset -22px 0 36px rgba(96, 165, 250, 0.16);
}

[data-theme="dark"] .fullscreen-book-caption {
  color: #e5edf7;
  border-color: rgba(96, 165, 250, 0.45);
  background: rgba(15, 23, 42, 0.78);
}

@media (max-width: 720px) {
  .fullscreen-book-fixed-page,
  .fullscreen-book-turn-page {
    width: 68%;
  }

  .fullscreen-book-caption {
    bottom: calc(18px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 28px);
    padding: 9px 13px;
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fullscreen-book-transition-layer,
  .fullscreen-book-vignette,
  .fullscreen-book-fixed-page,
  .fullscreen-book-turn-page,
  .fullscreen-book-edge,
  .fullscreen-book-caption {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}

/* FINAL MOBILE POLISH: compact header + non-overlapping Tabs/Pages controls */
@media (max-width: 760px) {
  html, body {
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  .app-shell {
    width: 100% !important;
    max-width: 100% !important;
    padding: 6px 6px 14px !important;
    margin: 0 !important;
  }

  .topbar.simplified-topbar,
  .topbar {
    position: sticky !important;
    top: 4px !important;
    z-index: 500 !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 7px !important;
    min-height: 0 !important;
    padding: 10px 10px 9px !important;
    margin: 0 0 8px !important;
    border-radius: 18px !important;
    overflow: hidden !important;
  }

  .topbar.simplified-topbar::after,
  .topbar::after {
    opacity: 0.45 !important;
    width: 160px !important;
    height: 160px !important;
    right: -70px !important;
    top: -80px !important;
  }

  .brand-block {
    display: grid !important;
    grid-template-columns: 42px minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 9px !important;
    min-width: 0 !important;
    width: 100% !important;
  }

  .logo-mark {
    display: grid !important;
    width: 42px !important;
    height: 42px !important;
    flex: 0 0 42px !important;
    border-radius: 14px !important;
    font-size: 0.88rem !important;
  }

  .brand-block > div {
    min-width: 0 !important;
  }

  .eyebrow,
  .section-kicker {
    margin: 0 0 1px !important;
    font-size: 0.67rem !important;
    line-height: 1 !important;
    letter-spacing: 0.11em !important;
  }

  .topbar h1,
  h1 {
    margin: 0 !important;
    font-size: clamp(1.05rem, 4.4vw, 1.28rem) !important;
    line-height: 1.05 !important;
    white-space: normal !important;
  }

  .topbar .subtitle,
  .subtitle {
    display: block !important;
    margin: 2px 0 0 !important;
    font-size: 0.78rem !important;
    line-height: 1 !important;
    color: var(--muted) !important;
  }

  .top-actions {
    width: 100% !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 7px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 1px 1px 3px !important;
    margin: 0 !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .top-actions::-webkit-scrollbar { display: none !important; }

  .top-actions > *,
  .top-actions > button,
  .top-actions .ghost-btn,
  .top-actions .primary-btn,
  .top-actions .success-btn,
  #clearBtn,
  #resetBtn {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: max-content !important;
    max-width: none !important;
    min-height: 34px !important;
    height: 34px !important;
    padding: 0 12px !important;
    border-radius: 999px !important;
    font-size: 0.82rem !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }

  #statusBadge,
  .status-badge.compact-status {
    display: none !important;
  }

  .workspace {
    margin-top: 0 !important;
    gap: 10px !important;
  }

  .editor-panel,
  .panel {
    border-radius: 18px !important;
  }

  .language-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 4px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 6px 6px 0 !important;
    min-height: 38px !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .language-tabs::-webkit-scrollbar { display: none !important; }

  .language-tabs .tab-btn,
  .language-tabs .rename-files-btn {
    flex: 0 0 auto !important;
    min-height: 34px !important;
    padding: 7px 14px !important;
    border-radius: 13px 13px 0 0 !important;
    font-size: 0.86rem !important;
    white-space: nowrap !important;
  }

  .tab-btn::after {
    display: none !important;
    content: '' !important;
  }

  .html-page-manager {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    align-items: stretch !important;
    padding: 8px !important;
    border-bottom: 1px solid var(--line) !important;
    background: color-mix(in srgb, var(--solid-card) 94%, var(--primary-soft)) !important;
  }

  .page-manager-left {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 6px !important;
    width: 100% !important;
    min-width: 0 !important;
    align-items: stretch !important;
  }

  .page-manager-label {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 2px !important;
    color: var(--primary-dark) !important;
    font-size: 0.72rem !important;
    line-height: 1.1 !important;
    letter-spacing: 0.08em !important;
    text-transform: uppercase !important;
    white-space: nowrap !important;
  }

  #htmlPageSelect {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: 40px !important;
    padding: 8px 14px !important;
    border-radius: 16px !important;
    font-size: 0.93rem !important;
    line-height: 1.15 !important;
    font-weight: 900 !important;
  }

  .page-manager-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 7px !important;
    width: 100% !important;
    min-width: 0 !important;
    align-items: stretch !important;
  }

  .page-manager-actions .page-manager-btn {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 38px !important;
    padding: 0 8px !important;
    border-radius: 16px !important;
    font-size: 0.84rem !important;
    white-space: nowrap !important;
  }

  .page-manager-actions .page-manager-btn.danger,
  .page-manager-actions .danger {
    grid-column: 1 / -1 !important;
  }

  .editor-wrap {
    grid-template-columns: 42px minmax(0, 1fr) !important;
    min-height: calc(100dvh - 250px) !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }

  .line-numbers,
  .editor-stack,
  #codeEditor,
  .code-match-layer {
    min-height: calc(100dvh - 250px) !important;
  }

  .line-numbers {
    padding: 12px 6px !important;
    font-size: 13px !important;
  }

  #codeEditor,
  .code-match-layer {
    padding: 12px !important;
    font-size: 13px !important;
    line-height: 1.6 !important;
  }

  .code-helper-float-btn {
    right: 10px !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    min-height: 40px !important;
    padding: 0 14px !important;
    font-size: 0.86rem !important;
    border-radius: 999px !important;
  }

  .suggestion-box {
    right: 8px !important;
    bottom: calc(62px + env(safe-area-inset-bottom)) !important;
    width: min(360px, calc(100vw - 16px)) !important;
    max-height: 220px !important;
  }
}

@media (max-width: 420px) {
  .top-actions > button,
  .top-actions .ghost-btn,
  .top-actions .primary-btn,
  .top-actions .success-btn {
    min-height: 33px !important;
    height: 33px !important;
    padding: 0 11px !important;
    font-size: 0.78rem !important;
  }

  .topbar h1,
  h1 {
    font-size: clamp(1rem, 4.8vw, 1.18rem) !important;
  }

  .topbar .subtitle,
  .subtitle {
    font-size: 0.72rem !important;
  }

  .page-manager-actions {
    grid-template-columns: 1fr 1fr !important;
  }

  .page-manager-actions .page-manager-btn {
    font-size: 0.8rem !important;
  }
}

/* FINAL MOBILE OVERLAP FIX: keep tabs clean and move renaming to Tabs/Pages controls */
@media (max-width: 760px) {
  .language-tabs {
    position: relative !important;
    z-index: 2 !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: flex-end !important;
    gap: 4px !important;
    min-height: 42px !important;
    height: 42px !important;
    max-height: 42px !important;
    padding: 6px 6px 0 !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
  }

  .language-tabs .tab-btn {
    flex: 1 0 31% !important;
    min-width: 108px !important;
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    margin: 0 !important;
    transform: none !important;
  }

  /* The current file can already be renamed using the Tabs/Pages Rename button.
     Hide this extra button on phones so it cannot overlap the file dropdown. */
  .language-tabs #renameFilesBtn,
  .language-tabs .rename-files-btn {
    display: none !important;
  }

  .html-page-manager {
    position: relative !important;
    z-index: 1 !important;
    margin-top: 0 !important;
    padding: 9px 8px 10px !important;
    clear: both !important;
  }

  .page-manager-left {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 6px !important;
  }

  .page-manager-label {
    position: static !important;
    display: block !important;
    width: 100% !important;
    padding: 0 2px !important;
    margin: 0 !important;
    transform: none !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  #htmlPageSelect {
    position: static !important;
    display: block !important;
    width: 100% !important;
    min-height: 42px !important;
    height: 42px !important;
    margin: 0 !important;
    padding: 8px 42px 8px 14px !important;
    border-radius: 18px !important;
    line-height: 1.1 !important;
  }

  .page-manager-actions {
    margin-top: 2px !important;
  }

  .page-manager-actions .page-manager-btn {
    min-height: 40px !important;
    height: 40px !important;
  }
}

@media (max-width: 420px) {
  .language-tabs .tab-btn {
    min-width: 98px !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
    font-size: 0.82rem !important;
  }
}

/* Mobile preview controls: replace Split/Stacked/Big Preview with Desktop View. */
.desktop-preview-toggle {
  display: none;
}

@media (max-width: 760px) {
  .preview-panel .preview-actions .layout-btn[data-layout] {
    display: none !important;
  }

  .preview-panel .preview-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
    width: 100% !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn,
  .preview-panel .preview-actions #fullPreviewBtn,
  .preview-panel .preview-actions #exitPreviewBtn,
  .preview-panel .preview-actions #backToEditorPreviewBtn,
  .preview-panel .preview-actions #resultFromPreviewBtn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 44px !important;
    width: 100% !important;
    white-space: nowrap !important;
  }

  .preview-panel .preview-actions #exitPreviewBtn.hidden,
  .preview-panel .preview-actions #backToEditorPreviewBtn.hidden,
  .preview-panel .preview-actions #resultFromPreviewBtn.hidden {
    display: none !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn.active {
    color: white !important;
    border-color: transparent !important;
    background: linear-gradient(135deg, #2563eb, #06b6d4) !important;
    box-shadow: 0 12px 26px rgba(37, 99, 235, 0.22) !important;
  }

  .preview-panel.mobile-desktop-preview {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .preview-panel.mobile-desktop-preview #previewFrame {
    width: 1024px !important;
    max-width: none !important;
    min-width: 1024px !important;
    min-height: 620px !important;
  }

  .preview-panel.mobile-desktop-preview::after {
    content: 'Desktop preview: swipe sideways to inspect the full page.';
    display: block;
    padding: 8px 12px 12px;
    color: var(--muted);
    background: var(--solid-card);
    font-size: 0.78rem;
    font-weight: 800;
  }

  body.preview-fullscreen-active .preview-panel .preview-actions #desktopPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions #desktopPreviewBtn,
  #previewPanel:fullscreen .preview-actions #desktopPreviewBtn,
  #previewPanel:-webkit-full-screen .preview-actions #desktopPreviewBtn {
    display: none !important;
  }
}

/* Mobile Desktop Monitor Preview: phone view can inspect true desktop-style output. */
.preview-frame-shell {
  position: relative;
  background: #ffffff;
}

.desktop-monitor-label {
  display: none;
}

@media (max-width: 760px) {
  .preview-panel .preview-actions #desktopPreviewBtn {
    font-size: 0 !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn::before {
    content: 'Desktop Monitor';
    font-size: 0.88rem;
  }

  .preview-panel.mobile-desktop-preview {
    overflow: visible !important;
  }

  .preview-panel.mobile-desktop-preview .preview-frame-shell {
    margin: 12px;
    padding: 14px 14px 38px;
    overflow: hidden;
    border: 7px solid #111827;
    border-radius: 24px;
    background:
      linear-gradient(#0f172a, #0f172a) padding-box,
      linear-gradient(135deg, #334155, #020617) border-box;
    box-shadow:
      inset 0 0 0 1px rgba(255,255,255,0.13),
      0 18px 45px rgba(2, 6, 23, 0.32);
  }

  .preview-panel.mobile-desktop-preview .preview-frame-shell::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 12px;
    width: 76px;
    height: 8px;
    border-radius: 999px;
    transform: translateX(-50%);
    background: linear-gradient(90deg, #64748b, #cbd5e1, #64748b);
    opacity: 0.8;
  }

  .preview-panel.mobile-desktop-preview .preview-frame-shell::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 138px;
    height: 12px;
    border-radius: 16px 16px 0 0;
    transform: translateX(-50%);
    background: linear-gradient(180deg, #334155, #111827);
  }

  .preview-panel.mobile-desktop-preview .desktop-monitor-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: -2px 0 9px;
    color: #dbeafe;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .preview-panel.mobile-desktop-preview .desktop-monitor-label::after {
    content: '1366px view';
    color: #93c5fd;
    font-size: 0.66rem;
    font-weight: 1000;
  }

  .preview-panel.mobile-desktop-preview #previewFrame {
    display: block !important;
    width: 1366px !important;
    min-width: 1366px !important;
    max-width: none !important;
    height: 768px !important;
    min-height: 768px !important;
    border: 0 !important;
    border-radius: 10px !important;
    background: white !important;
    transform: scale(calc((100vw - 86px) / 1366));
    transform-origin: top left;
  }

  .preview-panel.mobile-desktop-preview .preview-frame-shell {
    height: calc(((100vw - 86px) / 1366) * 768 + 74px);
  }

  .preview-panel.mobile-desktop-preview::after {
    content: 'Desktop Monitor: this is a scaled computer-screen view. Tap Full Screen, then rotate your phone sideways for a wider desktop preview.' !important;
    display: block !important;
    margin: 0 12px 12px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    color: var(--muted);
    background: var(--solid-card);
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1.35;
  }

  body.preview-fullscreen-active .preview-panel.mobile-desktop-preview,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-desktop-preview,
  #previewPanel:fullscreen.mobile-desktop-preview,
  #previewPanel:-webkit-full-screen.mobile-desktop-preview {
    background: #020617 !important;
  }

  body.preview-fullscreen-active .preview-panel.mobile-desktop-preview .preview-frame-shell,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-desktop-preview .preview-frame-shell,
  #previewPanel:fullscreen.mobile-desktop-preview .preview-frame-shell,
  #previewPanel:-webkit-full-screen.mobile-desktop-preview .preview-frame-shell {
    width: calc(100vw - 18px) !important;
    max-width: 100vw !important;
    margin: 74px auto 10px !important;
    height: calc(((100vw - 82px) / 1366) * 768 + 74px) !important;
  }

  body.preview-fullscreen-active .preview-panel.mobile-desktop-preview #previewFrame,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-desktop-preview #previewFrame,
  #previewPanel:fullscreen.mobile-desktop-preview #previewFrame,
  #previewPanel:-webkit-full-screen.mobile-desktop-preview #previewFrame {
    transform: scale(calc((100vw - 82px) / 1366)) !important;
  }

  @media (orientation: landscape) and (max-height: 520px) {
    body.preview-fullscreen-active .preview-panel.mobile-desktop-preview .preview-frame-shell,
    body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-desktop-preview .preview-frame-shell,
    #previewPanel:fullscreen.mobile-desktop-preview .preview-frame-shell,
    #previewPanel:-webkit-full-screen.mobile-desktop-preview .preview-frame-shell {
      width: calc(100vw - 24px) !important;
      margin-top: 58px !important;
      height: calc(100vh - 70px) !important;
      overflow: auto !important;
      -webkit-overflow-scrolling: touch !important;
    }

    body.preview-fullscreen-active .preview-panel.mobile-desktop-preview #previewFrame,
    body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-desktop-preview #previewFrame,
    #previewPanel:fullscreen.mobile-desktop-preview #previewFrame,
    #previewPanel:-webkit-full-screen.mobile-desktop-preview #previewFrame {
      transform: scale(calc((100vw - 88px) / 1366)) !important;
    }
  }
}

/* Final mobile landscape / desktop monitor preview fix */
@media (hover: none) and (pointer: coarse), (max-width: 760px), (orientation: landscape) and (max-height: 560px) {
  .preview-panel .preview-actions .layout-btn[data-layout] {
    display: none !important;
  }

  .preview-panel .preview-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn,
  .preview-panel .preview-actions #fullPreviewBtn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 42px !important;
    width: 100% !important;
    padding: 0 12px !important;
    border-radius: 999px !important;
    font-size: 0.9rem !important;
    white-space: nowrap !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn::before {
    content: 'Desktop Monitor' !important;
    font-size: 0.9rem !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn {
    font-size: 0 !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn.active::before {
    content: 'Phone View' !important;
  }
}

/* Keep fullscreen preview controls compact on phone landscape. */
@media (orientation: landscape) and (max-height: 560px) {
  body.preview-fullscreen-active .preview-panel .panel-header,
  body.preview-fullscreen-active .preview-panel .preview-header,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header,
  #previewPanel:fullscreen .panel-header,
  #previewPanel:fullscreen .preview-header,
  #previewPanel:-webkit-full-screen .panel-header,
  #previewPanel:-webkit-full-screen .preview-header {
    top: 8px !important;
    right: 8px !important;
    bottom: auto !important;
    left: auto !important;
    width: auto !important;
  }

  body.preview-fullscreen-active .preview-actions,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions,
  #previewPanel:fullscreen .preview-actions,
  #previewPanel:-webkit-full-screen .preview-actions {
    display: inline-flex !important;
    grid-template-columns: none !important;
    width: auto !important;
    max-width: calc(100vw - 18px) !important;
    gap: 6px !important;
    padding: 5px !important;
    border-radius: 999px !important;
    background: rgba(15, 23, 42, 0.82) !important;
    box-shadow: 0 12px 30px rgba(2, 6, 23, 0.24) !important;
  }

  body.preview-fullscreen-active #backToEditorPreviewBtn,
  body.preview-fullscreen-active #resultFromPreviewBtn,
  body.preview-fullscreen-active #exitPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #backToEditorPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #resultFromPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #exitPreviewBtn,
  #previewPanel:fullscreen #backToEditorPreviewBtn,
  #previewPanel:fullscreen #resultFromPreviewBtn,
  #previewPanel:fullscreen #exitPreviewBtn,
  #previewPanel:-webkit-full-screen #backToEditorPreviewBtn,
  #previewPanel:-webkit-full-screen #resultFromPreviewBtn,
  #previewPanel:-webkit-full-screen #exitPreviewBtn {
    min-height: 32px !important;
    width: auto !important;
    padding: 0 11px !important;
    font-size: 0.78rem !important;
    border-radius: 999px !important;
    white-space: nowrap !important;
  }

  body.preview-fullscreen-active .preview-actions #desktopPreviewBtn,
  body.preview-fullscreen-active .preview-actions #fullPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #desktopPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #fullPreviewBtn,
  #previewPanel:fullscreen .preview-actions #desktopPreviewBtn,
  #previewPanel:fullscreen .preview-actions #fullPreviewBtn,
  #previewPanel:-webkit-full-screen .preview-actions #desktopPreviewBtn,
  #previewPanel:-webkit-full-screen .preview-actions #fullPreviewBtn {
    display: none !important;
  }
}

/* Desktop monitor preview should not create a huge blank/tall frame on phone. */
@media (hover: none) and (pointer: coarse), (max-width: 760px), (orientation: landscape) and (max-height: 560px) {
  .preview-panel.mobile-desktop-preview,
  .preview-panel.mobile-landscape-desktop-preview {
    overflow: visible !important;
  }

  .preview-panel.mobile-desktop-preview .preview-frame-shell,
  .preview-panel.mobile-landscape-desktop-preview .preview-frame-shell {
    position: relative !important;
    overflow: hidden !important;
    max-width: calc(100vw - 18px) !important;
    min-height: 0 !important;
    border: 5px solid #111827 !important;
    border-radius: 18px !important;
    background: #0f172a !important;
    box-shadow: 0 14px 35px rgba(2, 6, 23, 0.28) !important;
  }

  .preview-panel.mobile-desktop-preview #previewFrame,
  .preview-panel.mobile-landscape-desktop-preview #previewFrame {
    display: block !important;
    flex: none !important;
    border: 0 !important;
    border-radius: 8px !important;
    background: #ffffff !important;
  }

  .preview-panel.mobile-desktop-preview .desktop-monitor-label,
  .preview-panel.mobile-landscape-desktop-preview .desktop-monitor-label {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    height: 28px !important;
    margin: 0 !important;
    padding: 0 4px 6px !important;
    color: #dbeafe !important;
    font-size: 0.66rem !important;
    line-height: 1 !important;
  }

  .preview-panel.mobile-desktop-preview::after,
  .preview-panel.mobile-landscape-desktop-preview::after {
    display: none !important;
    content: none !important;
  }
}

/* In fullscreen/landscape, use the phone screen as the monitor. No tall stand, no wasted space. */
@media (orientation: landscape) and (max-height: 560px) {
  body.preview-fullscreen-active .preview-panel.mobile-desktop-preview,
  body.preview-fullscreen-active .preview-panel.mobile-landscape-desktop-preview,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-desktop-preview,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-landscape-desktop-preview,
  #previewPanel:fullscreen.mobile-desktop-preview,
  #previewPanel:fullscreen.mobile-landscape-desktop-preview,
  #previewPanel:-webkit-full-screen.mobile-desktop-preview,
  #previewPanel:-webkit-full-screen.mobile-landscape-desktop-preview {
    display: grid !important;
    place-items: center !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #020617 !important;
  }

  body.preview-fullscreen-active .preview-panel.mobile-desktop-preview .preview-frame-shell,
  body.preview-fullscreen-active .preview-panel.mobile-landscape-desktop-preview .preview-frame-shell,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-desktop-preview .preview-frame-shell,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-landscape-desktop-preview .preview-frame-shell,
  #previewPanel:fullscreen.mobile-desktop-preview .preview-frame-shell,
  #previewPanel:fullscreen.mobile-landscape-desktop-preview .preview-frame-shell,
  #previewPanel:-webkit-full-screen.mobile-desktop-preview .preview-frame-shell,
  #previewPanel:-webkit-full-screen.mobile-landscape-desktop-preview .preview-frame-shell {
    margin: 0 auto !important;
    border-width: 4px !important;
    border-radius: 10px !important;
    box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.32), 0 18px 45px rgba(2, 6, 23, 0.38) !important;
  }

  body.preview-fullscreen-active .preview-panel.mobile-desktop-preview .preview-frame-shell::before,
  body.preview-fullscreen-active .preview-panel.mobile-desktop-preview .preview-frame-shell::after,
  body.preview-fullscreen-active .preview-panel.mobile-landscape-desktop-preview .preview-frame-shell::before,
  body.preview-fullscreen-active .preview-panel.mobile-landscape-desktop-preview .preview-frame-shell::after,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-desktop-preview .preview-frame-shell::before,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-desktop-preview .preview-frame-shell::after,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-landscape-desktop-preview .preview-frame-shell::before,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-landscape-desktop-preview .preview-frame-shell::after,
  #previewPanel:fullscreen.mobile-desktop-preview .preview-frame-shell::before,
  #previewPanel:fullscreen.mobile-desktop-preview .preview-frame-shell::after,
  #previewPanel:fullscreen.mobile-landscape-desktop-preview .preview-frame-shell::before,
  #previewPanel:fullscreen.mobile-landscape-desktop-preview .preview-frame-shell::after,
  #previewPanel:-webkit-full-screen.mobile-desktop-preview .preview-frame-shell::before,
  #previewPanel:-webkit-full-screen.mobile-desktop-preview .preview-frame-shell::after,
  #previewPanel:-webkit-full-screen.mobile-landscape-desktop-preview .preview-frame-shell::before,
  #previewPanel:-webkit-full-screen.mobile-landscape-desktop-preview .preview-frame-shell::after {
    display: none !important;
    content: none !important;
  }

  body.preview-fullscreen-active .preview-panel.mobile-desktop-preview .desktop-monitor-label,
  body.preview-fullscreen-active .preview-panel.mobile-landscape-desktop-preview .desktop-monitor-label,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-desktop-preview .desktop-monitor-label,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel.mobile-landscape-desktop-preview .desktop-monitor-label,
  #previewPanel:fullscreen.mobile-desktop-preview .desktop-monitor-label,
  #previewPanel:fullscreen.mobile-landscape-desktop-preview .desktop-monitor-label,
  #previewPanel:-webkit-full-screen.mobile-desktop-preview .desktop-monitor-label,
  #previewPanel:-webkit-full-screen.mobile-landscape-desktop-preview .desktop-monitor-label {
    display: none !important;
  }
}


/* ==========================================================================
   MOBILE DESKTOP PREVIEW LAYOUT REPAIR - 2026-07-10 v3
   Centers the embedded monitor and gives fullscreen a clean, fitted canvas.
   ========================================================================== */

.right-column,
.preview-panel,
.preview-frame-shell {
  min-width: 0;
}

@media (hover: none) and (pointer: coarse), (max-width: 760px) {
  .preview-panel.mobile-desktop-preview,
  .preview-panel.mobile-landscape-desktop-preview {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }

  .preview-panel.mobile-desktop-preview .preview-frame-shell,
  .preview-panel.mobile-landscape-desktop-preview .preview-frame-shell {
    box-sizing: border-box !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding: 0 !important;
    max-width: calc(100% - 12px) !important;
  }

  .preview-panel.mobile-desktop-preview #previewFrame,
  .preview-panel.mobile-landscape-desktop-preview #previewFrame {
    box-sizing: border-box !important;
    margin: 0 !important;
  }

  /* Keep the normal in-page monitor centered inside the preview card. */
  body:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen)
    .preview-panel.mobile-desktop-preview .preview-frame-shell {
    border: 5px solid #111827 !important;
    border-radius: 18px !important;
  }

  body:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen)
    .preview-panel.mobile-desktop-preview .desktop-monitor-label {
    position: absolute !important;
    top: 0 !important;
    left: 8px !important;
    right: 8px !important;
    z-index: 2 !important;
    height: 30px !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen)
    .preview-panel.mobile-desktop-preview .preview-frame-shell::before {
    bottom: 8px !important;
  }

  body:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen)
    .preview-panel.mobile-desktop-preview .preview-frame-shell::after {
    bottom: 0 !important;
  }
}

/* Fullscreen preview: output first, compact controls at the bottom. */
body.preview-fullscreen-active .preview-panel,
#previewPanel:fullscreen,
#previewPanel:-webkit-full-screen,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel {
  position: fixed !important;
  inset: 0 !important;
  z-index: 50000 !important;
  display: flex !important;
  flex-direction: column !important;
  width: 100dvw !important;
  height: 100dvh !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: #020617 !important;
  box-shadow: none !important;
  overflow: hidden !important;
}

body.preview-fullscreen-active .preview-panel .preview-frame-shell,
#previewPanel:fullscreen .preview-frame-shell,
#previewPanel:-webkit-full-screen .preview-frame-shell,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-frame-shell {
  order: 1 !important;
  flex: 0 0 auto !important;
  align-self: center !important;
  box-sizing: border-box !important;
  margin: auto !important;
  padding: 0 !important;
  border: 4px solid #1e293b !important;
  border-radius: 10px !important;
  background: #0f172a !important;
  box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.22), 0 16px 44px rgba(0, 0, 0, 0.35) !important;
  overflow: hidden !important;
}

body.preview-fullscreen-active .preview-panel .preview-frame-shell::before,
body.preview-fullscreen-active .preview-panel .preview-frame-shell::after,
#previewPanel:fullscreen .preview-frame-shell::before,
#previewPanel:fullscreen .preview-frame-shell::after,
#previewPanel:-webkit-full-screen .preview-frame-shell::before,
#previewPanel:-webkit-full-screen .preview-frame-shell::after,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-frame-shell::before,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-frame-shell::after {
  display: none !important;
  content: none !important;
}

body.preview-fullscreen-active .preview-panel .desktop-monitor-label,
#previewPanel:fullscreen .desktop-monitor-label,
#previewPanel:-webkit-full-screen .desktop-monitor-label,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .desktop-monitor-label {
  display: none !important;
}

body.preview-fullscreen-active .preview-panel .panel-header,
body.preview-fullscreen-active .preview-panel .preview-header,
#previewPanel:fullscreen .panel-header,
#previewPanel:fullscreen .preview-header,
#previewPanel:-webkit-full-screen .panel-header,
#previewPanel:-webkit-full-screen .preview-header,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
  position: relative !important;
  inset: auto !important;
  order: 2 !important;
  z-index: 50010 !important;
  flex: 0 0 auto !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 7px max(8px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)) !important;
  border: 0 !important;
  border-top: 1px solid rgba(148, 163, 184, 0.22) !important;
  border-radius: 0 !important;
  background: rgba(2, 6, 23, 0.94) !important;
  box-shadow: 0 -10px 28px rgba(2, 6, 23, 0.3) !important;
  pointer-events: auto !important;
}

body.preview-fullscreen-active .preview-panel .preview-header > div:first-child,
#previewPanel:fullscreen .preview-header > div:first-child,
#previewPanel:-webkit-full-screen .preview-header > div:first-child,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header > div:first-child {
  display: none !important;
}

body.preview-fullscreen-active .preview-panel .preview-actions,
#previewPanel:fullscreen .preview-actions,
#previewPanel:-webkit-full-screen .preview-actions,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
  display: flex !important;
  grid-template-columns: none !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 7px !important;
  width: auto !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 4px !important;
  border: 1px solid rgba(148, 163, 184, 0.3) !important;
  border-radius: 999px !important;
  background: rgba(15, 23, 42, 0.96) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28) !important;
  pointer-events: auto !important;
}

body.preview-fullscreen-active .preview-actions .layout-btn[data-layout],
body.preview-fullscreen-active .preview-actions #desktopPreviewBtn,
body.preview-fullscreen-active .preview-actions #fullPreviewBtn,
#previewPanel:fullscreen .preview-actions .layout-btn[data-layout],
#previewPanel:fullscreen .preview-actions #desktopPreviewBtn,
#previewPanel:fullscreen .preview-actions #fullPreviewBtn,
#previewPanel:-webkit-full-screen .preview-actions .layout-btn[data-layout],
#previewPanel:-webkit-full-screen .preview-actions #desktopPreviewBtn,
#previewPanel:-webkit-full-screen .preview-actions #fullPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions .layout-btn[data-layout],
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #desktopPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #fullPreviewBtn {
  display: none !important;
}

body.preview-fullscreen-active #backToEditorPreviewBtn,
body.preview-fullscreen-active #resultFromPreviewBtn,
body.preview-fullscreen-active #exitPreviewBtn,
#previewPanel:fullscreen #backToEditorPreviewBtn,
#previewPanel:fullscreen #resultFromPreviewBtn,
#previewPanel:fullscreen #exitPreviewBtn,
#previewPanel:-webkit-full-screen #backToEditorPreviewBtn,
#previewPanel:-webkit-full-screen #resultFromPreviewBtn,
#previewPanel:-webkit-full-screen #exitPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #backToEditorPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #resultFromPreviewBtn,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #exitPreviewBtn {
  position: static !important;
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  align-items: center !important;
  justify-content: center !important;
  width: auto !important;
  min-width: 0 !important;
  min-height: 38px !important;
  height: 38px !important;
  margin: 0 !important;
  padding: 0 16px !important;
  border-radius: 999px !important;
  font-size: 0.84rem !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

body.preview-fullscreen-active #backToEditorPreviewBtn.hidden,
body.preview-fullscreen-active #resultFromPreviewBtn.hidden,
body.preview-fullscreen-active #exitPreviewBtn.hidden,
#previewPanel:fullscreen #backToEditorPreviewBtn.hidden,
#previewPanel:fullscreen #resultFromPreviewBtn.hidden,
#previewPanel:fullscreen #exitPreviewBtn.hidden,
#previewPanel:-webkit-full-screen #backToEditorPreviewBtn.hidden,
#previewPanel:-webkit-full-screen #resultFromPreviewBtn.hidden,
#previewPanel:-webkit-full-screen #exitPreviewBtn.hidden,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #backToEditorPreviewBtn.hidden,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #resultFromPreviewBtn.hidden,
body.editor-fullscreen-active.preview-inside-editor-fullscreen #exitPreviewBtn.hidden {
  display: none !important;
}

@media (orientation: landscape) and (max-height: 620px) {
  body.preview-fullscreen-active .preview-panel .panel-header,
  body.preview-fullscreen-active .preview-panel .preview-header,
  #previewPanel:fullscreen .panel-header,
  #previewPanel:fullscreen .preview-header,
  #previewPanel:-webkit-full-screen .panel-header,
  #previewPanel:-webkit-full-screen .preview-header,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
    padding-top: 4px !important;
    padding-bottom: calc(4px + env(safe-area-inset-bottom)) !important;
  }

  body.preview-fullscreen-active #backToEditorPreviewBtn,
  body.preview-fullscreen-active #resultFromPreviewBtn,
  body.preview-fullscreen-active #exitPreviewBtn,
  #previewPanel:fullscreen #backToEditorPreviewBtn,
  #previewPanel:fullscreen #resultFromPreviewBtn,
  #previewPanel:fullscreen #exitPreviewBtn,
  #previewPanel:-webkit-full-screen #backToEditorPreviewBtn,
  #previewPanel:-webkit-full-screen #resultFromPreviewBtn,
  #previewPanel:-webkit-full-screen #exitPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #backToEditorPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #resultFromPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #exitPreviewBtn {
    min-height: 34px !important;
    height: 34px !important;
    padding: 0 13px !important;
    font-size: 0.78rem !important;
  }
}

/* Admin: student assistance controls */
.admin-settings-card {
  margin: 18px 20px 0;
  padding: 18px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--primary-soft) 58%, var(--solid-card)), var(--solid-card) 62%);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.admin-settings-heading,
.assistance-master-row,
.assistance-settings-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.admin-settings-heading {
  align-items: flex-start;
  margin-bottom: 14px;
}

.admin-settings-heading h3 {
  margin-bottom: 5px;
}

.assistance-mode-badge {
  flex: 0 0 auto;
  border: 1px solid color-mix(in srgb, var(--success) 42%, var(--line));
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--success);
  background: var(--success-soft);
  font-size: 0.75rem;
  font-weight: 1000;
  letter-spacing: 0.06em;
  white-space: nowrap;
  text-transform: uppercase;
}

.assistance-mode-badge.off {
  border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
  color: var(--danger);
  background: var(--danger-soft);
}

.assistance-master-row {
  margin-bottom: 12px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--solid-card) 90%, var(--primary-soft));
}

.assistance-master-row > div,
.assistance-option-copy {
  min-width: 0;
}

.assistance-master-row strong,
.assistance-master-row small,
.assistance-option-copy strong,
.assistance-option-copy small {
  display: block;
}

.assistance-master-row small,
.assistance-option-copy small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
}

.assistance-settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.assistance-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 104px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--solid-card);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.assistance-option:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}

.assistance-option-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--primary-soft);
  font-size: 1.15rem;
}

.admin-settings-card.master-disabled .assistance-option {
  opacity: 0.58;
}

.admin-switch {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.admin-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.admin-switch-track {
  position: relative;
  display: block;
  width: 48px;
  height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 28%, var(--solid-card));
  transition: background 160ms ease, border-color 160ms ease;
}

.admin-switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 7px rgba(15, 23, 42, 0.3);
  transition: transform 160ms ease;
}

.admin-switch input:checked + .admin-switch-track {
  border-color: var(--success);
  background: var(--success);
}

.admin-switch input:checked + .admin-switch-track .admin-switch-thumb {
  transform: translateX(20px);
}

.admin-switch input:focus-visible + .admin-switch-track {
  outline: 3px solid var(--primary-soft);
  outline-offset: 2px;
}

.assistance-settings-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 14px;
}

.assistance-settings-actions button {
  min-height: 44px;
}

#publishAssistanceBtn.requires-login {
  border-color: var(--warning);
  color: color-mix(in srgb, var(--warning) 72%, var(--text));
  background: color-mix(in srgb, var(--warning) 14%, var(--solid-card));
}

.assistance-settings-status {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--primary-soft) 46%, transparent);
}

.assistance-settings-status.success {
  color: var(--success);
  background: var(--success-soft);
}

.assistance-settings-status.warning {
  color: color-mix(in srgb, var(--warning) 78%, var(--text));
  background: color-mix(in srgb, var(--warning) 14%, var(--solid-card));
}

.assistance-settings-status.error {
  color: var(--danger);
  background: var(--danger-soft);
}

.assistance-feature-hidden,
body.code-suggestions-disabled #suggestionBox,
body.code-helper-disabled #codeHelperFloatingBtn,
body.code-helper-disabled #errorCheckerPanel,
body.teacher-feedback-disabled #aiReviewTopBtn,
body.teacher-feedback-disabled #aiReviewPanel {
  display: none !important;
}

@media (max-width: 1000px) {
  .assistance-settings-grid {
    grid-template-columns: 1fr;
  }

  .assistance-option {
    min-height: 0;
  }
}

@media (max-width: 820px) {
  /* One continuous scroll keeps the new settings and rubric builder reachable. */
  #adminOverlay .admin-modal,
  body.admin-open #adminOverlay .admin-modal {
    display: block !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  #adminOverlay .modal-header {
    position: sticky !important;
    top: 0 !important;
  }

  #studentAssistanceSettings {
    margin: 10px 10px 0 !important;
    padding: 12px !important;
    border-radius: 16px !important;
  }

  #adminOverlay .pin-screen,
  #adminOverlay .admin-form {
    display: grid !important;
    flex: none !important;
    min-height: auto !important;
    overflow: visible !important;
    padding: 12px 10px calc(90px + env(safe-area-inset-bottom)) !important;
  }

  #adminOverlay .pin-screen.hidden,
  #adminOverlay .admin-form.hidden {
    display: none !important;
  }

  .admin-settings-heading {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .assistance-mode-badge {
    justify-self: start;
  }

  .assistance-master-row {
    padding: 11px;
  }

  .assistance-option {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 11px;
  }

  .assistance-option-icon {
    width: 34px;
    height: 34px;
  }

  .assistance-settings-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .assistance-settings-actions button {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .assistance-option {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .assistance-option-icon {
    display: none;
  }
}

/* Keep login/form visibility reliable despite older high-specificity admin rules. */
body.admin-open #adminOverlay .pin-screen.teacher-login-screen.hidden,
body.admin-open #adminOverlay .admin-form.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  body.admin-open #adminOverlay .pin-screen.teacher-login-screen {
    min-height: auto !important;
    place-items: start stretch !important;
    padding: 12px 10px calc(90px + env(safe-area-inset-bottom)) !important;
  }

  body.admin-open #adminOverlay .pin-screen.teacher-login-screen.hidden {
    display: none !important;
  }
}

/* ========================================================================== 
   DESKTOP PREVIEW ISOLATION - 2026-07-10
   The monitor simulation and phone bottom toolbar must never affect computers.
   ========================================================================== */

html[data-device-mode="desktop"] .desktop-preview-toggle {
  display: none !important;
}


html[data-device-mode="desktop"] .preview-panel .preview-actions {
  display: flex !important;
  grid-template-columns: none !important;
  flex-wrap: wrap !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 8px !important;
  width: auto !important;
}

html[data-device-mode="desktop"] .preview-panel .preview-actions .layout-btn[data-layout],
html[data-device-mode="desktop"] .preview-panel .preview-actions #fullPreviewBtn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: auto !important;
  min-height: 38px !important;
  padding: 0 14px !important;
  font-size: 0.86rem !important;
  white-space: nowrap !important;
}

html[data-device-mode="desktop"] .preview-panel .preview-actions #exitPreviewBtn.hidden,
html[data-device-mode="desktop"] .preview-panel .preview-actions #backToEditorPreviewBtn.hidden,
html[data-device-mode="desktop"] .preview-panel .preview-actions #resultFromPreviewBtn.hidden {
  display: none !important;
}

html[data-device-mode="desktop"] .preview-panel.mobile-desktop-preview,
html[data-device-mode="desktop"] .preview-panel.mobile-landscape-desktop-preview {
  width: auto !important;
  max-width: none !important;
  overflow: hidden !important;
}

html[data-device-mode="desktop"] .preview-panel .preview-frame-shell {
  position: relative !important;
  display: block !important;
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  height: auto !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: #ffffff !important;
  box-shadow: none !important;
  overflow: hidden !important;
}

html[data-device-mode="desktop"] .preview-panel .preview-frame-shell::before,
html[data-device-mode="desktop"] .preview-panel .preview-frame-shell::after,
html[data-device-mode="desktop"] .preview-panel .desktop-monitor-label {
  display: none !important;
  content: none !important;
}

html[data-device-mode="desktop"] .preview-panel #previewFrame {
  position: static !important;
  inset: auto !important;
  display: block !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  height: auto !important;
  max-height: none !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  transform: none !important;
  transform-origin: center center !important;
}

/* Normal desktop fullscreen: full output canvas with compact controls on top. */
html[data-device-mode="desktop"] body.preview-fullscreen-active .preview-panel,
html[data-device-mode="desktop"] #previewPanel:fullscreen,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen,
html[data-device-mode="desktop"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel {
  position: fixed !important;
  inset: 0 !important;
  z-index: 50000 !important;
  display: flex !important;
  flex-direction: column !important;
  width: 100vw !important;
  height: 100vh !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: #ffffff !important;
  box-shadow: none !important;
  overflow: hidden !important;
}

html[data-device-mode="desktop"] body.preview-fullscreen-active .preview-panel .preview-frame-shell,
html[data-device-mode="desktop"] #previewPanel:fullscreen .preview-frame-shell,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen .preview-frame-shell,
html[data-device-mode="desktop"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-frame-shell {
  order: 1 !important;
  flex: 1 1 auto !important;
  align-self: stretch !important;
  width: 100% !important;
  height: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: #ffffff !important;
  box-shadow: none !important;
  overflow: hidden !important;
}

html[data-device-mode="desktop"] body.preview-fullscreen-active .preview-panel #previewFrame,
html[data-device-mode="desktop"] #previewPanel:fullscreen #previewFrame,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen #previewFrame,
html[data-device-mode="desktop"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel #previewFrame {
  position: static !important;
  inset: auto !important;
  flex: 1 1 auto !important;
  width: 100% !important;
  height: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: 100% !important;
  max-height: 100% !important;
  margin: 0 !important;
  border: 0 !important;
  transform: none !important;
  transform-origin: center center !important;
}

html[data-device-mode="desktop"] body.preview-fullscreen-active .preview-panel .panel-header,
html[data-device-mode="desktop"] body.preview-fullscreen-active .preview-panel .preview-header,
html[data-device-mode="desktop"] #previewPanel:fullscreen .panel-header,
html[data-device-mode="desktop"] #previewPanel:fullscreen .preview-header,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen .panel-header,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen .preview-header,
html[data-device-mode="desktop"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .panel-header,
html[data-device-mode="desktop"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
  position: absolute !important;
  top: 12px !important;
  right: 12px !important;
  bottom: auto !important;
  left: auto !important;
  order: initial !important;
  z-index: 50010 !important;
  display: flex !important;
  justify-content: flex-end !important;
  align-items: center !important;
  width: auto !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 999px !important;
  background: transparent !important;
  box-shadow: none !important;
  pointer-events: none !important;
}

html[data-device-mode="desktop"] body.preview-fullscreen-active .preview-panel .preview-actions,
html[data-device-mode="desktop"] #previewPanel:fullscreen .preview-actions,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen .preview-actions,
html[data-device-mode="desktop"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
  display: flex !important;
  grid-template-columns: none !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 8px !important;
  width: auto !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 8px !important;
  border: 1px solid rgba(191, 219, 254, 0.92) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, 0.92) !important;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.16) !important;
  backdrop-filter: blur(12px) !important;
  pointer-events: auto !important;
}

html[data-device-mode="desktop"] body.preview-fullscreen-active #backToEditorPreviewBtn,
html[data-device-mode="desktop"] body.preview-fullscreen-active #resultFromPreviewBtn,
html[data-device-mode="desktop"] body.preview-fullscreen-active #exitPreviewBtn,
html[data-device-mode="desktop"] #previewPanel:fullscreen #backToEditorPreviewBtn,
html[data-device-mode="desktop"] #previewPanel:fullscreen #resultFromPreviewBtn,
html[data-device-mode="desktop"] #previewPanel:fullscreen #exitPreviewBtn,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen #backToEditorPreviewBtn,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen #resultFromPreviewBtn,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen #exitPreviewBtn {
  position: static !important;
  width: auto !important;
  min-width: 0 !important;
  min-height: 38px !important;
  height: 38px !important;
  margin: 0 !important;
  padding: 0 14px !important;
  border-radius: 999px !important;
  font-size: 0.84rem !important;
  white-space: nowrap !important;
}

html[data-device-mode="desktop"] body.preview-fullscreen-active #backToEditorPreviewBtn.hidden,
html[data-device-mode="desktop"] body.preview-fullscreen-active #resultFromPreviewBtn.hidden,
html[data-device-mode="desktop"] body.preview-fullscreen-active #exitPreviewBtn.hidden,
html[data-device-mode="desktop"] #previewPanel:fullscreen #backToEditorPreviewBtn.hidden,
html[data-device-mode="desktop"] #previewPanel:fullscreen #resultFromPreviewBtn.hidden,
html[data-device-mode="desktop"] #previewPanel:fullscreen #exitPreviewBtn.hidden,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen #backToEditorPreviewBtn.hidden,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen #resultFromPreviewBtn.hidden,
html[data-device-mode="desktop"] #previewPanel:-webkit-full-screen #exitPreviewBtn.hidden {
  display: none !important;
}

/* ========================================================================== 
   FINAL PHONE-ONLY PREVIEW CONTROLS - 2026-07-10
   Re-applies the mobile monitor experience without changing computer layout.
   ========================================================================== */

/* Phone: hide desktop layout choices and show only the dedicated monitor tools. */
html[data-device-mode="phone"] .preview-panel .preview-actions .layout-btn[data-layout] {
  display: none !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  gap: 8px !important;
  width: 100% !important;
  max-width: none !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn,
html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 42px !important;
  padding: 0 10px !important;
  border-radius: 999px !important;
  font-size: 0.84rem !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn {
  font-size: 0 !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn::before {
  content: 'Desktop Monitor';
  font-size: 0.84rem !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn.active::before {
  content: 'Phone View';
}

html[data-device-mode="phone"] .preview-panel .preview-actions #exitPreviewBtn.hidden,
html[data-device-mode="phone"] .preview-panel .preview-actions #backToEditorPreviewBtn.hidden,
html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn.hidden,
html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn.hidden {
  display: none !important;
}

html[data-device-mode="phone"] .preview-panel.mobile-desktop-preview,
html[data-device-mode="phone"] .preview-panel.mobile-landscape-desktop-preview {
  width: 100% !important;
  max-width: 100% !important;
  overflow: hidden !important;
}

html[data-device-mode="phone"] body:not(.preview-fullscreen-active):not(.preview-inside-editor-fullscreen)
  .preview-panel.mobile-desktop-preview .preview-frame-shell {
  margin-left: auto !important;
  margin-right: auto !important;
  max-width: calc(100% - 12px) !important;
}

/* Phone fullscreen: fitted output canvas with a small bottom control bar. */
html[data-device-mode="phone"] body.preview-fullscreen-active .preview-panel,
html[data-device-mode="phone"] #previewPanel:fullscreen,
html[data-device-mode="phone"] #previewPanel:-webkit-full-screen,
html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel {
  position: fixed !important;
  inset: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  width: 100dvw !important;
  height: 100dvh !important;
  padding: 0 !important;
  background: #020617 !important;
  overflow: hidden !important;
}

html[data-device-mode="phone"] body.preview-fullscreen-active .preview-panel .preview-frame-shell,
html[data-device-mode="phone"] #previewPanel:fullscreen .preview-frame-shell,
html[data-device-mode="phone"] #previewPanel:-webkit-full-screen .preview-frame-shell,
html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-frame-shell {
  order: 1 !important;
  flex: 0 0 auto !important;
  align-self: center !important;
  margin: auto !important;
  max-width: calc(100dvw - 10px) !important;
  max-height: calc(100dvh - 72px) !important;
  overflow: hidden !important;
}

html[data-device-mode="phone"] body.preview-fullscreen-active .preview-panel .preview-header,
html[data-device-mode="phone"] #previewPanel:fullscreen .preview-header,
html[data-device-mode="phone"] #previewPanel:-webkit-full-screen .preview-header,
html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
  position: relative !important;
  inset: auto !important;
  order: 2 !important;
  flex: 0 0 auto !important;
  width: 100% !important;
  padding: 6px max(7px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(7px, env(safe-area-inset-left)) !important;
  border-top: 1px solid rgba(148, 163, 184, 0.22) !important;
  background: rgba(2, 6, 23, 0.96) !important;
}

html[data-device-mode="phone"] body.preview-fullscreen-active .preview-panel .preview-actions,
html[data-device-mode="phone"] #previewPanel:fullscreen .preview-actions,
html[data-device-mode="phone"] #previewPanel:-webkit-full-screen .preview-actions,
html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions {
  display: flex !important;
  grid-template-columns: none !important;
  flex-wrap: nowrap !important;
  justify-content: center !important;
  gap: 6px !important;
  width: auto !important;
  max-width: 100% !important;
  padding: 3px !important;
}

html[data-device-mode="phone"] body.preview-fullscreen-active .preview-actions .layout-btn[data-layout],
html[data-device-mode="phone"] body.preview-fullscreen-active .preview-actions #desktopPreviewBtn,
html[data-device-mode="phone"] body.preview-fullscreen-active .preview-actions #fullPreviewBtn,
html[data-device-mode="phone"] #previewPanel:fullscreen .preview-actions .layout-btn[data-layout],
html[data-device-mode="phone"] #previewPanel:fullscreen .preview-actions #desktopPreviewBtn,
html[data-device-mode="phone"] #previewPanel:fullscreen .preview-actions #fullPreviewBtn,
html[data-device-mode="phone"] #previewPanel:-webkit-full-screen .preview-actions .layout-btn[data-layout],
html[data-device-mode="phone"] #previewPanel:-webkit-full-screen .preview-actions #desktopPreviewBtn,
html[data-device-mode="phone"] #previewPanel:-webkit-full-screen .preview-actions #fullPreviewBtn {
  display: none !important;
}

html[data-device-mode="phone"] body.preview-fullscreen-active #backToEditorPreviewBtn,
html[data-device-mode="phone"] body.preview-fullscreen-active #resultFromPreviewBtn,
html[data-device-mode="phone"] body.preview-fullscreen-active #exitPreviewBtn,
html[data-device-mode="phone"] #previewPanel:fullscreen #backToEditorPreviewBtn,
html[data-device-mode="phone"] #previewPanel:fullscreen #resultFromPreviewBtn,
html[data-device-mode="phone"] #previewPanel:fullscreen #exitPreviewBtn,
html[data-device-mode="phone"] #previewPanel:-webkit-full-screen #backToEditorPreviewBtn,
html[data-device-mode="phone"] #previewPanel:-webkit-full-screen #resultFromPreviewBtn,
html[data-device-mode="phone"] #previewPanel:-webkit-full-screen #exitPreviewBtn {
  width: auto !important;
  min-width: 0 !important;
  min-height: 34px !important;
  height: 34px !important;
  padding: 0 12px !important;
  border-radius: 999px !important;
  font-size: 0.76rem !important;
  white-space: nowrap !important;
}

/* Landscape phone fullscreen always uses the complete 1366 x 768 desktop view. */
@media (orientation: landscape) and (max-height: 620px) {
  html[data-device-mode="phone"] body.preview-fullscreen-active .preview-panel,
  html[data-device-mode="phone"] #previewPanel:fullscreen,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel {
    place-content: center !important;
  }

  html[data-device-mode="phone"] body.preview-fullscreen-active .preview-panel .preview-frame-shell,
  html[data-device-mode="phone"] #previewPanel:fullscreen .preview-frame-shell,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen .preview-frame-shell,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-frame-shell {
    max-height: calc(100dvh - 58px) !important;
    border-width: 3px !important;
    border-radius: 8px !important;
  }

  html[data-device-mode="phone"] body.preview-fullscreen-active .preview-panel .preview-header,
  html[data-device-mode="phone"] #previewPanel:fullscreen .preview-header,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen .preview-header,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-header {
    padding-top: 3px !important;
    padding-bottom: calc(3px + env(safe-area-inset-bottom)) !important;
  }
}

/* Narrow-screen safety net: keep the phone preview controls correct even when
   a mobile browser reports an unusual user agent or pointer type. */
@media (max-width: 760px) {
  .preview-panel .preview-actions .layout-btn[data-layout] {
    display: none !important;
  }

  .preview-panel .desktop-preview-toggle,
  .preview-panel .preview-actions #desktopPreviewBtn,
  .preview-panel .preview-actions #fullPreviewBtn {
    display: inline-flex !important;
  }

  .preview-panel .preview-actions {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    gap: 8px !important;
    width: 100% !important;
    max-width: none !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn,
  .preview-panel .preview-actions #fullPreviewBtn {
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    min-width: 0 !important;
  }
}

/* =========================================================
   Free Student Accounts, Welcome Gate, Projects & Tracker
   ========================================================= */
body.entry-gate-active,
body.student-dashboard-active,
body.student-auth-open {
  overflow: hidden;
}

.entry-gate,
.student-auth-overlay,
.student-dashboard-screen {
  position: fixed;
  inset: 0;
  z-index: 12000;
}

.entry-gate {
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  background:
    radial-gradient(circle at 14% 14%, rgba(37, 99, 235, 0.32), transparent 30rem),
    radial-gradient(circle at 88% 80%, rgba(34, 197, 94, 0.2), transparent 28rem),
    linear-gradient(145deg, var(--bg), var(--bg-2));
}

.entry-card {
  width: min(760px, 100%);
  padding: clamp(24px, 4vw, 48px);
  border: 1px solid var(--line-strong);
  border-radius: 32px;
  background: var(--card);
  box-shadow: var(--shadow-strong);
  text-align: center;
  backdrop-filter: blur(18px);
}

.entry-logo,
.student-auth-icon {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  margin: 0 auto 18px;
  border-radius: 24px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  box-shadow: 0 18px 40px rgba(37, 99, 235, 0.28);
  font-size: 1.6rem;
  font-weight: 900;
}

.entry-card h1,
.student-auth-card h2,
.student-dashboard-header h1,
.dashboard-hero-card h2 {
  margin: 6px 0 10px;
}

.entry-lead {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 1.05rem;
}

.entry-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.entry-choice {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 124px;
  padding: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  color: var(--text);
  background: var(--solid-card);
  text-align: left;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.entry-choice:hover,
.entry-choice:focus-visible {
  transform: translateY(-3px);
  border-color: var(--primary);
  box-shadow: var(--shadow);
  outline: none;
}

.entry-choice.primary-choice {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #2563eb, #0891b2);
}

.entry-choice.resume-choice {
  min-height: auto;
  margin: 0 0 16px;
  border-color: rgba(22, 163, 74, 0.42);
  background: var(--success-soft);
}

.entry-choice-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.24);
  font-size: 1.6rem;
}

.guest-choice .entry-choice-icon,
.resume-choice .entry-choice-icon {
  background: var(--primary-soft);
}

.entry-choice strong,
.entry-choice small {
  display: block;
}

.entry-choice strong {
  margin-bottom: 6px;
  font-size: 1.03rem;
}

.entry-choice small {
  color: inherit;
  opacity: 0.82;
  line-height: 1.45;
}

.entry-free-note {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.student-auth-overlay {
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: auto;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(12px);
}

.student-auth-card {
  position: relative;
  width: min(470px, 100%);
  padding: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 28px;
  background: var(--solid-card);
  box-shadow: var(--shadow-strong);
}

.student-auth-card label {
  display: grid;
  gap: 7px;
  margin-top: 16px;
  font-weight: 800;
}

.student-auth-card input,
.student-register-grid input,
.student-register-grid select,
.student-tracker-toolbar input,
.student-tracker-toolbar select,
.project-toolbar input,
.project-toolbar select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 10px 13px;
  color: var(--text);
  background: var(--solid-card);
}

.student-auth-card input:focus,
.student-register-grid input:focus,
.student-register-grid select:focus,
.student-tracker-toolbar input:focus,
.student-tracker-toolbar select:focus,
.project-toolbar input:focus,
.project-toolbar select:focus {
  border-color: var(--primary);
  outline: 3px solid var(--primary-soft);
}

.auth-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
}

.password-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.password-toggle-btn {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 0 14px;
  color: var(--text);
  background: var(--bg-2);
  font-weight: 800;
  cursor: pointer;
}

.wide-btn {
  width: 100%;
  margin-top: 14px;
}

.password-change-overlay {
  z-index: 12100;
}

.student-dashboard-screen {
  overflow: auto;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.2), transparent 30rem),
    linear-gradient(145deg, var(--bg), var(--bg-2));
}

.student-dashboard-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: min(1260px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0;
  background: linear-gradient(to bottom, var(--bg) 72%, transparent);
}

.dashboard-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.dashboard-brand .logo-mark {
  flex: 0 0 auto;
}

.dashboard-header-actions,
.student-register-actions,
.student-import-preview-head,
.student-admin-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.student-dashboard-main {
  width: min(1260px, calc(100% - 32px));
  margin: 0 auto;
  padding: 10px 0 48px;
}

.dashboard-hero-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: clamp(22px, 4vw, 36px);
  border: 1px solid var(--line-strong);
  border-radius: 28px;
  color: #fff;
  background: linear-gradient(135deg, #1d4ed8, #0891b2);
  box-shadow: var(--shadow);
}

.dashboard-hero-card p {
  margin: 0;
  opacity: 0.86;
}

.dashboard-new-btn {
  flex: 0 0 auto;
  color: #17324d;
  background: #fff;
}

.project-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 210px;
  gap: 12px;
  margin: 22px 0 14px;
}

.project-search-box {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  padding-left: 13px;
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  background: var(--solid-card);
}

.project-search-box input {
  border: 0;
  outline: 0;
  background: transparent;
}

.dashboard-status {
  min-height: 24px;
  margin: 8px 0;
  color: var(--muted);
}

.student-projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}

.student-project-card {
  display: flex;
  flex-direction: column;
  min-height: 240px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--solid-card);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.student-project-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.project-card-top,
.project-score-row,
.project-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.project-card-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--primary-soft);
  font-size: 1.25rem;
}

.project-status-pill,
.student-account-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 900;
  background: var(--primary-soft);
}

.project-status-pill.passed,
.student-account-pill.active {
  color: #166534;
  background: var(--success-soft);
}

.project-status-pill.checked {
  color: #92400e;
  background: #fef3c7;
}

.student-project-card h3 {
  margin: 16px 0 6px;
  overflow-wrap: anywhere;
}

.project-card-meta,
.project-card-activity {
  margin: 3px 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.project-score-row {
  margin-top: auto;
  padding-top: 16px;
}

.project-score-value {
  font-size: 1.2rem;
  font-weight: 900;
}

.project-card-actions {
  margin-top: 14px;
}

.project-card-actions button:first-child {
  flex: 1;
}

.empty-projects-card {
  grid-column: 1 / -1;
  padding: 44px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: 24px;
  background: var(--card);
  text-align: center;
}

.student-account-strip {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  width: 100%;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.student-greeting {
  font-weight: 900;
}

.student-save-state {
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  background: var(--bg-2);
  font-size: 0.78rem;
  font-weight: 800;
}

.student-save-state.saving {
  color: #92400e;
  background: #fef3c7;
}

.student-save-state.error {
  color: var(--danger);
  background: var(--danger-soft);
}

.guest-account-strip {
  color: var(--muted);
  font-size: 0.88rem;
}

.student-accounts-admin-card {
  padding: 22px;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background: linear-gradient(145deg, var(--solid-card), var(--bg-2));
}

.student-admin-heading {
  align-items: flex-start;
}

.student-admin-heading h3 {
  margin: 4px 0 7px;
}

.student-admin-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.student-admin-summary > div {
  display: grid;
  gap: 3px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--solid-card);
}

.student-admin-summary strong {
  font-size: 1.4rem;
}

.student-admin-summary span {
  color: var(--muted);
  font-size: 0.78rem;
}

.student-register-grid {
  display: grid;
  grid-template-columns: 1fr 1.6fr 1fr 1.2fr;
  gap: 12px;
}

.student-register-grid label,
.student-tracker-toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.student-register-actions {
  justify-content: flex-start;
  margin-top: 14px;
}

.student-import-preview {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--solid-card);
}

.student-import-preview-head small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.student-import-table-wrap,
.student-tracker-table-wrap {
  max-width: 100%;
  margin: 12px 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 15px;
}

.student-import-table,
.student-tracker-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: var(--solid-card);
}

.student-import-table th,
.student-import-table td,
.student-tracker-table th,
.student-tracker-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 0.84rem;
}

.student-import-table th,
.student-tracker-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: var(--bg-2);
}

.import-row-error {
  color: var(--danger);
  font-weight: 800;
}

.import-row-valid {
  color: var(--success);
  font-weight: 800;
}

.student-tracker-toolbar {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.student-cell-name {
  display: block;
  font-weight: 900;
}

.student-cell-id,
.student-cell-sub {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.75rem;
}

.admin-section-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 28px 0 12px;
  color: var(--muted);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
}

.admin-section-divider::before,
.admin-section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.admin-student-projects-overlay {
  z-index: 13000;
}

.admin-student-projects-card {
  width: min(900px, 100%);
  max-height: min(84vh, 850px);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  background: var(--solid-card);
  box-shadow: var(--shadow-strong);
}

.admin-student-projects-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.admin-student-projects-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.admin-project-row {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) repeat(3, auto);
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-2);
}

.admin-project-row strong,
.admin-project-row small {
  display: block;
}

.admin-project-row small {
  margin-top: 4px;
  color: var(--muted);
}

.project-name-card {
  width: min(500px, 100%);
}

[data-theme="dark"] .entry-choice.primary-choice,
[data-theme="dark"] .dashboard-hero-card {
  color: #fff;
}

[data-theme="dark"] .project-status-pill.checked {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.18);
}

[data-theme="dark"] .student-save-state.saving {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.18);
}

@media (max-width: 900px) {
  .entry-choice-grid,
  .student-register-grid,
  .student-tracker-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .student-admin-summary {
    grid-template-columns: 1fr 1fr;
  }

  .student-dashboard-header {
    align-items: flex-start;
  }

  .dashboard-hero-card {
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .entry-gate,
  .student-auth-overlay {
    padding: 12px;
  }

  .entry-card,
  .student-auth-card {
    padding: 22px 18px;
    border-radius: 22px;
  }

  .entry-choice-grid,
  .student-register-grid,
  .student-tracker-toolbar,
  .project-toolbar {
    grid-template-columns: 1fr;
  }

  .entry-choice {
    min-height: 105px;
  }

  .student-dashboard-header,
  .dashboard-hero-card,
  .student-admin-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .dashboard-header-actions,
  .student-register-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .dashboard-new-btn {
    width: 100%;
  }

  .student-projects-grid {
    grid-template-columns: 1fr;
  }

  .student-account-strip {
    justify-content: center;
  }

  .admin-project-row {
    grid-template-columns: 1fr 1fr;
  }

  .admin-project-row > :first-child {
    grid-column: 1 / -1;
  }
}

/* =========================================================
   FINAL DESKTOP REPAIR: student account banner must never
   overlap the editor tabs on PC. Mobile rules stay separate.
   ========================================================= */
@media (min-width: 821px) {
  .topbar.simplified-topbar,
  .topbar {
    grid-template-columns: minmax(300px, 440px) minmax(0, 1fr) !important;
    grid-template-rows: auto auto !important;
    align-items: center !important;
    max-height: none !important;
    min-height: 64px !important;
    overflow: visible !important;
    row-gap: 8px !important;
    margin-bottom: 12px !important;
  }

  .topbar .brand-block {
    grid-column: 1 !important;
    grid-row: 1 !important;
  }

  .topbar .top-actions {
    grid-column: 2 !important;
    grid-row: 1 !important;
  }

  .student-account-strip,
  .guest-account-strip {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 12px !important;
    width: 100% !important;
    min-height: 42px !important;
    padding: 8px 12px !important;
    margin: 0 !important;
    border: 1px solid rgba(147, 197, 253, 0.58) !important;
    border-radius: 14px !important;
    background: linear-gradient(135deg, rgba(239, 246, 255, 0.92), rgba(255, 255, 255, 0.92)) !important;
    color: var(--text) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75) !important;
    position: static !important;
    transform: none !important;
  }

  .student-account-strip.hidden,
  .guest-account-strip.hidden {
    display: none !important;
  }

  .guest-account-strip span,
  .student-greeting {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 0.88rem !important;
    font-weight: 900 !important;
  }

  #guestLoginToSaveBtn,
  #myProjectsBtn,
  #studentHeaderLogoutBtn {
    flex: 0 0 auto !important;
    min-height: 34px !important;
    height: 34px !important;
    padding: 0 14px !important;
    border-radius: 999px !important;
    font-size: 0.82rem !important;
  }

  .student-save-state {
    flex: 0 0 auto !important;
  }

  .workspace,
  .workspace[data-layout='split'] {
    margin-top: 0 !important;
    gap: 14px !important;
  }

  .editor-panel .language-tabs {
    display: flex !important;
    align-items: flex-end !important;
    gap: 6px !important;
    min-height: 46px !important;
    padding: 8px 14px 0 !important;
    overflow: hidden !important;
    flex-wrap: nowrap !important;
  }

  .editor-panel .tab-btn,
  .editor-panel .rename-files-btn {
    flex: 0 0 auto !important;
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 16px !important;
    border-radius: 13px 13px 0 0 !important;
    font-size: 0.86rem !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }

  .editor-panel .rename-files-btn {
    margin-left: 4px !important;
    border-radius: 12px !important;
  }

  .html-page-manager {
    min-height: 48px !important;
    padding: 8px 12px !important;
    gap: 12px !important;
  }

  .page-manager-left {
    flex: 1 1 auto !important;
    max-width: min(520px, 58vw) !important;
  }

  #htmlPageSelect {
    max-width: 430px !important;
  }

  .page-manager-actions {
    justify-content: flex-end !important;
  }

  .page-manager-btn {
    min-height: 34px !important;
    height: 34px !important;
    padding: 0 13px !important;
    font-size: 0.82rem !important;
  }

  .editor-wrap,
  .line-numbers {
    min-height: calc(100vh - 250px) !important;
  }
}

@media (min-width: 821px) and (max-width: 1180px) {
  .topbar.simplified-topbar,
  .topbar {
    grid-template-columns: 1fr !important;
  }

  .topbar .brand-block,
  .topbar .top-actions,
  .student-account-strip,
  .guest-account-strip {
    grid-column: 1 / -1 !important;
  }

  .topbar .top-actions {
    grid-row: 2 !important;
    justify-content: flex-start !important;
  }

  .student-account-strip,
  .guest-account-strip {
    grid-row: 3 !important;
  }
}

/* =========================================================
   FINAL PHONE ENTRY FIX: keep welcome/login clean on phones only
   and keep the desktop layout untouched.
   ========================================================= */
body.entry-gate-active > .app-shell {
  display: none !important;
}

body.entry-gate-active > .hidden-admin-trigger {
  display: none !important;
}

/* Strict student routing: after login, never reveal the editor before Projects. */
body.student-route-lock > .app-shell,
body.student-route-lock > .hidden-admin-trigger,
body.student-dashboard-active > .app-shell,
body.student-dashboard-active > .hidden-admin-trigger {
  display: none !important;
}

body.student-route-lock {
  overflow: hidden !important;
}

body.entry-gate-active .entry-gate.hidden,
body.student-auth-open .student-auth-overlay.hidden,
body.student-dashboard-active .student-dashboard-screen.hidden {
  display: none !important;
}

html[data-device-mode="phone"] body.entry-gate-active,
html[data-device-mode="phone"] body.student-auth-open,
html[data-device-mode="phone"] body.student-dashboard-active {
  width: 100% !important;
  max-width: 100% !important;
  overflow: hidden !important;
}

html[data-device-mode="phone"] .entry-gate {
  position: fixed !important;
  inset: 0 !important;
  z-index: 60000 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100vw !important;
  width: 100dvw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: 100% !important;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  background:
    radial-gradient(circle at 16% 8%, rgba(59, 130, 246, 0.38), transparent 18rem),
    radial-gradient(circle at 86% 92%, rgba(34, 197, 94, 0.18), transparent 18rem),
    linear-gradient(145deg, #07111f 0%, #0f172a 52%, #020617 100%) !important;
}

html[data-device-mode="phone"] .entry-card {
  width: min(100%, 430px) !important;
  max-width: calc(100vw - 28px) !important;
  margin: auto !important;
  padding: 20px 16px 18px !important;
  border: 1px solid rgba(148, 163, 184, 0.34) !important;
  border-radius: 26px !important;
  color: #f8fafc !important;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.96), rgba(17, 24, 39, 0.92)) !important;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.08) !important;
  text-align: left !important;
  backdrop-filter: blur(16px) !important;
  box-sizing: border-box !important;
}

html[data-device-mode="phone"] .entry-logo {
  width: 48px !important;
  height: 48px !important;
  margin: 0 0 14px !important;
  border-radius: 16px !important;
  font-size: 1rem !important;
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.32) !important;
}

html[data-device-mode="phone"] .entry-card .section-kicker {
  margin: 0 0 6px !important;
  color: #93c5fd !important;
  font-size: 0.72rem !important;
  line-height: 1.1 !important;
  letter-spacing: 0.17em !important;
  text-transform: uppercase !important;
  white-space: normal !important;
}

html[data-device-mode="phone"] .entry-card h1 {
  margin: 0 0 7px !important;
  color: #f8fafc !important;
  font-size: clamp(1.35rem, 7vw, 2rem) !important;
  line-height: 1.05 !important;
  letter-spacing: -0.04em !important;
  text-wrap: balance !important;
}

html[data-device-mode="phone"] .entry-lead {
  margin: 0 0 16px !important;
  color: #cbd5e1 !important;
  font-size: 0.98rem !important;
  line-height: 1.4 !important;
}

html[data-device-mode="phone"] .entry-choice-grid {
  display: grid !important;
  grid-template-columns: 1fr !important;
  gap: 10px !important;
  width: 100% !important;
}

html[data-device-mode="phone"] .entry-choice,
html[data-device-mode="phone"] button.entry-choice {
  appearance: none !important;
  -webkit-appearance: none !important;
  display: grid !important;
  grid-template-columns: 42px minmax(0, 1fr) !important;
  align-items: center !important;
  gap: 12px !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 88px !important;
  margin: 0 !important;
  padding: 14px !important;
  border: 1px solid rgba(148, 163, 184, 0.28) !important;
  border-radius: 20px !important;
  color: #e5edff !important;
  background: rgba(15, 23, 42, 0.78) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06) !important;
  text-align: left !important;
  cursor: pointer !important;
  overflow: hidden !important;
}

html[data-device-mode="phone"] .entry-choice.primary-choice {
  border-color: rgba(125, 211, 252, 0.55) !important;
  color: #ffffff !important;
  background: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%) !important;
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.32) !important;
}

html[data-device-mode="phone"] .entry-choice-icon {
  display: grid !important;
  place-items: center !important;
  width: 42px !important;
  height: 42px !important;
  border-radius: 14px !important;
  background: rgba(255, 255, 255, 0.16) !important;
  font-size: 1.25rem !important;
  line-height: 1 !important;
}

html[data-device-mode="phone"] .entry-choice > span:not(.entry-choice-icon) {
  min-width: 0 !important;
  display: block !important;
}

html[data-device-mode="phone"] .entry-choice strong,
html[data-device-mode="phone"] .entry-choice small {
  display: block !important;
  min-width: 0 !important;
  white-space: normal !important;
  overflow-wrap: anywhere !important;
}

html[data-device-mode="phone"] .entry-choice strong {
  margin: 0 0 3px !important;
  font-size: 1rem !important;
  line-height: 1.15 !important;
  letter-spacing: -0.02em !important;
}

html[data-device-mode="phone"] .entry-choice small {
  color: inherit !important;
  opacity: 0.82 !important;
  font-size: 0.78rem !important;
  line-height: 1.35 !important;
}

html[data-device-mode="phone"] .entry-free-note {
  margin: 14px 0 0 !important;
  padding: 10px 12px !important;
  border: 1px solid rgba(34, 197, 94, 0.22) !important;
  border-radius: 16px !important;
  color: #bbf7d0 !important;
  background: rgba(22, 163, 74, 0.08) !important;
  font-size: 0.78rem !important;
  line-height: 1.35 !important;
  text-align: center !important;
}

html[data-device-mode="phone"] .student-auth-overlay {
  z-index: 61000 !important;
}

html[data-device-mode="phone"] .student-auth-card {
  width: min(100%, 420px) !important;
  max-width: calc(100vw - 28px) !important;
  padding: 22px 18px !important;
  border-radius: 24px !important;
}

@media (max-width: 380px) {
  html[data-device-mode="phone"] .entry-card {
    padding: 17px 13px 15px !important;
    border-radius: 22px !important;
  }

  html[data-device-mode="phone"] .entry-choice,
  html[data-device-mode="phone"] button.entry-choice {
    grid-template-columns: 38px minmax(0, 1fr) !important;
    gap: 10px !important;
    min-height: 82px !important;
    padding: 12px !important;
  }

  html[data-device-mode="phone"] .entry-choice-icon {
    width: 38px !important;
    height: 38px !important;
    font-size: 1.12rem !important;
  }

  html[data-device-mode="phone"] .entry-choice strong {
    font-size: 0.94rem !important;
  }

  html[data-device-mode="phone"] .entry-choice small {
    font-size: 0.72rem !important;
  }
}


/* =========================================================
   PHONE ACCOUNT MENU CLEANUP
   - Keeps desktop student strip unchanged
   - On phones, account details move into a compact two-line menu
   ========================================================= */
.student-menu-btn,
.student-account-menu {
  display: none;
}

html[data-device-mode="phone"] body.student-session-active .topbar.simplified-topbar,
html[data-device-mode="phone"] body.student-session-active .topbar {
  position: sticky !important;
  padding-right: 76px !important;
  overflow: visible !important;
}

html[data-device-mode="phone"] body.student-session-active #appSubtitleText {
  display: none !important;
}

html[data-device-mode="phone"] body.student-session-active .student-account-strip {
  display: none !important;
}

html[data-device-mode="phone"] body.student-session-active .student-menu-btn:not(.hidden) {
  display: inline-flex !important;
  position: absolute !important;
  top: 18px !important;
  right: 18px !important;
  z-index: 80 !important;
  width: 48px !important;
  height: 48px !important;
  min-width: 48px !important;
  min-height: 48px !important;
  align-items: center !important;
  justify-content: center !important;
  flex-direction: column !important;
  gap: 7px !important;
  border: 1px solid rgba(147, 197, 253, 0.35) !important;
  border-radius: 16px !important;
  background: rgba(15, 23, 42, 0.92) !important;
  box-shadow: 0 14px 28px rgba(2, 6, 23, 0.28), inset 0 1px 0 rgba(255,255,255,0.08) !important;
  color: #e5efff !important;
  cursor: pointer !important;
  -webkit-tap-highlight-color: transparent !important;
}

html[data-device-mode="phone"] body.student-session-active .student-menu-btn span {
  display: block !important;
  width: 22px !important;
  height: 3px !important;
  border-radius: 999px !important;
  background: currentColor !important;
  box-shadow: 0 0 12px rgba(96, 165, 250, 0.48) !important;
}

html[data-device-mode="phone"] body.student-session-active .student-menu-btn[aria-expanded="true"] {
  border-color: rgba(125, 92, 255, 0.7) !important;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.98), rgba(50, 42, 88, 0.98)) !important;
}

html[data-device-mode="phone"] body.student-session-active .student-account-menu:not(.hidden) {
  display: grid !important;
  position: absolute !important;
  top: 74px !important;
  right: 16px !important;
  left: auto !important;
  z-index: 90 !important;
  width: min(280px, calc(100vw - 32px)) !important;
  gap: 10px !important;
  padding: 14px !important;
  border: 1px solid rgba(147, 197, 253, 0.32) !important;
  border-radius: 22px !important;
  background: linear-gradient(145deg, rgba(16, 24, 39, 0.98), rgba(10, 17, 31, 0.98)) !important;
  box-shadow: 0 24px 55px rgba(2, 6, 23, 0.58), inset 0 1px 0 rgba(255,255,255,0.07) !important;
  color: #f8fbff !important;
}

html[data-device-mode="phone"] body.student-session-active .student-account-menu-head {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 10px !important;
  padding: 6px 4px 10px !important;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2) !important;
}

html[data-device-mode="phone"] body.student-session-active .student-account-menu-head strong {
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  font-size: 1rem !important;
  font-weight: 900 !important;
}

html[data-device-mode="phone"] body.student-session-active .student-account-menu .student-save-state {
  flex: 0 0 auto !important;
  background: rgba(219, 234, 254, 0.14) !important;
  color: #bfdbfe !important;
}

html[data-device-mode="phone"] body.student-session-active .student-account-menu .student-save-state.saving {
  background: rgba(245, 158, 11, 0.16) !important;
  color: #fde68a !important;
}

html[data-device-mode="phone"] body.student-session-active .student-account-menu .student-save-state.error {
  background: rgba(248, 113, 113, 0.16) !important;
  color: #fecaca !important;
}

html[data-device-mode="phone"] body.student-session-active .student-account-menu button {
  width: 100% !important;
  min-height: 48px !important;
  justify-content: center !important;
  border-radius: 16px !important;
  font-size: 1rem !important;
  font-weight: 900 !important;
}

html[data-device-mode="phone"] body.student-session-active .student-account-menu button.danger {
  color: #fecaca !important;
  border-color: rgba(248, 113, 113, 0.28) !important;
  background: rgba(127, 29, 29, 0.18) !important;
}

html[data-device-mode="phone"] body.student-session-active .topbar .brand-block {
  padding-right: 4px !important;
}

html[data-device-mode="phone"] body.student-session-active .topbar .brand-block h1,
html[data-device-mode="phone"] body.student-session-active .topbar h1 {
  max-width: calc(100vw - 150px) !important;
}


/* =========================================================
   PHONE GATE VISIBILITY HOTFIX
   The phone welcome styles use !important display rules, so hidden
   overlays need an equally specific final override. This prevents the
   welcome screen from staying stuck after Login, Continue, or Guest.
   ========================================================= */
html[data-device-mode="phone"] .entry-gate.hidden,
html[data-device-mode="phone"] .student-auth-overlay.hidden,
html[data-device-mode="phone"] .student-dashboard-screen.hidden,
html[data-device-mode="phone"] .project-name-overlay.hidden {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

html[data-device-mode="phone"] body:not(.entry-gate-active) > .entry-gate {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

html[data-device-mode="phone"] body:not(.student-auth-open) > .student-auth-overlay.hidden {
  display: none !important;
}

html[data-device-mode="phone"] body:not(.student-dashboard-active) > .student-dashboard-screen.hidden {
  display: none !important;
}


/* =========================================================
   FINAL MOBILE MENU SIZE + DESKTOP SAFETY FIX
   - keep phone menu compact
   - never show the phone menu button on desktop
   ========================================================= */
@media (max-width: 820px) {
  html[data-device-mode="phone"] body.student-session-active .topbar.simplified-topbar,
  html[data-device-mode="phone"] body.student-session-active .topbar {
    padding-right: 60px !important;
  }

  html[data-device-mode="phone"] body.student-session-active .student-menu-btn:not(.hidden) {
    top: 12px !important;
    right: 12px !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    gap: 5px !important;
    border-radius: 14px !important;
    box-shadow: 0 10px 20px rgba(2, 6, 23, 0.22), inset 0 1px 0 rgba(255,255,255,0.08) !important;
  }

  html[data-device-mode="phone"] body.student-session-active .student-menu-btn span {
    width: 18px !important;
    height: 2.5px !important;
  }

  html[data-device-mode="phone"] body.student-session-active .student-account-menu:not(.hidden) {
    top: 60px !important;
    right: 10px !important;
    width: min(260px, calc(100vw - 20px)) !important;
  }
}

@media (min-width: 821px) {
  .student-menu-btn,
  .student-account-menu,
  #studentMenuBtn,
  #studentAccountMenu {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body.student-session-active #studentAccountStrip.hidden {
    display: flex !important;
  }

  html[data-device-mode="phone"] body.student-session-active .student-account-strip {
    display: flex !important;
  }
}


/* =========================================================
   FINAL PHONE HEADER MENU PLACEMENT FIX
   The account menu button must not float over the action buttons.
   On phones it becomes part of the title row; the action row gets
   its own full-width horizontal scroll underneath.
   ========================================================= */
@media (max-width: 820px) {
  html[data-device-mode="phone"] body.student-session-active .topbar.simplified-topbar,
  html[data-device-mode="phone"] body.student-session-active .topbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) 42px !important;
    grid-template-rows: auto auto !important;
    column-gap: 10px !important;
    row-gap: 10px !important;
    align-items: center !important;
    padding: 14px 14px 12px !important;
    padding-right: 14px !important;
    overflow: visible !important;
  }

  html[data-device-mode="phone"] body.student-session-active .topbar .brand-block {
    grid-column: 1 !important;
    grid-row: 1 !important;
    min-width: 0 !important;
    width: 100% !important;
    padding-right: 0 !important;
  }

  html[data-device-mode="phone"] body.student-session-active .topbar .brand-block h1,
  html[data-device-mode="phone"] body.student-session-active .topbar h1 {
    max-width: 100% !important;
  }

  html[data-device-mode="phone"] body.student-session-active .topbar .top-actions {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 2px 4px !important;
    padding-right: 2px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }

  html[data-device-mode="phone"] body.student-session-active .topbar .top-actions::-webkit-scrollbar {
    display: none !important;
  }

  html[data-device-mode="phone"] body.student-session-active .student-menu-btn:not(.hidden) {
    grid-column: 2 !important;
    grid-row: 1 !important;
    position: static !important;
    top: auto !important;
    right: auto !important;
    justify-self: end !important;
    align-self: center !important;
    display: inline-flex !important;
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    min-height: 38px !important;
    flex: 0 0 38px !important;
    gap: 5px !important;
    border-radius: 13px !important;
    z-index: 20 !important;
  }

  html[data-device-mode="phone"] body.student-session-active .student-menu-btn span {
    width: 17px !important;
    height: 2.4px !important;
  }

  html[data-device-mode="phone"] body.student-session-active .student-account-menu:not(.hidden) {
    top: 66px !important;
    right: 12px !important;
    width: min(260px, calc(100vw - 24px)) !important;
  }
}


/* =========================================================
   FINAL HEADER BRAND TEXT FIX
   - blue label: Sir JR Web Coding App
   - main line: grammar-correct Grade 8 MCSian tagline
   ========================================================= */
.brand-block .eyebrow {
  text-transform: none !important;
  letter-spacing: 0.06em !important;
}

#appTitleText {
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
}

@media (max-width: 820px) {
  html[data-device-mode="phone"] #appTitleText {
    font-size: clamp(0.88rem, 4.3vw, 1.04rem) !important;
    line-height: 1.12 !important;
  }

  html[data-device-mode="phone"] .brand-block .eyebrow {
    font-size: 0.67rem !important;
    letter-spacing: 0.05em !important;
  }
}


/* =========================================================
   ADMIN TABBED LAYOUT (desktop + mobile)
   ========================================================= */
.admin-tabs-wrap {
  margin: 10px 0 16px;
}

.admin-tabs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--bg-2);
  scrollbar-width: thin;
}

.admin-tab-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 14px;
  padding: 11px 16px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.admin-tab-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.55);
}

.admin-tab-btn.active,
.admin-tab-btn[aria-selected="true"] {
  color: #0f172a;
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  border-color: rgba(59, 130, 246, 0.35);
  box-shadow: 0 8px 18px rgba(59,130,246,0.16);
}

.admin-tab-panel {
  display: none;
}

.admin-tab-panel.active {
  display: block;
}

#adminForm.admin-form {
  display: none;
}

#adminForm.admin-form.visible {
  display: block;
}

#adminForm.admin-form.visible.hidden {
  display: none;
}

#activitiesRubricsAdmin {
  display: none;
}

#activitiesRubricsAdmin.active {
  display: block;
}

@media (max-width: 820px) {
  .admin-modal {
    width: min(100vw - 14px, 1000px) !important;
    max-height: calc(100vh - 10px) !important;
    padding: 16px !important;
    border-radius: 18px !important;
  }

  .modal-header {
    gap: 10px;
    align-items: flex-start;
  }

  .modal-header h2 {
    font-size: 1.08rem;
    line-height: 1.2;
  }

  .admin-tabs-wrap {
    position: sticky;
    top: 0;
    z-index: 5;
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,255,255,0.92));
    padding-bottom: 8px;
  }

  .admin-tabs {
    gap: 8px;
    padding: 4px;
    border-radius: 16px;
  }

  .admin-tab-btn {
    padding: 10px 14px;
    font-size: 0.92rem;
  }

  .student-admin-heading,
  .admin-settings-heading,
  .manual-rubric-header,
  .admin-activity-manager,
  .rubric-toolbar {
    gap: 12px;
  }

  .student-admin-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .student-register-actions,
  .assistance-settings-actions,
  .admin-activity-actions,
  .manual-rubric-actions,
  .admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .student-register-actions > *,
  .assistance-settings-actions > *,
  .admin-activity-actions > *,
  .manual-rubric-actions > *,
  .admin-actions > * {
    flex: 1 1 100%;
  }

  .student-tracker-toolbar,
  .form-grid,
  .manual-score-row {
    grid-template-columns: 1fr !important;
  }
}

/* =========================================================
   FINAL ADMIN STUDENTS PHONE LAYOUT
   - makes the Students tab truly phone-friendly
   - desktop/tablet layouts stay unchanged
   ========================================================= */
@media (max-width: 820px) {
  #adminOverlay.modal-overlay {
    padding: 4px !important;
    align-items: stretch !important;
  }

  #adminOverlay .admin-modal {
    width: 100% !important;
    max-width: none !important;
    height: calc(100dvh - 8px) !important;
    max-height: calc(100dvh - 8px) !important;
    margin: 0 !important;
    padding: 12px !important;
    border-radius: 16px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  #adminOverlay .modal-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 20 !important;
    display: grid !important;
    grid-template-columns: 1fr auto !important;
    gap: 8px !important;
    padding: 10px 4px 10px !important;
    background: linear-gradient(180deg, rgba(248,250,252,0.99), rgba(248,250,252,0.94)) !important;
    backdrop-filter: blur(10px) !important;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18) !important;
  }

  #adminOverlay .modal-header .section-kicker {
    font-size: 0.66rem !important;
  }

  #adminOverlay .modal-header h2 {
    margin: 2px 0 !important;
    font-size: 1rem !important;
    line-height: 1.15 !important;
  }

  #adminOverlay .modal-header .muted-text {
    display: none !important;
  }

  #adminOverlay #closeAdminBtn {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
  }

  #adminOverlay .admin-tabs-wrap {
    position: sticky !important;
    top: 60px !important;
    z-index: 19 !important;
    margin: 0 -4px 12px !important;
    padding: 8px 4px 10px !important;
    background: linear-gradient(180deg, rgba(248,250,252,0.98), rgba(248,250,252,0.92)) !important;
    backdrop-filter: blur(10px) !important;
  }

  #adminOverlay .admin-tabs {
    display: flex !important;
    gap: 7px !important;
    padding: 4px !important;
    overflow-x: auto !important;
    border-radius: 15px !important;
    scroll-snap-type: x proximity !important;
  }

  #adminOverlay .admin-tab-btn {
    flex: 0 0 auto !important;
    min-height: 40px !important;
    padding: 9px 12px !important;
    border-radius: 12px !important;
    font-size: 0.84rem !important;
    scroll-snap-align: start !important;
  }

  #studentAccountsAdmin.student-accounts-admin-card {
    padding: 12px !important;
    border-radius: 18px !important;
  }

  #studentAccountsAdmin .student-admin-heading {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    margin-bottom: 12px !important;
  }

  #studentAccountsAdmin .student-admin-heading h3 {
    margin: 2px 0 5px !important;
    font-size: 1.02rem !important;
    line-height: 1.18 !important;
  }

  #studentAccountsAdmin .student-admin-heading .muted-text {
    font-size: 0.78rem !important;
    line-height: 1.35 !important;
  }

  #studentAccountsAdmin #refreshStudentsBtn {
    width: 100% !important;
    min-height: 40px !important;
    justify-content: center !important;
  }

  #studentAccountsAdmin .student-admin-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    margin: 12px 0 !important;
  }

  #studentAccountsAdmin .student-admin-summary > div {
    min-height: 72px !important;
    padding: 10px !important;
    border-radius: 14px !important;
    text-align: center !important;
    align-content: center !important;
  }

  #studentAccountsAdmin .student-admin-summary strong {
    font-size: 1.2rem !important;
    line-height: 1 !important;
  }

  #studentAccountsAdmin .student-admin-summary span {
    font-size: 0.7rem !important;
  }

  #studentAccountsAdmin .student-register-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  #studentAccountsAdmin .student-register-grid label,
  #studentAccountsAdmin .student-tracker-toolbar label {
    gap: 5px !important;
    font-size: 0.75rem !important;
  }

  #studentAccountsAdmin .student-register-grid input,
  #studentAccountsAdmin .student-register-grid select,
  #studentAccountsAdmin .student-tracker-toolbar input,
  #studentAccountsAdmin .student-tracker-toolbar select {
    min-height: 42px !important;
    border-radius: 12px !important;
    font-size: 0.9rem !important;
    padding: 9px 11px !important;
  }

  #studentAccountsAdmin .student-register-actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    margin-top: 12px !important;
  }

  #studentAccountsAdmin .student-register-actions button,
  #studentAccountsAdmin #confirmStudentImportBtn,
  #studentAccountsAdmin #cancelStudentImportBtn {
    width: 100% !important;
    min-height: 42px !important;
    justify-content: center !important;
    border-radius: 13px !important;
    font-size: 0.9rem !important;
  }

  #studentAccountsAdmin .student-import-preview {
    padding: 10px !important;
    border-radius: 16px !important;
  }

  #studentAccountsAdmin .student-import-preview-head {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  #studentAccountsAdmin .student-import-table-wrap {
    overflow-x: auto !important;
    border-radius: 12px !important;
  }

  #studentAccountsAdmin .student-import-table {
    min-width: 680px !important;
  }

  #studentAccountsAdmin .student-import-table th,
  #studentAccountsAdmin .student-import-table td {
    padding: 8px 9px !important;
    font-size: 0.74rem !important;
  }

  #studentAccountsAdmin .student-tracker-toolbar {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 9px !important;
    margin-top: 14px !important;
    padding: 10px !important;
    border: 1px solid var(--line) !important;
    border-radius: 16px !important;
    background: var(--solid-card) !important;
  }

  #studentAccountsAdmin .student-tracker-table-wrap {
    margin-top: 12px !important;
    overflow: visible !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
  }

  #studentAccountsAdmin .student-tracker-table {
    display: block !important;
    min-width: 0 !important;
    width: 100% !important;
    border-collapse: separate !important;
    background: transparent !important;
  }

  #studentAccountsAdmin .student-tracker-table thead {
    display: none !important;
  }

  #studentAccountsAdmin .student-tracker-table tbody {
    display: grid !important;
    gap: 10px !important;
    width: 100% !important;
  }

  #studentAccountsAdmin .student-tracker-table tr {
    display: block !important;
    padding: 12px !important;
    border: 1px solid var(--line-strong) !important;
    border-radius: 18px !important;
    background: linear-gradient(145deg, var(--solid-card), var(--bg-2)) !important;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08) !important;
  }

  #studentAccountsAdmin .student-tracker-table td {
    display: flex !important;
    align-items: flex-start !important;
    justify-content: space-between !important;
    gap: 12px !important;
    width: 100% !important;
    padding: 9px 0 !important;
    border: 0 !important;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18) !important;
    font-size: 0.84rem !important;
    text-align: right !important;
  }

  #studentAccountsAdmin .student-tracker-table td:last-child {
    display: block !important;
    border-bottom: 0 !important;
    padding-bottom: 0 !important;
  }

  #studentAccountsAdmin .student-tracker-table td::before {
    flex: 0 0 88px !important;
    color: var(--muted) !important;
    font-size: 0.72rem !important;
    font-weight: 900 !important;
    text-align: left !important;
    text-transform: uppercase !important;
    letter-spacing: 0.04em !important;
  }

  #studentAccountsAdmin .student-tracker-table td:nth-of-type(1)::before { content: "Student"; }
  #studentAccountsAdmin .student-tracker-table td:nth-of-type(2)::before { content: "Section"; }
  #studentAccountsAdmin .student-tracker-table td:nth-of-type(3)::before { content: "Account"; }
  #studentAccountsAdmin .student-tracker-table td:nth-of-type(4)::before { content: "Projects"; }
  #studentAccountsAdmin .student-tracker-table td:nth-of-type(5)::before { content: "Last Activity"; }
  #studentAccountsAdmin .student-tracker-table td:nth-of-type(6)::before { content: "Action"; }

  #studentAccountsAdmin .student-tracker-table td:nth-of-type(1) {
    display: block !important;
    text-align: left !important;
    padding-top: 0 !important;
  }

  #studentAccountsAdmin .student-tracker-table td:nth-of-type(1)::before {
    display: block !important;
    margin-bottom: 6px !important;
  }

  #studentAccountsAdmin .student-cell-name {
    font-size: 0.96rem !important;
    line-height: 1.2 !important;
  }

  #studentAccountsAdmin .student-cell-id,
  #studentAccountsAdmin .student-cell-sub {
    font-size: 0.72rem !important;
  }

  #studentAccountsAdmin .student-tracker-table td:last-child button,
  #studentAccountsAdmin .student-tracker-table td:last-child .ghost-btn,
  #studentAccountsAdmin .student-tracker-table td:last-child .primary-btn {
    width: 100% !important;
    min-height: 40px !important;
    justify-content: center !important;
    border-radius: 12px !important;
    margin-top: 6px !important;
  }
}


/* =========================================================
   TRUE PHONE ADMIN STUDENTS FIX
   - prevents any horizontal clipping in Admin > Students
   - keeps desktop unchanged
   ========================================================= */
@media (max-width: 820px) {
  body.admin-open,
  body.admin-open html {
    overflow-x: hidden !important;
  }

  body.admin-open #adminOverlay.modal-overlay,
  #adminOverlay.modal-overlay {
    width: 100vw !important;
    max-width: 100vw !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  body.admin-open #adminOverlay .admin-modal,
  #adminOverlay .admin-modal {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding: 0 !important;
  }

  #adminOverlay .modal-header {
    padding: 12px 12px 10px !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  #adminOverlay .modal-header > div,
  #adminOverlay .modal-header h2 {
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
  }

  #adminOverlay .admin-tabs-wrap {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 8px 10px 10px !important;
    top: 58px !important;
    overflow: hidden !important;
  }

  #adminOverlay .admin-tabs {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
  }

  #adminOverlay .admin-form.visible,
  #adminOverlay .admin-form,
  #adminOverlay form#adminForm {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    padding: 10px 10px 18px !important;
    margin: 0 !important;
    overflow-x: hidden !important;
  }

  #adminOverlay .admin-tab-panel.active,
  #studentAccountsAdmin.student-accounts-admin-card {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    overflow-x: hidden !important;
  }

  #studentAccountsAdmin.student-accounts-admin-card {
    padding: 14px !important;
    border-radius: 18px !important;
  }

  #studentAccountsAdmin,
  #studentAccountsAdmin * {
    min-width: 0 !important;
  }

  #studentAccountsAdmin .student-admin-heading {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  #studentAccountsAdmin .student-admin-heading .muted-text {
    display: none !important;
  }

  #studentAccountsAdmin .student-admin-heading h3 {
    font-size: 1.08rem !important;
    line-height: 1.2 !important;
    overflow-wrap: anywhere !important;
  }

  #studentAccountsAdmin #refreshStudentsBtn {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 42px !important;
    padding: 0 12px !important;
    white-space: normal !important;
    overflow: hidden !important;
    text-overflow: clip !important;
    justify-content: center !important;
  }

  #studentAccountsAdmin .student-admin-summary {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 12px 0 !important;
    overflow: hidden !important;
  }

  #studentAccountsAdmin .student-admin-summary > div {
    width: 100% !important;
    min-width: 0 !important;
    padding: 12px 10px !important;
    border-radius: 15px !important;
  }

  #studentAccountsAdmin .student-admin-summary strong,
  #studentAccountsAdmin .student-admin-summary span {
    max-width: 100% !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  #studentAccountsAdmin .student-register-grid,
  #studentAccountsAdmin .student-tracker-toolbar,
  #studentAccountsAdmin .student-register-actions {
    width: 100% !important;
    max-width: 100% !important;
    grid-template-columns: 1fr !important;
  }

  #studentAccountsAdmin label,
  #studentAccountsAdmin input,
  #studentAccountsAdmin select,
  #studentAccountsAdmin textarea,
  #studentAccountsAdmin button {
    max-width: 100% !important;
  }

  #studentAccountsAdmin input,
  #studentAccountsAdmin select {
    width: 100% !important;
  }

  #studentAccountsAdmin .student-import-table-wrap {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
  }

  #studentAccountsAdmin .student-tracker-table-wrap,
  #studentAccountsAdmin .student-tracker-table,
  #studentAccountsAdmin .student-tracker-table tbody,
  #studentAccountsAdmin .student-tracker-table tr,
  #studentAccountsAdmin .student-tracker-table td {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  #studentAccountsAdmin .student-tracker-table td {
    flex-wrap: wrap !important;
    text-align: left !important;
    overflow-wrap: anywhere !important;
  }

  #studentAccountsAdmin .student-tracker-table td::before {
    flex: 0 0 100% !important;
    margin-bottom: 3px !important;
  }

  #studentAccountsAdmin .student-tracker-table td > * {
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
  }
}

@media (max-width: 430px) {
  #studentAccountsAdmin .student-admin-summary {
    grid-template-columns: 1fr !important;
  }

  #adminOverlay .admin-tab-btn {
    font-size: 0.8rem !important;
    padding: 9px 11px !important;
  }
}

/* =========================================================
   SMART INLINE HINTS
   ========================================================= */
.smart-inline-hint {
  position: fixed;
  z-index: 9999;
  width: min(320px, calc(100vw - 20px));
  padding: 14px 14px 12px;
  border: 1px solid rgba(37, 99, 235, 0.25);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 22px 48px rgba(15, 23, 42, 0.24), 0 0 0 1px rgba(255,255,255,0.7) inset;
  color: #0f172a;
  font-size: 0.9rem;
  line-height: 1.35;
  backdrop-filter: blur(16px);
}

.smart-inline-hint.hidden {
  display: none !important;
}

.smart-inline-kicker {
  margin: 0 28px 6px 0;
  color: #2563eb;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.smart-inline-hint strong {
  display: block;
  margin: 0 24px 6px 0;
  font-size: 0.98rem;
  line-height: 1.25;
}

.smart-inline-hint span {
  display: block;
  color: #475569;
}

.smart-inline-close {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: #eef2ff;
  color: #1e293b;
  font-weight: 900;
  cursor: pointer;
}

.smart-inline-fix {
  margin-top: 12px;
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  color: white;
  font-weight: 900;
  cursor: pointer;
}


body.editor-fullscreen-active #editorPanel .smart-inline-hint,
#editorPanel:fullscreen .smart-inline-hint {
  z-index: 100120;
}

[data-theme="dark"] .smart-inline-hint {
  background: rgba(15, 23, 42, 0.98);
  border-color: rgba(96, 165, 250, 0.35);
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.42), 0 0 0 1px rgba(255,255,255,0.06) inset;
  color: #f8fbff;
}

[data-theme="dark"] .smart-inline-hint span {
  color: #cbd5e1;
}

[data-theme="dark"] .smart-inline-close {
  background: rgba(96, 165, 250, 0.14);
  color: #e5efff;
}

body.code-helper-disabled .smart-inline-hint {
  display: none !important;
}

@media (max-width: 820px) {
  .smart-inline-hint {
    left: 10px !important;
    right: 10px !important;
    width: auto;
    max-width: none !important;
    font-size: 0.88rem;
  }
}


/* =========================================================
   PROJECT DELETE CONFIRMATION LAYER FIX
   Keep custom alert/confirm dialogs above student dashboard,
   project naming, admin, fullscreen, and mobile overlays.
   ========================================================= */
.app-dialog-overlay {
  z-index: 950000 !important;
}


/* CODEPEN POLISH PASS: Auto Run, preview loading, and clearer project action states */
.auto-run-btn,
.fullscreen-auto-run-btn {
  border-color: #bae6fd !important;
  color: #075985 !important;
  background: #e0f2fe !important;
}

.auto-run-btn.active,
.fullscreen-auto-run-btn.active {
  color: #ffffff !important;
  border-color: transparent !important;
  background: linear-gradient(135deg, #2563eb, #06b6d4) !important;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.18) !important;
}

.preview-panel.preview-loading .preview-frame-shell::before,
.preview-panel.preview-waiting .preview-frame-shell::before,
.preview-panel.preview-runtime-warning .preview-frame-shell::before {
  position: absolute;
  z-index: 8;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 1000;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.16);
}

.preview-panel.preview-loading .preview-frame-shell::before {
  content: 'Rendering preview...';
  color: #075985;
  background: rgba(224, 242, 254, 0.96);
  border: 1px solid #bae6fd;
}

.preview-panel.preview-waiting .preview-frame-shell::before {
  content: 'Still loading... check JS';
  color: #92400e;
  background: rgba(254, 243, 199, 0.96);
  border: 1px solid #fde68a;
}

.preview-panel.preview-runtime-warning .preview-frame-shell::before {
  content: 'JavaScript issue detected';
  color: #991b1b;
  background: rgba(254, 226, 226, 0.96);
  border: 1px solid #fecaca;
}

.preview-panel.preview-loading .preview-frame-shell::after {
  content: '';
  position: absolute;
  z-index: 7;
  top: 17px;
  right: 152px;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(2, 132, 199, 0.24);
  border-top-color: #0284c7;
  animation: previewSpin 0.85s linear infinite;
  pointer-events: none;
}

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

.student-project-card.project-action-busy {
  opacity: 0.78;
  pointer-events: none;
}

.student-project-card [data-project-action]:disabled,
.top-actions button:disabled,
.fullscreen-editor-actions button:disabled {
  opacity: 0.58 !important;
  cursor: wait !important;
}

@media (max-width: 760px) {
  .auto-run-btn {
    min-width: 86px !important;
  }

  .preview-panel.preview-loading .preview-frame-shell::before,
  .preview-panel.preview-waiting .preview-frame-shell::before,
  .preview-panel.preview-runtime-warning .preview-frame-shell::before {
    top: 8px;
    right: 8px;
    font-size: 0.72rem;
  }

  .preview-panel.preview-loading .preview-frame-shell::after {
    top: 13px;
    right: 140px;
  }
}


/* SUPER STUDIO UPGRADE */

.studio-hidden {
  display: none !important;
}

.studio-launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: fit-content;
  min-height: 36px;
  margin: 8px 0 6px;
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 900;
}

.studio-launcher span {
  line-height: 1;
}

body.super-studio-disabled #superStudioLauncher,
body.super-studio-disabled #superStudioToolbar,
body.super-studio-disabled #superStudioPanel,
body.super-studio-disabled .super-studio-only {
  display: none !important;
}

.super-studio-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px;
  margin: 8px 0 10px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(6, 182, 212, 0.08));
}

.studio-toolbar-left,
.studio-toolbar-actions,
.studio-device-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.studio-badge,
.studio-quality-chip,
.studio-mini-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
  font-weight: 800;
}

.studio-badge-hot {
  color: #0f172a;
  border-color: rgba(37, 99, 235, 0.2);
  background: linear-gradient(135deg, #dbeafe, #cffafe);
}

.studio-quality-chip {
  color: #14532d;
  border-color: rgba(22, 163, 74, 0.24);
  background: #dcfce7;
}

.studio-btn {
  min-height: 34px;
  padding: 8px 11px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.studio-btn.strong {
  color: #1e3a8a;
  border-color: rgba(37, 99, 235, 0.22);
  background: #dbeafe;
}

.super-studio-panel {
  display: grid;
  gap: 10px;
  margin: 8px 0 12px;
  padding: 14px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.super-studio-panel.collapsed {
  display: none;
}

.studio-score-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
}

.studio-score-ring {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border: 7px solid rgba(37, 99, 235, 0.18);
  border-radius: 50%;
  color: #1e3a8a;
  background: linear-gradient(135deg, #eff6ff, #ecfeff);
  font-weight: 950;
  line-height: 1;
}

.studio-score-ring span {
  font-size: 1.35rem;
}

.studio-score-ring small {
  font-size: 0.66rem;
  color: var(--muted);
}

.super-studio-panel h3 {
  margin: 0;
  font-size: 1rem;
}

.super-studio-panel p {
  margin: 4px 0 0;
  color: var(--muted);
}

.studio-progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.22);
}

.studio-progress-track span {
  display: block;
  width: 5%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #06b6d4, #22c55e);
  transition: width 0.25s ease;
}

.studio-coach-issues {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
}

.studio-issue-item {
  display: grid;
  gap: 3px;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(255, 255, 255, 0.8);
}

.studio-issue-item strong {
  font-size: 0.86rem;
}

.studio-issue-item span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.studio-issue-item.error {
  border-color: rgba(239, 68, 68, 0.25);
  background: #fef2f2;
}

.studio-issue-item.warning {
  border-color: rgba(245, 158, 11, 0.28);
  background: #fffbeb;
}

.studio-issue-item.pass {
  border-color: rgba(34, 197, 94, 0.26);
  background: #f0fdf4;
}

.studio-device-controls {
  padding: 4px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.66);
}

.studio-device-controls button {
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--muted);
  background: transparent;
  font-size: 0.76rem;
  font-weight: 850;
  cursor: pointer;
}

.studio-device-controls button.active {
  color: white;
  background: linear-gradient(135deg, var(--primary), #06b6d4);
}

.preview-panel.studio-device-phone:not(.mobile-desktop-preview) .preview-frame-shell,
.preview-panel.studio-device-tablet:not(.mobile-desktop-preview) .preview-frame-shell,
.preview-panel.studio-device-laptop:not(.mobile-desktop-preview) .preview-frame-shell {
  display: flex;
  justify-content: center;
  padding: 16px;
  border-radius: 20px;
  background: radial-gradient(circle at top, rgba(37, 99, 235, 0.12), rgba(15, 23, 42, 0.06));
}

.preview-panel.studio-device-phone:not(.mobile-desktop-preview) #previewFrame,
.preview-panel.studio-device-tablet:not(.mobile-desktop-preview) #previewFrame,
.preview-panel.studio-device-laptop:not(.mobile-desktop-preview) #previewFrame {
  border: 10px solid #111827;
  border-radius: 24px;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.22);
}

.preview-panel.studio-device-phone:not(.mobile-desktop-preview) #previewFrame {
  width: min(390px, 100%);
  min-height: 720px;
}

.preview-panel.studio-device-tablet:not(.mobile-desktop-preview) #previewFrame {
  width: min(820px, 100%);
  min-height: 760px;
}

.preview-panel.studio-device-laptop:not(.mobile-desktop-preview) #previewFrame {
  width: min(1280px, 100%);
  min-height: 720px;
  border-radius: 18px;
}

.studio-command-overlay {
  position: fixed;
  z-index: 50000;
  inset: 0;
  display: grid;
  place-items: start center;
  padding: min(8vh, 72px) 16px 16px;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(8px);
}

.studio-command-overlay.hidden {
  display: none;
}

.studio-command-card {
  width: min(720px, 100%);
  max-height: min(760px, 88dvh);
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 24px;
  background: var(--solid-card);
  box-shadow: var(--shadow-strong);
}

.studio-command-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.studio-command-head h2 {
  margin: 0;
}

.studio-command-input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  font: inherit;
  font-weight: 750;
  outline: none;
}

.studio-command-input:focus {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.studio-command-list,
.studio-snapshots-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.studio-command-item,
.studio-snapshot-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  text-align: left;
}

.studio-command-item {
  cursor: pointer;
}

.studio-command-item.active,
.studio-command-item:hover {
  border-color: rgba(37, 99, 235, 0.35);
  background: #eff6ff;
}

.studio-command-item span,
.studio-snapshot-item strong {
  font-weight: 900;
}

.studio-command-item small,
.studio-snapshot-item small,
.studio-command-note {
  color: var(--muted);
  font-size: 0.78rem;
}

.studio-snapshot-item > div:first-child {
  display: grid;
  gap: 3px;
}

.studio-snapshot-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.studio-empty-box {
  padding: 18px;
  border: 1px dashed rgba(148, 163, 184, 0.36);
  border-radius: 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.62);
  text-align: center;
}

[data-theme="dark"] .studio-badge,
[data-theme="dark"] .studio-quality-chip,
[data-theme="dark"] .studio-mini-chip,
[data-theme="dark"] .super-studio-panel,
[data-theme="dark"] .studio-command-input,
[data-theme="dark"] .studio-command-item,
[data-theme="dark"] .studio-snapshot-item,
[data-theme="dark"] .studio-empty-box,
[data-theme="dark"] .studio-device-controls {
  background: rgba(15, 23, 42, 0.76);
}

[data-theme="dark"] .studio-badge-hot,
[data-theme="dark"] .studio-quality-chip,
[data-theme="dark"] .studio-command-item.active,
[data-theme="dark"] .studio-command-item:hover {
  color: #e0f2fe;
  background: rgba(37, 99, 235, 0.24);
}

@media (max-width: 760px) {
  .studio-launcher {
    width: 100%;
    margin: 6px 0;
  }

  .super-studio-toolbar,
  .studio-score-card,
  .studio-command-item,
  .studio-snapshot-item {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .super-studio-toolbar,
  .studio-toolbar-left,
  .studio-toolbar-actions {
    justify-content: stretch;
  }

  .studio-toolbar-actions .studio-btn,
  .studio-toolbar-left > span {
    flex: 1 1 auto;
    justify-content: center;
  }

  .studio-score-card {
    display: grid;
  }

  .studio-score-ring {
    justify-self: center;
  }

  .studio-device-controls {
    width: 100%;
    justify-content: center;
    border-radius: 18px;
  }

  .preview-panel.studio-device-phone:not(.mobile-desktop-preview) #previewFrame,
  .preview-panel.studio-device-tablet:not(.mobile-desktop-preview) #previewFrame,
  .preview-panel.studio-device-laptop:not(.mobile-desktop-preview) #previewFrame {
    width: 100%;
    min-height: 620px;
  }
}


/* FINAL DESKTOP OVERFLOW + COMPACT STUDIO FIX */
html,
body {
  max-width: 100%;
  overflow-x: hidden !important;
}

.app-shell,
.topbar,
.workspace,
.panel,
.editor-panel,
.preview-panel,
.result-panel,
.right-column {
  max-width: 100%;
}

.workspace,
.editor-panel,
.preview-panel,
.result-panel,
.editor-wrap,
.editor-stack {
  min-width: 0 !important;
}

/* Super Studio should appear only as a small optional button beside Rename Files. */
.language-tabs #superStudioLauncher.studio-launcher {
  flex: 0 0 auto !important;
  align-self: flex-end !important;
  width: auto !important;
  min-width: 0 !important;
  min-height: 32px !important;
  height: 32px !important;
  margin: 0 0 0 6px !important;
  padding: 0 12px !important;
  border-radius: 999px !important;
  font-size: 0.82rem !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

.language-tabs #superStudioLauncher.studio-launcher strong {
  line-height: 1 !important;
}

/* The opened tools can wrap locally, but they must never make the whole page scroll sideways. */
#superStudioToolbar,
#superStudioPanel {
  max-width: 100% !important;
  overflow-x: hidden !important;
}

.studio-toolbar-left,
.studio-toolbar-actions {
  min-width: 0 !important;
}

/* Prevent the desktop page/browser from getting a left-right scrollbar.
   Long student code stays inside the editor instead of stretching the app. */
#codeEditor,
.code-match-layer {
  max-width: 100% !important;
}

@media (min-width: 821px) {
  .editor-panel #codeEditor {
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  .editor-panel #codeEditor,
  .editor-panel .code-match-layer {
    white-space: pre-wrap !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }
}

/* On phone, keep Studio in the existing scrollable tab row instead of creating vertical space. */
@media (max-width: 820px) {
  .language-tabs #superStudioLauncher.studio-launcher {
    display: inline-flex !important;
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 82px !important;
    height: 36px !important;
    min-height: 36px !important;
    margin: 0 0 0 4px !important;
    padding: 0 10px !important;
    font-size: 0.78rem !important;
  }

  .language-tabs #superStudioLauncher.studio-hidden,
  .language-tabs #superStudioLauncher.hidden,
  body.super-studio-disabled .language-tabs #superStudioLauncher {
    display: none !important;
  }

  .super-studio-toolbar {
    margin: 6px 8px 8px !important;
  }
}

/* FINAL FIX: Studio launcher placement must not break mobile tabs or overlap the file selector. */
.language-tabs.has-studio-launcher #superStudioLauncher.studio-launcher,
.language-tabs #superStudioLauncher.studio-launcher-desktop {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
}

.page-manager-actions.has-studio-launcher {
  min-width: 0 !important;
}

.page-manager-actions #superStudioLauncher.studio-launcher {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 5px !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 38px !important;
  height: 38px !important;
  margin: 0 !important;
  padding: 0 8px !important;
  border-radius: 16px !important;
  font-size: 0.82rem !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

@media (max-width: 760px) {
  /* Hide the desktop slot on phones; JS moves the same button into the page manager action row. */
  .language-tabs #superStudioLauncher.studio-launcher {
    display: none !important;
  }

  .page-manager-actions.has-studio-launcher {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 7px !important;
    width: 100% !important;
    align-items: stretch !important;
  }

  .page-manager-actions.has-studio-launcher #superStudioLauncher.studio-launcher {
    display: inline-flex !important;
    grid-column: auto !important;
  }

  .page-manager-actions.has-studio-launcher #superStudioLauncher.studio-hidden,
  .page-manager-actions.has-studio-launcher #superStudioLauncher.hidden,
  body.super-studio-disabled .page-manager-actions #superStudioLauncher {
    display: none !important;
  }

  .page-manager-actions.has-studio-launcher .page-manager-btn,
  .page-manager-actions.has-studio-launcher #superStudioLauncher.studio-launcher {
    min-height: 40px !important;
    height: 40px !important;
    font-size: 0.8rem !important;
  }

  .page-manager-actions.has-studio-launcher .danger {
    grid-column: 1 / -1 !important;
  }
}

@media (max-width: 420px) {
  .page-manager-actions.has-studio-launcher {
    grid-template-columns: 1fr 1fr !important;
  }

  .page-manager-actions.has-studio-launcher .danger,
  .page-manager-actions.has-studio-launcher #deleteHtmlPageBtn {
    grid-column: auto !important;
  }
}


/* FINAL READABILITY FIXES: light-mode dashboard hero + dark-mode account strip */
.dashboard-hero-card .section-kicker {
  color: rgba(255, 255, 255, 0.96) !important;
  text-shadow: 0 1px 2px rgba(8, 15, 35, 0.24);
}

.dashboard-hero-card h2 {
  color: #ffffff !important;
  text-shadow: 0 2px 10px rgba(8, 15, 35, 0.24);
}

.dashboard-hero-card p {
  color: rgba(255, 255, 255, 0.96) !important;
  opacity: 1 !important;
  line-height: 1.55;
}

.dashboard-new-btn {
  color: #0f2852 !important;
  border: 1px solid rgba(255, 255, 255, 0.72) !important;
  box-shadow: 0 10px 24px rgba(8, 15, 35, 0.16);
}

.dashboard-new-btn:hover,
.dashboard-new-btn:focus-visible {
  color: #0b1f40 !important;
  background: #f8fbff !important;
}

@media (min-width: 821px) {
  [data-theme="dark"] .student-account-strip,
  [data-theme="dark"] .guest-account-strip {
    border-color: rgba(96, 165, 250, 0.3) !important;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(30, 41, 59, 0.94)) !important;
    color: #e5edf7 !important;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.04),
      0 10px 22px rgba(2, 6, 23, 0.2) !important;
  }

  [data-theme="dark"] .student-greeting,
  [data-theme="dark"] .guest-account-strip span {
    color: #f8fafc !important;
  }

  [data-theme="dark"] .student-save-state {
    color: #dbeafe !important;
    background: rgba(96, 165, 250, 0.16) !important;
    border: 1px solid rgba(96, 165, 250, 0.28);
  }

  [data-theme="dark"] .student-save-state.saving {
    color: #fde68a !important;
    background: rgba(245, 158, 11, 0.16) !important;
    border-color: rgba(245, 158, 11, 0.22) !important;
  }

  [data-theme="dark"] .student-save-state.error {
    color: #fecdd3 !important;
    background: rgba(251, 113, 133, 0.16) !important;
    border-color: rgba(251, 113, 133, 0.2) !important;
  }

  [data-theme="dark"] #myProjectsBtn,
  [data-theme="dark"] #studentHeaderLogoutBtn,
  [data-theme="dark"] #guestLoginToSaveBtn {
    color: #e5edf7 !important;
    border-color: rgba(71, 85, 105, 0.95) !important;
    background: rgba(2, 6, 23, 0.5) !important;
    box-shadow: none !important;
  }

  [data-theme="dark"] #myProjectsBtn:hover,
  [data-theme="dark"] #studentHeaderLogoutBtn:hover,
  [data-theme="dark"] #guestLoginToSaveBtn:hover,
  [data-theme="dark"] #myProjectsBtn:focus-visible,
  [data-theme="dark"] #studentHeaderLogoutBtn:focus-visible,
  [data-theme="dark"] #guestLoginToSaveBtn:focus-visible {
    background: rgba(15, 23, 42, 0.9) !important;
    border-color: rgba(96, 165, 250, 0.34) !important;
  }

  [data-theme="dark"] #studentHeaderLogoutBtn,
  [data-theme="dark"] #guestLoginToSaveBtn.ghost-btn.danger {
    color: #fecdd3 !important;
  }
}

/* FINAL ADMIN/RUBRIC READABILITY + TABLE OVERFLOW FIX */
#adminOverlay,
#adminOverlay * {
  min-width: 0;
}

#adminOverlay .admin-modal {
  color: var(--text);
}

#adminOverlay .admin-form,
#adminOverlay .admin-tab-panel,
#adminOverlay .manual-rubric-card,
#adminOverlay .rubric-table-scroll,
#adminOverlay .manual-rubric-scroll {
  max-width: 100%;
}

/* Keep Remove inside its Action column instead of overflowing sideways. */
.manual-rubric-input-table th:last-child,
.manual-rubric-input-table td:last-child,
.manual-rubric-row-action {
  width: 130px !important;
  min-width: 130px !important;
  max-width: 130px !important;
  text-align: center !important;
}

.remove-manual-rubric-row,
.rubric-criterion-cell .remove-criterion {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  min-height: 40px !important;
  height: auto !important;
  padding: 8px 10px !important;
  border-radius: 999px !important;
  font-size: 0.86rem !important;
  line-height: 1.1 !important;
  white-space: nowrap !important;
}

.manual-rubric-scroll,
.rubric-table-scroll {
  overflow-x: auto !important;
  overflow-y: visible !important;
  scrollbar-width: thin;
}

.manual-rubric-input-table,
.teacher-rubric-table {
  max-width: none;
}

.manual-rubric-input-table textarea,
.teacher-rubric-table textarea,
.rubric-level-cell textarea {
  color: var(--text);
}

.manual-rubric-input-table textarea::placeholder,
.teacher-rubric-table textarea::placeholder,
.rubric-level-cell textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 82%, transparent);
}

/* Dark mode: admin rubric areas must use dark cards instead of pale cards with white text. */
[data-theme="dark"] #adminOverlay .admin-modal,
[data-theme="dark"] #adminOverlay .admin-form,
[data-theme="dark"] #activitiesRubricsAdmin {
  color: #e5edf7 !important;
}

[data-theme="dark"] .admin-tabs-wrap {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.92)) !important;
}

[data-theme="dark"] .admin-tabs {
  border-color: rgba(96, 165, 250, 0.28) !important;
  background: rgba(2, 6, 23, 0.36) !important;
}

[data-theme="dark"] .admin-tab-btn {
  color: #cbd5e1 !important;
}

[data-theme="dark"] .admin-tab-btn:hover,
[data-theme="dark"] .admin-tab-btn:focus-visible {
  color: #ffffff !important;
  background: rgba(30, 41, 59, 0.95) !important;
}

[data-theme="dark"] .admin-tab-btn.active,
[data-theme="dark"] .admin-tab-btn[aria-selected="true"] {
  color: #ffffff !important;
  border-color: rgba(56, 189, 248, 0.45) !important;
  background: linear-gradient(135deg, #6d28d9, #0284c7) !important;
  box-shadow: 0 10px 24px rgba(14, 165, 233, 0.18) !important;
}

[data-theme="dark"] .admin-section-divider {
  color: #cbd5e1 !important;
}

[data-theme="dark"] .admin-section-divider::before,
[data-theme="dark"] .admin-section-divider::after {
  background: rgba(148, 163, 184, 0.28) !important;
}

[data-theme="dark"] .manual-rubric-card,
[data-theme="dark"] .rubric-table-note,
[data-theme="dark"] .rubric-table-scroll,
[data-theme="dark"] .manual-rubric-scroll,
[data-theme="dark"] .scale-rubric-table {
  color: #e5edf7 !important;
  border-color: rgba(96, 165, 250, 0.24) !important;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(17, 24, 39, 0.98)) !important;
  box-shadow: 0 12px 30px rgba(2, 6, 23, 0.26) !important;
}

[data-theme="dark"] .manual-rubric-header h3,
[data-theme="dark"] .rubric-toolbar h3,
[data-theme="dark"] .manual-score-row label,
[data-theme="dark"] .teacher-rubric-table th,
[data-theme="dark"] .manual-rubric-input-table th {
  color: #f8fafc !important;
}

[data-theme="dark"] .manual-rubric-header .section-kicker,
[data-theme="dark"] .rubric-toolbar .section-kicker,
[data-theme="dark"] #activitiesRubricsAdmin .section-kicker {
  color: #93c5fd !important;
}

[data-theme="dark"] .manual-rubric-header .muted-text,
[data-theme="dark"] .rubric-toolbar .muted-text,
[data-theme="dark"] .rubric-table-note,
[data-theme="dark"] .helper-note,
[data-theme="dark"] .manual-rubric-status {
  color: #cbd5e1 !important;
}

[data-theme="dark"] .rubric-import-badge {
  color: #dbeafe !important;
  border-color: rgba(96, 165, 250, 0.32) !important;
  background: rgba(96, 165, 250, 0.14) !important;
}

[data-theme="dark"] .manual-score-row input,
[data-theme="dark"] .manual-rubric-input-table textarea,
[data-theme="dark"] .teacher-rubric-table input,
[data-theme="dark"] .teacher-rubric-table select,
[data-theme="dark"] .teacher-rubric-table textarea,
[data-theme="dark"] .rubric-level-cell input,
[data-theme="dark"] .rubric-level-cell textarea,
[data-theme="dark"] .criterion-mini-grid input,
[data-theme="dark"] .criterion-mini-grid select {
  color: #f8fafc !important;
  border-color: rgba(96, 165, 250, 0.24) !important;
  background: rgba(2, 6, 23, 0.72) !important;
}

[data-theme="dark"] .manual-score-row input:focus,
[data-theme="dark"] .manual-rubric-input-table textarea:focus,
[data-theme="dark"] .teacher-rubric-table input:focus,
[data-theme="dark"] .teacher-rubric-table select:focus,
[data-theme="dark"] .teacher-rubric-table textarea:focus {
  color: #ffffff !important;
  border-color: #60a5fa !important;
  background: rgba(2, 6, 23, 0.92) !important;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18) !important;
}

[data-theme="dark"] .manual-rubric-input-table textarea::placeholder,
[data-theme="dark"] .teacher-rubric-table textarea::placeholder,
[data-theme="dark"] .rubric-level-cell textarea::placeholder {
  color: #94a3b8 !important;
}

[data-theme="dark"] .manual-rubric-input-table th,
[data-theme="dark"] .teacher-rubric-table thead th,
[data-theme="dark"] .scale-rubric-head {
  color: #f8fafc !important;
  border-color: rgba(96, 165, 250, 0.22) !important;
  background: rgba(30, 41, 59, 0.95) !important;
}

[data-theme="dark"] .manual-rubric-input-table td,
[data-theme="dark"] .teacher-rubric-table td,
[data-theme="dark"] .scale-level-row {
  color: #e5edf7 !important;
  border-color: rgba(96, 165, 250, 0.18) !important;
  background: rgba(15, 23, 42, 0.88) !important;
}

[data-theme="dark"] .rubric-criterion-cell,
[data-theme="dark"] .criterion-card,
[data-theme="dark"] .manual-rubric-input-row {
  color: #e5edf7 !important;
  border-color: rgba(96, 165, 250, 0.2) !important;
  background: rgba(15, 23, 42, 0.92) !important;
}

[data-theme="dark"] .criterion-number {
  color: #dbeafe !important;
  background: rgba(37, 99, 235, 0.28) !important;
}

[data-theme="dark"] .rubric-score-label,
[data-theme="dark"] .teacher-rubric-table td::before,
[data-theme="dark"] .manual-rubric-input-table td::before {
  color: #93c5fd !important;
}

[data-theme="dark"] .remove-manual-rubric-row,
[data-theme="dark"] .remove-criterion {
  color: #fecdd3 !important;
  border-color: rgba(251, 113, 133, 0.28) !important;
  background: rgba(2, 6, 23, 0.72) !important;
}

[data-theme="dark"] .manual-rubric-status.success {
  color: #86efac !important;
}

[data-theme="dark"] .manual-rubric-status.error {
  color: #fecdd3 !important;
}

@media (max-width: 820px) {
  .manual-rubric-input-table th:last-child,
  .manual-rubric-input-table td:last-child,
  .manual-rubric-row-action {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .remove-manual-rubric-row {
    width: 100% !important;
  }

  [data-theme="dark"] #adminOverlay .modal-header {
    color: #e5edf7 !important;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.94)) !important;
  }

  [data-theme="dark"] #adminOverlay .admin-tabs-wrap {
    background: linear-gradient(180deg, rgba(15, 23, 42, 1), rgba(15, 23, 42, 0.92)) !important;
  }
}

/* FINAL OUTPUT CONTROL MENU + RUBRIC BADGE FIT FIX */
.ai-badge {
  width: auto !important;
  min-width: 64px !important;
  height: 44px !important;
  padding: 0 10px !important;
  border-radius: 999px !important;
  font-size: 0.82rem !important;
  line-height: 1 !important;
  text-align: center !important;
  white-space: nowrap !important;
  overflow: visible !important;
}

#previewControlsToggle.preview-controls-toggle {
  width: 42px !important;
  min-width: 42px !important;
  height: 42px !important;
  min-height: 42px !important;
  padding: 0 !important;
  border-radius: 50% !important;
  font-size: 1.05rem !important;
  line-height: 1 !important;
  color: #0f2852 !important;
  border: 1px solid rgba(147, 197, 253, 0.7) !important;
  background: rgba(255, 255, 255, 0.92) !important;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14) !important;
}

#previewControlsToggle.preview-controls-toggle:hover,
#previewControlsToggle.preview-controls-toggle:focus-visible,
.preview-actions.output-menu-open #previewControlsToggle.preview-controls-toggle {
  color: #ffffff !important;
  border-color: transparent !important;
  background: linear-gradient(135deg, #2563eb, #06b6d4) !important;
  outline: none !important;
}

[data-theme="dark"] #previewControlsToggle.preview-controls-toggle {
  color: #e5edf7 !important;
  border-color: rgba(96, 165, 250, 0.36) !important;
  background: rgba(15, 23, 42, 0.9) !important;
}

@media (min-width: 761px) {
  body.preview-fullscreen-active.preview-has-back-editor .preview-panel .preview-actions,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions,
  #previewPanel:fullscreen .preview-actions,
  #previewPanel:-webkit-full-screen .preview-actions {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    width: auto !important;
    max-width: calc(100vw - 24px) !important;
    padding: 6px !important;
    border-radius: 999px !important;
    transition: max-width 0.18s ease, background 0.18s ease, box-shadow 0.18s ease !important;
  }

  body.preview-fullscreen-active.preview-has-back-editor .preview-panel .preview-actions:not(.output-menu-open),
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions:not(.output-menu-open) {
    gap: 0 !important;
    padding: 4px !important;
    background: rgba(255, 255, 255, 0.62) !important;
    border: 1px solid rgba(147, 197, 253, 0.48) !important;
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.12) !important;
    backdrop-filter: blur(12px) !important;
  }

  [data-theme="dark"] body.preview-fullscreen-active.preview-has-back-editor .preview-panel .preview-actions:not(.output-menu-open),
  [data-theme="dark"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-panel .preview-actions:not(.output-menu-open) {
    background: rgba(15, 23, 42, 0.62) !important;
    border-color: rgba(96, 165, 250, 0.3) !important;
  }

  body.preview-fullscreen-active.preview-has-back-editor .preview-actions #previewControlsToggle:not(.hidden),
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions #previewControlsToggle:not(.hidden),
  #previewPanel:fullscreen .preview-actions #previewControlsToggle:not(.hidden),
  #previewPanel:-webkit-full-screen .preview-actions #previewControlsToggle:not(.hidden) {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    pointer-events: auto !important;
  }

  body.preview-fullscreen-active.preview-has-back-editor .preview-actions:not(.output-menu-open) #backToEditorPreviewBtn,
  body.preview-fullscreen-active.preview-has-back-editor .preview-actions:not(.output-menu-open) #resultFromPreviewBtn,
  body.preview-fullscreen-active.preview-has-back-editor .preview-actions:not(.output-menu-open) #exitPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions:not(.output-menu-open) #backToEditorPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions:not(.output-menu-open) #resultFromPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions:not(.output-menu-open) #exitPreviewBtn {
    display: none !important;
  }

  body.preview-fullscreen-active.preview-has-back-editor .preview-actions.output-menu-open #backToEditorPreviewBtn,
  body.preview-fullscreen-active.preview-has-back-editor .preview-actions.output-menu-open #resultFromPreviewBtn,
  body.preview-fullscreen-active.preview-has-back-editor .preview-actions.output-menu-open #exitPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions.output-menu-open #backToEditorPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions.output-menu-open #resultFromPreviewBtn,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel .preview-actions.output-menu-open #exitPreviewBtn {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
}

@media (max-width: 760px) {
  #previewControlsToggle.preview-controls-toggle {
    display: none !important;
  }
}


/* FINAL DESKTOP HEADER HOVER ACCOUNT STRIP
   Desktop only: keep account actions hidden until the header is hovered/focused,
   then slide them down smoothly. Phone/mobile menu rules remain unchanged. */
@media (min-width: 821px) {
  body.student-session-active .topbar.simplified-topbar,
  body.student-session-active .topbar,
  body.guest-session-active .topbar.simplified-topbar,
  body.guest-session-active .topbar {
    grid-template-rows: auto 0fr !important;
    row-gap: 0 !important;
    transition: grid-template-rows 0.24s ease, row-gap 0.24s ease, box-shadow 0.2s ease !important;
  }

  body.student-session-active .topbar:hover,
  body.student-session-active .topbar:focus-within,
  body.guest-session-active .topbar:hover,
  body.guest-session-active .topbar:focus-within {
    grid-template-rows: auto auto !important;
    row-gap: 8px !important;
  }

  body.student-session-active .student-account-strip:not(.hidden),
  body.guest-session-active .guest-account-strip:not(.hidden) {
    max-height: 0 !important;
    min-height: 0 !important;
    height: auto !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    opacity: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
    transform: translateY(-12px) scaleY(0.96) !important;
    transform-origin: top center !important;
    border-color: transparent !important;
    box-shadow: none !important;
    transition:
      max-height 0.26s ease,
      min-height 0.26s ease,
      padding 0.26s ease,
      opacity 0.18s ease,
      transform 0.26s ease,
      border-color 0.2s ease,
      box-shadow 0.2s ease !important;
  }

  body.student-session-active .topbar:hover .student-account-strip:not(.hidden),
  body.student-session-active .topbar:focus-within .student-account-strip:not(.hidden),
  body.guest-session-active .topbar:hover .guest-account-strip:not(.hidden),
  body.guest-session-active .topbar:focus-within .guest-account-strip:not(.hidden) {
    max-height: 58px !important;
    min-height: 42px !important;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: translateY(0) scaleY(1) !important;
  }

  body.student-session-active .topbar:hover .student-account-strip:not(.hidden),
  body.student-session-active .topbar:focus-within .student-account-strip:not(.hidden) {
    border-color: rgba(147, 197, 253, 0.58) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75) !important;
  }

  [data-theme="dark"] body.student-session-active .topbar:hover .student-account-strip:not(.hidden),
  [data-theme="dark"] body.student-session-active .topbar:focus-within .student-account-strip:not(.hidden) {
    border-color: rgba(96, 165, 250, 0.3) !important;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.04),
      0 10px 22px rgba(2, 6, 23, 0.2) !important;
  }

  /* Keep desktop title readable even when the student name is long. */
  body.student-session-active #appTitleText {
    font-size: clamp(1rem, 1.55vw, 1.48rem) !important;
    line-height: 1.08 !important;
    max-width: 100% !important;
  }
}


/* FINAL FULL EDITOR STUDIO DEDUPE FIX: Format/Snapshot live only inside the Studio drawer. */
#fullscreenFormatBtn,
#fullscreenSnapshotBtn {
  display: none !important;
}


/* PREMIUM FULLSCREEN EDITOR <-> OUTPUT TRANSITION */
.fullscreen-book-transition-layer {
  background:
    radial-gradient(circle at 50% 46%, rgba(37, 99, 235, 0.22), transparent 30rem),
    radial-gradient(circle at 50% 55%, rgba(34, 197, 94, 0.12), transparent 24rem),
    linear-gradient(135deg, rgba(2, 6, 23, 0.14), rgba(15, 23, 42, 0.28)) !important;
  backdrop-filter: blur(7px) saturate(1.25) !important;
  animation: premiumTransitionLayerIn 1240ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

.fullscreen-book-stage {
  filter: drop-shadow(0 38px 82px rgba(15, 23, 42, 0.28));
  animation: premiumStageFloat 1240ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

.fullscreen-book-fixed-page,
.fullscreen-book-turn-page {
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.99), rgba(239, 246, 255, 0.98) 48%, rgba(191, 219, 254, 0.96)),
    linear-gradient(180deg, transparent, rgba(37, 99, 235, 0.08)) !important;
  box-shadow:
    0 40px 120px rgba(15, 23, 42, 0.30),
    inset 24px 0 34px rgba(255, 255, 255, 0.58),
    inset -34px 0 46px rgba(37, 99, 235, 0.17) !important;
}

.fullscreen-book-highlight {
  opacity: 0.86 !important;
  background:
    linear-gradient(108deg, transparent 0%, rgba(255, 255, 255, 0.86) 40%, rgba(255, 255, 255, 0.18) 50%, transparent 64%),
    repeating-linear-gradient(0deg, rgba(37, 99, 235, 0.032) 0 2px, transparent 2px 15px) !important;
  animation: premiumLightSweep 1240ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

.fullscreen-book-edge {
  width: 42px !important;
  background: linear-gradient(90deg, transparent, rgba(96, 165, 250, 0.58), rgba(255, 255, 255, 0.72), rgba(96, 165, 250, 0.42), transparent) !important;
  filter: blur(0.3px);
  animation: premiumEdgePass 1240ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

.fullscreen-book-caption {
  left: 50% !important;
  top: 50% !important;
  bottom: auto !important;
  transform: translate(-50%, -50%) scale(0.96) !important;
  display: grid !important;
  place-items: center !important;
  min-width: min(520px, calc(100vw - 44px)) !important;
  max-width: calc(100vw - 44px) !important;
  min-height: 118px !important;
  border: 1px solid rgba(147, 197, 253, 0.72) !important;
  border-radius: 32px !important;
  padding: 28px 34px !important;
  color: #0f2852 !important;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(239, 246, 255, 0.80)),
    radial-gradient(circle at top left, rgba(96, 165, 250, 0.24), transparent 18rem) !important;
  backdrop-filter: blur(20px) saturate(1.35) !important;
  box-shadow:
    0 36px 110px rgba(15, 23, 42, 0.30),
    inset 0 1px 0 rgba(255, 255, 255, 0.82) !important;
  font-size: clamp(1.18rem, 2.35vw, 2rem) !important;
  line-height: 1.08 !important;
  text-align: center !important;
  letter-spacing: -0.02em !important;
  animation: premiumCenterCaption 1240ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

.fullscreen-book-caption::before {
  content: '🖥️';
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin: 0 0 12px;
  border-radius: 18px;
  color: #ffffff;
  background: linear-gradient(135deg, #2563eb, #06b6d4 58%, #22c55e);
  box-shadow: 0 16px 42px rgba(37, 99, 235, 0.34);
  font-size: 1.25rem;
}

.fullscreen-book-transition-layer.to-editor .fullscreen-book-caption::before {
  content: '⌨️';
}

.fullscreen-book-caption::after {
  content: 'Please wait...';
  display: block;
  margin-top: 11px;
  color: #42627e;
  font-size: clamp(0.74rem, 1.2vw, 0.88rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.88;
}

.fullscreen-book-transition-layer.to-preview .fullscreen-book-turn-page {
  animation: premiumBookTurnToPreview 1240ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

.fullscreen-book-transition-layer.to-editor .fullscreen-book-turn-page {
  animation: premiumBookTurnToEditor 1240ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

.fullscreen-book-transition-layer.to-preview .fullscreen-book-fixed-page {
  animation: premiumBookFixedToPreview 1240ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

.fullscreen-book-transition-layer.to-editor .fullscreen-book-fixed-page {
  animation: premiumBookFixedToEditor 1240ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
}

body.editor-fullscreen-active.preview-inside-editor-fullscreen.book-preview-revealing #editorPanel .preview-panel {
  animation: premiumPreviewReveal 560ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
  transform-origin: center center !important;
  will-change: transform, opacity, filter !important;
}

body.editor-fullscreen-active.book-editor-revealing #editorPanel .language-tabs,
body.editor-fullscreen-active.book-editor-revealing #editorPanel .html-page-manager,
body.editor-fullscreen-active.book-editor-revealing #editorPanel .editor-wrap,
body.editor-fullscreen-active.book-editor-revealing #fullscreenEditorActions,
body.editor-fullscreen-active.book-editor-revealing #superStudioToolbar,
body.editor-fullscreen-active.book-editor-revealing #codeHelperFloatingBtn {
  animation: premiumEditorReveal 620ms cubic-bezier(0.16, 0.84, 0.22, 1) both !important;
  transform-origin: center top !important;
  will-change: transform, opacity, filter !important;
}

[data-theme="dark"] .fullscreen-book-transition-layer {
  background:
    radial-gradient(circle at 50% 46%, rgba(96, 165, 250, 0.18), transparent 30rem),
    radial-gradient(circle at 50% 55%, rgba(34, 197, 94, 0.10), transparent 24rem),
    linear-gradient(135deg, rgba(0, 0, 0, 0.40), rgba(2, 6, 23, 0.68)) !important;
}

[data-theme="dark"] .fullscreen-book-fixed-page,
[data-theme="dark"] .fullscreen-book-turn-page {
  background:
    linear-gradient(120deg, rgba(15, 23, 42, 0.99), rgba(30, 41, 59, 0.98) 48%, rgba(37, 99, 235, 0.34)),
    #0f172a !important;
  box-shadow:
    0 42px 120px rgba(0, 0, 0, 0.58),
    inset 24px 0 34px rgba(255, 255, 255, 0.055),
    inset -34px 0 46px rgba(96, 165, 250, 0.18) !important;
}

[data-theme="dark"] .fullscreen-book-caption {
  color: #f8fafc !important;
  border-color: rgba(96, 165, 250, 0.45) !important;
  background:
    linear-gradient(135deg, rgba(15, 23, 42, 0.92), rgba(30, 41, 59, 0.76)),
    radial-gradient(circle at top left, rgba(96, 165, 250, 0.16), transparent 18rem) !important;
  box-shadow:
    0 36px 110px rgba(0, 0, 0, 0.60),
    inset 0 1px 0 rgba(255, 255, 255, 0.08) !important;
}

[data-theme="dark"] .fullscreen-book-caption::after {
  color: #bfdbfe;
}

@keyframes premiumTransitionLayerIn {
  0% { opacity: 0; }
  12%, 86% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes premiumStageFloat {
  0% { opacity: 0; transform: translateY(24px) scale(0.985); filter: blur(1.4px); }
  12% { opacity: 1; }
  50% { transform: translateY(0) scale(1); filter: blur(0); }
  100% { opacity: 0; transform: translateY(-18px) scale(1.01); filter: blur(1px); }
}

@keyframes premiumCenterCaption {
  0% { opacity: 0; transform: translate(-50%, -42%) scale(0.90); filter: blur(10px); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1); filter: blur(0); }
  72% { opacity: 1; transform: translate(-50%, -50%) scale(1); filter: blur(0); }
  100% { opacity: 0; transform: translate(-50%, -58%) scale(0.96); filter: blur(8px); }
}

@keyframes premiumBookTurnToPreview {
  0% { opacity: 0; transform: translateX(62%) rotateY(-72deg) scaleX(0.94); filter: blur(2.2px) brightness(1.04); }
  12% { opacity: 1; }
  40% { opacity: 1; transform: translateX(-3%) rotateY(-7deg) scaleX(1); filter: blur(0) brightness(1); }
  55% { opacity: 1; transform: translateX(-18%) rotateY(13deg) scaleX(1.018); filter: blur(0); }
  100% { opacity: 0; transform: translateX(-118%) rotateY(64deg) scaleX(0.94); filter: blur(2px) brightness(1.08); }
}

@keyframes premiumBookTurnToEditor {
  0% { opacity: 0; transform: translateX(-62%) rotateY(72deg) scaleX(0.94); filter: blur(2.2px) brightness(1.04); }
  12% { opacity: 1; }
  40% { opacity: 1; transform: translateX(3%) rotateY(7deg) scaleX(1); filter: blur(0) brightness(1); }
  55% { opacity: 1; transform: translateX(18%) rotateY(-13deg) scaleX(1.018); filter: blur(0); }
  100% { opacity: 0; transform: translateX(118%) rotateY(-64deg) scaleX(0.94); filter: blur(2px) brightness(1.08); }
}

@keyframes premiumBookFixedToPreview {
  0% { opacity: 0.16; transform: translateX(12%) scale(0.982); filter: blur(1.2px); }
  42% { opacity: 0.48; transform: translateX(1.5%) scale(0.996); filter: blur(0); }
  58% { opacity: 0.68; transform: translateX(0) scale(1); filter: blur(0); }
  100% { opacity: 0; transform: translateX(-5%) scale(1.014); filter: blur(1px); }
}

@keyframes premiumBookFixedToEditor {
  0% { opacity: 0.16; transform: translateX(-12%) scale(0.982); filter: blur(1.2px); }
  42% { opacity: 0.48; transform: translateX(-1.5%) scale(0.996); filter: blur(0); }
  58% { opacity: 0.68; transform: translateX(0) scale(1); filter: blur(0); }
  100% { opacity: 0; transform: translateX(5%) scale(1.014); filter: blur(1px); }
}

@keyframes premiumEdgePass {
  0%, 100% { opacity: 0; transform: translateX(-50%) scaleX(0.55); }
  40%, 58% { opacity: 0.78; transform: translateX(-50%) scaleX(2.25); }
}

@keyframes premiumLightSweep {
  0% { opacity: 0; transform: translateX(28%); }
  22%, 66% { opacity: 0.86; }
  100% { opacity: 0; transform: translateX(-20%); }
}

@keyframes premiumPreviewReveal {
  0% { opacity: 0; transform: translateY(18px) scale(0.972); filter: blur(10px) saturate(0.85); }
  62% { opacity: 1; transform: translateY(-2px) scale(1.006); filter: blur(0) saturate(1.04); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: none; }
}

@keyframes premiumEditorReveal {
  0% { opacity: 0; transform: translateY(-18px) scale(0.985); filter: blur(8px) saturate(0.9); }
  62% { opacity: 1; transform: translateY(2px) scale(1.004); filter: blur(0) saturate(1.03); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: none; }
}

@media (max-width: 720px) {
  .fullscreen-book-caption {
    min-width: min(360px, calc(100vw - 28px)) !important;
    min-height: 96px !important;
    border-radius: 24px !important;
    padding: 20px 22px !important;
    font-size: 1.08rem !important;
  }

  .fullscreen-book-caption::before {
    width: 44px;
    height: 44px;
    margin-bottom: 9px;
    border-radius: 15px;
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fullscreen-book-transition-layer,
  .fullscreen-book-stage,
  .fullscreen-book-highlight,
  .fullscreen-book-edge,
  .fullscreen-book-caption,
  body.editor-fullscreen-active.preview-inside-editor-fullscreen.book-preview-revealing #editorPanel .preview-panel,
  body.editor-fullscreen-active.book-editor-revealing #editorPanel .language-tabs,
  body.editor-fullscreen-active.book-editor-revealing #editorPanel .html-page-manager,
  body.editor-fullscreen-active.book-editor-revealing #editorPanel .editor-wrap,
  body.editor-fullscreen-active.book-editor-revealing #fullscreenEditorActions,
  body.editor-fullscreen-active.book-editor-revealing #superStudioToolbar,
  body.editor-fullscreen-active.book-editor-revealing #codeHelperFloatingBtn {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}


/* FINAL STUDIO TOGGLE UX FIX */
.studio-launcher.is-active {
  color: #1e3a8a;
  border-color: rgba(37, 99, 235, 0.3);
  background: linear-gradient(135deg, #dbeafe, #e0f2fe) !important;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.12);
}

.studio-launcher.is-active strong {
  color: #1e3a8a;
}


/* FINAL ACTIVITY POPUP + STUDENT RUBRIC VIEW */
.activity-launch-btn.activity-empty {
  color: #1d4ed8;
  border-color: rgba(37, 99, 235, 0.25);
  background: linear-gradient(135deg, #eff6ff, #f8fbff);
}

.activity-launch-btn.activity-selected {
  color: #14532d;
  border-color: rgba(34, 197, 94, 0.35);
  background: linear-gradient(135deg, #dcfce7, #f0fdf4);
}

.activity-launch-btn.needs-attention {
  color: #991b1b !important;
  border-color: rgba(220, 38, 38, 0.35) !important;
  background: linear-gradient(135deg, #fee2e2, #fff7ed) !important;
}

#activityCard.activity-popup:not(.collapsed-card) {
  position: fixed !important;
  inset: 0 !important;
  z-index: 12400 !important;
  display: grid !important;
  place-items: center !important;
  width: 100% !important;
  height: 100dvh !important;
  margin: 0 !important;
  padding: clamp(14px, 3vw, 28px) !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: rgba(2, 6, 23, 0.64) !important;
  box-shadow: none !important;
  backdrop-filter: blur(12px);
  overflow: auto !important;
  animation: activityBackdropIn 0.18s ease both;
}

.activity-popup-panel {
  width: min(900px, 100%);
  max-height: min(760px, calc(100dvh - 32px));
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 28px;
  padding: clamp(18px, 3vw, 26px);
  color: var(--text);
  background: linear-gradient(145deg, var(--solid-card), var(--bg-2));
  box-shadow: 0 26px 90px rgba(2, 6, 23, 0.38);
  animation: activityPanelIn 0.24s cubic-bezier(.2,.9,.2,1) both;
}

.activity-popup-head,
.activity-rubric-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.activity-popup-head h2,
.activity-rubric-head h2 {
  margin: 4px 0 6px;
}

.activity-close-btn,
.activity-rubric-head .icon-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.2rem;
}

.activity-popup-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 18px;
  align-items: stretch;
}

.activity-popup .activity-main {
  display: grid;
  gap: 14px;
}

.activity-popup .activity-select-row {
  display: grid;
  grid-template-columns: 140px minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.activity-popup .activity-stats {
  display: grid;
  gap: 12px;
  align-content: start;
}

.activity-stat-card,
.activity-stats > .activity-stat-card {
  width: 100%;
  min-width: 0;
  min-height: 118px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  padding: 18px 14px;
  color: var(--text);
  background: var(--solid-card);
  text-align: center;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08);
}

button.activity-stat-card {
  cursor: pointer;
}

.criteria-stat-card {
  position: relative;
  overflow: hidden;
}

.criteria-stat-card:not(.disabled)::after {
  content: '';
  position: absolute;
  inset: auto 16px 12px;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #06b6d4);
}

.criteria-stat-card:hover,
.criteria-stat-card:focus-visible {
  border-color: var(--primary);
  outline: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.criteria-stat-card.disabled {
  cursor: not-allowed;
  opacity: 0.78;
}

.stat-hint {
  display: block;
  margin-top: 7px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 900;
}

.activity-rubric-overlay {
  position: fixed;
  inset: 0;
  z-index: 12500;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 28px);
  background: rgba(2, 6, 23, 0.68);
  backdrop-filter: blur(12px);
  overflow: auto;
  animation: activityBackdropIn 0.18s ease both;
}

.activity-rubric-card {
  width: min(1180px, 100%);
  max-height: min(820px, calc(100dvh - 28px));
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 28px;
  padding: clamp(18px, 3vw, 26px);
  color: var(--text);
  background: linear-gradient(145deg, var(--solid-card), var(--bg-2));
  box-shadow: 0 26px 90px rgba(2, 6, 23, 0.4);
  animation: activityPanelIn 0.24s cubic-bezier(.2,.9,.2,1) both;
}

.activity-rubric-table-wrap {
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--solid-card);
}

.student-rubric-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.student-rubric-table th,
.student-rubric-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 14px;
  text-align: left;
  vertical-align: top;
}

.student-rubric-table th:last-child,
.student-rubric-table td:last-child {
  border-right: 0;
}

.student-rubric-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--text);
  background: color-mix(in srgb, var(--primary-soft) 55%, var(--solid-card));
  font-weight: 1000;
}

.student-rubric-table tbody th {
  width: 220px;
  color: var(--text);
  background: color-mix(in srgb, var(--bg-2) 72%, var(--solid-card));
  font-weight: 900;
}

.student-rubric-table tbody th span {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-right: 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--primary);
  font-size: 0.78rem;
}

.student-rubric-table td strong {
  display: inline-flex;
  margin-bottom: 7px;
  border-radius: 999px;
  padding: 4px 8px;
  color: #1e3a8a;
  background: var(--primary-soft);
  font-size: 0.78rem;
}

.student-rubric-table td span {
  display: block;
  color: var(--muted);
  line-height: 1.42;
}

[data-theme="dark"] .activity-launch-btn.activity-empty {
  color: #dbeafe;
  background: rgba(96, 165, 250, 0.14);
}

[data-theme="dark"] .activity-launch-btn.activity-selected {
  color: #dcfce7;
  background: rgba(34, 197, 94, 0.14);
}

[data-theme="dark"] .activity-popup-panel,
[data-theme="dark"] .activity-rubric-card {
  background: linear-gradient(145deg, #0f172a, #111827);
}

[data-theme="dark"] .student-rubric-table thead th {
  background: #1e293b;
}

[data-theme="dark"] .student-rubric-table tbody th {
  background: #111827;
}

[data-theme="dark"] .student-rubric-table td strong {
  color: #dbeafe;
  background: rgba(96, 165, 250, 0.18);
}

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

@keyframes activityPanelIn {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 820px) {
  .activity-popup-grid {
    grid-template-columns: 1fr;
  }

  .activity-popup .activity-select-row {
    grid-template-columns: 1fr;
  }

  .activity-popup .activity-stats {
    grid-template-columns: 1fr 1fr;
  }

  .activity-stat-card,
  .activity-stats > .activity-stat-card {
    min-height: 100px;
  }
}

@media (max-width: 520px) {
  .activity-popup .activity-stats {
    grid-template-columns: 1fr;
  }

  .activity-popup-head,
  .activity-rubric-head {
    align-items: stretch;
  }
}

/* Coach percentage is now labeled as a quick code health check, not a grade. */
.studio-quality-chip::after {
  content: 'not grade';
  margin-left: 6px;
  border-radius: 999px;
  padding: 2px 6px;
  color: var(--muted);
  background: rgba(148, 163, 184, 0.16);
  font-size: 0.64rem;
  font-weight: 900;
  text-transform: uppercase;
}


/* FINAL ACTIVITY POPUP CENTERING + PREMIUM SPACING */
body.activity-popup-open {
  overflow: hidden !important;
}

#activityCard.activity-popup:not(.collapsed-card) {
  left: 0 !important;
  right: 0 !important;
  top: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  max-width: none !important;
  min-width: 0 !important;
  height: 100dvh !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: clamp(18px, 4vw, 44px) !important;
}

#activityCard.activity-popup:not(.collapsed-card) .activity-popup-panel {
  width: min(980px, calc(100vw - clamp(36px, 8vw, 88px))) !important;
  max-width: 980px !important;
  margin: auto !important;
  border-radius: 32px !important;
  padding: clamp(22px, 3vw, 34px) !important;
  transform-origin: center center !important;
}

#activityCard.activity-popup:not(.collapsed-card) .activity-popup-grid {
  grid-template-columns: minmax(0, 1fr) minmax(210px, 250px) !important;
  gap: clamp(18px, 3vw, 28px) !important;
}

#activityCard.activity-popup:not(.collapsed-card) .activity-popup-head {
  margin-bottom: 22px !important;
}

#activityCard.activity-popup:not(.collapsed-card) .activity-select-row {
  border-radius: 22px !important;
  padding: 14px !important;
  background: color-mix(in srgb, var(--bg-2) 74%, var(--solid-card)) !important;
}

#activityCard.activity-popup:not(.collapsed-card) .activity-stats {
  gap: 14px !important;
}

#activityCard.activity-popup:not(.collapsed-card) .activity-stat-card {
  min-height: 132px !important;
  display: grid !important;
  place-items: center !important;
  align-content: center !important;
}

@media (min-width: 821px) {
  #activityCard.activity-popup:not(.collapsed-card) .activity-popup-panel {
    translate: 0 0 !important;
  }
}

@media (max-width: 820px) {
  #activityCard.activity-popup:not(.collapsed-card) {
    align-items: flex-start !important;
    padding: 14px !important;
  }

  #activityCard.activity-popup:not(.collapsed-card) .activity-popup-panel {
    width: 100% !important;
    max-height: calc(100dvh - 28px) !important;
    border-radius: 24px !important;
  }

  #activityCard.activity-popup:not(.collapsed-card) .activity-popup-grid {
    grid-template-columns: 1fr !important;
  }
}


/* FINAL OUTPUT PREVIEW RESULT BUTTON */
.preview-panel .preview-actions #resultFromPreviewBtn.preview-result-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  border-color: transparent;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  box-shadow: 0 8px 18px rgba(22, 163, 74, 0.18);
}

.preview-panel .preview-actions #resultFromPreviewBtn.preview-result-btn:hover,
.preview-panel .preview-actions #resultFromPreviewBtn.preview-result-btn:focus-visible {
  color: #ffffff;
  background: linear-gradient(135deg, #15803d, #16a34a);
}

html[data-device-mode="desktop"] .preview-panel .preview-actions #resultFromPreviewBtn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: auto !important;
  min-height: 38px !important;
  padding: 0 14px !important;
  font-size: 0.86rem !important;
  white-space: nowrap !important;
}

html[data-device-mode="desktop"] .preview-panel .preview-actions #resultFromPreviewBtn.hidden,
.preview-panel .preview-actions #resultFromPreviewBtn.hidden {
  display: none !important;
}


/* PHONE STUDIO CLOSE FIX: Studio button stays visible and becomes Hide Studio when open. */
#superStudioLauncher.studio-launcher.is-active {
  color: #1e3a8a;
  border-color: rgba(37, 99, 235, 0.3);
  background: linear-gradient(135deg, #dbeafe, #e0f2fe) !important;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.12);
}

@media (max-width: 760px) {
  body.super-studio-open .page-manager-actions.has-studio-launcher #superStudioLauncher.studio-launcher {
    display: inline-flex !important;
  }

  body.super-studio-open .page-manager-actions.has-studio-launcher {
    align-items: stretch !important;
  }
}


/* FINAL MOBILE OUTPUT PREVIEW CONTROLS + SMOOTH RUN SCROLL */
.preview-panel {
  scroll-margin-top: 82px;
}

@media (max-width: 820px) {
  .preview-panel {
    scroll-margin-top: 92px;
  }
}

html[data-device-mode="phone"] .preview-panel .preview-header {
  align-items: flex-start !important;
  gap: 12px !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 7px !important;
  width: 100% !important;
  max-width: none !important;
  margin-top: 4px !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn,
html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn,
html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 40px !important;
  height: 40px !important;
  padding: 0 8px !important;
  border-radius: 999px !important;
  font-size: 0.76rem !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  box-shadow: none !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn.preview-result-btn {
  grid-column: auto !important;
  color: #ffffff !important;
  background: linear-gradient(135deg, #16a34a, #22c55e) !important;
  box-shadow: 0 8px 18px rgba(22, 163, 74, 0.16) !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn::before {
  font-size: 0.76rem !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn.hidden {
  display: none !important;
}

@media (max-width: 420px) {
  html[data-device-mode="phone"] .preview-panel .preview-actions {
    gap: 6px !important;
  }

  html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn,
  html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn,
  html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn {
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 6px !important;
    font-size: 0.7rem !important;
  }

  html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn::before {
    content: 'Monitor' !important;
    font-size: 0.7rem !important;
  }
}


/* FINAL FIX: phone Output Preview buttons + exact Run top-align */
html[data-device-mode="phone"] .preview-panel .preview-header {
  overflow: hidden !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 6px !important;
  width: 100% !important;
  max-width: 100% !important;
  margin-top: 4px !important;
  overflow: hidden !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions .layout-btn[data-layout],
html[data-device-mode="phone"] .preview-panel .preview-actions #previewControlsToggle {
  display: none !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn,
html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn,
html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  min-height: 38px !important;
  height: 38px !important;
  padding: 0 5px !important;
  border-radius: 999px !important;
  font-size: 0 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: clip !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn::before,
html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn::before,
html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn::before {
  display: inline-block !important;
  max-width: 100% !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  font-size: 0.68rem !important;
  font-weight: 900 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn::before {
  content: '🖥️ Monitor' !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn.active::before {
  content: '📱 Phone' !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn::before {
  content: '⛶ Full' !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn::before {
  content: '✓ Result' !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn.preview-result-btn {
  color: #ffffff !important;
  background: linear-gradient(135deg, #16a34a, #22c55e) !important;
  box-shadow: 0 8px 18px rgba(22, 163, 74, 0.14) !important;
}

html[data-device-mode="phone"] .preview-panel .preview-actions #exitPreviewBtn.hidden,
html[data-device-mode="phone"] .preview-panel .preview-actions #backToEditorPreviewBtn.hidden,
html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn.hidden,
html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn.hidden {
  display: none !important;
}

@media (max-width: 360px) {
  html[data-device-mode="phone"] .preview-panel .preview-actions {
    gap: 5px !important;
  }

  html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn::before {
    font-size: 0.62rem !important;
  }
}


/* FINAL MOBILE POLISH + PERFORMANCE PASS */
html,
body {
  overscroll-behavior-y: contain;
}

@media (max-width: 760px) {
  html,
  body,
  .app-shell,
  .workspace,
  .panel,
  .preview-panel,
  .editor-panel {
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  .preview-panel .preview-header,
  html[data-device-mode="phone"] .preview-panel .preview-header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: start !important;
    gap: 12px !important;
    padding: 16px !important;
  }

  .preview-panel .preview-header > div,
  html[data-device-mode="phone"] .preview-panel .preview-header > div {
    min-width: 0 !important;
  }

  .preview-panel .preview-header h2,
  .preview-panel .preview-header p {
    overflow-wrap: anywhere !important;
  }

  .preview-panel .preview-actions,
  html[data-device-mode="phone"] .preview-panel .preview-actions {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 7px !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    overflow: hidden !important;
  }

  .preview-panel .preview-actions .layout-btn[data-layout],
  .preview-panel .preview-actions #previewControlsToggle,
  html[data-device-mode="phone"] .preview-panel .preview-actions .layout-btn[data-layout],
  html[data-device-mode="phone"] .preview-panel .preview-actions #previewControlsToggle {
    display: none !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn,
  .preview-panel .preview-actions #fullPreviewBtn,
  .preview-panel .preview-actions #resultFromPreviewBtn,
  html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn,
  html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn,
  html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 5px !important;
    border-radius: 999px !important;
    font-size: 0 !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: clip !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn::before,
  .preview-panel .preview-actions #fullPreviewBtn::before,
  .preview-panel .preview-actions #resultFromPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn::before {
    display: inline-block !important;
    max-width: 100% !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    font-size: 0.7rem !important;
    font-weight: 900 !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    color: var(--text) !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn::before {
    content: attr(data-mobile-label) !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn:not([data-mobile-label])::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn:not([data-mobile-label])::before {
    content: '🖥️ Monitor' !important;
  }

  .preview-panel .preview-actions #fullPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn::before {
    content: '⛶ Full' !important;
  }

  .preview-panel .preview-actions #resultFromPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn::before {
    content: '✓ Result' !important;
    color: #ffffff !important;
  }

  .preview-panel .preview-actions #resultFromPreviewBtn.preview-result-btn,
  html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn.preview-result-btn {
    color: transparent !important;
    background: linear-gradient(135deg, #16a34a, #22c55e) !important;
    box-shadow: 0 8px 16px rgba(22, 163, 74, 0.14) !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn.hidden,
  .preview-panel .preview-actions #fullPreviewBtn.hidden,
  .preview-panel .preview-actions #resultFromPreviewBtn.hidden,
  .preview-panel .preview-actions #exitPreviewBtn.hidden,
  .preview-panel .preview-actions #backToEditorPreviewBtn.hidden,
  html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn.hidden,
  html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn.hidden,
  html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn.hidden,
  html[data-device-mode="phone"] .preview-panel .preview-actions #exitPreviewBtn.hidden,
  html[data-device-mode="phone"] .preview-panel .preview-actions #backToEditorPreviewBtn.hidden {
    display: none !important;
  }
}

@media (max-width: 360px) {
  .preview-panel .preview-actions,
  html[data-device-mode="phone"] .preview-panel .preview-actions {
    gap: 5px !important;
  }

  .preview-panel .preview-actions #desktopPreviewBtn::before,
  .preview-panel .preview-actions #fullPreviewBtn::before,
  .preview-panel .preview-actions #resultFromPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn::before,
  html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn::before {
    font-size: 0.62rem !important;
  }
}


/* FINAL PHONE PREVIEW FULLSCREEN FIX: phone view should fill the screen, not sit as a small centered rectangle. */
@media (max-width: 760px) {
  html[data-device-mode="phone"] body.preview-fullscreen-active #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview),
  html[data-device-mode="phone"] #previewPanel:fullscreen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview),
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview),
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) {
    inset: 0 !important;
    width: 100dvw !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #ffffff !important;
    overflow: hidden !important;
  }

  html[data-device-mode="phone"] body.preview-fullscreen-active #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-frame-shell,
  html[data-device-mode="phone"] #previewPanel:fullscreen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-frame-shell,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-frame-shell,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-frame-shell {
    order: 1 !important;
    flex: 1 1 auto !important;
    align-self: stretch !important;
    width: 100dvw !important;
    height: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #ffffff !important;
    box-shadow: none !important;
    overflow: hidden !important;
  }

  html[data-device-mode="phone"] body.preview-fullscreen-active #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #previewFrame,
  html[data-device-mode="phone"] #previewPanel:fullscreen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #previewFrame,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #previewFrame,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #previewFrame {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    max-height: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #ffffff !important;
  }

  html[data-device-mode="phone"] body.preview-fullscreen-active #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-header,
  html[data-device-mode="phone"] #previewPanel:fullscreen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-header,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-header,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-header {
    order: 2 !important;
    flex: 0 0 auto !important;
    padding: 7px max(8px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)) !important;
    border-top: 1px solid rgba(15, 23, 42, 0.12) !important;
    border-bottom: 0 !important;
    background: rgba(248, 251, 255, 0.98) !important;
  }

  html[data-device-mode="phone"] body.preview-fullscreen-active #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-header > div:first-child,
  html[data-device-mode="phone"] #previewPanel:fullscreen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-header > div:first-child,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-header > div:first-child,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-header > div:first-child {
    display: none !important;
  }

  html[data-device-mode="phone"] body.preview-fullscreen-active #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-actions,
  html[data-device-mode="phone"] #previewPanel:fullscreen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-actions,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-actions,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) .preview-actions {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 7px !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  html[data-device-mode="phone"] body.preview-fullscreen-active #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #backToEditorPreviewBtn,
  html[data-device-mode="phone"] body.preview-fullscreen-active #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #resultFromPreviewBtn,
  html[data-device-mode="phone"] body.preview-fullscreen-active #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #exitPreviewBtn,
  html[data-device-mode="phone"] #previewPanel:fullscreen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #backToEditorPreviewBtn,
  html[data-device-mode="phone"] #previewPanel:fullscreen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #resultFromPreviewBtn,
  html[data-device-mode="phone"] #previewPanel:fullscreen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #exitPreviewBtn,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #backToEditorPreviewBtn,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #resultFromPreviewBtn,
  html[data-device-mode="phone"] #previewPanel:-webkit-full-screen:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #exitPreviewBtn,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #backToEditorPreviewBtn,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #resultFromPreviewBtn,
  html[data-device-mode="phone"] body.editor-fullscreen-active.preview-inside-editor-fullscreen #editorPanel #previewPanel:not(.mobile-desktop-preview):not(.mobile-landscape-desktop-preview) #exitPreviewBtn {
    display: inline-flex !important;
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 8px !important;
    font-size: 0.72rem !important;
  }
}


/* FINAL ADMIN LOGIN CHOICE FIX */
.admin-login-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 6px;
  margin: 0 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--bg-2);
}

.admin-login-mode-btn {
  min-height: 40px;
  border: 0;
  border-radius: 14px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
  cursor: pointer;
}

.admin-login-mode-btn.active,
.admin-login-mode-btn[aria-selected="true"] {
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.2);
}

.admin-login-panel.hidden {
  display: none !important;
}

.admin-login-panel.active {
  display: block;
}

.admin-login-panel .wide-btn {
  margin-top: 14px;
}

[data-theme="dark"] .admin-login-switch {
  background: rgba(2, 6, 23, 0.36);
}

[data-theme="dark"] .admin-login-mode-btn {
  color: #cbd5e1;
}

[data-theme="dark"] .admin-login-mode-btn.active,
[data-theme="dark"] .admin-login-mode-btn[aria-selected="true"] {
  color: #fff;
}


/* CRITICAL MOBILE SCROLL REGRESSION FIX
   Normal editor pages must always be vertically scrollable on phones.
   Only real overlays/fullscreen states are allowed to lock the page. */
@media (max-width: 760px) {
  html[data-device-mode="phone"],
  html[data-device-mode="phone"] body {
    max-width: 100% !important;
    overflow-x: hidden !important;
    touch-action: pan-y !important;
  }

  html[data-device-mode="phone"] body:not(.entry-gate-active):not(.student-dashboard-active):not(.student-auth-open):not(.student-route-lock):not(.admin-open):not(.activity-popup-open):not(.preview-fullscreen-active):not(.editor-fullscreen-active) {
    position: static !important;
    height: auto !important;
    min-height: 100dvh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: auto !important;
  }

  html[data-device-mode="phone"] body:not(.entry-gate-active):not(.student-dashboard-active):not(.student-auth-open):not(.student-route-lock):not(.admin-open):not(.activity-popup-open):not(.preview-fullscreen-active):not(.editor-fullscreen-active) .app-shell,
  html[data-device-mode="phone"] body:not(.entry-gate-active):not(.student-dashboard-active):not(.student-auth-open):not(.student-route-lock):not(.admin-open):not(.activity-popup-open):not(.preview-fullscreen-active):not(.editor-fullscreen-active) #workspace {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  html[data-device-mode="phone"] body:not(.entry-gate-active):not(.student-dashboard-active):not(.student-auth-open):not(.student-route-lock):not(.admin-open):not(.activity-popup-open):not(.preview-fullscreen-active):not(.editor-fullscreen-active) .editor-panel,
  html[data-device-mode="phone"] body:not(.entry-gate-active):not(.student-dashboard-active):not(.student-auth-open):not(.student-route-lock):not(.admin-open):not(.activity-popup-open):not(.preview-fullscreen-active):not(.editor-fullscreen-active) .preview-panel,
  html[data-device-mode="phone"] body:not(.entry-gate-active):not(.student-dashboard-active):not(.student-auth-open):not(.student-route-lock):not(.admin-open):not(.activity-popup-open):not(.preview-fullscreen-active):not(.editor-fullscreen-active) .right-column {
    overflow: visible !important;
  }

  /* Dark-mode readability for the normal phone Output Preview buttons. */
  [data-theme="dark"] html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn,
  [data-theme="dark"] html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn {
    color: transparent !important;
    border-color: rgba(96, 165, 250, 0.34) !important;
    background: rgba(15, 23, 42, 0.9) !important;
  }

  [data-theme="dark"] html[data-device-mode="phone"] .preview-panel .preview-actions #desktopPreviewBtn::before,
  [data-theme="dark"] html[data-device-mode="phone"] .preview-panel .preview-actions #fullPreviewBtn::before {
    color: #e5edf7 !important;
  }

  [data-theme="dark"] html[data-device-mode="phone"] .preview-panel .preview-actions #resultFromPreviewBtn.preview-result-btn::before {
    color: #ffffff !important;
  }
}


/* FINAL FIX: phone dark-mode Full button text must stay readable */
html[data-device-mode="phone"] [data-theme="dark"] .preview-panel .preview-actions #fullPreviewBtn,
html[data-device-mode="phone"] [data-theme="dark"] .preview-panel .preview-actions #fullPreviewBtn.strong,
html[data-device-mode="phone"] [data-theme="dark"] .preview-panel .preview-actions #fullPreviewBtn.layout-btn,
html[data-device-mode="phone"] [data-theme="dark"] .preview-panel .preview-actions #fullPreviewBtn:not(.hidden) {
  color: #064e3b !important;
  border-color: rgba(74, 222, 128, 0.65) !important;
  background: linear-gradient(135deg, #dcfce7, #bbf7d0) !important;
  text-shadow: none !important;
  opacity: 1 !important;
  filter: none !important;
}

html[data-device-mode="phone"] [data-theme="dark"] .preview-panel .preview-actions #fullPreviewBtn::before,
html[data-device-mode="phone"] [data-theme="dark"] .preview-panel .preview-actions #fullPreviewBtn.strong::before,
html[data-device-mode="phone"] [data-theme="dark"] .preview-panel .preview-actions #fullPreviewBtn.layout-btn::before {
  content: '⛶ Full' !important;
  color: #064e3b !important;
  -webkit-text-fill-color: #064e3b !important;
  opacity: 1 !important;
  text-shadow: none !important;
  filter: none !important;
  font-weight: 1000 !important;
}

html[data-device-mode="phone"] [data-theme="dark"] .preview-panel .preview-actions #desktopPreviewBtn::before {
  color: #e5edf7 !important;
  -webkit-text-fill-color: #e5edf7 !important;
}

html[data-device-mode="phone"] [data-theme="dark"] .preview-panel .preview-actions #resultFromPreviewBtn::before {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}


/* HARD FINAL PHONE SCROLL + FULL BUTTON FIX
   This intentionally overrides older mobile patches at the very end. */
@media (max-width: 820px) {
  html[data-device-mode="phone"],
  html[data-device-mode="phone"] body,
  html[data-device-mode="phone"] body.editor-scroll-unlocked {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100dvh !important;
    max-height: none !important;
    position: static !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: auto !important;
  }

  html[data-device-mode="phone"] body.editor-scroll-unlocked .app-shell,
  html[data-device-mode="phone"] body.editor-scroll-unlocked #workspace,
  html[data-device-mode="phone"] body.editor-scroll-unlocked .workspace,
  html[data-device-mode="phone"] body.editor-scroll-unlocked .editor-panel,
  html[data-device-mode="phone"] body.editor-scroll-unlocked .preview-panel,
  html[data-device-mode="phone"] body.editor-scroll-unlocked .right-column {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }

  html[data-device-mode="phone"] body.editor-scroll-unlocked .app-shell {
    display: block !important;
  }

  /* Keep real full-screen views locked only while they are truly active. */
  html[data-device-mode="phone"] body.editor-fullscreen-active,
  html[data-device-mode="phone"] body.preview-fullscreen-active,
  html[data-device-mode="phone"] body.entry-gate-active,
  html[data-device-mode="phone"] body.student-dashboard-active,
  html[data-device-mode="phone"] body.student-auth-open,
  html[data-device-mode="phone"] body.admin-open,
  html[data-device-mode="phone"] body.activity-popup-open {
    overflow: hidden !important;
    height: 100dvh !important;
  }

  /* Dark-mode mobile Full button: make actual text black and remove pale pseudo-label conflicts. */
  html[data-device-mode="phone"][data-theme="dark"] #previewPanel .preview-actions #fullPreviewBtn,
  html[data-device-mode="phone"][data-theme="dark"] #previewPanel .preview-actions #fullPreviewBtn.layout-btn,
  html[data-device-mode="phone"][data-theme="dark"] #previewPanel .preview-actions #fullPreviewBtn.strong {
    color: #07111f !important;
    -webkit-text-fill-color: #07111f !important;
    background: linear-gradient(135deg, #dcfce7, #bbf7d0) !important;
    border-color: rgba(74, 222, 128, 0.72) !important;
    text-shadow: none !important;
    opacity: 1 !important;
    filter: none !important;
    font-weight: 1000 !important;
    font-size: 0.82rem !important;
  }

  html[data-device-mode="phone"][data-theme="dark"] #previewPanel .preview-actions #fullPreviewBtn::before,
  html[data-device-mode="phone"][data-theme="dark"] #previewPanel .preview-actions #fullPreviewBtn::after {
    color: #07111f !important;
    -webkit-text-fill-color: #07111f !important;
    opacity: 1 !important;
    text-shadow: none !important;
    filter: none !important;
  }
}


/* EMERGENCY FINAL FIX: phone preview buttons must use real text only, no duplicated pseudo labels. */
@media (max-width: 820px) {
  html[data-device-mode="phone"] #previewPanel .preview-actions #fullPreviewBtn::before,
  html[data-device-mode="phone"] #previewPanel .preview-actions #fullPreviewBtn::after {
    content: none !important;
    display: none !important;
  }

  html[data-device-mode="phone"] #previewPanel .preview-actions #fullPreviewBtn,
  html[data-device-mode="phone"] #previewPanel .preview-actions #fullPreviewBtn.layout-btn,
  html[data-device-mode="phone"] #previewPanel .preview-actions #fullPreviewBtn.strong {
    color: #07111f !important;
    -webkit-text-fill-color: #07111f !important;
    background: linear-gradient(135deg, #dcfce7, #bbf7d0) !important;
    border-color: rgba(74, 222, 128, 0.75) !important;
    font-size: 0.78rem !important;
    font-weight: 1000 !important;
    letter-spacing: 0 !important;
    text-shadow: none !important;
    opacity: 1 !important;
    filter: none !important;
  }

  html[data-device-mode="phone"] #previewPanel .preview-actions #desktopPreviewBtn::before,
  html[data-device-mode="phone"] #previewPanel .preview-actions #desktopPreviewBtn::after,
  html[data-device-mode="phone"] #previewPanel .preview-actions #resultFromPreviewBtn::before,
  html[data-device-mode="phone"] #previewPanel .preview-actions #resultFromPreviewBtn::after {
    content: none !important;
    display: none !important;
  }

  html[data-device-mode="phone"] #previewPanel .preview-actions #desktopPreviewBtn,
  html[data-device-mode="phone"] #previewPanel .preview-actions #resultFromPreviewBtn {
    font-size: 0.76rem !important;
    font-weight: 1000 !important;
    letter-spacing: 0 !important;
  }

  /* Normal editor page must scroll on phones. Do not let old overlay/fullscreen locks trap it. */
  html[data-device-mode="phone"],
  html[data-device-mode="phone"] body.mobile-editor-normal,
  html[data-device-mode="phone"] body.editor-scroll-unlocked,
  html[data-device-mode="phone"] body.mobile-editor-normal:not(.preview-fullscreen-active):not(.editor-fullscreen-active) {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100dvh !important;
    max-height: none !important;
    position: static !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: auto !important;
  }

  html[data-device-mode="phone"] body.mobile-editor-normal:not(.preview-fullscreen-active):not(.editor-fullscreen-active) .app-shell,
  html[data-device-mode="phone"] body.mobile-editor-normal:not(.preview-fullscreen-active):not(.editor-fullscreen-active) #workspace,
  html[data-device-mode="phone"] body.mobile-editor-normal:not(.preview-fullscreen-active):not(.editor-fullscreen-active) .workspace,
  html[data-device-mode="phone"] body.mobile-editor-normal:not(.preview-fullscreen-active):not(.editor-fullscreen-active) .right-column,
  html[data-device-mode="phone"] body.mobile-editor-normal:not(.preview-fullscreen-active):not(.editor-fullscreen-active) .editor-panel,
  html[data-device-mode="phone"] body.mobile-editor-normal:not(.preview-fullscreen-active):not(.editor-fullscreen-active) .preview-panel,
  html[data-device-mode="phone"] body.mobile-editor-normal:not(.preview-fullscreen-active):not(.editor-fullscreen-active) .result-panel {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  html[data-device-mode="phone"] body.mobile-editor-normal:not(.preview-fullscreen-active):not(.editor-fullscreen-active) #workspace,
  html[data-device-mode="phone"] body.mobile-editor-normal:not(.preview-fullscreen-active):not(.editor-fullscreen-active) .workspace {
    display: flex !important;
    flex-direction: column !important;
  }
}


/* FINAL RESULT BUTTON VISIBILITY FIX - PHONE ONLY
   Keep Full fixed, and force the green Result button to show one real white label. */
@media (max-width: 820px) {
  html[data-device-mode="phone"] #previewPanel .preview-actions #resultFromPreviewBtn,
  html[data-device-mode="phone"] #previewPanel .preview-actions #resultFromPreviewBtn.preview-result-btn,
  html[data-device-mode="phone"] #previewPanel .preview-actions #resultFromPreviewBtn.layout-btn,
  html[data-device-mode="phone"] #previewPanel .preview-actions #resultFromPreviewBtn.strong {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 6px !important;
    border-radius: 999px !important;
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
    font-size: 0.76rem !important;
    font-weight: 1000 !important;
    line-height: 1 !important;
    letter-spacing: 0 !important;
    text-shadow: none !important;
    opacity: 1 !important;
    filter: none !important;
    background: linear-gradient(135deg, #16a34a, #22c55e) !important;
    border-color: rgba(22, 163, 74, 0.7) !important;
    box-shadow: 0 8px 16px rgba(22, 163, 74, 0.14) !important;
    overflow: hidden !important;
    white-space: nowrap !important;
    text-indent: 0 !important;
  }

  html[data-device-mode="phone"] #previewPanel .preview-actions #resultFromPreviewBtn::before,
  html[data-device-mode="phone"] #previewPanel .preview-actions #resultFromPreviewBtn::after {
    content: none !important;
    display: none !important;
  }

  html[data-device-mode="phone"] #previewPanel .preview-actions #resultFromPreviewBtn.hidden {
    display: none !important;
  }
}


/* FINAL HOMEPAGE PREMIUM REDESIGN */
.entry-gate {
  background:
    radial-gradient(circle at 18% 18%, rgba(59, 130, 246, 0.34), transparent 24rem),
    radial-gradient(circle at 84% 20%, rgba(6, 182, 212, 0.2), transparent 22rem),
    radial-gradient(circle at 72% 92%, rgba(34, 197, 94, 0.18), transparent 22rem),
    linear-gradient(145deg, #06111f 0%, #0f172a 52%, #020617 100%) !important;
}

.entry-card {
  position: relative;
  overflow: hidden;
  width: min(830px, 100%) !important;
  padding: clamp(30px, 4.6vw, 56px) !important;
  border: 1px solid rgba(147, 197, 253, 0.32) !important;
  border-radius: 38px !important;
  color: #f8fafc !important;
  background:
    linear-gradient(145deg, rgba(15, 23, 42, 0.9), rgba(17, 24, 39, 0.82)),
    radial-gradient(circle at top right, rgba(56, 189, 248, 0.22), transparent 22rem) !important;
  box-shadow:
    0 30px 90px rgba(2, 6, 23, 0.48),
    inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
  text-align: left !important;
  backdrop-filter: blur(22px) !important;
}

.entry-card::before,
.entry-card::after {
  content: '';
  position: absolute;
  pointer-events: none;
  border-radius: 999px;
  filter: blur(2px);
}

.entry-card::before {
  top: -90px;
  right: -80px;
  width: 230px;
  height: 230px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.35), transparent 68%);
}

.entry-card::after {
  bottom: -80px;
  left: -75px;
  width: 210px;
  height: 210px;
  background: radial-gradient(circle, rgba(34, 197, 94, 0.22), transparent 68%);
}

.entry-logo {
  position: relative;
  z-index: 1;
  width: 70px !important;
  height: 70px !important;
  margin: 0 0 22px !important;
  border-radius: 22px !important;
  background: linear-gradient(135deg, #2563eb 0%, #06b6d4 58%, #22c55e 100%) !important;
  box-shadow:
    0 18px 38px rgba(14, 165, 233, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.22) !important;
}

.entry-card .section-kicker {
  position: relative;
  z-index: 1;
  color: #93c5fd !important;
  letter-spacing: 0.22em !important;
}

.entry-card h1 {
  position: relative;
  z-index: 1;
  max-width: 620px;
  margin: 0 0 12px !important;
  color: #ffffff !important;
  font-size: clamp(2.35rem, 6vw, 4.55rem) !important;
  line-height: 0.98 !important;
  letter-spacing: -0.065em !important;
  text-shadow: 0 16px 36px rgba(0, 0, 0, 0.24) !important;
  text-wrap: balance;
}

.entry-lead {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 0 28px !important;
  color: #cbd5e1 !important;
  font-size: clamp(1rem, 2vw, 1.22rem) !important;
  line-height: 1.5 !important;
}

.entry-choice-grid {
  position: relative;
  z-index: 1;
  grid-template-columns: 1fr !important;
  gap: 14px !important;
}

.entry-choice,
button.entry-choice {
  position: relative;
  min-height: 108px !important;
  padding: 18px 20px !important;
  border: 1px solid rgba(148, 163, 184, 0.24) !important;
  border-radius: 24px !important;
  color: #e5edff !important;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.72), rgba(30, 41, 59, 0.54)) !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 14px 34px rgba(2, 6, 23, 0.16) !important;
}

.entry-choice::after {
  content: '→';
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 999px;
  color: #dbeafe;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 1000;
  transition: transform 0.18s ease, background 0.18s ease;
}

.entry-choice:hover::after,
.entry-choice:focus-visible::after {
  transform: translateX(3px);
  background: rgba(255, 255, 255, 0.16);
}

.entry-choice.primary-choice {
  border-color: rgba(125, 211, 252, 0.54) !important;
  color: #ffffff !important;
  background: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%) !important;
  box-shadow:
    0 20px 46px rgba(37, 99, 235, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.22) !important;
}

.entry-choice.resume-choice {
  margin-bottom: 14px !important;
  border-color: rgba(34, 197, 94, 0.36) !important;
  color: #eafff3 !important;
  background: linear-gradient(135deg, rgba(22, 163, 74, 0.24), rgba(15, 23, 42, 0.58)) !important;
}

.entry-choice-icon {
  width: 54px !important;
  height: 54px !important;
  border-radius: 18px !important;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.08)) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16) !important;
}

.entry-choice strong {
  color: inherit !important;
  font-size: 1.08rem !important;
  letter-spacing: -0.02em;
}

.entry-choice small {
  color: inherit !important;
  opacity: 0.86 !important;
  font-size: 0.94rem !important;
}

.entry-free-note {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 18px 0 0 !important;
  padding: 13px 16px !important;
  border: 1px solid rgba(34, 197, 94, 0.24) !important;
  border-radius: 18px !important;
  color: #bbf7d0 !important;
  background: rgba(22, 163, 74, 0.1) !important;
  text-align: center !important;
  font-weight: 800;
}

html[data-device-mode="phone"] .entry-gate {
  align-items: center !important;
  justify-content: center !important;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)) !important;
}

html[data-device-mode="phone"] .entry-card {
  width: min(100%, 440px) !important;
  padding: 24px 18px 20px !important;
  border-radius: 30px !important;
}

html[data-device-mode="phone"] .entry-logo {
  width: 58px !important;
  height: 58px !important;
  margin: 0 0 16px !important;
  border-radius: 19px !important;
}

html[data-device-mode="phone"] .entry-card h1 {
  font-size: clamp(2rem, 9.6vw, 3.05rem) !important;
  line-height: 0.98 !important;
  max-width: 100% !important;
}

html[data-device-mode="phone"] .entry-lead {
  margin-bottom: 18px !important;
  font-size: 0.96rem !important;
}

html[data-device-mode="phone"] .entry-choice,
html[data-device-mode="phone"] button.entry-choice {
  display: flex !important;
  grid-template-columns: none !important;
  min-height: 92px !important;
  padding: 15px !important;
  gap: 12px !important;
}

html[data-device-mode="phone"] .entry-choice::after {
  width: 30px !important;
  height: 30px !important;
  font-size: 0.9rem !important;
}

html[data-device-mode="phone"] .entry-choice-icon {
  width: 46px !important;
  height: 46px !important;
  border-radius: 16px !important;
}

html[data-device-mode="phone"] .entry-choice strong {
  font-size: 1rem !important;
}

html[data-device-mode="phone"] .entry-choice small {
  font-size: 0.78rem !important;
  line-height: 1.38 !important;
}

html[data-device-mode="phone"] .entry-free-note {
  margin-top: 14px !important;
  font-size: 0.76rem !important;
}


/* FINAL HOMEPAGE SCOPE FIX: desktop restored, mobile-only gentle redesign */
@media (min-width: 761px) {
  .entry-gate {
    display: grid !important;
    place-items: center !important;
    padding: 24px !important;
    overflow: auto !important;
    background:
      radial-gradient(circle at 14% 14%, rgba(37, 99, 235, 0.32), transparent 30rem),
      radial-gradient(circle at 88% 80%, rgba(34, 197, 94, 0.2), transparent 28rem),
      linear-gradient(145deg, var(--bg), var(--bg-2)) !important;
  }

  .entry-card {
    width: min(760px, 100%) !important;
    padding: clamp(24px, 4vw, 48px) !important;
    border: 1px solid var(--line-strong) !important;
    border-radius: 32px !important;
    color: var(--text) !important;
    background: var(--card) !important;
    box-shadow: var(--shadow-strong) !important;
    text-align: center !important;
    overflow: visible !important;
    backdrop-filter: blur(18px) !important;
  }

  .entry-card::before,
  .entry-card::after,
  .entry-choice::after {
    content: none !important;
    display: none !important;
  }

  .entry-logo {
    width: 76px !important;
    height: 76px !important;
    margin: 0 auto 18px !important;
    border-radius: 24px !important;
    background: linear-gradient(135deg, #2563eb, #06b6d4) !important;
    box-shadow: 0 18px 40px rgba(37, 99, 235, 0.28) !important;
    font-size: 1.6rem !important;
  }

  .entry-card .section-kicker {
    margin: 0 0 8px !important;
    color: var(--primary) !important;
    font-size: 0.76rem !important;
    letter-spacing: 0.12em !important;
  }

  .entry-card h1 {
    max-width: none !important;
    margin: 6px 0 10px !important;
    color: var(--text) !important;
    font-size: clamp(1.9rem, 4vw, 3.2rem) !important;
    line-height: 1.02 !important;
    letter-spacing: normal !important;
    text-shadow: none !important;
  }

  .entry-lead {
    max-width: none !important;
    margin: 0 0 24px !important;
    color: var(--muted) !important;
    font-size: 1.05rem !important;
    line-height: 1.45 !important;
  }

  .entry-choice-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 16px !important;
  }

  .entry-choice,
  button.entry-choice {
    display: flex !important;
    align-items: center !important;
    gap: 16px !important;
    width: 100% !important;
    min-height: 124px !important;
    padding: 20px !important;
    border: 1px solid var(--line-strong) !important;
    border-radius: 22px !important;
    color: var(--text) !important;
    background: var(--solid-card) !important;
    box-shadow: none !important;
    text-align: left !important;
  }

  .entry-choice.primary-choice {
    color: #fff !important;
    border-color: transparent !important;
    background: linear-gradient(135deg, #2563eb, #0891b2) !important;
  }

  .entry-choice.resume-choice {
    min-height: auto !important;
    margin: 0 0 16px !important;
    color: var(--text) !important;
    border-color: rgba(22, 163, 74, 0.42) !important;
    background: var(--success-soft) !important;
  }

  .entry-choice-icon {
    width: 50px !important;
    height: 50px !important;
    border-radius: 16px !important;
    background: rgba(255, 255, 255, 0.24) !important;
    box-shadow: none !important;
    font-size: 1.6rem !important;
  }

  .guest-choice .entry-choice-icon,
  .resume-choice .entry-choice-icon {
    background: var(--primary-soft) !important;
  }

  .entry-choice strong {
    margin-bottom: 6px !important;
    color: inherit !important;
    font-size: 1.03rem !important;
    letter-spacing: normal !important;
  }

  .entry-choice small {
    color: inherit !important;
    opacity: 0.82 !important;
    font-size: inherit !important;
    line-height: 1.45 !important;
  }

  .entry-free-note {
    display: block !important;
    width: auto !important;
    margin: 20px 0 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    color: var(--muted) !important;
    background: transparent !important;
    font-size: 0.88rem !important;
    font-weight: 400 !important;
    text-align: center !important;
  }
}

html[data-device-mode="phone"] .entry-gate {
  background:
    radial-gradient(circle at 18% 8%, rgba(59, 130, 246, 0.36), transparent 17rem),
    radial-gradient(circle at 88% 94%, rgba(34, 197, 94, 0.16), transparent 17rem),
    linear-gradient(145deg, #07111f 0%, #101827 58%, #020617 100%) !important;
}

html[data-device-mode="phone"] .entry-card {
  width: min(100%, 410px) !important;
  max-width: calc(100vw - 28px) !important;
  padding: 20px 16px 17px !important;
  border-radius: 24px !important;
  text-align: left !important;
  overflow: hidden !important;
}

html[data-device-mode="phone"] .entry-card::before,
html[data-device-mode="phone"] .entry-card::after {
  content: none !important;
  display: none !important;
}

html[data-device-mode="phone"] .entry-logo {
  width: 48px !important;
  height: 48px !important;
  margin: 0 0 13px !important;
  border-radius: 16px !important;
  font-size: 1rem !important;
}

html[data-device-mode="phone"] .entry-card .section-kicker {
  margin: 0 0 7px !important;
  font-size: 0.68rem !important;
  letter-spacing: 0.15em !important;
}

html[data-device-mode="phone"] .entry-card h1 {
  margin: 0 0 8px !important;
  font-size: clamp(1.45rem, 6.8vw, 2.1rem) !important;
  line-height: 1.08 !important;
  letter-spacing: -0.035em !important;
  text-shadow: none !important;
}

html[data-device-mode="phone"] .entry-lead {
  margin: 0 0 15px !important;
  font-size: 0.9rem !important;
  line-height: 1.4 !important;
}

html[data-device-mode="phone"] .entry-choice-grid {
  gap: 9px !important;
}

html[data-device-mode="phone"] .entry-choice,
html[data-device-mode="phone"] button.entry-choice {
  display: grid !important;
  grid-template-columns: 42px minmax(0, 1fr) !important;
  min-height: 78px !important;
  padding: 12px 13px !important;
  gap: 11px !important;
  border-radius: 18px !important;
}

html[data-device-mode="phone"] .entry-choice::after {
  content: none !important;
  display: none !important;
}

html[data-device-mode="phone"] .entry-choice-icon {
  width: 42px !important;
  height: 42px !important;
  border-radius: 14px !important;
  font-size: 1.12rem !important;
}

html[data-device-mode="phone"] .entry-choice strong {
  margin: 0 0 3px !important;
  font-size: 0.96rem !important;
  line-height: 1.14 !important;
}

html[data-device-mode="phone"] .entry-choice small {
  font-size: 0.74rem !important;
  line-height: 1.32 !important;
}

html[data-device-mode="phone"] .entry-free-note {
  margin-top: 12px !important;
  padding: 9px 10px !important;
  border-radius: 14px !important;
  font-size: 0.72rem !important;
  line-height: 1.3 !important;
}

@media (max-width: 380px) {
  html[data-device-mode="phone"] .entry-card {
    padding: 17px 13px 15px !important;
  }

  html[data-device-mode="phone"] .entry-card h1 {
    font-size: clamp(1.28rem, 6.4vw, 1.75rem) !important;
  }

  html[data-device-mode="phone"] .entry-choice,
  html[data-device-mode="phone"] button.entry-choice {
    grid-template-columns: 38px minmax(0, 1fr) !important;
    min-height: 74px !important;
    padding: 11px !important;
  }
}


/* FINAL MOBILE HOMEPAGE CENTER + THEME SWITCH (mobile only; desktop untouched) */
.entry-theme-toggle {
  display: none;
}

html[data-device-mode="phone"] .entry-card {
  text-align: center !important;
}

html[data-device-mode="phone"] .entry-logo {
  margin-left: auto !important;
  margin-right: auto !important;
}

html[data-device-mode="phone"] .entry-card .section-kicker,
html[data-device-mode="phone"] .entry-card h1,
html[data-device-mode="phone"] .entry-lead {
  text-align: center !important;
}

html[data-device-mode="phone"] .entry-lead {
  max-width: 340px;
  margin-left: auto !important;
  margin-right: auto !important;
}

html[data-device-mode="phone"] .entry-theme-toggle {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 38px;
  margin: 0 auto 14px;
  padding: 6px 13px 6px 7px;
  border: 1px solid rgba(147, 197, 253, 0.35);
  border-radius: 999px;
  color: #dbeafe;
  background: rgba(15, 23, 42, 0.68);
  box-shadow: 0 12px 28px rgba(2, 6, 23, 0.18), inset 0 1px 0 rgba(255,255,255,0.08);
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

html[data-device-mode="phone"] .entry-theme-switch {
  position: relative;
  display: inline-flex;
  width: 43px;
  height: 24px;
  border-radius: 999px;
  background: linear-gradient(135deg, #60a5fa, #06b6d4);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.16);
}

html[data-device-mode="phone"] .entry-theme-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 4px 10px rgba(2, 6, 23, 0.24);
  transition: transform 0.22s ease;
}

html[data-device-mode="phone"] .entry-theme-toggle.is-dark .entry-theme-thumb {
  transform: translateX(19px);
}

html[data-device-mode="phone"] .entry-choice,
html[data-device-mode="phone"] button.entry-choice {
  text-align: left !important;
}

html[data-device-mode="phone"] .entry-free-note {
  text-align: center !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-gate {
  background:
    radial-gradient(circle at 18% 8%, rgba(59, 130, 246, 0.24), transparent 17rem),
    radial-gradient(circle at 88% 94%, rgba(34, 197, 94, 0.12), transparent 17rem),
    linear-gradient(145deg, #eef6ff 0%, #f8fbff 58%, #e8f2ff 100%) !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-card {
  color: #0f2852 !important;
  border-color: rgba(147, 197, 253, 0.72) !important;
  background: rgba(255, 255, 255, 0.92) !important;
  box-shadow: 0 26px 70px rgba(37, 99, 235, 0.16) !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-card .section-kicker {
  color: #2563eb !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-card h1 {
  color: #0f2852 !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-lead,
html[data-device-mode="phone"][data-theme="light"] .entry-choice small {
  color: #334155 !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-theme-toggle {
  color: #1e3a8a;
  border-color: rgba(37, 99, 235, 0.2);
  background: rgba(239, 246, 255, 0.95);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.12), inset 0 1px 0 rgba(255,255,255,0.75);
}

html[data-device-mode="phone"][data-theme="light"] .entry-theme-switch {
  background: linear-gradient(135deg, #fbbf24, #fde68a);
}

html[data-device-mode="phone"][data-theme="light"] .entry-theme-thumb {
  transform: translateX(0) !important;
}


/* FINAL MOBILE HOMEPAGE LIGHT READABILITY FIX (mobile only) */
html[data-device-mode="phone"][data-theme="light"] .entry-choice:not(.primary-choice),
html[data-device-mode="phone"][data-theme="light"] button.entry-choice:not(.primary-choice) {
  color: #0f2852 !important;
  border-color: rgba(148, 163, 184, 0.38) !important;
  background: linear-gradient(135deg, #ffffff 0%, #f8fbff 100%) !important;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08) !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-choice:not(.primary-choice):hover,
html[data-device-mode="phone"][data-theme="light"] button.entry-choice:not(.primary-choice):hover,
html[data-device-mode="phone"][data-theme="light"] .entry-choice:not(.primary-choice):focus-visible,
html[data-device-mode="phone"][data-theme="light"] button.entry-choice:not(.primary-choice):focus-visible {
  border-color: rgba(37, 99, 235, 0.42) !important;
  background: linear-gradient(135deg, #ffffff 0%, #eef6ff 100%) !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-choice:not(.primary-choice) strong,
html[data-device-mode="phone"][data-theme="light"] button.entry-choice:not(.primary-choice) strong {
  color: #0f2852 !important;
  opacity: 1 !important;
  text-shadow: none !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-choice:not(.primary-choice) small,
html[data-device-mode="phone"][data-theme="light"] button.entry-choice:not(.primary-choice) small {
  color: #475569 !important;
  opacity: 1 !important;
  text-shadow: none !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-choice:not(.primary-choice) .entry-choice-icon,
html[data-device-mode="phone"][data-theme="light"] button.entry-choice:not(.primary-choice) .entry-choice-icon {
  color: #1e3a8a !important;
  border: 1px solid rgba(37, 99, 235, 0.12) !important;
  background: linear-gradient(135deg, #dbeafe 0%, #f8fbff 100%) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.8) !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-choice.primary-choice strong,
html[data-device-mode="phone"][data-theme="light"] .entry-choice.primary-choice small,
html[data-device-mode="phone"][data-theme="light"] button.entry-choice.primary-choice strong,
html[data-device-mode="phone"][data-theme="light"] button.entry-choice.primary-choice small {
  color: #ffffff !important;
  opacity: 1 !important;
  text-shadow: 0 1px 2px rgba(15, 23, 42, 0.22) !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-choice.primary-choice .entry-choice-icon,
html[data-device-mode="phone"][data-theme="light"] button.entry-choice.primary-choice .entry-choice-icon {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.22) !important;
}

html[data-device-mode="phone"][data-theme="light"] .entry-free-note {
  color: #166534 !important;
  border: 1px solid rgba(34, 197, 94, 0.28) !important;
  background: linear-gradient(135deg, #ecfdf5 0%, #f0fdf4 100%) !important;
  font-weight: 800 !important;
  opacity: 1 !important;
  text-shadow: none !important;
}


/* FINAL DESKTOP PRACTICE BUTTON SAFETY
   Once entry-gate-active is removed, the homepage must not keep covering the editor. */
body:not(.entry-gate-active) > #entryGate,
body:not(.entry-gate-active) > .entry-gate {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

body.guest-session-active > .app-shell,
body.student-session-active > .app-shell {
  display: block !important;
}


/* FINAL DESKTOP HOMEPAGE THEME SWITCH + READABILITY
   Desktop/tablet only. Phone homepage keeps its existing mobile-specific styling. */
@media (min-width: 761px) {
  .entry-card {
    padding-top: clamp(54px, 5vw, 68px) !important;
  }

  .entry-theme-toggle {
    position: absolute;
    top: 22px;
    right: 22px;
    z-index: 3;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 40px;
    padding: 7px 15px 7px 8px;
    border: 1px solid rgba(147, 197, 253, 0.36);
    border-radius: 999px;
    color: #dbeafe;
    background: rgba(15, 23, 42, 0.72);
    box-shadow: 0 14px 34px rgba(2, 6, 23, 0.2), inset 0 1px 0 rgba(255,255,255,0.08);
    font-size: 0.84rem;
    font-weight: 900;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .entry-theme-toggle:hover,
  .entry-theme-toggle:focus-visible {
    transform: translateY(-1px);
    border-color: rgba(147, 197, 253, 0.58);
    box-shadow: 0 18px 38px rgba(2, 6, 23, 0.24), inset 0 1px 0 rgba(255,255,255,0.1);
    outline: none;
  }

  .entry-theme-switch {
    position: relative;
    display: inline-flex;
    width: 46px;
    height: 26px;
    border-radius: 999px;
    background: linear-gradient(135deg, #60a5fa, #06b6d4);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.16);
  }

  .entry-theme-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 4px 10px rgba(2, 6, 23, 0.25);
    transition: transform 0.22s ease;
  }

  .entry-theme-toggle.is-dark .entry-theme-thumb {
    transform: translateX(20px);
  }

  html[data-theme="light"] .entry-gate {
    background:
      radial-gradient(circle at 14% 12%, rgba(37, 99, 235, 0.22), transparent 30rem),
      radial-gradient(circle at 88% 82%, rgba(34, 197, 94, 0.14), transparent 28rem),
      linear-gradient(145deg, #eef6ff 0%, #f8fbff 54%, #e7f0ff 100%) !important;
  }

  html[data-theme="light"] .entry-card {
    color: #0f2852 !important;
    border-color: rgba(147, 197, 253, 0.78) !important;
    background:
      linear-gradient(145deg, rgba(255,255,255,0.94), rgba(248,251,255,0.9)),
      radial-gradient(circle at top right, rgba(59, 130, 246, 0.12), transparent 23rem) !important;
    box-shadow: 0 28px 80px rgba(37, 99, 235, 0.16), inset 0 1px 0 rgba(255,255,255,0.82) !important;
  }

  html[data-theme="light"] .entry-card .section-kicker {
    color: #2563eb !important;
    text-shadow: none !important;
  }

  html[data-theme="light"] .entry-card h1 {
    color: #0f2852 !important;
    text-shadow: none !important;
  }

  html[data-theme="light"] .entry-lead {
    color: #334155 !important;
  }

  html[data-theme="light"] .entry-theme-toggle {
    color: #1e3a8a !important;
    border-color: rgba(37, 99, 235, 0.22) !important;
    background: rgba(239, 246, 255, 0.96) !important;
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.12), inset 0 1px 0 rgba(255,255,255,0.76) !important;
  }

  html[data-theme="light"] .entry-theme-switch {
    background: linear-gradient(135deg, #fbbf24, #fde68a) !important;
  }

  html[data-theme="light"] .entry-theme-thumb {
    transform: translateX(0) !important;
  }

  html[data-theme="light"] .entry-choice:not(.primary-choice),
  html[data-theme="light"] button.entry-choice:not(.primary-choice) {
    color: #0f2852 !important;
    border-color: rgba(148, 163, 184, 0.34) !important;
    background: linear-gradient(135deg, #ffffff 0%, #f8fbff 100%) !important;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08) !important;
  }

  html[data-theme="light"] .entry-choice:not(.primary-choice)::after {
    color: #1e3a8a !important;
    background: #dbeafe !important;
  }

  html[data-theme="light"] .entry-choice:not(.primary-choice) strong,
  html[data-theme="light"] .entry-choice:not(.primary-choice) small,
  html[data-theme="light"] button.entry-choice:not(.primary-choice) strong,
  html[data-theme="light"] button.entry-choice:not(.primary-choice) small {
    color: #0f2852 !important;
    opacity: 1 !important;
    text-shadow: none !important;
  }

  html[data-theme="light"] .entry-choice:not(.primary-choice) small,
  html[data-theme="light"] button.entry-choice:not(.primary-choice) small {
    color: #475569 !important;
  }

  html[data-theme="light"] .entry-choice:not(.primary-choice) .entry-choice-icon,
  html[data-theme="light"] button.entry-choice:not(.primary-choice) .entry-choice-icon {
    color: #1e3a8a !important;
    border: 1px solid rgba(37, 99, 235, 0.12) !important;
    background: linear-gradient(135deg, #dbeafe 0%, #f8fbff 100%) !important;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.8) !important;
  }

  html[data-theme="light"] .entry-choice.primary-choice strong,
  html[data-theme="light"] .entry-choice.primary-choice small,
  html[data-theme="light"] button.entry-choice.primary-choice strong,
  html[data-theme="light"] button.entry-choice.primary-choice small {
    color: #ffffff !important;
    opacity: 1 !important;
    text-shadow: 0 1px 2px rgba(15, 23, 42, 0.22) !important;
  }

  html[data-theme="light"] .entry-free-note {
    color: #166534 !important;
    border: 1px solid rgba(34, 197, 94, 0.28) !important;
    background: linear-gradient(135deg, #ecfdf5 0%, #f0fdf4 100%) !important;
    opacity: 1 !important;
    text-shadow: none !important;
  }

  html[data-theme="dark"] .entry-theme-toggle {
    color: #dbeafe !important;
  }
}


/* FINAL APP ICON + RESPONSIVE HOME/HEADER STABILITY PASS */
.entry-logo.app-coded-eight,
.logo-mark.app-coded-eight {
  position: relative !important;
  display: grid !important;
  place-items: center !important;
  overflow: visible !important;
  isolation: isolate !important;
  color: #ffffff !important;
  background: linear-gradient(135deg, #2563eb 0%, #06b6d4 58%, #22c55e 100%) !important;
}

.entry-logo.app-coded-eight .logo-code,
.logo-mark.app-coded-eight .logo-code {
  position: relative !important;
  z-index: 2 !important;
  font-weight: 1000 !important;
  letter-spacing: -0.08em !important;
  line-height: 1 !important;
  transform: translateX(-3px) !important;
}

.entry-logo.app-coded-eight .logo-eight,
.logo-mark.app-coded-eight .logo-eight {
  position: absolute !important;
  right: -6px !important;
  bottom: -6px !important;
  z-index: 3 !important;
  display: grid !important;
  place-items: center !important;
  width: 24px !important;
  height: 24px !important;
  border: 2px solid rgba(255,255,255,0.92) !important;
  border-radius: 999px !important;
  color: #0f172a !important;
  background: radial-gradient(circle at 35% 32%, #ffffff 0 32%, #111827 34% 100%) !important;
  box-shadow: 0 6px 14px rgba(2, 6, 23, 0.32) !important;
  font-size: 0.68rem !important;
  font-weight: 1000 !important;
  line-height: 1 !important;
}

.logo-mark.app-coded-eight .logo-eight {
  right: -5px !important;
  bottom: -5px !important;
  width: 18px !important;
  height: 18px !important;
  border-width: 1.5px !important;
  font-size: 0.54rem !important;
}

/* Home page: controlled size across browsers. No oversized welcome card. */
.entry-gate {
  min-height: 100dvh !important;
  min-height: 100vh !important;
  padding: clamp(10px, 2.2vh, 20px) clamp(12px, 2vw, 24px) !important;
  align-items: center !important;
  justify-items: center !important;
}

.entry-card {
  width: min(620px, calc(100vw - 28px)) !important;
  max-height: calc(100dvh - 24px) !important;
  max-height: calc(100vh - 24px) !important;
  overflow: auto !important;
  padding: clamp(20px, 3vh, 30px) clamp(18px, 3vw, 32px) !important;
  border-radius: clamp(22px, 3vw, 30px) !important;
  scrollbar-width: thin !important;
}

.entry-logo {
  width: clamp(54px, 7vh, 64px) !important;
  height: clamp(54px, 7vh, 64px) !important;
  margin-bottom: clamp(10px, 1.8vh, 16px) !important;
  border-radius: 20px !important;
}

.entry-card .section-kicker {
  margin-bottom: 8px !important;
  font-size: clamp(0.68rem, 1.4vw, 0.82rem) !important;
}

.entry-card h1 {
  max-width: 100% !important;
  margin-bottom: clamp(8px, 1.4vh, 12px) !important;
  font-size: clamp(1.85rem, 4.8vw, 2.75rem) !important;
  line-height: 1.05 !important;
  letter-spacing: -0.045em !important;
}

.entry-lead {
  max-width: 560px !important;
  margin-bottom: clamp(14px, 2.2vh, 20px) !important;
  font-size: clamp(0.92rem, 1.5vw, 1.04rem) !important;
  line-height: 1.42 !important;
}

.entry-choice-grid {
  gap: clamp(9px, 1.5vh, 12px) !important;
}

.entry-choice,
button.entry-choice {
  min-height: clamp(70px, 10vh, 88px) !important;
  padding: clamp(12px, 1.8vh, 16px) !important;
  border-radius: 20px !important;
}

.entry-choice-icon {
  width: clamp(42px, 6vh, 50px) !important;
  height: clamp(42px, 6vh, 50px) !important;
  border-radius: 15px !important;
  font-size: 1.25rem !important;
}

.entry-choice strong {
  font-size: clamp(0.95rem, 1.7vw, 1.05rem) !important;
}

.entry-choice small {
  font-size: clamp(0.76rem, 1.5vw, 0.88rem) !important;
  line-height: 1.32 !important;
}

.entry-free-note {
  margin-top: clamp(10px, 1.6vh, 14px) !important;
  padding: 10px 12px !important;
  font-size: clamp(0.72rem, 1.4vw, 0.82rem) !important;
  line-height: 1.25 !important;
}

.entry-theme-toggle {
  min-height: 34px !important;
  padding: 5px 12px 5px 7px !important;
  font-size: 0.78rem !important;
}

.entry-theme-switch {
  width: 40px !important;
  height: 23px !important;
}

.entry-theme-thumb {
  width: 17px !important;
  height: 17px !important;
}

.entry-theme-toggle.is-dark .entry-theme-thumb {
  transform: translateX(17px) !important;
}

@media (min-width: 761px) {
  .entry-card {
    width: min(600px, calc(100vw - 40px)) !important;
  }

  .entry-choice-grid {
    grid-template-columns: 1fr !important;
  }

  .entry-theme-toggle {
    top: 16px !important;
    right: 16px !important;
  }
}

@media (max-width: 760px) {
  html[data-device-mode="phone"] .entry-gate {
    padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom)) !important;
  }

  html[data-device-mode="phone"] .entry-card {
    width: min(430px, calc(100vw - 20px)) !important;
    max-height: calc(100dvh - 20px) !important;
    max-height: calc(100vh - 20px) !important;
    padding: 18px 16px 16px !important;
    border-radius: 24px !important;
  }

  html[data-device-mode="phone"] .entry-card h1 {
    font-size: clamp(1.72rem, 7.8vw, 2.35rem) !important;
    line-height: 1.08 !important;
  }

  html[data-device-mode="phone"] .entry-lead {
    font-size: 0.9rem !important;
    margin-bottom: 14px !important;
  }

  html[data-device-mode="phone"] .entry-choice,
  html[data-device-mode="phone"] button.entry-choice {
    min-height: 74px !important;
    padding: 12px !important;
    gap: 10px !important;
  }

  html[data-device-mode="phone"] .entry-choice::after {
    display: none !important;
  }

  html[data-device-mode="phone"] .entry-choice-icon {
    width: 42px !important;
    height: 42px !important;
  }

  html[data-device-mode="phone"] .entry-free-note {
    font-size: 0.72rem !important;
  }
}

/* Desktop/tablet header: never let controls get covered on different browsers/screen sizes. */
@media (min-width: 821px) {
  .app-shell {
    width: min(1480px, calc(100% - 18px)) !important;
    padding-top: 12px !important;
  }

  .topbar.simplified-topbar,
  .topbar {
    display: grid !important;
    grid-template-columns: minmax(230px, 360px) minmax(0, 1fr) !important;
    grid-auto-rows: auto !important;
    gap: 8px 12px !important;
    padding: 12px 14px !important;
    border-radius: 18px !important;
    overflow: visible !important;
    max-height: none !important;
  }

  .topbar .brand-block {
    min-width: 0 !important;
    gap: 10px !important;
  }

  .topbar .logo-mark {
    flex: 0 0 42px !important;
    width: 42px !important;
    height: 42px !important;
    border-radius: 14px !important;
    font-size: 0.78rem !important;
  }

  .topbar h1,
  #appTitleText {
    max-width: 100% !important;
    margin-bottom: 2px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: clamp(1rem, 1.35vw, 1.28rem) !important;
    line-height: 1.08 !important;
  }

  .topbar .eyebrow,
  .topbar .subtitle {
    font-size: 0.64rem !important;
    line-height: 1 !important;
    margin-bottom: 2px !important;
  }

  .topbar .top-actions {
    min-width: 0 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 6px !important;
    overflow: visible !important;
    max-width: 100% !important;
  }

  .top-actions .primary-btn,
  .top-actions .success-btn,
  .top-actions .ghost-btn,
  .top-actions > button,
  .top-actions .status-badge {
    flex: 0 1 auto !important;
    min-width: 0 !important;
    min-height: 34px !important;
    height: 34px !important;
    max-height: 34px !important;
    padding: 0 10px !important;
    border-radius: 999px !important;
    font-size: clamp(0.68rem, 0.82vw, 0.78rem) !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }

  #statusBadge,
  .status-badge.compact-status {
    flex-basis: auto !important;
    width: auto !important;
    min-width: 76px !important;
    max-width: 104px !important;
  }
}

@media (min-width: 821px) and (max-width: 1180px) {
  .topbar.simplified-topbar,
  .topbar {
    grid-template-columns: 1fr !important;
  }

  .topbar .top-actions {
    grid-column: 1 / -1 !important;
    justify-content: flex-start !important;
  }

  .top-actions .primary-btn,
  .top-actions .success-btn,
  .top-actions .ghost-btn,
  .top-actions > button,
  .top-actions .status-badge {
    height: 32px !important;
    min-height: 32px !important;
    padding: 0 9px !important;
    font-size: 0.68rem !important;
  }
}


/* FINAL CLEAN HOME FIX: no inner scrollbar, no hanging mini badge */
.entry-card {
  max-height: none !important;
  overflow: visible !important;
  scrollbar-width: auto !important;
}

.entry-gate {
  min-height: 100svh !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

.entry-logo.app-coded-eight,
.logo-mark.app-coded-eight {
  overflow: hidden !important;
  border-radius: 50% !important;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.28) 0 11%, transparent 12%),
    radial-gradient(circle at center, #1f2937 0 48%, #020617 49% 100%) !important;
  border: 2px solid rgba(255, 255, 255, 0.16) !important;
  box-shadow:
    0 14px 32px rgba(2, 6, 23, 0.24),
    inset 0 3px 8px rgba(255, 255, 255, 0.16),
    inset 0 -10px 22px rgba(0, 0, 0, 0.32) !important;
}

.entry-logo.app-coded-eight .logo-code,
.logo-mark.app-coded-eight .logo-code {
  display: grid !important;
  place-items: center !important;
  width: 62% !important;
  height: 48% !important;
  transform: none !important;
  border-radius: 999px !important;
  color: #0f172a !important;
  background: #ffffff !important;
  font-size: 0.78em !important;
  letter-spacing: -0.13em !important;
  text-shadow: none !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.8) !important;
}

.entry-logo.app-coded-eight .logo-eight,
.logo-mark.app-coded-eight .logo-eight {
  display: none !important;
  content: none !important;
}

@media (min-width: 761px) {
  .entry-gate {
    align-items: center !important;
    padding: clamp(10px, 2vh, 18px) clamp(12px, 2vw, 22px) !important;
  }

  .entry-card {
    width: min(580px, calc(100vw - 44px)) !important;
    padding: clamp(18px, 2.4vh, 26px) clamp(20px, 3vw, 30px) !important;
  }

  .entry-logo.app-coded-eight {
    width: clamp(54px, 6.2vh, 62px) !important;
    height: clamp(54px, 6.2vh, 62px) !important;
    margin-bottom: clamp(8px, 1.3vh, 12px) !important;
  }

  .entry-card h1 {
    font-size: clamp(1.72rem, 4.2vw, 2.45rem) !important;
    line-height: 1.06 !important;
    margin-bottom: 8px !important;
  }

  .entry-lead {
    margin-bottom: clamp(10px, 1.6vh, 16px) !important;
    font-size: clamp(0.86rem, 1.35vw, 0.98rem) !important;
  }

  .entry-choice,
  button.entry-choice {
    min-height: clamp(62px, 8.4vh, 76px) !important;
    padding: clamp(10px, 1.5vh, 14px) !important;
  }

  .entry-choice-icon {
    width: clamp(38px, 5vh, 46px) !important;
    height: clamp(38px, 5vh, 46px) !important;
  }

  .entry-free-note {
    margin-top: clamp(8px, 1.2vh, 12px) !important;
    padding: 9px 12px !important;
  }
}

@media (max-height: 680px) and (min-width: 761px) {
  .entry-gate {
    align-items: start !important;
  }

  .entry-card {
    margin: 10px auto !important;
    padding: 16px 22px !important;
  }

  .entry-logo.app-coded-eight {
    width: 50px !important;
    height: 50px !important;
    margin-bottom: 8px !important;
  }

  .entry-card .section-kicker {
    margin-bottom: 5px !important;
  }

  .entry-card h1 {
    font-size: clamp(1.5rem, 3.4vw, 2.1rem) !important;
    margin-bottom: 6px !important;
  }

  .entry-lead {
    margin-bottom: 10px !important;
    font-size: 0.86rem !important;
  }

  .entry-choice-grid {
    gap: 8px !important;
  }

  .entry-choice,
  button.entry-choice {
    min-height: 58px !important;
    padding: 9px 12px !important;
  }

  .entry-choice small {
    font-size: 0.74rem !important;
  }

  .entry-free-note {
    margin-top: 8px !important;
    padding: 8px 10px !important;
  }
}

@media (max-width: 760px) {
  html[data-device-mode="phone"] .entry-card {
    max-height: none !important;
    overflow: visible !important;
  }

  html[data-device-mode="phone"] .entry-gate {
    align-items: center !important;
    overflow-y: auto !important;
  }

  html[data-device-mode="phone"] .entry-logo.app-coded-eight {
    border-radius: 50% !important;
  }
}

/* HOTFIX: clean fullscreen action toolbar background so buttons stay inside the pill */
body.editor-fullscreen-active #fullscreenEditorActions,
#editorPanel:fullscreen #fullscreenEditorActions,
body.editor-fullscreen-active .fullscreen-editor-actions,
#editorPanel:fullscreen .fullscreen-editor-actions {
  top: 8px !important;
  right: 12px !important;
  left: auto !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 8px !important;
  width: auto !important;
  max-width: calc(100vw - 24px) !important;
  min-height: 44px !important;
  height: 44px !important;
  padding: 4px !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  border-radius: 999px !important;
  border: 1px solid rgba(148, 163, 184, 0.42) !important;
  background: rgba(241, 245, 249, 0.96) !important;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14) !important;
  backdrop-filter: blur(10px) !important;
  overflow: hidden !important;
  isolation: isolate !important;
}

[data-theme="dark"] body.editor-fullscreen-active #fullscreenEditorActions,
[data-theme="dark"] #editorPanel:fullscreen #fullscreenEditorActions,
[data-theme="dark"] body.editor-fullscreen-active .fullscreen-editor-actions,
[data-theme="dark"] #editorPanel:fullscreen .fullscreen-editor-actions {
  border-color: rgba(96, 165, 250, 0.34) !important;
  background: rgba(15, 23, 42, 0.96) !important;
  box-shadow: 0 14px 30px rgba(2, 6, 23, 0.42) !important;
}

body.editor-fullscreen-active #fullscreenRunBtn,
body.editor-fullscreen-active #fullscreenAutoRunBtn,
body.editor-fullscreen-active #fullscreenResultBtn,
body.editor-fullscreen-active #exitEditorStickyBtn,
#editorPanel:fullscreen #fullscreenRunBtn,
#editorPanel:fullscreen #fullscreenAutoRunBtn,
#editorPanel:fullscreen #fullscreenResultBtn,
#editorPanel:fullscreen #exitEditorStickyBtn {
  height: 36px !important;
  min-height: 36px !important;
  max-height: 36px !important;
  margin: 0 !important;
  box-shadow: none !important;
  transform: none !important;
}

body.editor-fullscreen-active #editorPanel .language-tabs,
#editorPanel:fullscreen .language-tabs {
  padding-right: 352px !important;
}

@media (max-width: 760px) {
  body.editor-fullscreen-active #fullscreenEditorActions,
  #editorPanel:fullscreen #fullscreenEditorActions,
  body.editor-fullscreen-active .fullscreen-editor-actions,
  #editorPanel:fullscreen .fullscreen-editor-actions {
    left: 10px !important;
    right: 10px !important;
    top: auto !important;
    bottom: calc(62px + env(safe-area-inset-bottom)) !important;
    max-width: none !important;
    width: auto !important;
    height: 46px !important;
    min-height: 46px !important;
    justify-content: center !important;
  }

  body.editor-fullscreen-active #editorPanel .language-tabs,
  #editorPanel:fullscreen .language-tabs {
    padding-right: 8px !important;
  }
}


/* FINAL RESPONSIVE DESKTOP HOMEPAGE FIX
   Wide screens should not look like a tiny phone card floating in empty space. */
@media (min-width: 900px) {
  body.entry-gate-active {
    min-height: 100svh !important;
    overflow-y: auto !important;
  }

  .entry-gate {
    min-height: 100svh !important;
    display: grid !important;
    place-items: center !important;
    padding: clamp(18px, 3vh, 34px) clamp(24px, 4vw, 56px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }

  .entry-card {
    position: relative !important;
    display: grid !important;
    grid-template-columns: minmax(280px, 0.92fr) minmax(360px, 1.08fr) !important;
    grid-template-areas:
      "logo actions"
      "kicker actions"
      "title actions"
      "lead actions"
      "theme actions"
      "note note" !important;
    align-items: center !important;
    column-gap: clamp(28px, 4vw, 56px) !important;
    row-gap: 8px !important;
    width: min(1040px, calc(100vw - 72px)) !important;
    max-width: 1040px !important;
    min-height: auto !important;
    max-height: none !important;
    padding: clamp(30px, 4.8vh, 44px) clamp(34px, 5vw, 56px) !important;
    overflow: visible !important;
    text-align: left !important;
  }

  .entry-logo {
    grid-area: logo !important;
    width: clamp(64px, 6vw, 82px) !important;
    height: clamp(64px, 6vw, 82px) !important;
    margin: 0 0 clamp(8px, 1.4vh, 14px) 0 !important;
  }

  .entry-card .section-kicker {
    grid-area: kicker !important;
    margin: 0 0 2px !important;
    text-align: left !important;
  }

  .entry-card h1 {
    grid-area: title !important;
    max-width: 460px !important;
    margin: 0 !important;
    text-align: left !important;
    font-size: clamp(2.2rem, 3.45vw, 3.35rem) !important;
    line-height: 0.98 !important;
    letter-spacing: -0.055em !important;
  }

  .entry-lead {
    grid-area: lead !important;
    max-width: 430px !important;
    margin: 12px 0 0 !important;
    text-align: left !important;
    font-size: clamp(0.95rem, 1.12vw, 1.08rem) !important;
    line-height: 1.55 !important;
  }

  .entry-theme-toggle {
    grid-area: theme !important;
    position: static !important;
    justify-self: start !important;
    align-self: start !important;
    width: fit-content !important;
    margin: 18px 0 0 !important;
  }

  #resumeStudentBtn,
  .entry-choice-grid {
    grid-area: actions !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  #resumeStudentBtn:not(.hidden) + .entry-choice-grid {
    margin-top: 12px !important;
  }

  .entry-choice-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 14px !important;
    align-self: center !important;
  }

  .entry-choice,
  button.entry-choice {
    width: 100% !important;
    min-height: 82px !important;
    padding: 16px 18px !important;
    text-align: left !important;
    border-radius: 22px !important;
  }

  .entry-choice-icon {
    width: 50px !important;
    height: 50px !important;
  }

  .entry-choice strong {
    font-size: 1.08rem !important;
  }

  .entry-choice small {
    font-size: 0.88rem !important;
    line-height: 1.4 !important;
  }

  .entry-free-note {
    grid-area: note !important;
    margin: clamp(18px, 2vh, 24px) 0 0 !important;
    padding: 12px 16px !important;
    text-align: center !important;
    font-size: 0.9rem !important;
  }
}

/* Medium desktop/tablet landscape: still centered, but not huge and not cramped. */
@media (min-width: 761px) and (max-width: 899px) {
  .entry-gate {
    place-items: center !important;
    padding: 18px !important;
  }

  .entry-card {
    width: min(680px, calc(100vw - 36px)) !important;
    padding: 44px 36px 28px !important;
  }

  .entry-card h1 {
    font-size: clamp(2rem, 5vw, 2.8rem) !important;
  }
}

/* Short browser heights: compact the homepage without adding an ugly inner scrollbar. */
@media (min-width: 900px) and (max-height: 720px) {
  .entry-gate {
    place-items: start center !important;
    padding-top: 14px !important;
    padding-bottom: 14px !important;
  }

  .entry-card {
    width: min(980px, calc(100vw - 56px)) !important;
    padding: 24px 36px !important;
    column-gap: 34px !important;
  }

  .entry-logo {
    width: 58px !important;
    height: 58px !important;
    margin-bottom: 6px !important;
  }

  .entry-card h1 {
    font-size: clamp(1.9rem, 3vw, 2.55rem) !important;
  }

  .entry-lead {
    margin-top: 8px !important;
    font-size: 0.92rem !important;
  }

  .entry-theme-toggle {
    margin-top: 12px !important;
  }

  .entry-choice,
  button.entry-choice {
    min-height: 68px !important;
    padding: 12px 15px !important;
  }

  .entry-choice-icon {
    width: 42px !important;
    height: 42px !important;
  }

  .entry-choice small {
    font-size: 0.78rem !important;
  }

  .entry-free-note {
    margin-top: 12px !important;
    padding: 9px 12px !important;
  }
}

/* Very wide monitors: keep the design comfortably sized, not oversized or tiny. */
@media (min-width: 1280px) {
  .entry-card {
    width: min(1080px, 72vw) !important;
  }
}

/* EMERGENCY SAFE HOMEPAGE LAYOUT FIX
   Keep the desktop homepage pleasing without overlapping cards. */
@media (min-width: 761px) {
  body.entry-gate-active {
    min-height: 100svh !important;
    overflow-y: auto !important;
  }

  .entry-gate {
    display: grid !important;
    place-items: center !important;
    min-height: 100svh !important;
    padding: clamp(18px, 3vh, 34px) 24px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }

  .entry-card {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    width: min(760px, calc(100vw - 48px)) !important;
    max-width: 760px !important;
    min-height: auto !important;
    max-height: none !important;
    padding: clamp(28px, 4vh, 42px) clamp(28px, 4vw, 48px) !important;
    text-align: center !important;
    overflow: visible !important;
    row-gap: 0 !important;
    column-gap: 0 !important;
    grid-template-columns: none !important;
    grid-template-areas: none !important;
  }

  .entry-logo {
    width: 62px !important;
    height: 62px !important;
    margin: 0 auto 12px !important;
    grid-area: auto !important;
  }

  .entry-card .section-kicker {
    grid-area: auto !important;
    text-align: center !important;
    margin: 0 0 8px !important;
  }

  .entry-card h1 {
    grid-area: auto !important;
    width: 100% !important;
    max-width: 620px !important;
    margin: 0 auto 10px !important;
    text-align: center !important;
    font-size: clamp(2.2rem, 4vw, 3.1rem) !important;
    line-height: 1.06 !important;
    letter-spacing: -0.045em !important;
  }

  .entry-lead {
    grid-area: auto !important;
    width: 100% !important;
    max-width: 560px !important;
    margin: 0 auto 20px !important;
    text-align: center !important;
    font-size: clamp(0.95rem, 1.15vw, 1.05rem) !important;
    line-height: 1.5 !important;
  }

  .entry-theme-toggle {
    grid-area: auto !important;
    position: absolute !important;
    top: 22px !important;
    right: 22px !important;
    align-self: auto !important;
    justify-self: auto !important;
    margin: 0 !important;
  }

  #resumeStudentBtn,
  .entry-choice-grid {
    grid-area: auto !important;
    width: 100% !important;
    max-width: 640px !important;
    min-width: 0 !important;
  }

  #resumeStudentBtn.hidden {
    display: none !important;
  }

  #resumeStudentBtn:not(.hidden) {
    display: flex !important;
    margin: 0 auto 12px !important;
  }

  .entry-choice-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    margin: 0 auto !important;
    align-self: stretch !important;
  }

  .entry-choice,
  button.entry-choice {
    width: 100% !important;
    min-height: 78px !important;
    padding: 15px 18px !important;
    border-radius: 22px !important;
    text-align: left !important;
    transform: none !important;
  }

  .entry-choice:hover,
  button.entry-choice:hover,
  .entry-choice:focus-visible,
  button.entry-choice:focus-visible {
    transform: translateY(-2px) !important;
  }

  .entry-choice-icon {
    width: 48px !important;
    height: 48px !important;
    flex: 0 0 48px !important;
  }

  .entry-choice strong {
    font-size: 1.08rem !important;
    line-height: 1.2 !important;
  }

  .entry-choice small {
    font-size: 0.86rem !important;
    line-height: 1.38 !important;
  }

  .entry-free-note {
    grid-area: auto !important;
    width: 100% !important;
    max-width: 640px !important;
    margin: 16px auto 0 !important;
    padding: 12px 16px !important;
    text-align: center !important;
    font-size: 0.9rem !important;
  }
}

@media (min-width: 761px) and (max-height: 720px) {
  .entry-gate {
    place-items: start center !important;
    padding-top: 12px !important;
    padding-bottom: 12px !important;
  }

  .entry-card {
    width: min(700px, calc(100vw - 44px)) !important;
    padding: 22px 34px !important;
  }

  .entry-logo {
    width: 50px !important;
    height: 50px !important;
    margin-bottom: 7px !important;
  }

  .entry-card .section-kicker {
    margin-bottom: 4px !important;
  }

  .entry-card h1 {
    font-size: clamp(1.85rem, 3vw, 2.45rem) !important;
    margin-bottom: 6px !important;
  }

  .entry-lead {
    margin-bottom: 12px !important;
    font-size: 0.9rem !important;
  }

  .entry-choice,
  button.entry-choice {
    min-height: 64px !important;
    padding: 11px 14px !important;
  }

  .entry-choice-icon {
    width: 42px !important;
    height: 42px !important;
    flex-basis: 42px !important;
  }

  .entry-choice small {
    font-size: 0.78rem !important;
  }

  .entry-free-note {
    margin-top: 10px !important;
    padding: 9px 12px !important;
  }
}

/* PREMIUM FULLSCREEN STUDIO TAB: make Studio feel like a special shiny tool tab,
   but keep it out of the normal tab row so it does not look cramped. */
@media (min-width: 821px) {
  body.editor-fullscreen-active .editor-panel .language-tabs,
  #editorPanel:fullscreen .language-tabs {
    position: relative !important;
    overflow: visible !important;
    isolation: isolate !important;
    margin-bottom: 40px !important;
    padding-right: 18px !important;
  }

  body.editor-fullscreen-active .editor-panel .language-tabs #superStudioLauncher.studio-launcher-desktop,
  #editorPanel:fullscreen .language-tabs #superStudioLauncher.studio-launcher-desktop {
    position: absolute !important;
    top: calc(100% - 1px) !important;
    right: 18px !important;
    z-index: 8 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 7px !important;
    min-width: 126px !important;
    width: auto !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 14px !important;
    margin: 0 !important;
    border-radius: 0 0 16px 16px !important;
    border: 1px solid rgba(109, 175, 255, 0.55) !important;
    border-top: none !important;
    background:
      linear-gradient(180deg, rgba(10, 22, 47, 0.98) 0%, rgba(12, 32, 68, 0.98) 42%, rgba(23, 118, 255, 0.98) 100%) !important;
    color: #f7fbff !important;
    box-shadow:
      0 14px 26px rgba(4, 12, 28, 0.28),
      0 6px 16px rgba(20, 110, 255, 0.18),
      inset 0 1px 0 rgba(255, 255, 255, 0.22),
      inset 0 -1px 0 rgba(0, 0, 0, 0.16) !important;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.28) !important;
    overflow: hidden !important;
    font-weight: 800 !important;
    letter-spacing: 0.02em !important;
    transform: translateY(0) !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease, background 0.2s ease !important;
  }

  body.editor-fullscreen-active .editor-panel .language-tabs #superStudioLauncher.studio-launcher-desktop::before,
  #editorPanel:fullscreen .language-tabs #superStudioLauncher.studio-launcher-desktop::before {
    content: '' !important;
    position: absolute !important;
    left: 6px !important;
    right: 6px !important;
    top: 0 !important;
    height: 58% !important;
    border-radius: 0 0 14px 14px !important;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.06)) !important;
    pointer-events: none !important;
  }

  body.editor-fullscreen-active .editor-panel .language-tabs #superStudioLauncher.studio-launcher-desktop:hover,
  #editorPanel:fullscreen .language-tabs #superStudioLauncher.studio-launcher-desktop:hover {
    transform: translateY(2px) !important;
    box-shadow:
      0 18px 30px rgba(4, 12, 28, 0.3),
      0 8px 18px rgba(20, 110, 255, 0.22),
      inset 0 1px 0 rgba(255, 255, 255, 0.24),
      inset 0 -1px 0 rgba(0, 0, 0, 0.16) !important;
    filter: saturate(1.08) brightness(1.03) !important;
  }

  body.editor-fullscreen-active .editor-panel .language-tabs #superStudioLauncher.studio-launcher-desktop.is-active,
  #editorPanel:fullscreen .language-tabs #superStudioLauncher.studio-launcher-desktop.is-active {
    background:
      linear-gradient(180deg, rgba(38, 17, 90, 0.99) 0%, rgba(24, 39, 96, 0.99) 46%, rgba(0, 181, 255, 0.99) 100%) !important;
    box-shadow:
      0 16px 28px rgba(18, 18, 44, 0.33),
      0 8px 20px rgba(0, 191, 255, 0.2),
      inset 0 1px 0 rgba(255, 255, 255, 0.25),
      inset 0 -1px 0 rgba(0, 0, 0, 0.18) !important;
  }

  body.editor-fullscreen-active .editor-panel .language-tabs #superStudioLauncher.studio-launcher-desktop span,
  #editorPanel:fullscreen .language-tabs #superStudioLauncher.studio-launcher-desktop span {
    position: relative !important;
    z-index: 1 !important;
    font-size: 0.96rem !important;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.22)) !important;
  }

  body.editor-fullscreen-active .editor-panel .language-tabs #superStudioLauncher.studio-launcher-desktop strong,
  #editorPanel:fullscreen .language-tabs #superStudioLauncher.studio-launcher-desktop strong {
    position: relative !important;
    z-index: 1 !important;
    font-size: 0.84rem !important;
    font-weight: 800 !important;
    color: #ffffff !important;
  }
}

/* HOTFIX: keep Super Studio launcher and command overlays visible inside Full Editor */
@media (min-width: 821px) {
  body.editor-fullscreen-active #superStudioLauncher.studio-launcher:not(.studio-hidden),
  #editorPanel:fullscreen #superStudioLauncher.studio-launcher:not(.studio-hidden) {
    position: fixed !important;
    top: 53px !important;
    right: 18px !important;
    left: auto !important;
    z-index: 32000 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 7px !important;
    min-width: 126px !important;
    width: auto !important;
    height: 40px !important;
    min-height: 40px !important;
    margin: 0 !important;
    padding: 0 14px !important;
    border-radius: 0 0 16px 16px !important;
    border: 1px solid rgba(109, 175, 255, 0.58) !important;
    border-top: none !important;
    background: linear-gradient(180deg, rgba(10, 22, 47, 0.99), rgba(12, 36, 78, 0.99) 44%, rgba(18, 132, 255, 0.99)) !important;
    color: #ffffff !important;
    box-shadow: 0 16px 30px rgba(4, 12, 28, 0.28), 0 8px 20px rgba(20, 110, 255, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.24) !important;
    text-shadow: 0 1px 0 rgba(0,0,0,0.28) !important;
    overflow: hidden !important;
    pointer-events: auto !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  body.editor-fullscreen-active #superStudioLauncher.studio-launcher:not(.studio-hidden)::before,
  #editorPanel:fullscreen #superStudioLauncher.studio-launcher:not(.studio-hidden)::before {
    content: '' !important;
    position: absolute !important;
    left: 7px !important;
    right: 7px !important;
    top: 0 !important;
    height: 58% !important;
    border-radius: 0 0 14px 14px !important;
    background: linear-gradient(180deg, rgba(255,255,255,0.36), rgba(255,255,255,0.06)) !important;
    pointer-events: none !important;
  }

  body.editor-fullscreen-active #superStudioLauncher.studio-launcher:not(.studio-hidden) span,
  body.editor-fullscreen-active #superStudioLauncher.studio-launcher:not(.studio-hidden) strong,
  #editorPanel:fullscreen #superStudioLauncher.studio-launcher:not(.studio-hidden) span,
  #editorPanel:fullscreen #superStudioLauncher.studio-launcher:not(.studio-hidden) strong {
    position: relative !important;
    z-index: 1 !important;
    color: #ffffff !important;
  }
}

body.editor-fullscreen-active #editorPanel .studio-command-overlay.inside-editor-fullscreen,
#editorPanel:fullscreen .studio-command-overlay.inside-editor-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  z-index: 36000 !important;
  display: grid !important;
  place-items: center !important;
}

body.editor-fullscreen-active #editorPanel .studio-command-overlay.inside-editor-fullscreen.hidden,
#editorPanel:fullscreen .studio-command-overlay.inside-editor-fullscreen.hidden {
  display: none !important;
}

body.editor-fullscreen-active #editorPanel .studio-command-card,
#editorPanel:fullscreen .studio-command-card {
  z-index: 36001 !important;
}


/* FULL EDITOR BOTTOM DOCK: keep Studio and Code Helper together for a cleaner premium look */
.fullscreen-bottom-tools {
  position: fixed !important;
  right: 20px !important;
  bottom: calc(20px + env(safe-area-inset-bottom)) !important;
  z-index: 7800 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 10px !important;
  padding: 10px !important;
  border-radius: 999px !important;
  border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--line)) !important;
  background: color-mix(in srgb, var(--solid-card) 90%, var(--primary-soft)) !important;
  backdrop-filter: blur(14px) saturate(1.1) !important;
  -webkit-backdrop-filter: blur(14px) saturate(1.1) !important;
  box-shadow: 0 24px 54px rgba(15, 23, 42, 0.22) !important;
  opacity: 1 !important;
  transform: translateY(0) !important;
  transition: opacity 0.2s ease, transform 0.22s ease !important;
}

.fullscreen-bottom-tools.hidden {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(10px) !important;
}

body.editor-fullscreen-active #fullscreenBottomTools #superStudioLauncher,
#editorPanel:fullscreen #fullscreenBottomTools #superStudioLauncher,
body.editor-fullscreen-active #fullscreenBottomTools #codeHelperFloatingBtn,
#editorPanel:fullscreen #fullscreenBottomTools #codeHelperFloatingBtn {
  position: relative !important;
  left: auto !important;
  right: auto !important;
  top: auto !important;
  bottom: auto !important;
  margin: 0 !important;
  z-index: auto !important;
}

body.editor-fullscreen-active #fullscreenBottomTools #superStudioLauncher,
#editorPanel:fullscreen #fullscreenBottomTools #superStudioLauncher {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 10px !important;
  min-width: 148px !important;
  height: 48px !important;
  padding: 0 22px !important;
  border-radius: 999px !important;
  border: 1px solid rgba(59, 130, 246, 0.35) !important;
  color: #ffffff !important;
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 38%, #0ea5e9 72%, #0f172a 100%) !important;
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.28), inset 0 1px 0 rgba(255,255,255,0.18) !important;
}

body.editor-fullscreen-active #fullscreenBottomTools #superStudioLauncher::before,
#editorPanel:fullscreen #fullscreenBottomTools #superStudioLauncher::before {
  content: '' !important;
  position: absolute !important;
  inset: 1px !important;
  border-radius: inherit !important;
  background: linear-gradient(135deg, rgba(255,255,255,0.18), rgba(255,255,255,0.02) 42%, rgba(14,165,233,0.06) 100%) !important;
  pointer-events: none !important;
}

body.editor-fullscreen-active #fullscreenBottomTools #superStudioLauncher span,
body.editor-fullscreen-active #fullscreenBottomTools #superStudioLauncher strong,
#editorPanel:fullscreen #fullscreenBottomTools #superStudioLauncher span,
#editorPanel:fullscreen #fullscreenBottomTools #superStudioLauncher strong {
  position: relative !important;
  z-index: 1 !important;
  color: #ffffff !important;
}

body.editor-fullscreen-active #fullscreenBottomTools #codeHelperFloatingBtn,
#editorPanel:fullscreen #fullscreenBottomTools #codeHelperFloatingBtn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-width: 164px !important;
  height: 48px !important;
  padding: 0 22px !important;
  border-radius: 999px !important;
  font-size: 0.96rem !important;
  color: var(--primary-strong, var(--primary-dark)) !important;
  background: color-mix(in srgb, var(--solid-card) 92%, var(--primary-soft)) !important;
  border: 1px solid color-mix(in srgb, var(--primary) 32%, var(--line)) !important;
  box-shadow: 0 14px 28px rgba(37, 99, 235, 0.16) !important;
}

body.editor-fullscreen-active #editorPanel > #codeHelperFloatingBtn:not(.code-helper-docked),
#editorPanel:fullscreen > #codeHelperFloatingBtn:not(.code-helper-docked) {
  right: 22px !important;
  bottom: calc(22px + env(safe-area-inset-bottom)) !important;
}

@media (max-width: 760px) {
  .fullscreen-bottom-tools {
    display: none !important;
  }
}

/* HOTFIX: remove obsolete Full Editor top gap after moving Studio to bottom dock */
body.editor-fullscreen-active #editorPanel .language-tabs,
#editorPanel:fullscreen .language-tabs,
body.editor-fullscreen-active .editor-panel .language-tabs,
#editorPanel:fullscreen .editor-panel .language-tabs {
  margin-bottom: 0 !important;
}

body.editor-fullscreen-active #htmlPageManager,
#editorPanel:fullscreen #htmlPageManager {
  margin-top: 0 !important;
  transform: none !important;
}

body.editor-fullscreen-active #editorPanel .language-tabs + #htmlPageManager,
#editorPanel:fullscreen .language-tabs + #htmlPageManager {
  border-top: 0 !important;
}
