:root {
  --bg: #eef2f5;
  --panel: #ffffff;
  --ink: #10151f;
  --muted: #657184;
  --line: #d9e0ea;
  --accent: #4f883d;
  --accent-dark: #3d6f2e;
  --paper: #ffffff;
  --card-border: #f37c83;
  --heading-color: #030712;
  --heading-font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --heading-scale: 1;
  --image-scale: 0.6;
  --image-offset-y: -28%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@font-face {
  font-family: "Elementarz";
  src: url("elementarz.ttf") format("truetype");
  font-display: swap;
}


* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  min-height: 42px;
  border: 1px solid #c6d1df;
  border-radius: 8px;
  background: #fff;
  color: #152033;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  border-color: #8ea0b7;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-dark);
}

button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  min-height: 100vh;
}

.settings-panel {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 24px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand-block {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 17px;
}

.panel-section {
  display: grid;
  gap: 14px;
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}

.two-column-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.controls-grid {
  grid-template-columns: 1fr 1fr;
}

.controls-grid h2,
.controls-grid .field:last-child {
  grid-column: 1 / -1;
}

.controls-grid .field:nth-of-type(3) {
  grid-column: 1 / -1;
}

.controls-grid .field:nth-of-type(4) {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: #263244;
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

input,
select {
  min-height: 40px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 11px;
  line-height: 1.45;
}

#itemsInput {
  height: 180px;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.segmented-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
}

.segmented-toggle button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
}

.segmented-toggle button.is-active {
  background: var(--accent);
  color: #fff;
}

.image-options {
  display: grid;
  gap: 14px;
}

.ai-button {
  width: 100%;
}

.download-section {
  position: sticky;
  bottom: 0;
  background: var(--panel);
}

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

.category-tile {
  min-height: 92px;
  display: grid;
  grid-template-rows: 54px auto;
  gap: 6px;
  align-items: center;
  justify-items: center;
  padding: 8px 6px;
  border: 1px solid #d8e1ee;
  border-radius: 8px;
  background: #fff;
  color: #172033;
  cursor: pointer;
}

.category-tile:hover,
.category-tile.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
}

.category-thumb {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
}

.category-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.category-tile span {
  width: 100%;
  color: #263244;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
}

.file-drop {
  display: grid;
  gap: 5px;
  padding: 14px;
  border: 1px dashed #9eb0c5;
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
}

.file-drop.compact {
  min-height: 42px;
  align-content: center;
  padding: 9px 12px;
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-drop span {
  font-weight: 800;
}

.upload-label {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.upload-icon {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.validation-box {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.individual-images {
  display: grid;
  gap: 10px;
}

.individual-images h3 {
  margin: 4px 0 0;
  font-size: 14px;
}

.individual-image-list {
  display: grid;
  gap: 8px;
  max-height: 340px;
  overflow: auto;
  padding-right: 2px;
}

.image-assignment {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid #d8e1ee;
  border-radius: 8px;
  background: #fff;
}

.assignment-name {
  min-width: 0;
}

.assignment-name strong,
.assignment-name small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.assignment-name strong {
  font-size: 13px;
}

.assignment-name small {
  color: var(--muted);
  font-size: 12px;
}

.assignment-preview {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #d8e1ee;
  border-radius: 7px;
  background: #f8fafc;
  color: #8090a6;
  font-size: 11px;
  font-weight: 800;
}

.assignment-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.assignment-actions {
  display: flex;
  gap: 6px;
}

.assignment-button,
.remove-image {
  min-height: 34px;
  padding: 0 9px;
  border: 1px solid #c6d1df;
  border-radius: 7px;
  background: #fff;
  color: #152033;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.remove-image {
  width: 34px;
  padding: 0;
}

.remove-image:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.validation-box {
  padding: 12px;
  border-radius: 8px;
  background: #f8fafc;
}

.image-picker {
  width: min(920px, calc(100vw - 28px));
  max-height: min(780px, calc(100vh - 28px));
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.ai-dialog {
  width: min(560px, calc(100vw - 28px));
  margin: 50px auto auto;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.ai-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.ai-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.language-field {
  display: grid;
  gap: 9px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.language-field legend {
  color: #263244;
  font-size: 13px;
  font-weight: 800;
}

.language-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.language-pills label {
  cursor: pointer;
}

.language-pills input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.language-pills span {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 0 13px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  color: #263244;
  font-size: 13px;
  font-weight: 800;
}

.language-pills input:checked + span {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, white);
  color: #24491b;
}

.image-picker::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.picker-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

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

.picker-header h2 {
  font-size: 22px;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.picker-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.picker-grid-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
}

.picker-grid-layout h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.picker-grid-layout .category-grid,
.picker-image-grid {
  max-height: 510px;
  overflow: auto;
  padding-right: 2px;
}

.picker-image-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.library-image-tile {
  min-height: 84px;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 8px 6px;
  border: 1px solid #d8e1ee;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.library-image-tile:hover {
  border-color: var(--accent);
}

.library-image-tile img {
  max-width: 70px;
  max-height: 70px;
  object-fit: contain;
}

.validation-box strong {
  color: #172033;
}

.preview-panel {
  min-width: 0;
  padding: 12px clamp(16px, 3vw, 42px) 24px;
}

.preview-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  max-width: 980px;
  margin: 0 auto 8px;
}

.preview-toolbar .eyebrow {
  font-size: 10px;
  margin-bottom: 2px;
}

.preview-toolbar h2 {
  font-size: 18px;
}

.preview-actions {
  display: grid;
  gap: 4px;
  justify-items: end;
}

.preview-actions button {
  min-height: 30px;
  padding: 0 12px;
  font-size: 13px;
}

.preview-actions p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.pages {
  display: grid;
  gap: 22px;
  justify-content: center;
}

.page {
  width: min(100%, 210mm);
  max-width: 210mm;
  min-width: 0;
  aspect-ratio: 210 / 297;
  display: grid;
  gap: 5mm;
  padding: 5mm;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 16px 44px rgba(15, 23, 42, 0.16);
}

.pdf-export {
  width: 210mm;
  background: #fff;
}

.pdf-export .page {
  width: 210mm !important;
  height: 297mm !important;
  max-width: none;
  margin: 0;
  box-shadow: none;
  break-after: page;
  page-break-after: always;
}

.pdf-export .page:last-child {
  break-after: auto;
  page-break-after: auto;
}

.page.cards-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

.page.cards-6 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

.page.cards-8 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
}

.game-card {
  --card-border: #f37c83;
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1.2mm solid var(--card-border);
  border-radius: 8mm;
  background: #fff;
  color: #060b15;
}

.card-half {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;
  padding: 4mm 5mm 1mm;
}

.card-half.no-image {
  grid-template-rows: auto auto;
  align-content: center;
  gap: 7mm;
}

.card-half + .divider + .card-half {
  padding-top: 1mm;
  padding-bottom: 4mm;
}

.game-card h3 {
  max-width: 100%;
  min-width: 0;
  margin: 0;
  color: var(--heading-color);
  font-family: var(--heading-font);
  font-size: calc(clamp(22px, 5.5vw, 54px) * var(--heading-scale));
  font-weight: 950;
  line-height: 0.95;
  letter-spacing: 0;
  text-align: center;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  white-space: nowrap;
}

.image-slot {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 1mm 0;
}

.image-slot img {
  max-width: calc(100% * var(--image-scale));
  max-height: calc(100% * var(--image-scale));
  object-fit: contain;
  transform: translateY(var(--image-offset-y));
}

.image-slot img.placeholder-art {
  opacity: 0.55;
}

.emoji-art {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: calc(clamp(34px, 7.8vw, 82px) * var(--image-scale));
  line-height: 1;
  transform: translateY(var(--image-offset-y));
}

.game-card p {
  max-width: 100%;
  margin: 0;
  font-size: clamp(15px, 2.8vw, 28px);
  line-height: 1.1;
  text-align: center;
  overflow-wrap: anywhere;
}

.divider {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 2mm;
  padding: 0 6mm;
  color: var(--card-border);
}

.divider::before,
.divider::after {
  content: "";
  border-top: 0.45mm solid currentColor;
  opacity: 0.42;
}

.divider span {
  width: auto;
  height: auto;
  transform: none;
  border-radius: 0;
  background: transparent;
  font-size: 5mm;
  line-height: 1;
}

.divider span::before {
  content: "♥";
}

.card-logo {
  position: absolute;
  width: 9mm;
  height: auto;
  right: 2mm;
  bottom: 2mm;
  object-fit: contain;
  opacity: 0.9;
}

@media (max-width: 799px) {
  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .settings-panel {
    position: relative;
    height: auto;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-panel {
    height: auto;
    overflow: visible;
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }

  .two-column-fields,
  .picker-actions,
  .picker-grid-layout {
    grid-template-columns: 1fr;
  }

  .preview-toolbar {
    align-items: start;
    flex-direction: column;
  }

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

  .page {
    gap: 2.5mm;
    padding: 3mm;
  }
}

@media (min-width: 800px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app-shell {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }

  .settings-panel,
  .preview-panel {
    height: 100vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }
}

@media (min-width: 800px) and (max-width: 980px) {
  .game-card h3 {
    font-size: calc(clamp(22px, 3.35vw, 30px) * var(--heading-scale));
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  body {
    background: #fff;
  }

  .settings-panel,
  .preview-toolbar {
    display: none !important;
  }

  .app-shell,
  .preview-panel,
  .pages {
    display: block;
    padding: 0;
    margin: 0;
  }

  .page {
    width: 210mm !important;
    height: 297mm !important;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }

  .page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .cards-4 .game-card h3 {
    font-size: calc(15mm * var(--heading-scale));
  }

  .cards-4 .emoji-art {
    font-size: calc(38mm * var(--image-scale));
  }

  .cards-4 .game-card p {
    font-size: 7mm;
  }

  .cards-6 .game-card h3 {
    font-size: calc(11mm * var(--heading-scale));
  }

  .cards-6 .emoji-art {
    font-size: calc(26mm * var(--image-scale));
  }

  .cards-6 .game-card p {
    font-size: 5.2mm;
  }

  .cards-8 .game-card h3 {
    font-size: calc(8.5mm * var(--heading-scale));
  }

  .cards-8 .emoji-art {
    font-size: calc(19mm * var(--image-scale));
  }

  .cards-8 .game-card p {
    font-size: 4.2mm;
  }
}
