/* =========================================================
   Koblingen - Moderne, elegant styling (CSS)
   Inspirert av NYT Connections med premium norsk design
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Outfit:wght@500;600;700;800&display=swap');

:root {
  /* Lys modus fargepalett */
  --bg-primary: #F8FAFC;
  --bg-secondary: #FFFFFF;
  --bg-tile: #E9ECEF;
  --bg-tile-hover: #DEE2E6;
  --text-primary: #1E293B;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --border-color: #E2E8F0;
  
  /* Valgt brikke */
  --tile-selected-bg: #475569;
  --tile-selected-color: #FFFFFF;
  --tile-selected-border: #334155;
  --tile-shadow: 0 3px 6px rgba(0, 0, 0, 0.04);
  --tile-selected-shadow: 0 4px 12px rgba(30, 41, 59, 0.25);

  /* Koblingen Vanskelighetsgrader */
  --cat-yellow-bg: #F9DF6D;
  --cat-yellow-text: #2D2200;
  --cat-green-bg: #A0C35A;
  --cat-green-text: #162804;
  --cat-blue-bg: #85A8D8;
  --cat-blue-text: #0C1F38;
  --cat-purple-bg: #B574C5;
  --cat-purple-text: #280B33;

  /* UI Aksenter */
  --primary-brand: #2563EB;
  --primary-brand-hover: #1D4ED8;
  --accent-gold: #F59E0B;
  --error-color: #EF4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Mørk modus fargepalett */
[data-theme="dark"] {
  --bg-primary: #0F172A;
  --bg-secondary: #1E293B;
  --bg-tile: #26334D;
  --bg-tile-hover: #334155;
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --border-color: #334155;

  --tile-selected-bg: #3B82F6;
  --tile-selected-color: #FFFFFF;
  --tile-selected-border: #60A5FA;
  --tile-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
  --tile-selected-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);

  --cat-yellow-bg: #EAB308;
  --cat-yellow-text: #1E1700;
  --cat-green-bg: #22C55E;
  --cat-green-text: #05230D;
  --cat-blue-bg: #3B82F6;
  --cat-blue-text: #051937;
  --cat-purple-bg: #A855F7;
  --cat-purple-text: #1F0833;
}

/* Grunnleggende reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
html::-webkit-scrollbar, body::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* App Wrapper */
.game-wrapper {
  width: 100%;
  max-width: 580px;
  min-height: auto;
  display: flex;
  flex-direction: column;
  padding: 8px 16px 18px 16px;
}

/* Minimalistisk topplinje: Spillet er helt øverst */
.game-top-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  text-align: center;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-name-compact {
  font-family: 'Outfit', sans-serif;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.4px;
  color: var(--text-primary);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.puzzle-title-badge {
  font-size: 12px;
  font-weight: 700;
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary-brand);
  border: 1px solid rgba(37, 99, 235, 0.25);
  padding: 3px 10px;
  border-radius: var(--radius-full);
}

[data-theme="dark"] .puzzle-title-badge {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border-color: rgba(96, 165, 250, 0.35);
}

.instruction-text {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0;
}

/* Alt av valg og verktøy under spillet */
.controls-panel-under {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border-color);
  width: 100%;
}

.puzzle-selector-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.selector-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.selector-heading {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--text-primary);
}

.puzzle-date-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Raske temapiller */
.theme-filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.theme-filter-row::-webkit-scrollbar {
  display: none;
}

.theme-filter-pill {
  background: var(--bg-tile);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.theme-filter-pill:hover {
  background: var(--bg-tile-hover);
  color: var(--text-primary);
}

.theme-filter-pill.active {
  background: var(--primary-brand);
  color: #ffffff;
  border-color: var(--primary-brand);
}

.puzzle-select-wrapper select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
}

.puzzle-select-wrapper select:focus {
  border-color: var(--primary-brand);
}

.puzzle-select-wrapper select optgroup {
  font-weight: 800;
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

.puzzle-select-wrapper select option {
  font-weight: 500;
  color: var(--text-primary);
  padding: 4px;
}

/* Verktøylinje under */
.bottom-tools-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.tool-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tool-btn span {
  font-size: 16px;
  line-height: 1;
}

.tool-btn:hover {
  background: var(--bg-tile);
  border-color: var(--text-muted);
  transform: translateY(-1px);
}

/* Hovedrutenett og løste kategorier */
.board-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

/* Løste gruppe-bannere */
.solved-categories-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.solved-category-banner {
  width: 100%;
  border-radius: var(--radius-md);
  padding: 14px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.solved-category-banner.animate-slide-down {
  animation: slideDownFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.solved-title {
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.solved-words {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  opacity: 0.95;
}

/* 4x4 Ordrutenett */
.words-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
}

.word-tile {
  aspect-ratio: 1.15;
  background-color: var(--bg-tile);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--tile-shadow);
  transition: transform var(--transition-fast), background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  word-break: break-word;
}

.word-tile:hover {
  background-color: var(--bg-tile-hover);
  transform: translateY(-2px);
}

.word-tile:active {
  transform: scale(0.96);
}

.word-tile.selected {
  background-color: var(--tile-selected-bg);
  color: var(--tile-selected-color);
  border-color: var(--tile-selected-border);
  box-shadow: var(--tile-selected-shadow);
  transform: translateY(-2px);
}

/* Animasjoner for brikker og bannere */
@keyframes shake-animation {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}

.word-tile.shake-error {
  animation: shake-animation 0.38s ease-in-out !important;
  border-color: var(--error-color) !important;
  background-color: rgba(239, 68, 68, 0.15) !important;
  color: var(--error-color) !important;
}

@keyframes pop-animation {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.word-tile.tile-solved-pop {
  animation: pop-animation 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  z-index: 10;
}

@keyframes slide-down-banner {
  0% { opacity: 0; transform: translateY(-16px) scale(0.96); }
  60% { transform: translateY(2px) scale(1.01); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.solved-category-banner.animate-slide-down {
  animation: slide-down-banner 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Fremdriftslinje for løste brett */
.progress-bar-container {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--text-secondary);
}

.progress-text-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.progress-text-row strong {
  color: var(--primary-brand);
}

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--border-color);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6 0%, #10b981 100%);
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Feilforsøk (Mistakes) Visning */
.mistakes-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.mistakes-dots {
  display: flex;
  gap: 8px;
  align-items: center;
}

.mistake-pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--tile-selected-bg);
  transition: transform var(--transition-bounce), opacity 0.3s ease;
}

.mistake-pip.spent {
  opacity: 0.15;
  transform: scale(0.7);
}

/* Handlingsknapper */
.action-buttons-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: auto;
}

.btn-game {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: var(--radius-full);
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.btn-game:hover:not(:disabled) {
  background: var(--bg-tile);
  transform: translateY(-1px);
}

.btn-game:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-game:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-submit {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}

.btn-submit:hover:not(:disabled) {
  background: var(--tile-selected-bg);
}

.btn-hint-mini {
  background: transparent;
  color: var(--accent-gold);
  border-color: rgba(245, 158, 11, 0.3);
  font-size: 13px;
  padding: 10px 16px;
}

.btn-hint-mini:hover:not(:disabled) {
  background: rgba(245, 158, 11, 0.1);
}

/* Toast Notifikasjoner */
.toast-notification {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-30px);
  background-color: #1E293B;
  color: #FFFFFF;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  z-index: 1000;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
}

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

/* Modaler */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  padding: 24px;
  position: relative;
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-title {
  font-family: 'Outfit', sans-serif;
  font-size: 20px;
  font-weight: 800;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

.modal-close:hover {
  color: var(--text-primary);
}

/* Hjelp-modal farge-forklaring */
.help-level-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}

.help-level-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 700;
}

/* Statistikk-boks */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  text-align: center;
  margin: 20px 0;
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-number {
  font-family: 'Outfit', sans-serif;
  font-size: 26px;
  font-weight: 800;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

/* Slutt-skjerm Emoji rutenett */
.emoji-grid-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 20px 0;
}

.emoji-row {
  display: flex;
  gap: 4px;
}

.emoji-box {
  font-size: 22px;
  line-height: 1;
}

/* Spillbygger Form */
.builder-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.form-input {
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.builder-cat-card {
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.builder-words-inputs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.builder-words-inputs input {
  padding: 8px;
  font-size: 13px;
  text-transform: uppercase;
}

/* Animasjoner */
@keyframes slideDownFade {
  0% {
    opacity: 0;
    transform: translateY(-16px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.tile-solved-pop {
  animation: tilePop 0.4s ease forwards;
}

@keyframes tilePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); filter: brightness(1.2); }
  100% { transform: scale(0.9); opacity: 0; }
}

.shake-error {
  animation: shake 0.38s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-3px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

.shuffling {
  animation: shufflePop 0.18s ease;
}

@keyframes shufflePop {
  50% { transform: scale(0.9) rotate(2deg); opacity: 0.7; }
}

/* Konfetti */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  opacity: 0.9;
  animation: fall 2.8s linear forwards;
}

@keyframes fall {
  0% {
    top: -20px;
    transform: rotate(0deg) translateX(0);
  }
  100% {
    top: 105vh;
    transform: rotate(720deg) translateX(80px);
  }
}

/* Mobil-tilpasninger (ned til 360px) */
@media (max-width: 440px) {
  .game-wrapper {
    padding: 8px 12px 20px 12px;
  }
  
  .words-grid {
    gap: 6px;
  }

  .word-tile {
    font-size: 11px;
    padding: 4px;
    border-radius: var(--radius-sm);
  }

  .btn-game {
    font-size: 13px;
    padding: 10px 16px;
  }

  .brand-name {
    font-size: 18px;
  }
}
