/* MDA web app layout — sidebar card library + canvas drop zones.
   Uses Silka if present in ./fonts (Silka-Regular.woff2, Silka-Bold.woff2). */
@font-face {
  font-family: "Silka";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: local("Silka"), local("Silka-Regular"), url("fonts/Silka-Regular.woff2") format("woff2");
}

@font-face {
  font-family: "Silka";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: local("Silka Bold"), local("Silka-Bold"), url("fonts/Silka-Bold.woff2") format("woff2");
}

:root {
  --topbar-bg: #0b111a;
  --topbar-fg: #e5e7eb;
  --bg-window: #0f1621;
  --bg-sidebar: #131a26;
  --bg-canvas: #0f1621;
  --bg-zone: #1a2231;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.35);

  --accent-blue: #3b82f6;
  --accent-orange: #ff9f0a;
  --accent-green: #30d158;
  --accent-red: #ff453a;
  --accent-label: rgba(255, 255, 255, 0.08);

  --deck-ocean: #6d789e;
  --deck-clay: #a03a0c;
  --deck-stone: #8c8177;
  --deck-sand: #e7d1a9;

  --text-primary: #e5e7eb;
  --text-secondary: #c7ced8;
  --text-muted: #9aa4b5;

  --radius-large: 18px;
  --radius-medium: 12px;
  --radius-small: 8px;

  --transition-fast: 150ms ease-out;

  /* Slot sizing derived from deck cards: add ~3mm margin each side. */
  --slot-extra: 6mm;
  /* Slot size aligned to card CSS (54mm width, 1:1.4 ratio) */
  --slot-width: 54mm;
  --slot-height: calc(var(--slot-width) * 1.4);
  --slot-row-gap: 24px;
  --slot-col-gap: 24px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  min-height: 100vh;
}

body {
  font-family: "Zalando Sans", "Silka", "Inter", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 20% 20%, #131c29 0, #0b111a 40%, #070b11 100%);
  color: var(--text-primary);
}

.page {
  padding: 0;
  min-height: calc(100vh - 52px);
}

main {
  display: block;
  margin: 0;
  padding-top: 4px;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  background: var(--topbar-bg);
  color: var(--topbar-fg);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 14px;
}

.tabbar {
  flex: 1;
  display: flex;
  justify-content: center;
}

.switcher {
  display: inline-flex;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  max-width: 520px;
  width: 100%;
  justify-content: center;
}

.switcher__btn {
  border: none;
  background: transparent;
  color: var(--topbar-fg);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  letter-spacing: 0.02em;
  min-width: 110px;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.switcher__btn.is-active {
  background: #ffffff;
  color: #0b111a;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.lang-toggle {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.lang-btn {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--topbar-fg);
  border-radius: 8px;
  padding: 6px 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.lang-btn.is-active {
  background: #ffffff;
  color: #0b111a;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.topbar-actions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.project-menu {
  position: fixed;
  z-index: 60;
  width: 240px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(19, 26, 38, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
}

.project-menu__item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  padding: 10px 10px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}

.project-menu__item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.project-menu__item.is-danger {
  color: #ff453a;
}

.project-menu__sep {
  height: 1px;
  background: rgba(255, 255, 255, 0.10);
  margin: 6px 4px;
  border-radius: 999px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

/* App layout */
.mda-app {
  position: relative;
  width: 100%;
  height: 100vh;
  margin: 0;
  background: var(--bg-window);
  overflow: hidden;
  display: grid;
  grid-template-columns: calc(var(--card-width) + 48px) minmax(0, 1fr);
}

/* Sidebar */
.sidebar {
  background: var(--bg-sidebar);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  width: 100%;
  min-width: 0;
  height: 100%;
  z-index: 3;
}

.sidebar-header {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.library-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  background: #0f1724;
}

.library-toggle__btn {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 8px 10px;
  background: #131b28;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast), border-color var(--transition-fast);
}

.library-toggle__btn.is-active {
  background: #1f2a3a;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.app-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.card-library {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 16px;
  overscroll-behavior: contain;
  background: #0d131d;
}

.card-library::-webkit-scrollbar {
  width: 10px;
}

.card-library::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
}

/* Preview view */
.preview-hero {
  background: #0f1720;
  color: #fff;
  padding: 20px 24px 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.preview-hero h1 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.preview-hero .meta {
  font-size: 13px;
  color: #cbd2d9;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.preview-main {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  padding: 24px;
  max-width: 1300px;
  margin: 0 auto;
  color: var(--text-primary);
}

.preview-left {
  flex: 1 1 70%;
  min-width: 0;
}

.preview-right {
  flex: 0 0 30%;
  min-width: 260px;
}

.preview-notes,
.preview-deck {
  background: #0f1720;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px 14px 10px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.preview-notes h3,
.preview-deck h3 {
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: var(--text-primary);
}

.preview-deck__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.preview-deck__title {
  margin: 0;
}

.preview-deck__meta {
  min-width: 34px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: var(--text-secondary);
}

.preview-deck__hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.preview-deck__empty {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 10px 8px 14px;
}

.preview-deck .mda-card-grid {
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 12px;
}

#view-preview .card-toggle {
  position: absolute;
  left: 10px;
  top: 10px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.65);
  background: rgba(255, 255, 255, 0.92);
  color: #0b111a;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}

#view-preview .mda-card.is-excluded img {
  opacity: 0.35;
  filter: grayscale(1);
}

.preview-notes textarea {
  width: 100%;
  min-height: 320px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 12px;
  resize: vertical;
  font-size: 14pt;
  font-family: "Zalando Sans", "Silka", "Inter", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
  color: var(--text-primary);
  background: #0b111a;
  outline: none;
  box-sizing: border-box;
}

.preview-notes textarea:focus {
  border-color: #0f1720;
  box-shadow: 0 0 0 3px rgba(15, 23, 32, 0.16);
  background: #ffffff;
}

.legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0;
}

.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 32, 0.8);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4);
}

.preview-toggle {
  max-width: 520px;
  margin: 12px 0 6px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  color: var(--text-primary);
}

.mda-card-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

#view-preview .mda-card {
  transition: transform 180ms ease-out, opacity 180ms ease-out, box-shadow 140ms ease;
}

#view-preview .mda-card.is-hiding {
  transform: translateX(-120%) !important;
  opacity: 0;
  pointer-events: none;
}

#view-preview .card-hide {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.65);
  background: rgba(255, 255, 255, 0.92);
  color: #0b111a;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}

.undo-toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  z-index: 9999;

  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 999px;

  background: rgba(11, 17, 26, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);

  max-width: min(420px, calc(100vw - 24px));
  transition: transform 180ms ease-out, opacity 180ms ease-out;
}

.undo-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.undo-toast__message {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.undo-toast__action {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.92);
  color: #0b111a;
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.22);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.undo-toast__action:hover {
  filter: brightness(0.98);
}

.undo-toast__action:active {
  transform: translateY(1px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.22);
}

.undo-toast__action:focus-visible {
  outline: 2px solid rgba(59, 130, 246, 0.9);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .undo-toast {
    transition: opacity 0ms;
    transform: translate(-50%, 0);
  }

  .undo-toast__action {
    transition: none;
  }
}

@media (max-width: 980px) {
  .preview-main {
    flex-direction: column;
    max-height: 70vh;
    overflow-y: auto;
    padding: 16px;
  }

  .preview-right {
    flex-basis: auto;
    min-width: 100%;
  }

  .preview-notes textarea {
    min-height: 200px;
  }

  .mda-card-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

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

/* Print/export helpers */
body.print-canvas-only {
  background: #ffffff;
}

body.print-canvas-only .topbar,
body.print-canvas-only .sidebar {
  display: none !important;
}

body.print-canvas-only #view-preview {
  display: none !important;
}

body.print-canvas-only #view-app {
  display: block !important;
}

body.print-canvas-only .mda-app {
  position: relative;
  width: auto;
  height: auto;
  margin-top: 0;
  background: #ffffff;
  box-shadow: none;
  padding: 12px 16px 24px;
}

body.print-canvas-only .canvas {
  position: relative;
  inset: auto;
  top: 0;
  bottom: 0;
  width: 100%;
  height: 100vh;
  padding: 0;
  overflow: visible;
}

body.print-canvas-only .canvas-header .btn {
  display: none !important;
}

body.print-canvas-only .card-close {
  display: none !important;
}

@media print {
  body {
    background: #ffffff;
  }

  .topbar,
  .sidebar {
    display: none !important;
  }

  #view-preview {
    display: none !important;
  }

  #view-app {
    display: block !important;
  }

  .mda-app {
    position: relative;
    width: auto;
    height: auto;
    margin-top: 0;
    background: #ffffff;
    box-shadow: none;
    padding: 12px 16px 24px;
  }

  .canvas {
    position: relative;
    inset: auto;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    padding: 0;
    overflow: visible;
  }

  .canvas-header .btn,
  .card-close {
    display: none !important;
  }
}

.card-group + .card-group {
  margin-top: 16px;
}

.card-group-title {
  margin: 0 4px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* Full card style inside sidebar using deck CSS */
.sidebar .mda-card {
  width: 100%;
  max-width: calc(var(--card-width) * 0.92);
  aspect-ratio: 62 / 93;
  margin: 0 auto 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  background: transparent;
  cursor: grab;
}

.sidebar .mda-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  border-radius: inherit;
  pointer-events: none;
  background: #0d1118;
}

/* Cards in sidebar and canvas (image-based) */
.mda-app .mda-card {
  width: calc(var(--card-width) * 0.92);
  aspect-ratio: 62 / 93;
  margin: 0 auto 12px;
  background: transparent;
  cursor: grab;
  position: relative;
  user-select: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  border-radius: var(--card-radius, 8px);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.mda-app .mda-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  border-radius: inherit;
  pointer-events: none;
  background: #ffffff;
}

.mda-card--compact {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 90px;
  color: #0b111a;
  border: 2px solid rgba(0,0,0,0.15);
  box-shadow: 0 10px 24px rgba(0,0,0,0.25);
  position: relative;
  background: transparent;
}

.mda-card--compact .mda-card__label {
  font-weight: 800;
  font-size: 24px;
  letter-spacing: 0.01em;
  text-align: center;
}

.mda-card__inner {
  position: absolute;
  inset: 10px;
  background: #ffffff;
  color: #0b111a;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.18);
}

.mda-card--ocean.mda-card--compact { background: var(--deck-ocean); }
.mda-card--clay.mda-card--compact { background: var(--deck-clay); color: #fff; }
.mda-card--stone.mda-card--compact { background: var(--deck-stone); }
.mda-card--sand.mda-card--compact { background: var(--deck-sand); }

.mda-app .mda-card:active {
  cursor: grabbing;
  transform: scale(1.02);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.24);
  z-index: 10;
}

/* Close button for cards placed on canvas */
.card-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #6b7280;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast);
}

.mda-card.in-canvas .card-close {
  opacity: 1;
  pointer-events: auto;
}

.mda-card.in-canvas:hover .card-close {
  transform: scale(1.05);
  background: #ffffff;
  border-color: rgba(100, 116, 139, 0.9);
}

/* Canvas */
.canvas {
  position: relative;
  inset: 0;
  background: var(--bg-canvas);
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  overflow: hidden;
  z-index: 1;
  min-width: 0;
}

.canvas-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.canvas-title-group {
  min-width: 0;
}

.canvas-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.canvas-subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.canvas-actions {
  display: flex;
  gap: 8px;
}

/* Buttons */
.btn {
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  background: #1f2937;
  color: #e5e7eb;
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}

.btn-primary {
  background: var(--accent-blue);
  color: #ffffff;
  border-color: rgba(59, 130, 246, 0.7);
}

.btn-secondary {
  background: #111827;
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.12);
}

.btn:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transform: translateY(-0.5px);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

/* Canvas grid and zones */
.canvas-grid {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 18px 18px 22px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.canvas-zone {
  background: var(--bg-zone);
  border-radius: var(--radius-medium);
  border: 3px solid rgba(255, 255, 255, 0.12);
  padding: 26px 16px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
  position: relative;
  box-sizing: border-box;
}

.canvas-zone-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.canvas-zone-header p {
  margin: 3px 0 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

.canvas-zone-header {
  position: absolute;
  background: rgba(12, 16, 24, 0.9);
  padding: 8px 18px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.canvas-zone--sand .canvas-zone-header,
.canvas-zone--sand .canvas-zone-header h2,
.canvas-zone--sand .canvas-zone-header p {
  color: #0b111a;
  background: #e7d1a9;
}

.canvas-zone-header p {
  display: none;
}

/* Cards inside zones with explicit slots */
.canvas-zone-cards {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  padding: 10px 12px 12px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 1), minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
  justify-items: center;
}

.canvas-slot {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

.canvas-zone .mda-card {
  margin: 0;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 62 / 93;
  background: transparent;
}

/* Mechanics & Dynamics: fit 2×3 with breathing space by sizing to row-height */
.canvas-zone--ocean .mda-card,
.canvas-zone--clay .mda-card {
  height: 92%;
  width: auto;
}

/* Aesthetics: fit 3 cards by sizing to column-width */
.canvas-zone--stone .mda-card,
.canvas-zone--sand .mda-card {
  width: 92%;
  height: auto;
}

.drag-floating {
  pointer-events: none;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.2);
  transform: scale(1.02);
}

.drag-proxy {
  border-radius: var(--card-radius, 8px);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.3);
  transform: scale(1.02);
  opacity: 0.96;
}

/* Specific placement of zones */
.canvas-zone--mechanics {
  grid-column: 1 / 2;
  grid-row: 1 / 3;
}

.canvas-zone--mechanics-secondary {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
}

.canvas-zone--negative {
  grid-column: 3 / 4;
  grid-row: 1 / 2;
}

.canvas-zone--positive {
  grid-column: 3 / 4;
  grid-row: 2 / 3;
}

.canvas-zone--ocean {
  background: #6d789e;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  grid-column: 1 / 2;
  grid-row: 1 / 3;
  --cols: 2;
  --rows: 3;
}

.canvas-zone--clay {
  background: #a03a0c;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  --cols: 2;
  --rows: 3;
}

.canvas-zone--stone {
  background: #8c8177;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  grid-column: 3 / 4;
  grid-row: 1 / 2;
  --cols: 3;
  --rows: 1;
}

.canvas-zone--sand {
  background: #e7d1a9;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  grid-column: 3 / 4;
  grid-row: 2 / 3;
  --cols: 3;
  --rows: 1;
}

.canvas-zone--stone .canvas-slot {
  border-color: rgba(32, 32, 32, 0.7);
}

.canvas-zone--sand .canvas-slot {
  border-color: rgba(32, 32, 32, 0.7);
}

.canvas-zone--ocean .canvas-zone-header {
  background: #6d789e;
  color: #ffffff;
  left: 50%;
  top: -20px;
  width: 170px;
  transform: translateX(-50%);
}

.canvas-zone--clay .canvas-zone-header {
  background: #a03a0c;
  color: #ffffff;
  left: 50%;
  top: -20px;
  width: 170px;
  transform: translateX(-50%);
}

.canvas-zone--stone .canvas-zone-header {
  background: #8c8177;
  color: #ffffff;
  left: 50%;
  top: -20px;
  width: 230px;
  transform: translateX(-50%);
}

.canvas-zone--sand .canvas-zone-header {
  background: #e7d1a9;
  color: #2d1c0a;
  left: 50%;
  top: -20px;
  width: 230px;
  transform: translateX(-50%);
}

/* States for drag-and-drop */
.canvas-zone.is-highlighted {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.06);
}

.canvas-zone.is-invalid {
  border-color: var(--accent-red);
  background: #fff5f5;
}

/* Responsive */
@media (max-width: 1024px) {
  .mda-app {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .canvas-grid {
    padding: 14px 14px 18px;
    gap: 14px;
  }
}

@media (max-width: 768px) {
  .mda-app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    height: auto;
  }

  .sidebar {
    max-height: 260px;
  }

  .canvas {
    margin-top: 8px;
  }
}

@media (max-width: 900px) {
  :root {
    --topbar-mobile: 50px;
    --canvas-mobile-height: 55vh;
    --slot-height: calc((var(--canvas-mobile-height) - 30px) / 6);
  }

  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-mobile);
    padding: 6px 8px;
    gap: 6px;
  }

  .brand {
    font-size: 12px;
    letter-spacing: 0.06em;
  }

  .tabbar {
    flex: 1;
    justify-content: flex-start;
  }

  .switcher {
    gap: 4px;
    padding: 2px;
    max-width: none;
  }

  .switcher__btn {
    min-width: 90px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .lang-toggle {
    gap: 4px;
  }

  .lang-btn {
    padding: 4px 8px;
    font-size: 12px;
  }

  .page {
    padding-top: var(--topbar-mobile);
    min-height: 100vh;
  }

  .ludo {
    padding: 12px 12px 14px;
    height: calc(100vh - var(--topbar-mobile));
    height: calc(100dvh - var(--topbar-mobile));
  }

  .mda-app {
    width: 100%;
    height: calc(100vh - var(--topbar-mobile));
    min-height: calc(100vh - var(--topbar-mobile));
    overflow: hidden;
    padding-bottom: 0;
    display: flex;
    flex-direction: column;
  }

  .sidebar {
    position: relative;
    width: 100%;
    min-width: 0;
    height: auto;
    border-radius: 0;
    box-shadow: none;
    border-left: none;
    border-right: none;
    flex: 0 0 auto;
  }

  .card-library {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 12px 12px;
    max-height: none;
  }
  .canvas {
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--canvas-mobile-height);
    min-height: var(--canvas-mobile-height);
    padding: 0 0 8px;
    flex: 1 1 auto;
  }

  .canvas-grid {
    position: relative;
    height: var(--canvas-mobile-height);
    padding: 12px;
    min-height: var(--canvas-mobile-height);
    max-height: none;
  }

  .canvas-zone {
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    height: auto;
    margin: 0 0 12px;
    padding-top: 18px;
    min-height: var(--canvas-mobile-height);
  }

  .canvas-zone.is-hidden-mobile {
    display: none;
  }

  .canvas-zone-header {
    display: none;
  }

  .canvas-zone-cards {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  /* Horizontal card layout */
  /* Canvas cards: large, fit six vertically */
  .mda-app .canvas-zone .mda-card {
    width: 80vw;
    max-width: 80vw;
    min-width: 0;
    height: min(var(--slot-height), calc(80vw / 2.85));
    aspect-ratio: 2.85 / 1;
    margin-left: auto;
    margin-right: auto;
  }

  .mda-app .canvas-zone .mda-card.mda-card--compact {
    min-height: min(var(--slot-height), calc(80vw / 2.85));
    height: min(var(--slot-height), calc(80vw / 2.85));
  }

  /* Library cards: show ~2.5 cards horizontally */
  .card-library .mda-card {
    flex: 0 0 60vw;
    width: 60vw;
    max-width: 60vw;
    min-width: 0;
    height: calc(60vw / 2.85);
    aspect-ratio: 2.85 / 1;
  }

  .canvas-zone-cards {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    align-content: center;
    width: 100%;
    padding: 6px 8px 10px;
    gap: 6px;
    min-height: var(--canvas-mobile-height);
  }

  .canvas-slot {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    flex: 0 0 var(--slot-height);
    min-height: var(--slot-height);
  }
}

/* --- Ludoscanner --- */
.ludo {
  --ludo-question-width: 50vw;
  --ludo-question-content-width: calc(var(--ludo-question-width) * 0.66);
  --ludo-board-width: 280px;
  --ludo-main-gap: 16px;
  max-width: 90vw;
  margin: 0 auto;
  padding: 18px 18px 26px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 52px);
  height: calc(100dvh - 52px);
}

.ludo-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin: 6px 0 14px;
}

.ludo-header__title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.ludo-header__title p {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.ludo-header__actions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.ludo-note {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  max-width: 620px;
}

.ludo-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--ludo-main-gap);
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}

@media (min-width: 981px) {
  .ludo:not(.is-finished) .ludo-main {
    grid-template-columns: minmax(0, var(--ludo-question-width, 50vw)) var(--ludo-board-width, 280px);
    width: min(calc(var(--ludo-question-width, 50vw) + var(--ludo-board-width, 280px) + var(--ludo-main-gap, 16px)), 100%);
    margin-left: auto;
    margin-right: auto;
  }

  .ludo:not(.is-finished) .ludo-remedies {
    width: min(calc(var(--ludo-question-width, 50vw) + var(--ludo-board-width, 280px) + var(--ludo-main-gap, 16px)), 100%);
  }
}

.ludo-content,
.ludo-board {
  border-radius: var(--radius-large);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(19, 26, 38, 0.55);
  box-shadow: var(--shadow-soft);
}

.ludo-content {
  width: var(--ludo-question-width, 100%);
  max-width: 100%;
  margin: 0 auto;
  padding: 16px;
  min-height: 0;
  overflow: auto;
}

.ludo-board {
  padding: 16px;
  position: relative;
  top: auto;
}

.ludo-progress {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.ludo-card {
  position: relative;
  user-select: none;
  touch-action: manipulation;
}

.ludo-card__frame {
  border-radius: 22px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.04));
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.ludo-card__paper {
  border-radius: 18px;
  background: #ffffff;
  color: #0b111a;
  padding: 18px 18px 20px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.26);
}

.ludo-card__id {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.10);
  font-weight: 900;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}

.ludo-card__kind {
  text-align: center;
  font-weight: 900;
  letter-spacing: 0.22em;
  color: #dc2626;
  font-size: 12px;
  margin-top: -28px;
  text-transform: uppercase;
}

.ludo-card__title {
  margin-top: 18px;
  text-align: center;
  font-weight: 900;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  font-size: 18px;
}

.ludo-card__divider {
  height: 2px;
  background: rgba(220, 38, 38, 0.55);
  margin: 14px 8px 14px;
  border-radius: 999px;
}

.ludo-card__body {
  width: min(var(--ludo-question-content-width, 100%), 100%);
  margin: 0 auto;
  text-align: center;
  font-size: 21px;
  line-height: 1.3;
  color: rgba(11, 17, 26, 0.92);
  white-space: pre-wrap;
}

.ludo-actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.ludo-action {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 10px 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  letter-spacing: 0.01em;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, border-color 140ms ease;
  user-select: none;
}

.ludo-action__key {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text-secondary);
}

.ludo-action__label {
  font-size: 13px;
}

.ludo-action--yes {
  border-color: rgba(48, 209, 88, 0.35);
}

.ludo-action--no {
  border-color: rgba(255, 69, 58, 0.35);
}

.ludo-action--unsure {
  border-color: rgba(255, 159, 10, 0.35);
}

.ludo-action--na {
  border-color: rgba(148, 163, 184, 0.35);
}

.ludo-action:hover {
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.32);
  transform: translateY(-1px);
}

.ludo-action:active {
  transform: translateY(0);
  box-shadow: none;
}

#ludoMount.is-animating .ludo-action,
#ludoMount.is-animating .btn {
  pointer-events: none;
}

.ludo-slots {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.ludo-slot {
  border-radius: 16px;
  padding: 12px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.10);
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: end;
  justify-items: center;
  gap: 6px;
  text-align: center;
}

.ludo-slot__label {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  line-height: 1.15;
  min-height: calc(2 * 1.15em);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.ludo-slot__count {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  min-width: 0;
  text-align: center;
  line-height: 1.1;
}

.ludo-slot--yes .ludo-slot__count {
  color: #30d158;
}

.ludo-slot--no .ludo-slot__count {
  color: #ff453a;
}

.ludo-slot--unsure .ludo-slot__count {
  color: #ff9f0a;
}

.ludo-results__header h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.ludo-empty {
  margin: 10px 0 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.ludo-result-group {
  margin-top: 14px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
}

.ludo-result-group h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.01em;
  color: var(--text-primary);
}

.ludo-result-subgroup h4 {
  margin: 10px 0 8px;
  font-size: 12px;
  font-weight: 900;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.ludo-result-item {
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(15, 22, 33, 0.45);
  padding: 10px 12px;
  margin-top: 8px;
}

.ludo-result-item summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--text-primary);
  outline: none;
}

.ludo-result-item__body {
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.ludo.is-finished .ludo-main {
  grid-template-columns: 1fr;
}

.ludo.is-finished .ludo-content {
  width: var(--ludo-question-width, 100%);
  max-width: 100%;
  margin-inline: auto;
}

.ludo-results__actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.ludo-remedies {
  margin-top: 14px;
  width: min(var(--ludo-question-width, 50vw), 100%);
  margin-left: auto;
  margin-right: auto;
  padding: 14px 16px 16px;
  border-radius: var(--radius-large);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(19, 26, 38, 0.55);
  box-shadow: var(--shadow-soft);
}

.ludo-remedies__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ludo-remedies__actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.ludo-remedies__title {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.ludo-remedies__meta {
  min-width: 34px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: var(--text-secondary);
}

.ludo-remedies__hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.ludo-remedies__empty {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.ludo-remedies__scroll {
  margin-top: 12px;
  max-height: clamp(220px, 32vh, 520px);
  overflow: auto;
  padding-right: 4px;
}

.ludo-remedies__list {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 34px 32px;
  margin: 0 auto;
  width: min(var(--ludo-question-content-width, 100%), 100%);
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 22px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
}

.ludo-remedies__paper-title {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #0b111a;
  text-align: left;
}

.ludo-remedies__group {
  border: 0;
  background: transparent;
  padding: 0;
}

.ludo-remedies__group-title {
  font-size: 12px;
  font-weight: 900;
  color: rgba(11, 17, 26, 0.78);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}

.ludo-remedies__items {
  margin: 0;
  padding-left: 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ludo-remedies__item {
  margin: 0;
  padding: 0;
  list-style-position: outside;
  color: #0b111a;
}

.ludo-remedies__item-id {
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.ludo-remedies__item-text {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: rgba(11, 17, 26, 0.78);
  white-space: pre-wrap;
}

.ludo-remedies__item-title {
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.01em;
}

.ludo-remedies__item::marker {
  font-weight: 900;
  color: #0b111a;
}

.ludo-remedies__item-head {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

@media (max-width: 980px) {
  .ludo-main {
    grid-template-columns: 1fr;
  }

  .ludo-board {
    position: relative;
    top: auto;
  }

  .ludo-slots {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .ludo-header {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ludo-action {
    transition: none;
  }
}
