:root {
  --ink: #0f1b2d;
  --muted: #66758a;
  --line: #cddceb;
  --panel: #ffffff;
  --paper: #fffdf8;
  --blue: #235f9f;
  --blue-dark: #184a7d;
  --green: #20876d;
  --orange: #f59a1b;
  --violet: #7656c7;
  --pink: #d84d89;
  --shadow: 0 24px 70px rgba(25, 62, 101, 0.14);
  font-family: Montserrat, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(32, 135, 109, 0.12), transparent 34rem),
    linear-gradient(180deg, #eef6fb 0%, #f8fbfe 42%, #edf4f9 100%);
  color: var(--ink);
}

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

.app-shell { padding: 18px; }

.workspace {
  width: min(1560px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 350px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.account-widget,
.preview-heading {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 14px 38px rgba(35, 95, 159, 0.08);
}

.control-panel {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 18px;
}

.library-link {
  width: max-content;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #164a7d;
  font-weight: 800;
  font-size: 0.84rem;
  text-decoration: none;
}

.library-link svg,
.button-stack svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-block {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 14px;
  align-items: center;
  margin: 14px 0 18px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(135deg, #fffdf8, #f4f9fd);
}

.brand-mark {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 8px 18px rgba(15, 27, 45, 0.12);
}

.brand-block p {
  margin: 0;
  color: #00836b;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.brand-block h1 {
  margin: 2px 0 2px;
  font-size: 1.45rem;
  line-height: 1.05;
}

.brand-block span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.25;
}

.controls {
  display: grid;
  gap: 13px;
}

.controls label,
.field-pair label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 0.86rem;
  font-weight: 700;
}

.controls small {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.quick-editor {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #cddceb;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(246, 250, 254, 0.98)),
    #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.quick-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-kicker {
  display: block;
  margin-bottom: 2px;
  color: #00836b;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.quick-editor h2 {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.1;
}

.mini-action {
  min-height: 32px;
  width: auto;
  padding: 0 12px;
  border: 1px solid #bcd1e6;
  border-radius: 999px;
  background: #fff;
  color: #164a7d;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.mini-action:hover,
.mini-action:focus-visible {
  border-color: var(--blue);
  background: #eef6ff;
  color: #123f6c;
}

.icon-palette {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
  border: 1px solid #d8e5f1;
  border-radius: 10px;
  background: linear-gradient(135deg, #fbfdff, #f1f7fc);
}

.icon-palette button {
  min-width: 0;
  min-height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #d8e5f1;
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 5px 14px rgba(35, 95, 159, 0.06);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

.icon-palette button:hover,
.icon-palette button:focus-visible {
  border-color: var(--blue);
  background: #eef6ff;
  transform: translateY(-1px);
}

.quick-editor textarea {
  min-height: 190px;
  border-radius: 10px;
  background:
    linear-gradient(transparent 31px, rgba(205, 220, 235, 0.45) 32px),
    #ffffff;
  background-size: 100% 32px;
  font-size: 0.9rem;
  line-height: 32px;
}

.quick-editor textarea::placeholder {
  color: #8aa0b7;
  font-weight: 600;
}

.quick-editor small {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  background: #edf6ff;
  color: #4f647b;
  font-weight: 600;
}

.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cddceb;
  border-radius: 8px;
  background: #fbfdff;
  color: var(--ink);
  font-weight: 650;
  outline: none;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 160px;
  padding: 12px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(35, 95, 159, 0.12);
  background: #fff;
}

.toggle-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid #dbe6f0;
  border-radius: 8px;
  background: #f8fbfe;
  font-weight: 650;
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--blue);
}

.button-stack {
  display: grid;
  gap: 9px;
  margin-top: 16px;
}

.button-stack button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #164a7d;
  font-weight: 800;
  cursor: pointer;
}

.button-stack button:hover,
.button-stack button:focus-visible {
  border-color: var(--blue);
  background: #eef6ff;
  color: #123f6c;
}

.button-stack .primary-btn {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 900;
}

.button-stack .primary-btn:hover,
.button-stack .primary-btn:focus-visible {
  background: var(--blue-dark);
  color: #fff;
}

.button-stack button:disabled {
  opacity: 0.62;
  cursor: wait;
}

.activity-panel {
  min-width: 0;
  display: grid;
  gap: 14px;
}

.preview-heading {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  border-top: 6px solid var(--orange);
}

.preview-heading p {
  margin: 0 0 3px;
  color: #00836b;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.preview-heading h2 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.1;
}

#card-count {
  min-width: 112px;
  padding: 9px 13px;
  border-radius: 999px;
  background: #edf5fc;
  color: #164a7d;
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
}

.preview-pages {
  display: grid;
  gap: 20px;
  justify-items: center;
  padding: 8px 0 26px;
}

.sheet {
  width: min(100%, 794px);
  aspect-ratio: 210 / 297;
  position: relative;
  display: grid;
  gap: 10px;
  padding: 34px;
  background: #fff;
  border: 1px solid #d6e2ed;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sheet.is-landscape {
  width: min(100%, 980px);
  aspect-ratio: 297 / 210;
}

.sheet.layout-4 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
.sheet.layout-6 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(3, 1fr); }
.sheet.layout-8 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(4, 1fr); }
.sheet.layout-9 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.sheet.layout-12 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); }
.sheet.is-landscape.layout-6 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); }
.sheet.is-landscape.layout-8 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr); }
.sheet.is-landscape.layout-12 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(3, 1fr); }

.cut-guides {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.cut-guide {
  position: absolute;
  display: block;
  color: rgba(91, 124, 155, 0.42);
}

.cut-guide.is-vertical {
  top: 22px;
  bottom: 22px;
  border-left: 1px dashed currentColor;
}

.cut-guide.is-horizontal {
  left: 22px;
  right: 22px;
  border-top: 1px dashed currentColor;
}

.card-preview {
  min-width: 0;
  min-height: 0;
  position: relative;
  z-index: 1;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 16px;
  border: 2px solid var(--card-border, #235f9f);
  border-radius: var(--card-radius, 14px);
  background: var(--card-bg, #f8fbff);
  overflow: hidden;
  text-align: center;
}

.card-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  border-top: 8px solid var(--card-accent, #f59a1b);
  opacity: 0.96;
  pointer-events: none;
}

.card-preview .category {
  position: absolute;
  top: 14px;
  left: 14px;
  max-width: calc(100% - 28px);
  color: var(--card-accent, #235f9f);
  font-size: 0.58rem;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-preview .icon {
  display: inline-grid;
  place-items: center;
  width: 1.32em;
  height: 1.32em;
  margin-top: 10px;
  margin-bottom: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.88),
    0 10px 22px rgba(15, 27, 45, 0.10);
  font-size: clamp(2rem, 5vw, 3.45rem);
  line-height: 1;
  filter: drop-shadow(0 8px 12px rgba(15, 27, 45, 0.12));
}

.card-preview .icon svg {
  width: 76%;
  height: 76%;
  display: block;
}

.card-preview strong {
  max-width: 100%;
  color: var(--ink);
  font-size: var(--title-size, 1.5rem);
  line-height: 1.08;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.card-preview p {
  margin: 0;
  max-width: 100%;
  color: #48586d;
  font-size: var(--text-size, 0.88rem);
  line-height: 1.28;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.card-preview .answer {
  min-width: 58%;
  padding-top: 8px;
  border-top: 2px solid rgba(35, 95, 159, 0.28);
  color: #164a7d;
  font-size: var(--answer-size, 0.94rem);
  font-weight: 900;
}

.card-preview .order {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--card-accent, #235f9f);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 900;
}

.card-preview.is-back {
  background:
    radial-gradient(circle at 50% 40%, rgba(245, 154, 27, 0.18), transparent 38%),
    linear-gradient(135deg, #f8fbff, #fffdf8);
}

.card-preview.is-placeholder {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none;
  opacity: 1;
}

.card-preview.is-placeholder::before {
  display: none;
}

.card-preview.is-brand-back {
  --card-bg: #f7fbff;
  --card-border: #235f9f;
  --card-accent: #f59a1b;
  background:
    linear-gradient(135deg, rgba(245, 154, 27, 0.08), transparent 42%),
    linear-gradient(315deg, rgba(32, 135, 109, 0.08), transparent 45%),
    var(--card-bg);
}

.card-preview.is-brand-back .category {
  color: #f59a1b;
}

.card-preview.is-brand-back .icon {
  color: #fff;
  background: linear-gradient(135deg, #f59a1b, #235f9f);
  box-shadow: 0 12px 24px rgba(35, 95, 159, 0.18);
  font-family: Montserrat, Arial, sans-serif;
  font-weight: 900;
}

.card-preview.is-brand-back .card-logo {
  width: clamp(58px, 38%, 92px);
  aspect-ratio: 1;
  object-fit: contain;
  padding: 7px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 12px 26px rgba(35, 95, 159, 0.14);
}

.card-preview.is-brand-back strong {
  color: #164a7d;
}

.theme-simple .card-preview {
  --card-bg: #fff;
  --card-border: #1f3b57;
  --card-accent: #235f9f;
}

.theme-colorful .card-preview:nth-child(4n + 1) { --card-bg: #edf5fc; --card-border: #235f9f; --card-accent: #235f9f; }
.theme-colorful .card-preview:nth-child(4n + 2) { --card-bg: #eef8f4; --card-border: #20876d; --card-accent: #20876d; }
.theme-colorful .card-preview:nth-child(4n + 3) { --card-bg: #fff5e7; --card-border: #f59a1b; --card-accent: #f59a1b; }
.theme-colorful .card-preview:nth-child(4n + 4) { --card-bg: #f2edff; --card-border: #7656c7; --card-accent: #7656c7; }

.theme-kids .card-preview:nth-child(4n + 1) { --card-bg: #fff1f7; --card-border: #d84d89; --card-accent: #d84d89; }
.theme-kids .card-preview:nth-child(4n + 2) { --card-bg: #eaf8ff; --card-border: #2486b9; --card-accent: #2486b9; }
.theme-kids .card-preview:nth-child(4n + 3) { --card-bg: #fff8d8; --card-border: #efa40f; --card-accent: #efa40f; }
.theme-kids .card-preview:nth-child(4n + 4) { --card-bg: #eaf8ed; --card-border: #21966e; --card-accent: #21966e; }

.theme-minimal .card-preview {
  --card-bg: #fff;
  --card-border: #d6e2ed;
  --card-accent: #0f1b2d;
}

.corners-straight .card-preview { --card-radius: 0; }
.font-small .card-preview { --title-size: 1.16rem; --text-size: 0.76rem; --answer-size: 0.82rem; }
.font-normal .card-preview { --title-size: 1.38rem; --text-size: 0.86rem; --answer-size: 0.92rem; }
.font-large .card-preview { --title-size: 1.62rem; --text-size: 0.98rem; --answer-size: 1.05rem; }
.layout-9 .card-preview,
.layout-12 .card-preview { padding: 13px 11px 11px; gap: 4px; }
.layout-9 .card-preview .icon,
.layout-12 .card-preview .icon { font-size: clamp(1.7rem, 3.4vw, 2.8rem); }
.layout-9 .card-preview strong,
.layout-12 .card-preview strong { font-size: calc(var(--title-size, 1.38rem) * 0.82); }
.layout-9 .card-preview p,
.layout-12 .card-preview p { font-size: calc(var(--text-size, 0.86rem) * 0.86); }

.mode-numbers .card-preview strong,
.mode-letters .card-preview strong {
  font-size: clamp(3rem, 7vw, 5.6rem);
  line-height: 0.92;
}

.mode-numbers .card-preview strong {
  font-size: var(--number-size, clamp(5.2rem, 12vw, 9.2rem));
}

.mode-numbers.layout-9 .card-preview strong,
.mode-numbers.layout-12 .card-preview strong,
.mode-letters.layout-9 .card-preview strong,
.mode-letters.layout-12 .card-preview strong {
  font-size: clamp(2.35rem, 5.8vw, 4.3rem);
}

.mode-numbers.layout-9 .card-preview strong,
.mode-numbers.layout-12 .card-preview strong {
  font-size: var(--number-size, clamp(4.2rem, 9vw, 7rem));
}

.mode-picturePairs .card-preview .icon {
  font-size: clamp(3.4rem, 7.5vw, 6.5rem);
}

.mode-picturePairs.layout-9 .card-preview .icon,
.mode-picturePairs.layout-12 .card-preview .icon {
  font-size: clamp(2.8rem, 6.4vw, 5.2rem);
}

.mode-qa .card-preview.is-answer-card {
  --card-bg: #f8fbff;
  --card-border: #235f9f;
  --card-accent: #164a7d;
}

.mode-qa .card-preview.is-answer-card strong {
  color: #164a7d;
}

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 1fr; }
  .control-panel { position: static; max-height: none; }
}

@media (max-width: 680px) {
  .app-shell { padding: 10px; }
  .control-panel { padding: 14px; }
  .brand-block { grid-template-columns: 54px 1fr; }
  .brand-mark { width: 54px; height: 54px; }
  .field-pair { grid-template-columns: 1fr; }
  .icon-palette { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .quick-editor textarea { min-height: 220px; }
  .preview-heading { align-items: flex-start; flex-direction: column; }
  .sheet,
  .sheet.is-landscape {
    width: 100%;
    padding: 14px;
    gap: 5px;
  }
  .cut-guides { display: none; }
  .card-preview {
    padding: 8px;
    border-width: 1.5px;
  }
  .card-preview .category {
    display: none;
  }
}

@media print {
  body { background: #fff; }
  .control-panel,
  .account-widget,
  .preview-heading,
  .scolatio-global-header,
  .scolatio-discovery-band,
  .generator-suggestions,
  .scolatio-site-footer {
    display: none !important;
  }
  .app-shell,
  .workspace,
  .activity-panel,
  .preview-pages {
    display: block;
    width: auto;
    padding: 0;
    margin: 0;
  }
  .sheet,
  .sheet.is-landscape {
    width: 210mm;
    height: 297mm;
    aspect-ratio: auto;
    box-shadow: none;
    border: 0;
    break-after: page;
    page-break-after: always;
  }
}
