:root {
  color-scheme: dark;
  --bg: #0f1317;
  --bg-soft: #141a20;
  --panel: #171d23;
  --panel-strong: #1d252d;
  --panel-soft: #121820;
  --text: #edf3f1;
  --muted: #9eaca9;
  --faint: #6e7c79;
  --border: #2b363f;
  --border-strong: #40515f;
  --blue: #5d9ed1;
  --blue-strong: #347fb6;
  --green: #45a36b;
  --yellow: #c29536;
  --red: #bd5252;
  --red-soft: #321e22;
  --focus: #9bd7ff;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

.learning-guides { margin-top: 20px; }
.rendered details.manual-audit { margin-top: 24px; padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-soft); font-size: .9em; }
.rendered details.manual-audit > summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.rendered details.manual-audit > ul { padding-left: 22px; }
.rendered details.manual-audit li { margin: 16px 0; overflow-wrap: anywhere; }
.rendered details.manual-audit blockquote { margin: 8px 0; padding-left: 12px; border-left: 2px solid var(--border-strong); color: var(--muted); }
.guide-courses { display: grid; gap: 20px; }
.guide-course h3 { margin: 0 0 10px; }
.guide-documents { display: flex; flex-wrap: wrap; gap: 8px; }
.guide-documents button { display: grid; gap: 5px; text-align: left; max-width: 100%; }
.guide-documents small { color: var(--muted); font-size: 11px; }
.guide-panel { width: min(1120px, 96vw); height: 92dvh; max-height: 96dvh; padding: 20px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); overflow: hidden; }
.guide-panel[open] { display: flex; flex-direction: column; }
.guide-panel::backdrop { background: rgba(0,0,0,.72); }
.guide-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.guide-toolbar > div { flex: 1 1 240px; }
.guide-toolbar h2 { margin: 0; font-size: 22px; overflow-wrap: anywhere; }
.guide-content.rendered { flex: 1; min-height: 0; max-height: none; overflow: auto; padding: 12px 20px 36px; font-size: 18px; line-height: 1.65; scroll-behavior: auto; overflow-wrap: anywhere; }
.guide-content table { max-width: 100%; overflow-x: auto; display: block; }
.guide-content a { color: var(--blue); }
.guide-content [id] { scroll-margin-top: 12px; }
.guide-obsidian-only { display: none !important; }
@media (max-width: 620px) {
  .guide-panel { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; padding: 12px; border-radius: 0; }
  .guide-toolbar h2 { font-size: 18px; }
  .guide-content.rendered { padding: 8px 2px 24px; font-size: 17px; }
  .guide-documents { display: grid; }
}
@media print {
  body.printing-guide { color-scheme: light; background: white !important; color: black !important; overflow: visible !important; }
  body.printing-guide > :not(#guidePanel) { display: none !important; }
  body.printing-guide #guidePanel { display: block !important; position: static !important; width: 100% !important; height: auto !important; max-height: none !important; max-width: none !important; margin: 0 !important; padding: 0 !important; border: 0 !important; overflow: visible !important; background: white !important; color: black !important; box-shadow: none !important; }
  body.printing-guide .guide-toolbar button, body.printing-guide #guideStatus { display: none !important; }
  body.printing-guide .guide-content { overflow: visible !important; height: auto !important; padding: 0; color: black !important; }
  body.printing-guide .guide-content table { display: table; font-size: 10pt; }
  body.printing-guide .guide-content th, body.printing-guide .guide-content td { color: black !important; background: white !important; border-color: #aaa; }
  body.printing-guide .guide-content pre, body.printing-guide .guide-content code { color: black !important; background: white !important; border-color: #aaa; }
  body.printing-guide .guide-content h1, body.printing-guide .guide-content h2, body.printing-guide .guide-content h3 { break-after: avoid; color: black !important; }
}

.consultation-head h2 {
  margin: 0;
  overflow-wrap: anywhere;
}

.reference-heading,
.consultation-head,
.consultation-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.card-references {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  background: var(--panel-soft);
}

.reference-heading {
  font-size: 12px;
  color: var(--muted);
}

.reference-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.reference-link {
  font-size: 13px;
  text-align: left;
  display: grid;
  gap: 4px;
}

.reference-link small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.rendered .study-inline-reference {
  padding: 1px 5px;
  min-height: auto;
  margin: 0 2px;
  font: inherit;
  line-height: inherit;
  color: var(--focus);
  border-color: var(--border-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: normal;
}

.review-criterion,
.consultation-context {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
}

.help-notice {
  margin: 0;
  font-size: 13px;
  color: var(--yellow);
}

.consultation-panel {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 75;
  width: var(--consultation-width, 360px);
  max-width: none;
  height: 100svh;
  max-height: 100svh;
  margin: 0;
  padding: 20px;
  border: 1px solid var(--border-strong);
  border-radius: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: auto;
  overscroll-behavior: contain;
}

.consultation-panel[open] {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 16px;
}

.consultation-panel[data-mode="modal"]::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.consultation-head {
  align-items: start;
  position: sticky;
  top: -20px;
  z-index: 1;
  background: var(--panel);
  padding-bottom: 10px;
}

body[data-consultation-mode="drawer"] .app-layout {
  width: calc(100% - var(--consultation-width, 360px) - 8px);
}

.consultation-resize-handle {
  position: fixed;
  top: 0;
  bottom: 0;
  right: calc(var(--consultation-width, 360px) - 4px);
  width: 12px;
  z-index: 76;
  cursor: col-resize;
  touch-action: none;
  border-left: 2px solid var(--border-strong);
}

.consultation-resize-handle:hover,
.consultation-resize-handle:focus-visible {
  border-color: var(--focus);
  background: rgba(93, 158, 209, 0.12);
}

body[data-consultation-mode="modal"] {
  overflow: hidden;
}

.consultation-head > div {
  flex: 1;
  min-width: 0;
}

.consultation-panel .consultation-content {
  padding: 0;
  min-height: auto;
  max-height: none;
  overflow: visible;
  font-size: 18px;
}

.consultation-mark-editor {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.consultation-mark-editor label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.consultation-mark-editor textarea {
  width: 100%;
  resize: vertical;
  font-size: 16px;
}

@media (max-width: 767px) {
  .consultation-panel {
    inset: 0;
    width: 100vw;
    height: 100svh;
    max-height: 100svh;
    margin: 0;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  }
}

body[data-review-size="compact"] {
  --review-font-size: 18px;
  --review-line-height: 1.62;
}

body[data-review-size="normal"] {
  --review-font-size: 22px;
  --review-line-height: 1.68;
}

body[data-review-size="large"] {
  --review-font-size: 26px;
  --review-line-height: 1.72;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
  overflow-x: clip;
}

body {
  margin: 0;
  width: 100%;
  min-width: 0;
  min-height: 100vh;
  overflow-x: hidden;
  /* clip taglia come hidden ma non crea un contenitore di scorrimento: serve alle barre fisse (palazzi). */
  overflow-x: clip;
  background:
    radial-gradient(circle at top left, rgba(93, 158, 209, 0.13), transparent 34rem),
    linear-gradient(180deg, #0f1317 0%, #0c1014 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #222b33;
  color: var(--text);
  padding: 10px 14px;
  font-weight: 750;
  cursor: pointer;
}

button:hover {
  border-color: var(--border-strong);
  background: #27323c;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f1419;
  color: var(--text);
  padding: 10px 12px;
}

textarea {
  min-height: 94px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  font-size: 19px;
  line-height: 1.2;
}

h3 {
  font-size: 16px;
  line-height: 1.25;
}

code {
  overflow-wrap: anywhere;
}

.hidden {
  display: none !important;
}

.mobile-appbar,
.mobile-nav-panel,
.mobile-only,
.mobile-flow-hints {
  display: none;
}

.primary-btn {
  border-color: #4a91c4;
  background: linear-gradient(180deg, #4f95c8 0%, #347fb6 100%);
  color: #061017;
}

.success-btn {
  background: #2f7f51;
  border-color: #4ba872;
}

.warn-btn {
  background: #8b6a22;
  border-color: #b88d34;
}

.danger-btn {
  background: #873b42;
  border-color: #b4515b;
}

.danger-outline-btn {
  border-color: #8d4d54;
  background: transparent;
  color: #ffc1c7;
}

.danger-outline-btn:hover {
  border-color: #b4515b;
  background: var(--red-soft);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(460px, 100%);
  display: grid;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(23, 29, 35, 0.96);
  box-shadow: var(--shadow);
}

.brand-mark,
.eyebrow {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-panel p,
.topbar p,
.panel p,
.small-status,
.error-text,
.source-info,
.preview-info {
  color: var(--muted);
}

.error-text {
  min-height: 20px;
  color: #ffb5bd;
}

.app-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  border-right: 1px solid var(--border);
  background: rgba(13, 17, 21, 0.94);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid #3f718e;
  border-radius: 8px;
  background: #13212b;
  color: #9bd7ff;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.main-nav {
  display: grid;
  align-content: start;
  gap: 6px;
}

.nav-btn {
  justify-content: flex-start;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--muted);
}

.nav-btn.active {
  background: #1b2630;
  color: var(--text);
  border-color: #48606f;
}

.session-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #335466;
  border-radius: 8px;
  background: #101a21;
}

.session-box span {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
}

.main-shell {
  min-width: 0;
  width: min(1480px, 100%);
  padding: 20px;
  display: grid;
  align-content: start;
  gap: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.topbar h1 {
  margin-top: 4px;
}

.topbar p:last-child {
  margin-top: 6px;
  line-height: 1.45;
}

.top-actions,
.toolbar,
.command-row,
.secondary-row,
.grade-row,
.action-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-banner {
  padding: 13px 14px;
  border: 1px solid #744c51;
  border-radius: 8px;
  background: var(--red-soft);
  color: #ffd2d7;
}

.status-banner[data-tone="ok"] {
  border-color: #35684d;
  background: #13261c;
  color: #bff2d2;
}

.page {
  min-width: 0;
  display: grid;
  gap: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card,
.panel,
.study-card,
.accumulo-card,
.report-item {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(23, 29, 35, 0.94);
}

.metric-card {
  padding: 16px;
  display: grid;
  gap: 8px;
}

.metric-card span,
label,
.detail-list dt,
.inline-details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-card strong {
  font-size: 28px;
}

.dashboard-grid,
.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 0.82fr);
  gap: 16px;
  align-items: start;
}

.split-layout.wide-left {
  grid-template-columns: minmax(360px, 1.15fr) minmax(320px, 0.85fr);
}

.panel {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.panel-head,
.page-head-row,
.panel-subhead {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.panel-head p,
.page-head-row p {
  margin-top: 5px;
  line-height: 1.45;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
}

.checkbox-label {
  grid-template-columns: auto 1fr;
  align-items: center;
  align-content: center;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}

.checkbox-label input {
  width: 18px;
  min-height: auto;
  height: 18px;
  accent-color: var(--blue);
}

.detail-list,
.inline-details {
  display: grid;
  gap: 10px;
  margin: 0;
}

.detail-list > div,
.inline-details > div {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(43, 54, 63, 0.72);
}

.detail-list > div:last-child,
.inline-details > div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.detail-list dd,
.inline-details dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.notice-box,
.empty-state,
.ok-box,
.warning-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #111820;
  line-height: 1.45;
}

.notice-box p,
.empty-state {
  color: var(--muted);
}

.ok-box {
  border-color: #315f47;
  background: #102019;
  color: #c7f3d6;
}

.warning-stack {
  display: grid;
  gap: 8px;
}

.warning-item {
  border-color: #7b6333;
  background: #2c2415;
  color: #f7dfa9;
}

.warning-item.blocking {
  border-color: #744c51;
  background: var(--red-soft);
  color: #ffd2d7;
}

.tree {
  max-height: min(60vh, 680px);
  overflow: auto;
  display: grid;
  gap: 2px;
  padding-right: 2px;
}

.tall-tree {
  max-height: min(68vh, 760px);
}

.tree-node {
  display: grid;
  gap: 2px;
}

.node-row {
  min-height: 38px;
  display: grid;
  grid-template-columns: 24px 22px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border-radius: 7px;
  padding: 5px 7px;
  cursor: pointer;
}

.node-row:hover {
  background: #222b33;
}

.node-row:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
  background: #222b33;
}

.twisty {
  color: var(--muted);
  text-align: center;
}

.node-row input {
  min-height: auto;
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.node-label {
  overflow-wrap: anywhere;
}

.node-count {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.children {
  margin-left: 22px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}

.full-input {
  flex: 1 1 240px;
}

.small-status,
.source-info,
.preview-info {
  min-height: 20px;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.session-page {
  max-width: 1560px;
  margin: 0 auto;
  width: 100%;
}

.session-hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 16px;
  border: 1px solid #334b5f;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(25, 37, 47, 0.96), rgba(17, 24, 31, 0.96));
}

.session-hero h1 {
  margin-top: 5px;
}

.session-hero p:last-child {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.session-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.segmented-control {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.segmented-control button {
  min-width: 40px;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-right: 1px solid var(--border);
  border-radius: 0;
}

.segmented-control button:last-child {
  border-right: 0;
}

.segmented-control button.active {
  background: var(--blue);
  color: #07131b;
}

.disabled-control {
  opacity: 0.5;
}

.disabled-control input {
  cursor: not-allowed;
}

.session-state-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.session-state-grid > div {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 12px;
  display: grid;
  gap: 5px;
}

.session-state-grid span,
.mini-stats,
.pill {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.session-state-grid strong {
  overflow-wrap: anywhere;
}

.study-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.study-card {
  overflow: hidden;
}

.study-card header {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.rendered {
  min-height: 240px;
  max-height: min(66vh, 780px);
  padding: 18px;
  overflow: auto;
  font-size: var(--review-font-size, 22px);
  line-height: var(--review-line-height, 1.68);
}


/* Card typography scales with the selected reading size. */
.rendered h1,
.rendered h2,
.rendered h3,
.rendered h4,
.rendered h5,
.rendered h6 {
  margin: 1.2em 0 0.55em;
  font-weight: 800;
  line-height: 1.3;
}

.rendered h1 { font-size: 1.45em; }
.rendered h2 { font-size: 1.3em; }
.rendered h3 { font-size: 1.15em; }
.rendered h4,
.rendered h5,
.rendered h6 { font-size: 1em; }

.rendered p {
  margin: 0.7em 0;
}

.rendered > :first-child,
.rendered section > :first-child {
  margin-top: 0;
}

.rendered > :last-child,
.rendered section > :last-child {
  margin-bottom: 0;
}

#pageSession .study-card .rendered {
  min-height: 0;
  max-height: none;
  overflow: visible;
}

.session-reading-toolbar {
  display: flex;
  justify-content: flex-end;
}

.session-reading-toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.session-reading-toolbar select {
  width: auto;
}

@media (min-width: 1024px) {
  body[data-session-layout="side-by-side"] .study-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

@media (min-width: 768px) {
  body[data-view="session"][data-focus-mode="true"] .app-layout {
    grid-template-columns: 1fr;
  }

  body[data-view="session"][data-focus-mode="true"] .sidebar,
  body[data-view="session"][data-focus-mode="true"] .topbar {
    display: none;
  }

  body[data-view="session"][data-focus-mode="true"] .main-shell {
    width: 100%;
    max-width: none;
    padding: 16px 24px;
  }
}

.muted-box {
  color: var(--muted);
}

.review-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 13px;
}

.grade-row button {
  flex: 1 1 160px;
  min-height: 52px;
}

.keyboard-hint,
.rating-status {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.rating-status {
  min-height: 18px;
}

.grade-row[aria-busy="true"] button {
  cursor: wait;
}

.secondary-row button {
  flex: 1 1 150px;
}

#audioPlayer {
  display: none;
  width: 100%;
}

.accumuli-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 14px;
}

.accumulo-card {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.accumulo-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.accumulo-card p {
  color: var(--muted);
  line-height: 1.45;
}

.sections-chip {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111820;
}

.accumulo-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}

.accumulo-stats > div {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111820;
}

.accumulo-stats span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.accumulo-stats strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.mini-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-stats span,
.pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  background: #111820;
}

.is-muted {
  opacity: 0.68;
}

.sticky-panel {
  position: sticky;
  top: 20px;
}

.list,
.report-list,
.command-copy-list {
  display: grid;
  gap: 10px;
}

.list-item,
.command-copy-list > div {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111820;
  padding: 12px;
  display: grid;
  gap: 6px;
}

.slim-item {
  padding: 10px;
}

.report-item {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.report-item.error {
  border-color: #754b51;
}

.report-item header {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.report-item p {
  color: var(--text);
  line-height: 1.5;
}

.command-copy-list span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.command-copy-list code {
  display: block;
  padding: 10px;
  border-radius: 7px;
  background: #0c1116;
  color: #cbe9ff;
}

.rendered img {
  max-width: 100%;
  height: auto;
}

.rendered table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}

.rendered th,
.rendered td {
  border: 1px solid var(--border);
  padding: 8px;
  vertical-align: top;
}

.rendered pre {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0c1116;
  padding: 12px;
}

.rendered code {
  background: #0c1116;
  border-radius: 6px;
  padding: 2px 5px;
}

.rendered mjx-container {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.rendered mjx-container.math-wide {
  padding-bottom: 6px;
  border-right: 3px solid var(--border-strong);
  background: linear-gradient(to left, rgba(93, 158, 209, 0.14), transparent 28px);
}

.rendered img.card-figure {
  cursor: zoom-in;
}

.figure-viewer {
  width: 100vw;
  max-width: 100vw;
  height: 100svh;
  max-height: 100svh;
  margin: 0;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  border: 0;
  background: var(--bg);
  color: var(--text);
}

.figure-viewer[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.figure-viewer::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

.figure-viewer-close {
  justify-self: end;
}

.figure-viewer-body {
  overflow: auto;
  touch-action: pan-x pan-y pinch-zoom;
}

.figure-viewer-body img {
  display: block;
  width: 100%;
  min-width: min(100%, 720px);
  height: auto;
}

@media (max-width: 767px) {
  .figure-viewer-body img {
    width: 200%;
    max-width: none;
  }
}

label small,
.metric-card small,
.ranking-row span,
.marked-copy small,
.question-preview {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: 0;
  text-transform: none;
}

button.marked {
  border-color: #c29536;
  background: #66501f;
  color: #fff0c7;
}

.session-summary {
  display: grid;
  gap: 16px;
  padding: 18px;
  border: 1px solid #405f4f;
  border-radius: 8px;
  background: #151e1a;
}

.scheduler-adaptation {
  border-color: #35556b;
  background: linear-gradient(135deg, rgba(24, 42, 54, 0.96), rgba(20, 29, 35, 0.96));
}

.scheduler-adaptation[data-status="active"] {
  border-color: #3f7456;
  background: linear-gradient(135deg, rgba(20, 42, 31, 0.96), rgba(20, 29, 35, 0.96));
}

.adaptation-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.adaptation-metrics > div {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(15, 20, 25, 0.66);
}

.adaptation-metrics dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.adaptation-metrics dd {
  margin: 0;
  font-size: 20px;
  font-weight: 850;
}

.summary-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.summary-columns > div {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 9px;
}

.ranking-row,
.trend-row {
  min-width: 0;
  display: grid;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111820;
}

.ranking-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.ranking-row > div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.ranking-row > div:last-child {
  text-align: right;
}

.trend-list,
.marked-list {
  display: grid;
  gap: 10px;
}

.trend-row {
  grid-template-columns: minmax(110px, 1fr) repeat(4, minmax(90px, auto));
  color: var(--muted);
  font-size: 13px;
}

.trend-row strong {
  color: var(--text);
}

.marked-card {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.2fr) auto;
  gap: 14px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #141a20;
}

.disabled-card {
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: center;
}

.marked-copy,
.marked-actions {
  display: grid;
  gap: 7px;
}

.marked-copy .pill {
  width: fit-content;
}

.compact-control {
  min-width: 150px;
}

@media (max-width: 1020px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    grid-template-rows: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .main-nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-btn {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .session-box {
    max-width: 100%;
  }

  .metric-grid,
  .dashboard-grid,
  .settings-grid,
  .split-layout,
  .split-layout.wide-left,
  .study-layout,
  .session-state-grid,
  .controls-grid {
    grid-template-columns: 1fr;
  }

  .sticky-panel {
    position: static;
  }
}

@media (max-width: 767px) {
  button {
    min-height: 48px;
    padding: 11px 13px;
  }

  input,
  textarea {
    min-height: 48px;
    font-size: 16px;
  }

  .app-layout {
    display: block;
    min-height: 100svh;
  }

  .mobile-appbar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 10px;
    align-items: center;
    min-height: calc(58px + env(safe-area-inset-top));
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    border-bottom: 1px solid var(--border);
    background: rgba(12, 16, 20, 0.98);
    backdrop-filter: blur(16px);
  }

  .mobile-appbar-title {
    min-width: 0;
    display: grid;
    gap: 2px;
  }

  .mobile-appbar-title strong,
  .mobile-appbar-title span,
  .mobile-progress {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-appbar-title strong {
    font-size: 15px;
  }

  .mobile-appbar-title span,
  .mobile-progress {
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
  }

  .mobile-progress {
    max-width: 86px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #111820;
  }

  #mobileMenuButton {
    min-height: 40px;
    padding: 8px 11px;
  }

  .mobile-nav-panel:not(.hidden) {
    position: fixed;
    top: calc(64px + env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    z-index: 70;
    display: grid;
    gap: 12px;
    max-height: calc(100svh - 82px - env(safe-area-inset-top));
    overflow: auto;
    padding: 12px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: rgba(19, 25, 31, 0.98);
    box-shadow: var(--shadow);
  }

  .mobile-nav-grid,
  .mobile-menu-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-session-actions {
    display: grid;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }

  .mobile-session-actions h2 {
    font-size: 15px;
  }

  .mobile-card-info {
    display: grid;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #0f1419;
    color: var(--muted);
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  .mobile-card-info strong {
    color: var(--text);
  }

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar,
  .topbar {
    display: none !important;
  }

  .main-shell {
    width: 100%;
    padding: 12px 10px calc(92px + env(safe-area-inset-bottom));
    gap: 12px;
  }

  body[data-view="session"] .main-shell {
    padding: 0 0 calc(98px + env(safe-area-inset-bottom));
  }

  body[data-view="sections"] .main-shell {
    padding-bottom: calc(148px + env(safe-area-inset-bottom));
  }

  .status-banner {
    margin: 0 10px;
  }

  body[data-view="session"] .status-banner.hidden {
    display: none !important;
  }

  #pageDashboard .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #pageDashboard .metric-card:nth-child(1),
  #pageDashboard .metric-card:nth-child(3),
  #pageDashboard .system-panel .detail-list > div:nth-child(1),
  #pageDashboard .system-panel .detail-list > div:nth-child(4),
  #pageDashboard .system-panel .detail-list > div:nth-child(5) {
    display: none;
  }

  #pageDashboard .action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #dashboardRebuildButton {
    grid-column: 1 / -1;
  }

  .session-page {
    width: 100%;
    max-width: none;
    min-height: calc(100svh - 64px - env(safe-area-inset-top));
    padding: 8px 10px 0;
    margin: 0;
    gap: 8px;
    touch-action: pan-y;
  }

  .session-hero {
    padding: 8px 10px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    background: transparent;
  }

  .session-hero .eyebrow,
  .session-actions {
    display: none;
  }

  .session-hero h1 {
    margin: 0;
    font-size: 20px;
    line-height: 1.2;
  }

  .session-hero p:last-child {
    margin-top: 4px;
    font-size: 13px;
  }

  .session-state-grid {
    display: block;
  }

  .session-state-grid > div {
    display: none;
  }

  .session-state-grid > div:nth-child(2) {
    display: grid;
    padding: 8px 10px;
    border-radius: 8px;
    background: #111820;
  }

  .session-state-grid > div:nth-child(2) span {
    display: none;
  }

  .session-state-grid > div:nth-child(2) strong {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
  }

  .study-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
  }

  body[data-answer-shown="false"] .answer-card {
    display: none;
  }

  .study-card {
    border-radius: 9px;
    background: rgba(23, 29, 35, 0.98);
  }

  .study-card header {
    padding: 9px 11px;
    font-size: 11px;
  }

  .rendered {
    min-height: auto;
    max-height: none;
    padding: 15px;
    font-size: var(--review-font-size, 22px);
    line-height: var(--review-line-height, 1.68);
  }

  #questionContent {
    font-size: calc(var(--review-font-size, 22px) + 2px);
    line-height: 1.58;
  }

  body[data-answer-shown="false"] #questionContent {
    min-height: 0;
  }

  body[data-answer-shown="true"] #questionContent {
    min-height: 0;
  }

  body[data-answer-shown="true"] #answerContent {
    min-height: 0;
    border-top: 1px solid rgba(43, 54, 63, 0.72);
  }

  .review-meta,
  .secondary-row,
  #audioPlayer,
  .source-info,
  .preview-info {
    display: none !important;
  }

  .grade-row {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 55;
    display: grid;
    gap: 8px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: rgba(12, 16, 20, 0.98);
    box-shadow: 0 -16px 38px rgba(0, 0, 0, 0.26);
  }

  body[data-view="session"][data-answer-shown="false"] .grade-row {
    grid-template-columns: minmax(0, 1fr) 104px;
  }

  body[data-view="session"][data-answer-shown="true"] .grade-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body[data-answer-shown="true"] #showAnswerButton,
  body[data-answer-shown="true"] #mobileCloseStudyButton {
    display: none !important;
  }

  .grade-row button {
    min-height: 60px;
    width: 100%;
    padding: 12px 8px;
    font-size: 15px;
    border-radius: 10px;
  }

  #showAnswerButton {
    font-size: 17px;
  }

  .accumuli-grid,
  .accumulo-stats,
  .adaptation-metrics,
  .settings-grid,
  .dashboard-grid,
  .split-layout,
  .split-layout.wide-left,
  .controls-grid {
    grid-template-columns: 1fr;
  }

  .keyboard-hint {
    display: none;
  }

  .accumulo-card {
    gap: 12px;
  }

  .accumulo-card header {
    grid-template-columns: 1fr;
  }

  .accumulo-card h3 {
    font-size: 19px;
  }

  .accumulo-stats {
    gap: 8px;
  }

  .accumulo-stats > div {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .accumulo-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .accumulo-actions .primary-btn {
    min-height: 58px;
    font-size: 17px;
  }

  .mobile-flow-hints {
    display: flex;
    gap: 6px;
    padding: 0;
    margin: 0;
    overflow-x: auto;
    list-style: none;
  }

  .mobile-flow-hints li {
    flex: 0 0 auto;
    padding: 6px 9px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #111820;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
  }

  .warning-item.blocking {
    border-width: 2px;
    font-size: 16px;
  }

  #pageSections .split-layout > .panel:last-child {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 50;
    padding: 10px;
    box-shadow: var(--shadow);
  }

  #pageSections .split-layout > .panel:last-child .panel-head,
  #pageSections .split-layout > .panel:last-child .detail-list {
    display: none;
  }

  #pageSections .command-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  #pageSections .command-row .primary-btn {
    min-height: 56px;
  }

  #sectionsTree {
    max-height: calc(100svh - 236px);
  }

  #reviewTree,
  #manageTree {
    max-height: 52svh;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar .full-input {
    grid-column: 1 / -1;
  }

  .node-row {
    min-height: 48px;
    padding: 7px 6px;
    grid-template-columns: 24px 28px minmax(0, 1fr);
  }

  .node-row input,
  .checkbox-label input {
    width: 24px;
    height: 24px;
  }

  .report-list,
  .command-copy-list {
    gap: 12px;
  }

  .report-item,
  .panel,
  .metric-card {
    padding: 13px;
  }

  .command-copy-list code {
    white-space: pre-wrap;
  }

  .main-shell {
    padding: 12px 10px calc(92px + env(safe-area-inset-bottom));
  }

  .sidebar {
    padding: 12px;
  }

  .topbar,
  .panel-head,
  .page-head-row,
  .panel-subhead,
  .session-hero,
  .accumulo-card header {
    display: grid;
  }

  h1 {
    font-size: 24px;
  }

  .metric-card strong {
    font-size: 24px;
  }

  .top-actions button,
  .toolbar button,
  .command-row button,
  .secondary-row button,
  .grade-row button,
  .session-actions button,
  .action-grid button {
    width: 100%;
  }

  .tree {
    max-height: 48vh;
  }

  .node-row {
    grid-template-columns: 24px 28px minmax(0, 1fr);
  }

  .node-count {
    grid-column: 3;
    white-space: normal;
  }

  .children {
    margin-left: 13px;
  }

  .rendered {
    min-height: auto;
    max-height: none;
    font-size: var(--review-font-size, 22px);
    padding: 15px;
  }

  .session-hero,
  .panel,
  .metric-card,
  .study-card,
  .accumulo-card,
  .report-item {
    border-radius: 8px;
  }

  .summary-columns,
  .marked-card {
    grid-template-columns: 1fr;
  }

  .disabled-card {
    align-items: stretch;
  }

  .session-summary .metric-grid,
  .analytics-panel .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .trend-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .trend-row strong {
    grid-column: 1 / -1;
  }
}

/* Palazzi della memoria (tappa 3) */
.palace-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.palace-item {
  display: grid;
  gap: 6px;
  text-align: left;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--text);
}

.palace-item span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.palace-item strong {
  font-size: 17px;
}

.palace-item-status[data-status="in uso"] {
  color: var(--green) !important;
  font-weight: 800;
}

.palace-item-status[data-status="bozza"] {
  color: var(--yellow) !important;
  font-weight: 800;
}

.palace-file-warning {
  color: var(--yellow) !important;
}

.palace-warning {
  display: grid;
  gap: 4px;
  border-left: 3px solid var(--yellow);
  padding-left: 10px;
}

.palace-warning[data-tone="error"] {
  border-left-color: var(--red);
}

.palace-warning code,
.place-box code {
  overflow-wrap: anywhere;
}

.palace-actions,
.walk-nav,
.walk-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.palace-side {
  margin: 8px 0;
}

.palace-side em {
  color: var(--blue);
  font-size: 13px;
}

.palace-side ul,
.palace-cards {
  margin: 4px 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.palace-parts {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.palace-cards li {
  display: grid;
  gap: 2px;
  color: var(--text);
}

.palace-cards li > span:last-child {
  color: var(--muted);
  font-size: 13px;
}

.palace-walk-here {
  margin-top: 8px;
}

.palace-walk {
  max-width: 820px;
}

.walk-body {
  display: grid;
  gap: 8px;
  min-height: 200px;
  font-size: 16px;
}

.walk-image img {
  max-width: 100%;
  border-radius: 8px;
}

.walk-nav {
  position: sticky;
  bottom: 0;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.walk-nav button {
  flex: 1 1 120px;
  min-height: 46px;
}

.report-palaces {
  display: grid;
  gap: 14px;
}

.report-palace {
  display: grid;
  gap: 8px;
}

.place-box {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--blue-strong);
  background: #15212c;
  line-height: 1.45;
}

.place-box[data-status="missing"] {
  border-color: var(--yellow);
  background: #2a2414;
}

.place-box[data-status="error"],
.place-box[data-status="conflict"] {
  border-color: var(--red);
  background: var(--red-soft);
}

.place-box .place-palace {
  color: var(--muted);
  font-size: 13px;
}

.place-box em {
  color: var(--muted);
}

.place-box img {
  max-width: 100%;
  margin-top: 8px;
  border-radius: 8px;
}

/* Palazzi, pagina continua (tappa 3, 22/10) */
.palace-detail {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.palace-detail.hidden {
  display: none;
}

.palace-note {
  color: var(--yellow);
  font-size: 13px;
}

.palace-note:empty {
  display: none;
}

.palace-finder {
  position: sticky;
  top: 0;
  z-index: 6;
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
}

.palace-index {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.palace-index button {
  flex: 0 0 auto;
  min-width: 38px;
  min-height: 30px;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
}

.palace-index button.has-cards {
  color: var(--text);
  border-color: var(--blue-strong);
  background: #15212c;
}

.palace-weak h3 {
  font-size: 15px;
  margin: 0 0 8px;
}

.weak-list {
  display: grid;
  gap: 6px;
}

.weak-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 10px;
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--red);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
}

.weak-row span {
  color: var(--muted);
  font-size: 13px;
}

.weak-row .weak-count {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  color: var(--red);
  font-weight: 800;
}

.palace-body {
  display: grid;
  gap: 18px;
}

.palace-tratto-block {
  display: grid;
  gap: 12px;
}

.tratto-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  padding: 14px 4px 4px;
  border-bottom: 2px solid var(--blue-strong);
  scroll-margin-top: 120px;
}

.tratto-head h3 {
  margin: 0;
  font-size: 20px;
}

.tratto-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.tratto-logic {
  flex-basis: 100%;
  margin: 2px 0 0;
  color: var(--muted);
  font-style: italic;
  line-height: 1.5;
}

.locus {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  scroll-margin-top: 120px;
  transition: box-shadow 0.3s, border-color 0.3s;
}

.locus-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.locus-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: 52px;
  padding: 0 8px;
  border-radius: 12px;
  background: var(--blue-strong);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
}

.locus-title h4 {
  margin: 0;
  font-size: 19px;
}

.locus-time {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.locus-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.locus-actions button,
.locus-study {
  min-height: 34px;
  padding: 4px 10px;
  font-size: 13px;
}

.locus-scene {
  margin: 0;
  color: var(--muted);
  font-style: italic;
  line-height: 1.5;
}

.locus-fields {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 12px;
  margin: 0;
}

.locus-fields > div {
  display: contents;
}

.locus-fields dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-top: 3px;
}

.locus-fields dd {
  margin: 0;
  line-height: 1.5;
}

.locus-center {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #15212c;
  border: 1px solid var(--blue-strong);
}

.center-label {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.locus-sides {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.locus-side {
  display: grid;
  align-content: start;
  gap: 8px;
}

.locus-side h5 {
  margin: 0;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.locus-object {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  scroll-margin-top: 120px;
}

.object-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  font-weight: 800;
}

.locus .ref {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.object-parts {
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 3px;
  font-size: 14px;
  color: var(--muted);
}

.object-parts li {
  scroll-margin-top: 120px;
}

.card-chips {
  display: grid;
  gap: 6px;
  margin-top: 4px;
}

.card-chip {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--blue-strong);
  border-left-width: 4px;
  background: #132230;
  color: var(--text);
}

.card-chip[data-status="da ripassare"] { border-left-color: var(--yellow); }
.card-chip.compact { padding: 5px 10px; background: transparent; }
.card-chip.compact .chip-question { -webkit-line-clamp: 1; }
.card-chip[data-status="nuova"] { border-left-color: var(--faint); }
.card-chip[data-status="disattivata"] { opacity: 0.6; }

.chip-level {
  color: var(--blue);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chip-level[data-level="2"] { color: var(--green); }
.chip-level[data-level="3"] { color: var(--yellow); }

.chip-question {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chip-state {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.palace-highlight {
  border-color: var(--yellow) !important;
  box-shadow: 0 0 0 3px rgba(194, 149, 54, 0.45);
}

.locus-image img {
  max-width: 100%;
  border-radius: 8px;
}

.palace-editable {
  display: inline-block;
  min-width: 3ch;
  padding: 0 4px;
  border-radius: 4px;
  outline: 1px dashed var(--border-strong);
  cursor: text;
}

.palace-editable:focus {
  outline: 2px solid var(--focus);
  background: var(--bg);
}

.palace-editable:empty::before {
  content: attr(data-placeholder);
  color: var(--faint);
}

.palace-changed {
  outline-color: var(--yellow) !important;
  background: rgba(194, 149, 54, 0.12);
}

.palace-edit-btn {
  min-height: 28px;
  padding: 2px 8px;
  font-size: 12px;
  border-style: dashed;
}

.palace-edit-btn.danger {
  color: var(--red);
}

.palace-edit-tools p {
  line-height: 1.5;
}

.palace-editbar {
  position: sticky;
  bottom: 0;
  z-index: 7;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border: 1px solid var(--yellow);
  border-radius: 10px;
  background: #221d10;
}

.palace-editbar span {
  color: var(--muted);
  font-size: 13px;
}

.palace-editbar-actions {
  display: flex;
  gap: 8px;
}

.palace-card-dialog {
  width: min(860px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  padding: 16px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
}

.palace-card-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.place-goto {
  justify-self: start;
  margin-top: 4px;
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
}

@media (max-width: 900px) {
  .locus-sides {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 620px) {
  .locus {
    padding: 12px;
  }

  .locus-head {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .locus-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .locus-num {
    min-width: 44px;
    height: 44px;
    font-size: 17px;
  }

  .locus-fields {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 767px) {
  .palace-finder {
    top: calc(58px + env(safe-area-inset-top));
    padding: 8px;
  }

  .locus,
  .locus-object,
  .object-parts li,
  .tratto-head {
    scroll-margin-top: 190px;
  }
}

/* Appendi, sposta, stacca e testo delle carte (22/10) */
.card-chip-wrap {
  display: grid;
  gap: 4px;
}

.chip-actions {
  display: flex;
  gap: 6px;
}

.chip-actions button,
.slot-btn {
  min-height: 30px;
  padding: 2px 10px;
  font-size: 12px;
}

.slot-btn {
  justify-self: start;
  border-style: dashed;
  color: var(--blue);
}

.slot-btn.move {
  border-style: solid;
  border-color: var(--yellow);
  color: var(--yellow);
}

.object-parts li .slot-btn {
  min-height: 24px;
  margin-left: 6px;
  padding: 0 8px;
}

.locus-center.empty {
  border-style: dashed;
  background: transparent;
}

.palace-movebar {
  border-color: var(--blue-strong);
  background: #13212d;
}

.attach-list {
  display: grid;
  gap: 6px;
  max-height: 60vh;
  overflow-y: auto;
  margin-top: 8px;
}

.attach-row {
  display: grid;
  gap: 2px;
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
}

.palace-card-editor {
  display: grid;
  gap: 10px;
}

.palace-card-editor textarea {
  width: 100%;
  box-sizing: border-box;
  font: 14px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px;
  resize: vertical;
}

.palace-strato-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px 14px;
  margin-bottom: 10px;
}

.palace-strato-form > span {
  color: var(--muted);
  font-size: 13px;
  flex-basis: 100%;
}

/* Appendi tutte (22/10) */
.palace-bulk-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px 14px;
  margin: 10px 0;
}

.palace-bulk-form label {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.palace-bulk-form select,
.palace-bulk-form input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.bulk-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 10px;
  align-items: baseline;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
}

.bulk-row[data-level="2"] { margin-left: 14px; }
.bulk-row[data-level="3"] { margin-left: 28px; }

.bulk-row .bulk-where {
  color: var(--blue);
  font-size: 13px;
  text-align: right;
}

.bulk-row.skipped .bulk-where {
  grid-column: 1 / -1;
  text-align: left;
  color: var(--yellow);
}

.palace-bulk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 8px;
}
