/* ==========================================================================
   LAYOUT SHELL — POLIGON DYDAKTYCZNY
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
}

button,
a,
input,
select,
[role="button"] {
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2.5px solid var(--focus-ring, var(--accent-primary));
  outline-offset: 2px;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.app-shell {
  min-height: 100dvh;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
}

/* Topbar (jeden wspólny komponent z safe-area-inset-top dla wszystkich modułów) */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
  max-width: 100vw;
  flex-shrink: 0;
  min-height: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
  height: auto;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: env(safe-area-inset-top, 0px) max(1.25rem, env(safe-area-inset-right, 0px)) 0 max(1.25rem, env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
  overflow-x: clip;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
  min-width: 0;
}

.topbar-back-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-alt);
  color: var(--text-primary);
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
}

.topbar-back-btn[hidden] {
  display: none !important;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-emblem {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--accent-primary);
  color: #ffffff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong {
  font-size: 0.92rem;
  letter-spacing: 0.05em;
  font-weight: 800;
}

.brand-text small {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.topbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border-subtle);
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 500;
}

.breadcrumb .crumb-sep {
  color: var(--text-muted);
}

.breadcrumb .crumb-current {
  color: var(--text-primary);
  font-weight: 700;
}

/* Theme switch */

/* Body grid */
.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-surface-alt);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.sidebar-scroll,
.cmdk-list,
.modal-card {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.sidebar-scroll::-webkit-scrollbar,
.cmdk-list::-webkit-scrollbar,
.modal-card::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.sidebar-scroll::-webkit-scrollbar-thumb,
.cmdk-list::-webkit-scrollbar-thumb,
.modal-card::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.sidebar-scroll::-webkit-scrollbar-track,
.cmdk-list::-webkit-scrollbar-track,
.modal-card::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-scroll {
  padding: 0.85rem 0.7rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.nav-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-bottom: 0.2rem;
}

.nav-item:hover:not(.disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
  border-color: rgba(47, 93, 58, 0.25);
}

.nav-item.disabled {
  opacity: 0.55;
  cursor: default;
}

.nav-icon {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: var(--bg-stage);
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.nav-item.active .nav-icon {
  background: var(--accent-primary);
  color: #ffffff;
}

.nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-tree-group:not(.open) .nav-tree-chevron {
  transform: rotate(-90deg);
}

.nav-tree-group:not(.open) .nav-tree-children {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

/* Main content */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 1.35rem 1.6rem 2.5rem;
  max-width: 1460px;
  margin: 0 auto;
  width: 100%;
}

/* Unified Tool Shell */
.tool-header-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.45rem 0.9rem;
  margin-bottom: 0.55rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  box-shadow: var(--shadow-sm);
}

.tool-title-block {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tool-title-block h1 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

/* Unified 2-Column Tool Stage */
.tool-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.95fr);
  gap: 1.15rem;
  align-items: start;
}

.tool-workspace.no-pedagogy {
  grid-template-columns: minmax(0, 1fr);
}

.stage-card,
.pedagogy-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: clip;
  min-width: 0;
  max-width: 100%;
}

.stage-toolbar {
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface-alt);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
  max-width: 100%;
}

.stage-body {
  position: relative;
  padding: 0.8rem;
  background: var(--bg-stage);
  min-width: 0;
  max-width: 100%;
}

/* Profil Canvas-First: scalona górna belka, popover opcji i lekka linia zadania */
.tool-header-card.is-canvas .tool-title-block {
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
}

.header-actions-group {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.settings-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.header-settings-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-alt);
}

.header-settings-btn.btn-danger-outline {
  border-color: var(--accent-red);
  background: var(--accent-red-soft);
  color: var(--accent-red);
}

.header-settings-tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--accent-primary);
  padding-left: 0.2rem;
  border-left: 1px solid var(--border-subtle);
}

.header-settings-tag.is-danger,
.header-settings-btn.btn-primary .header-settings-tag {
  color: inherit;
  border-left-color: currentColor;
  opacity: 0.85;
}

.popover-stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  font-size: 0.76rem;
  color: var(--text-secondary);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.42rem 0.6rem;
}

.stage-settings-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 45;
  width: min(330px, 90vw);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.settings-label {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.settings-divider {
  height: 1px;
  background: var(--border-subtle);
}

.settings-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  padding: 0.44rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-alt);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.settings-toggle-row:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

/* Globalny przełącznik Opcje (Uczeń / Wykładowca) */

.role-switch-btn:hover:not(.active) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.settings-toggle-row.is-active {
  border-color: var(--accent-amber);
  background: var(--accent-amber-soft);
}

.settings-toggle-pill {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 800;
  padding: 0.12rem 0.42rem;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.settings-toggle-row.is-active .settings-toggle-pill {
  border-color: var(--accent-amber);
  color: var(--accent-amber);
}

.stage-card.is-canvas .stage-toolbar.is-task-line {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.46rem 0.9rem;
  gap: 0.55rem 0.9rem;
}

.stage-card.is-canvas .stage-toolbar:empty {
  display: none;
}

.task-line-prompt {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.task-line-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.task-target-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.36rem;
  background: var(--accent-amber-soft);
  color: var(--accent-amber);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 800;
  font-size: 0.88rem;
  line-height: 1.25;
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: break-word;
}

.task-target-pill > .ui-svg {
  flex-shrink: 0;
}

.task-target-pill.is-mono {
  font-family: var(--font-mono);
}

.task-line-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.task-line-input {
  width: 112px;
  padding: 0.28rem 0.52rem;
  font-size: 0.86rem;
  font-weight: 700;
}

.task-line-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
}

.task-target-select {
  background: var(--accent-amber-soft);
  color: var(--accent-amber);
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(217, 119, 6, 0.42);
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
}

.task-target-select:focus {
  outline: 2px solid var(--accent-amber);
  outline-offset: 1px;
}

.inline-task-code {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.32rem 0.18rem 0.52rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
}

.inline-task-hash {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--text-muted);
  white-space: nowrap;
}

.inline-task-input {
  width: 58px;
  padding: 0.18rem 0.32rem;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.inline-task-go {
  padding: 0.22rem 0.48rem;
  font-size: 0.75rem;
}

.pedagogy-card {
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.pedagogy-card[hidden],
[hidden] {
  display: none !important;
}

.mobile-only {
  display: none !important;
}

.desktop-only {
  display: inline-flex !important;
}

/* Zwijany pasek boczny (desktop) i Tryb Rzutnika / Klasy */
.stage-card[data-tool-mode="instructor"],
.stage-card[data-tool-mode="exam"] {
  border-top: 1px solid var(--border-subtle);
}

html.sidebar-collapsed .sidebar,
html.projector-mode .sidebar {
  width: 0;
  min-width: 0;
  border-right: none;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

html.projector-mode.projector-sidebar-open .sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: min(288px, 85vw);
  min-width: min(288px, 85vw);
  border-right: 1px solid var(--border-strong);
  overflow: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
  z-index: 45;
  box-shadow: var(--shadow-lg);
}

.sidebar-backdrop.open {
  display: block;
  position: fixed;
  inset: var(--topbar-height) 0 0 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 42;
}

.sidebar {
  transition: width var(--transition-med), opacity var(--transition-fast);
}

html.projector-mode {
  font-size: 106%;
  --border-subtle: #b9c8b7;
  --border-strong: #6d836b;
  --text-muted: #39483d;
}

html.projector-mode .main-content {
  max-width: 1720px;
  padding: 0.9rem 1.35rem 2rem;
}

html.projector-mode .stage-card,
html.projector-mode .tool-header-card,
html.projector-mode .telemetry-box,
html.projector-mode .pedagogy-card,
html.projector-mode .stage-settings-popover {
  border-width: 1.5px;
  border-color: var(--border-strong);
  box-shadow: none;
}

html.projector-mode .telemetry-label,
html.projector-mode .task-code-label {
  color: var(--text-secondary);
}

@keyframes poligonViewEnter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.main-content.is-route-entering > section,
.main-content.is-route-entering > .tool-header-card {
  animation: poligonViewEnter 150ms ease-out;
}

.topbar-context-pill {
  display: none;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 0.22rem 0.62rem;
  flex: 1 1 0;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Dopasowanie pionowe na mniejszych ekranach / laptopach (bez wpływu na duże monitory) */
@media (max-height: 860px) and (min-width: 761px) {
  html.projector-mode {
    font-size: 100%;
  }

  .main-content,
  html.projector-mode .main-content {
    padding: 0.48rem 0.95rem 0.7rem;
  }

  .tool-header-card {
    padding: 0.34rem 0.72rem;
    margin-bottom: 0.38rem;
  }

  .stage-toolbar {
    padding: 0.36rem 0.72rem;
  }

  .stage-body {
    padding: 0.48rem 0.65rem;
  }
}

@media (max-width: 1380px) {
  .sidebar {
    width: 244px;
  }

  .main-content {
    padding: 1.05rem 1.2rem 2rem;
  }

  .tool-workspace {
    grid-template-columns: minmax(0, 1.4fr) minmax(295px, 0.9fr);
    gap: 0.95rem;
  }
}

@media (max-width: 1024px), (max-height: 560px) and (orientation: landscape) {
  html.in-tool-view,
  html.in-tool-view body {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  html.in-tool-view .app-shell {
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  html.in-tool-view .app-body {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  html.in-tool-view .main-content {
    flex: 1 1 0;
    min-height: 0;
    height: 100%;
    max-width: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  html.in-tool-view .tool-workspace {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  html.in-tool-view .stage-card {
    flex: 1 1 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  html.in-tool-view .stage-body {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
  }

  html.in-tool-view .stage-card[data-tool-id="terrain-contours"] > .stage-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tool-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .mobile-only {
    display: inline-flex !important;
  }

  .desktop-only {
    display: none !important;
  }

  .topbar {
    padding: env(safe-area-inset-top, 0px) max(0.6rem, env(safe-area-inset-right, 0px)) 0 max(0.6rem, env(safe-area-inset-left, 0px));
  }

  .topbar-divider,
  .breadcrumb,
  .brand-text small {
    display: none;
  }

  .topbar-context-pill {
    display: block;
  }

  .main-content {
    padding: 0.45rem max(0.6rem, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(0.6rem, env(safe-area-inset-left, 0px));
  }

  .tool-header-card {
    padding: 0.36rem 0.55rem;
    margin-bottom: 0.45rem;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem 0.45rem;
  }

  .tool-title-block {
    flex-wrap: nowrap;
    gap: 0.35rem;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
  }

  .tool-title-block h1.shell-title-has-tabs {
    display: none;
  }

  .tool-header-right {
    width: auto;
    min-width: 0;
    flex-shrink: 0;
  }

  .header-actions-group {
    width: auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 0.28rem;
  }
}

@media (max-width: 768px), (max-height: 560px) and (orientation: landscape) {
  :root {
    --topbar-height: 46px;
  }

  .topbar {
    padding: env(safe-area-inset-top, 0px) max(0.45rem, env(safe-area-inset-right, 0px)) 0 max(0.45rem, env(safe-area-inset-left, 0px));
    gap: 0.35rem;
  }

  .topbar-left {
    gap: 0.36rem;
    min-width: 0;
    flex: 1 1 0;
    overflow: hidden;
  }

  .topbar-right {
    gap: 0.26rem;
    flex: 0 0 auto;
  }

  .brand-text strong {
    font-size: 0.82rem;
  }

  .brand-emblem {
    width: 28px;
    height: 28px;
  }

  .topbar-context-pill {
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
    font-size: 0.76rem;
    padding: 0.16rem 0.4rem;
  }

  /* Natywny mobilny pasek narzędzia: [ ← ] [ Tytuł… ] ... [ żarówka ] [ wykres N ] [ PL · 360° ] */
  html.in-tool-view .topbar .brand {
    display: none !important;
  }

  .topbar-settings-btn {
    padding: 0 0.44rem !important;
    width: auto !important;
    min-width: 0 !important;
    height: 32px;
    gap: 0.26rem;
    flex-shrink: 0;
    white-space: nowrap;
  }

  .topbar-settings-btn > .ui-svg {
    display: none;
  }

  .topbar-settings-label {
    display: inline-flex !important;
    align-items: center;
    gap: 0.24rem;
    white-space: nowrap;
  }

  .topbar-locale-chip {
    font-size: 0.71rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    white-space: nowrap;
  }

  .topbar-settings-proj-tag {
    display: none;
  }

  html.in-tool-view .topbar-context-pill {
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
    font-size: 0.88rem;
    font-weight: 800;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .main-content {
    padding: 0.3rem max(0.38rem, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(0.38rem, env(safe-area-inset-left, 0px));
  }

  /* Odchudzenie zagnieżdżonych ramek na telefonach (koniec z okienkami w okienkach) */
  .tool-header-card {
    padding: 0.1rem 0.08rem 0.32rem;
    margin-bottom: 0.28rem;
    gap: 0.28rem 0.35rem;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
  }

  .tool-header-card.is-minimal-header {
    justify-content: flex-end;
    padding-bottom: 0.22rem;
  }

  html.in-tool-view .tool-title-block h1 {
    display: none;
  }

  .tool-title-block {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .tool-title-block::-webkit-scrollbar {
    display: none;
  }

  .header-actions-group {
    gap: 0.24rem;
  }

  .stage-card {
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    overflow: hidden;
  }

  .stage-toolbar,
  .stage-card.is-canvas .stage-toolbar.is-task-line {
    padding: 0.42rem 0.54rem;
    gap: 0.34rem 0.42rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
  }

  .stage-body {
    padding: 0;
    background: transparent;
  }

  .task-line-main {
    width: 100%;
    justify-content: space-between;
    gap: 0.32rem 0.42rem;
  }

  .task-line-actions {
    width: auto;
    gap: 0.3rem;
  }

  .inline-task-code {
    width: auto;
    gap: 0.22rem;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  :root {
    --topbar-height: 40px;
  }

  .topbar {
    position: sticky;
    top: 0;
    min-height: calc(40px + env(safe-area-inset-top, 0px));
    height: auto;
    padding: env(safe-area-inset-top, 0px) max(0.5rem, env(safe-area-inset-right, 0px)) 0 max(0.5rem, env(safe-area-inset-left, 0px));
    box-shadow: none;
  }

  .main-content {
    padding: 0.18rem max(0.45rem, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(0.45rem, env(safe-area-inset-left, 0px));
  }

  .tool-header-card {
    padding: 0.16rem 0.35rem;
    margin-bottom: 0.18rem;
  }
}

/* Czysty arkusz druku (Ctrl+P) dla kart pracy i zestawów ćwiczeń */
@media print {
  body {
    background: #ffffff;
    color: #000000;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .topbar,
.sidebar,
.sidebar-backdrop,
.toast-stack,
.modal-overlay,
.tool-header-right,
.tool-seq-nav,
.tool-title-block [data-nav="home"],
.ex-task-drawer,
.stage-settings-popover,
.map-cad-dock,
.stage-canvas-dock,
.inline-task-go,
.task-share-btn,
#tool-stage-toolbar .btn {
    display: none !important;
  }

  .main-content {
    max-width: 100%;
    padding: 0;
  }

  .tool-workspace {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .tool-header-card,
.stage-card,
.pedagogy-card {
    box-shadow: none !important;
    border-color: #cbd5e1 !important;
  }
}

/* Kompaktowy wybierak numeru zadania na telefonach (Punkt 5 UX) */
.inline-task-code .inline-task-pill {
  display: none;
  font-family: var(--font-mono);
  font-weight: 800;
}

.inline-task-picker-popover {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

@media (max-width: 1024px), (max-height: 560px) and (orientation: landscape) {
  .inline-task-code {
    width: auto;
    position: relative;
    padding: 0.14rem 0.25rem;
  }

  .inline-task-code .inline-task-pill {
    display: inline-flex;
  }

  .inline-task-picker-popover {
    display: none;
  }

  .inline-task-code.is-picker-open .inline-task-picker-popover {
    display: inline-flex;
    position: absolute;
    top: calc(100% + 6px);
    bottom: auto;
    left: 0;
    right: auto;
    z-index: 50;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 0.4rem 0.55rem;
    box-shadow: var(--shadow-lg);
    white-space: nowrap;
  }
}

@media (max-height: 560px) and (orientation: landscape) and (min-width: 560px) {
  .inline-task-code.is-picker-open .inline-task-picker-popover {
    left: auto;
    right: 0;
  }
}
