/* ==========================================================================
   Ordkongen.no - Stilark for «Lag ditt eget kryssord»
   ========================================================================== */

:root {
  --cb-primary: #0284c7;
  --cb-primary-hover: #0369a1;
  --cb-success: #10b981;
  --cb-success-hover: #059669;
  --cb-border: #e2e8f0;
  --cb-card-bg: #ffffff;
  --cb-cell-size: 34px;
}

/* Hovedinnpakning */
.builder-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem 1rem;
}

/* Header & Intro */
.builder-header {
  text-align: center;
  max-width: 800px;
  margin: 0 auto 2rem auto;
}

.builder-header .eyebrow {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--cb-primary);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-bottom: 0.4rem;
}

.builder-header h1 {
  font-family: var(--font-heading);
  font-size: 2.3rem;
  color: var(--primary, #0f172a);
  margin: 0 0 0.8rem 0;
  line-height: 1.2;
}

.builder-header p {
  color: var(--text-muted, #64748b);
  font-size: 1.08rem;
  line-height: 1.6;
  margin: 0;
}

/* Hurtigvelger for eksempler (Presets) */
.preset-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: #f8fafc;
  border: 1.5px solid var(--cb-border);
  padding: 0.85rem 1.25rem;
  border-radius: 16px;
  margin-bottom: 2rem;
}

.preset-label {
  font-size: 0.88rem;
  font-weight: 800;
  color: #475569;
}

.btn-preset {
  background: #ffffff;
  border: 1.5px solid var(--cb-border);
  padding: 0.4rem 0.85rem;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #1e293b;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-preset:hover {
  border-color: var(--cb-primary);
  color: var(--cb-primary);
  transform: translateY(-1px);
}

/* Split-layout for editor og preview */
.builder-workspace {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 2rem;
  align-items: start;
}

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

/* Venstre kolonne: Tabell og inntasting */
.builder-editor-card {
  background: var(--cb-card-bg);
  border: 1.5px solid var(--cb-border);
  border-radius: 20px;
  padding: 1.75rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
}

.title-input-group {
  margin-bottom: 1.5rem;
}

.title-input-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 800;
  color: #334155;
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-main-title {
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 1.15rem;
  font-weight: 700;
  border: 2px solid var(--cb-border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s;
  background: #ffffff;
  color: #0f172a;
}

.input-main-title:focus {
  border-color: var(--cb-primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

/* Inntastingstabell rad for rad */
.table-wrapper {
  overflow-x: auto;
  margin-bottom: 1rem;
}

.words-input-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 0.4rem;
}

.words-input-table th {
  text-align: left;
  font-size: 0.78rem;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.4rem 0.6rem;
}

.words-input-table td {
  padding: 0.2rem 0.3rem;
  vertical-align: middle;
}

.col-num {
  width: 32px;
  text-align: center;
}

.row-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: #f1f5f9;
  font-size: 0.78rem;
  font-weight: 800;
  color: #475569;
}

.col-word {
  width: 34%;
}

.col-clue {
  width: 58%;
}

.col-action {
  width: 38px;
  text-align: center;
}

.table-input {
  width: 100%;
  padding: 0.65rem 0.8rem;
  font-size: 0.95rem;
  border: 1.5px solid var(--cb-border);
  border-radius: 10px;
  outline: none;
  background: #ffffff;
  color: #0f172a;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.table-input:focus {
  border-color: var(--cb-primary);
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.15);
}

.input-word {
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.btn-delete-row {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 8px;
  transition: background 0.15s;
  opacity: 0.6;
}

.btn-delete-row:hover {
  opacity: 1;
  background: #fee2e2;
}

.table-footer-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.5rem;
}

.btn-add-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #f1f5f9;
  color: #0f172a;
  border: 1.5px dashed #cbd5e1;
  padding: 0.65rem 1.25rem;
  border-radius: 12px;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-add-row:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}

.table-hints-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.word-limit-note {
  font-size: 0.8rem;
  color: #0369a1;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  font-weight: 500;
}

.keyboard-hint {
  font-size: 0.78rem;
  color: #64748b;
  margin: 0;
}

/* Høyre kolonne: Live forhåndsvisning */
.builder-preview-panel {
  position: sticky;
  top: 90px;
  background: var(--cb-card-bg);
  border: 1.5px solid var(--cb-border);
  border-radius: 20px;
  padding: 1.5rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
}

.preview-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  border-bottom: 1.5px solid #f1f5f9;
  padding-bottom: 0.8rem;
}

.preview-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
}

.preview-stats-bar {
  display: flex;
  gap: 0.8rem;
  font-size: 0.85rem;
  color: #64748b;
  font-weight: 700;
}

.preview-stats-bar strong {
  color: #0f172a;
}

/* Brett-container */
.grid-preview-container {
  min-height: 280px;
  max-height: 480px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.empty-grid-placeholder {
  text-align: center;
  padding: 2rem 1rem;
  color: #475569;
}

/* Selve kryssord-nettet */
.custom-crossword-board {
  gap: 0;
  background: transparent;
  padding: 8px;
}

.cw-cell {
  width: var(--cb-cell-size);
  height: var(--cb-cell-size);
  box-sizing: border-box;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cw-cell--empty {
  background: transparent;
}

.cw-cell--active {
  background: #ffffff;
  border: 1.5px solid #0f172a;
  margin: -0.75px; /* Overlappende border */
}

.cw-number {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 0.58rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1;
}

.cw-letter {
  font-size: 1.1rem;
  font-weight: 900;
  color: #0f172a;
  display: none;
}

.cw-cell--active.show-letter .cw-letter {
  display: block;
}

/* Verktøylinje under preview */
.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
}

.btn-tool {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  border: 1.5px solid var(--cb-border);
  background: #ffffff;
  font-size: 0.85rem;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-tool:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}

.btn-tool.active {
  background: #ecfdf5;
  border-color: #10b981;
  color: #065f46;
}

/* Eksport-handlinger */
.export-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.btn-export-primary {
  grid-column: span 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: var(--cb-primary);
  color: #ffffff;
  border: none;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
  transition: transform 0.15s, background 0.15s;
}

.btn-export-primary:hover {
  background: var(--cb-primary-hover);
  transform: translateY(-1px);
}

.btn-export-secondary {
  grid-column: span 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: #10b981;
  color: #ffffff;
  border: none;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
  transition: transform 0.15s, background 0.15s;
}

.btn-export-secondary:hover {
  background: #059669;
  transform: translateY(-1px);
}

.btn-export-share {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: 12px;
  background: #f8fafc;
  color: #334155;
  border: 1.5px solid var(--cb-border);
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-export-share:hover {
  background: #f1f5f9;
}

/* Advarsel for uoppsatte ord */
.unplaced-alert {
  background: #fffbeb;
  border: 1.5px solid #fef3c7;
  border-left: 4px solid #f59e0b;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin-top: 1rem;
  font-size: 0.88rem;
  color: #92400e;
}

.unplaced-alert strong {
  display: block;
  margin-bottom: 0.3rem;
}

.unplaced-alert ul {
  margin: 0;
  padding-left: 1.2rem;
}

/* Ledetråder forhåndsvisning */
.preview-clues-wrapper {
  margin-top: 1.5rem;
  border-top: 1.5px solid #f1f5f9;
  padding-top: 1rem;
}

.preview-clues-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.preview-clues-col h4 {
  font-size: 0.88rem;
  font-weight: 800;
  color: #0f172a;
  margin: 0 0 0.5rem 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.clues-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 220px;
  overflow-y: auto;
}

.clue-item {
  font-size: 0.85rem;
  color: #334155;
  margin-bottom: 0.4rem;
  line-height: 1.4;
}

.clue-length {
  color: #94a3b8;
  font-size: 0.78rem;
}

.no-clues-note {
  font-size: 0.82rem;
  color: #94a3b8;
  font-style: italic;
}

/* Toast */
.builder-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(50px);
  background: #0f172a;
  color: #ffffff;
  padding: 0.8rem 1.5rem;
  border-radius: 99px;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 99999;
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.builder-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ==========================================================================
   PRINT LAYOUT (A4 Portrait - 100% Skreddersydd for skoleark)
   ========================================================================== */

#print-container {
  display: none;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 12mm 15mm;
  }

  /* Skjul hele nettstedet */
  header,
  footer,
  nav,
  .builder-workspace,
  .builder-header,
  .preset-bar,
  .seo-text-section,
  .breadcrumb,
  #builder-toast,
  .home-header,
  .home-footer,
  .no-print {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-family: 'Outfit', -apple-system, sans-serif !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* Vis kun print-container */
  #print-container {
    display: block !important;
    width: 100% !important;
  }

  /* Topptekst på utskrift */
  .print-header {
    border-bottom: 2px solid #000000;
    padding-bottom: 8px;
    margin-bottom: 16px;
  }

  .print-brand-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
    font-weight: 800;
    color: #475569;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .print-title {
    font-size: 1.6rem;
    font-weight: 900;
    margin: 0 0 10px 0;
    color: #000000;
  }

  .print-student-fields {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    font-weight: 700;
    color: #000000;
  }

  .print-field {
    border-bottom: 1.5px dotted #000000;
    display: inline-block;
  }

  /* Brettområde på print */
  .print-grid-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
  }

  .print-grid-wrapper .custom-crossword-board {
    padding: 0;
    width: max-content !important;
    margin: 0 auto;
  }

  .print-grid-wrapper .cw-cell {
    width: 28px !important;
    height: 28px !important;
    box-sizing: border-box !important;
  }

  .print-grid-wrapper .cw-cell--empty {
    border: none !important;
    background: transparent !important;
    visibility: hidden;
  }

  .print-grid-wrapper .cw-cell--active {
    border: 1.5px solid #000000 !important;
    background: #ffffff !important;
  }

  .print-grid-wrapper .cw-number {
    font-size: 0.55rem !important;
    color: #000000 !important;
  }

  /* Fasit-modus ved print */
  body.print-solution-mode .print-grid-wrapper .cw-letter {
    display: block !important;
    font-size: 0.95rem !important;
    font-weight: 900 !important;
    color: #047857 !important;
  }

  /* Ledetråder på print (2 kolonner) */
  .print-clues-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }

  .print-clues-section h3 {
    font-size: 0.95rem;
    font-weight: 900;
    text-transform: uppercase;
    margin: 0 0 6px 0;
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 3px;
  }

  .print-clues-section ol {
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.85rem;
    line-height: 1.45;
  }

  .print-clues-section li {
    margin-bottom: 4px;
  }

  /* Footer på utskrift */
  .print-footer {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    border-top: 1.5px solid #cbd5e1;
    padding-top: 6px;
    margin-top: 20px;
    font-size: 0.78rem;
    font-weight: 800;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
}
