@font-face {
  font-family: 'Gabarito';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url(fonts/Gabarito-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Gabarito';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url(fonts/Gabarito-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root{
  --gap: 1px;
  --pad: 16px;
  --maxCell: 68px;
  --cols: 5;
  --rows: 5;
  --vgap: clamp(8px, 2vh, 14px);
  --cell: min(var(--maxCell), calc((100vw - (2 * var(--pad)) - ((var(--cols) - 1) * var(--gap))) / var(--cols)), calc((100dvh - 155px) / 8));
  --radius: 0px;
  --align-inset: calc(var(--cell) * 0.16);

  /* Farger */
  --color-bg: #fff7ea;
  --color-text: #111;
  --color-text-muted: #666;
  --color-text-faint: #888;
  --color-white: #fffcf5;
  --color-dark: #222;
  --color-black: #000;
  --color-border: #ccc;
  --color-border-dark: #bbb;
  --color-border-light: #ddd;
  --color-surface: #f0f0f0;
  --color-surface-hover: #e0e0e0;
  --color-pill-bg: #f6f6f6;
  --color-preview: #e7e7e7;
  --color-close: tomato;

  /* Aksentfarger */
  --color-green: #498360;
  --color-green-hover: #7dd87d;
  --color-green-dark: #1a5928;
  --color-green-light: #e8ffe8;
  --color-green-light-hover: #d0ffd0;
  --color-green-link: #2e8b57;
  --color-orange: #FFA500;
  --color-teal: #20B2AA;
  --color-blue: #007AFF;
  --color-blue-outline: #2f6fff;
  --color-red: #b00020;
  --color-red-light: #ffe2e2;
  --color-orange-outline: #ff8a00;
  --color-blocked: rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; touch-action: manipulation; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  padding: var(--pad);
  font-family: 'Gabarito', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

h1 { margin: 0 0 10px; font-size: 20px; text-align: center; }

.date-label {
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  margin: 8px auto 2px;
  font-size: calc(var(--cell) * 0.22);
  font-weight: 400;
  text-align: left;
  line-height: 1;
}

.date-row {
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  margin: 8px auto 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.date-row .date-label {
  width: auto;
  margin: 0;
}

.date-game-selector {
  display: inline-flex;
  align-items: center;
}

.date-game-selector select {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-white);
  color: var(--color-text);
  font-size: 12px;
  padding: 3px 6px;
  max-width: calc(var(--cell) * 2.2);
}

#dbInfoLine {
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  margin: 12px auto 0;
  text-align: center;
}

.game-title {
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  margin: 0 auto -4px;
  font-size: calc(var(--cell) * 0.55);
  font-weight: bold;
  text-align: left;
}

.title-orange {
  color: var(--color-orange);
}
.title-teal {
  color: var(--color-orange);
}
.title-info {
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  margin: 0 auto calc(var(--cell) * 0.25);
  position: relative;
  min-height: calc(var(--cell) * 0.38 * 3);
  display: flex;
  align-items: flex-start;
}

.title {
  position: relative;
  z-index: 1002;
  font-size: calc(var(--cell) * 0.356);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  letter-spacing: 0.05em;
  margin-top: calc(var(--cell) * 0.356);
  margin-left: var(--align-inset);
  display: inline-block;
  text-decoration: none;
  color: inherit;
}

.title-grid {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 0;
  width: fit-content;
  margin-top: calc(var(--cell) * 0.06);
  margin-left: calc(var(--align-inset) * 0.3);
  text-decoration: none;
  color: inherit;
  z-index: 1002;
  transition: transform 0.3s ease;
}
.home-btn.visible + .title-info .title-grid {
  transform: translateX(calc(var(--cell) * 0.75));
}

.title-cell {
  width: calc(var(--cell) * 0.38);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: calc(var(--cell) * 0.305);
  font-weight: 700;
  line-height: 1;
}

.title-cell.blocked {
}

.wrap {
  display: grid;
  gap: var(--vgap);
  max-width: 980px;
  margin: 0 auto;
  padding-top: calc(var(--cell) * 0.15);
  width: 100%;
}

.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; }
button { padding: 10px 12px; border: 1px solid var(--color-border-dark); border-radius: 12px; background: var(--color-white); cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }

.pill { font-size: 12px; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--color-border); background: var(--color-pill-bg); }
.status { font-size: 14px; line-height: 1.3; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; }
.warn { color: var(--color-red); font-size: 13px; }

.tile-area { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; justify-content: center; position: relative; margin-top: var(--vgap); }
.tile-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap) + var(--gap) * 2 - 2px);
  justify-content: space-between;
}

.tile-row.completed {
  opacity: 0.5;
}

/* Brikke i hånden: varm oker med svart ramme */
.tile {
  width: calc(var(--cell) + 2px);
  height: var(--cell);
  background: #feefc0;
  border: none; outline: 1px solid #000;
  display: grid;
  place-items: center;
  cursor: grab;
  position: relative;
  user-select: none;
  touch-action: manipulation;
  z-index: 1;
}
.tile:active { cursor: grabbing; }
.tile.disabled { cursor: default; }

/* Tom brikke eller brikke som dras: behold størrelse, tegn grå firkant inni */
.tile.empty,
.tile.dragging,
.nextbox.empty,
.nextbox.dragging {
  background: transparent !important;
  border: none !important;
  outline: none !important;
  cursor: default;
  position: relative;
  overflow: hidden;
  z-index: 0;
}
.tile.empty::after,
.tile.dragging::after,
.nextbox.empty::after,
.nextbox.dragging::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  background: #f0e4d0;
  box-shadow: inset 0 0 0 1px var(--color-bg);
}
/* Skjul alt innhold i tom/dragging brikke */
.tile.empty *,
.tile.dragging *,
.nextbox.empty *,
.nextbox.dragging * {
  display: none !important;
}
.tile.dragging .letter,
.tile.dragging .points,
.nextbox.dragging .ch,
.nextbox.dragging .pt,
.nextbox.dragging .lbl {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

/* Brikke som flyttes: lysegrønn, svart ramme, skygge, lett gjennomsiktig */
.tile-drag-clone {
  background: #feefc0 !important;
  border: 1px solid #000 !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
  opacity: 0.85 !important;
}

/* Laste-animasjon: firkantene blinker forskjøvet */
.tile-loading,
.nextbox.tile-loading {
  background: transparent !important;
  border: none !important;
  position: relative;
  overflow: hidden;
  z-index: 0;
}
.tile-loading::after,
.nextbox.tile-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  background: #f0e4d0;
  box-shadow: inset 0 0 0 1px var(--color-bg);
  animation: square-blink 0.6s ease-in-out infinite;
}
.tile-loading *,
.nextbox.tile-loading * {
  display: none !important;
}

.tile-row > .tile-loading:nth-child(1)::after { animation-delay: 0s; }
.tile-row > *:nth-child(2).tile-loading::after { animation-delay: 0.1s; }
.tile-row > *:nth-child(3).tile-loading::after { animation-delay: 0.2s; }
.tile-row > *:nth-child(4).tile-loading::after { animation-delay: 0.3s; }
.tile-row > *:nth-child(5).tile-loading::after { animation-delay: 0.4s; }

@keyframes square-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.hand-ready {
  animation: hand-blink 1.5s ease-in-out infinite;
  cursor: pointer;
}

.hand-ready:nth-child(1) { animation-delay: 0s; }
.hand-ready:nth-child(2) { animation-delay: 0.3s; }
.hand-ready:nth-child(3) { animation-delay: 0.6s; }
.hand-ready:nth-child(4) { animation-delay: 0.9s; }
.hand-ready:nth-child(5) { animation-delay: 1.2s; }

@keyframes hand-blink {
  0%, 100% { background: var(--color-white); }
  50% { background: var(--color-border); }
}

.tile.hand-empty-blink::after,
.nextbox.hand-empty-blink::after {
  animation: empty-slot-blink 0.3s ease-in-out 0s 2;
  background: rgba(204, 204, 204, 0.55);
}

@keyframes empty-slot-blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

@keyframes button-pulse {
  0%, 100% { 
    transform: scale(1); 
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
  }
  50% { 
    transform: scale(1.05); 
    box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
  }
}

.letter { font-size: clamp(8px, calc(var(--cell) * 0.6), 35px); font-weight: 800; line-height: 1; }
.points {
  position: absolute;
  right: 6px;
  bottom: 5px;
  font-size: clamp(7px, calc(var(--cell) * 0.18), 12px);
  font-weight: 800;
  opacity: .85;
}

.nextbox {
  width: calc(var(--cell) + 2px);
  height: var(--cell);
  border: none; outline: 1px solid #000;
  display: grid;
  place-items: center;
  background: #feefc0;
  position: relative;
  user-select: none;
  z-index: 1;
}
.nextbox .lbl { display: none; }
.nextbox .ch {
  font-size: clamp(8px, calc(var(--cell) * 0.55), 32px);
  font-weight: 900;
  line-height: 1;
}
.nextbox .pt {
  position: absolute;
  right: 6px;
  bottom: 5px;
  font-size: clamp(7px, calc(var(--cell) * 0.18), 12px);
  font-weight: 800;
  opacity: .85;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  gap: var(--gap);
  user-select: none;
  width: fit-content;
  max-width: 100%;
  background: #000;
  padding: var(--gap);
  border-radius: 0;
  margin: 0 auto;
}

.cell {
  width: var(--cell); height: var(--cell);
  border: none;
  border-radius: 0;
  display: grid; place-items: center;
  background: var(--color-white);
  position: relative;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.cell.filled { background: #ffd377; cursor: pointer; }
.cell.active { background: #feefc0; cursor: move; } /* Lys oker bakgrunn */

/* Ubekreftede brikker: varm oker bakgrunn (kan flyttes) */
.cell.uncommitted {
  background: #feefc0;
}

/* Bekreftede brikker med ugyldige ord: mørk oker (samme som filled) */
.cell.confirmed {
  background: #ffd377;
}

/* Celle som dras - vis som tom celle */
.cell.cell-dragging {
  background: var(--color-white) !important;
}
.cell.cell-dragging > * {
  display: none !important;
}

/* Visuell feedback når brikke dras over tom celle */
.cell.drag-hover:not(.filled) {
  background: #f0e4d0;
}

/* Gyldige ord: dempet grønn */
.cell.valid {
  background: #c3d1b6;
  color: var(--color-text);
}

/* Låst spill: ikke-blokkerte brikker blir hvite */
.cell.game-locked {
  background: var(--color-white);
  color: var(--color-text);
}

/* Kryssord-blokk */
.cell.blocked {
  background: var(--color-blocked);
}
.cell.blocked .letter,
.cell.blocked .points {
  color: var(--color-white);
  opacity: 0.5;
}
.cell.blocked.locked {
  background: var(--color-black);
}
.cell.blocked.locked .letter,
.cell.blocked.locked .points {
  opacity: 0;
}

/* Hvit joker: blank bokstav med 0 poeng */
.cell.joker {
  background: var(--color-white);
}
.cell.joker .letter {
  opacity: 0;
}
.cell.joker .points {
  color: var(--color-text-muted);
  opacity: 1;
}

/* Smooth transitions for blocking/unblocking */
.cell {
  transition: background 0.35s ease-out;
}
.cell .letter,
.cell .points {
  transition: opacity 0.35s ease-out, color 0.35s ease-out;
}

/* When board is confirmed: hide hand */
.tile-area.hidden {
  display: none !important;
}

/* Game container */
.game-number-inline {
  position: absolute;
  right: calc(50% - (var(--cols) * var(--cell) + (var(--cols) + 1) * var(--gap)) / 2 + var(--gap) + var(--align-inset));
  top: calc(-1 * var(--cell) * 0.4);
  font-size: calc(var(--cell) * 0.27);
  font-weight: bold;
  line-height: 1;
}

.game-container {
  position: relative;
  margin: 0 auto;
}

/* Finalized buttons row - inside action-buttons */
.finalized-buttons {
  display: none;
  justify-content: space-between;
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  padding: 0 var(--align-inset);
  box-sizing: border-box;
}

.wrap.finalized .finalized-buttons {
  display: flex;
}


.final-btn {
  width: var(--cell);
  height: var(--cell);
  border: 1px solid #000;
  border-radius: 50%;
  background: var(--color-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.4);
  font-weight: bold;
  color: var(--color-text);
  opacity: 0;
  transform: translateX(-30px);
  transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

.final-btn.visible {
  opacity: 1;
  transform: translateX(0);
}




#btnFasit { background: #deeaf2; }
#btnBeste { background: #f8d4b0; }
#btnShareFinal { background: #f8d0c8; }

#btnBeste.active {
  background: #f1b266;
  border-width: 3px;
}

#btnBeste.leader-glow {
  animation: leader-ring 0.7s cubic-bezier(.22,.68,.36,1.4) 3;
}

@keyframes leader-ring {
  0%   { box-shadow: 0 0 0 0 #f1b266; scale: 1; }
  30%  { box-shadow: 0 0 0 10px #f1b266; scale: 1.1; }
  60%  { box-shadow: 0 0 0 18px rgba(241,178,102,0.25); scale: 0.97; }
  100% { box-shadow: 0 0 0 26px rgba(241,178,102,0); scale: 1; }
}

#btnFasit {
  font-size: calc(var(--cell) * 0.44);
}

#btnFasit.active {
  background: #b8d4e3;
  color: #000;
  border-width: 3px;
}

#btnShareFinal.active {
  background: #e85d4a;
  border-width: 3px;
}


/* Staggered fade-in for finalized buttons */
.wrap.finalized .final-btn {
  opacity: 1;
  transform: translateY(0);
}

.wrap.finalized .final-btn:nth-child(1) {
  transition-delay: 0.1s;
}
.wrap.finalized .final-btn:nth-child(2) {
  transition-delay: 0.2s;
}
.wrap.finalized .final-btn:nth-child(3) {
  transition-delay: 0.3s;
}
.wrap.finalized .final-btn:nth-child(4) {
  transition-delay: 0.4s;
}


/* Final overlay - absolutely positioned over grid */
.final-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: calc(
    var(--rows) * var(--cell) + (var(--rows) - 1) * var(--gap) + 2 * var(--gap) + 2px
  );
  background: var(--color-bg);
  overflow: hidden;
  z-index: 10;
}

.final-overlay.visible {
  display: block;
}

.final-overlay.stats-fullcover {
  height: auto;
  bottom: 0;
}

.final-overlay-board {
  display: none;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  gap: var(--gap);
  background: var(--color-black);
  padding: var(--gap);
  width: fit-content;
  margin: 0 auto;
  border: none;
  outline: none;
}

.final-overlay-board .cell {
  width: var(--cell);
  height: var(--cell);
  border: none;
  display: grid;
  place-items: center;
  background: var(--color-white);
  position: relative;
}

.final-overlay-board .cell.blocked {
  background: var(--color-black);
}

.final-overlay-board .cell.blocked .letter,
.final-overlay-board .cell.blocked .points {
  display: none;
}

#scoreValue.provisional {
  animation: score-blink 0.9s ease-in-out infinite;
}

@keyframes score-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.final-overlay-stats {
  display: none;
  width: calc(var(--cols) * var(--cell) + (var(--cols) + 1) * var(--gap));
  height: calc(5 * var(--cell) + 6 * var(--gap));
  margin: 0 auto;
  background: var(--color-dark);
  color: #000;
  padding: var(--gap);
  gap: var(--gap);
  box-sizing: border-box;
}

.final-overlay-stats.visible {
  display: grid;
  grid-template-rows: repeat(5, 1fr);
}

.final-overlay-stats .stat-row {
  background: var(--color-white);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: calc(var(--cell) * 0.42);
  font-weight: 500;
  padding: 0 8px 0 20px;
  overflow: hidden;
}

.final-overlay-stats .stat-heading {
  font-size: calc(var(--cell) * 0.45);
  font-weight: bold;
  padding: 0;
}

.stat-lang-select {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  outline: none;
  box-sizing: border-box;
  background: var(--color-white);
  color: #000;
  font-size: 90%;
  font-weight: 500;
  font-family: inherit;
  padding: 0 8px 0 20px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='12' viewBox='0 0 14 8'%3E%3Cpath d='M13 1L7 7L1 1' fill='none' stroke='%23000000' stroke-width='2.5' stroke-linejoin='miter' stroke-miterlimit='10'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 18px center;
  cursor: pointer;
}

.final-overlay-stats .stat-icon {
  font-size: calc(var(--cell) * 0.4);
  width: calc(var(--cell) * 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}


/* Mini 5x5 grid icon */
.mini-grid-svg {
  flex-shrink: 0;
}


/* Mini bar chart for highest score */
.mini-bars-svg {
  flex-shrink: 0;
}

.final-overlay-message {
  display: none;
  font-size: calc(var(--cell) * 0.6);
  font-weight: bold;
  text-align: center;
  color: #aab7bf;
  width: 100%;
  height: 100%;
  margin: 0;
  background: transparent;
  border: none;
  padding: 12px;
  box-sizing: border-box;
}

.final-overlay-message.visible {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  width: calc(var(--cols) * var(--cell) + (var(--cols) + 1) * var(--gap));
  height: calc(var(--rows) * var(--cell) + (var(--rows) + 1) * var(--gap));
  background: var(--color-white);
  border: 1px solid var(--color-black);
  margin: 0 auto;
  padding: 0;
}

.final-overlay-message-content {
  width: 100%;
  max-width: calc(var(--cell) * 5);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.final-overlay-message-title {
  font-size: calc(var(--cell) * 0.42);
  font-weight: 800;
  color: var(--color-text-dark);
  text-align: center;
}

.final-overlay-message-hint {
  font-size: calc(var(--cell) * 0.24);
  font-weight: 600;
  color: var(--color-text-dark);
  text-align: center;
}

.final-overlay-link-text {
  width: 100%;
  min-height: calc(var(--cell) * 1.2);
  resize: none;
  border: 1px solid var(--color-border-medium);
  border-radius: 10px;
  padding: 10px;
  font-family: var(--font-mono, monospace);
  font-size: calc(var(--cell) * 0.2);
  color: var(--color-text-dark);
  background: var(--color-white);
  box-sizing: border-box;
}

/* Fasit-overlay: anbefalt svart rute */
.cell.soln {
  outline: 3px solid var(--color-blue-outline);
  outline-offset: -3px;
}
/* Hvis spiller har blokkert men fasit vil ha hvit (vise konflikt) */
.cell.solnMismatch {
  outline: 3px solid var(--color-orange-outline);
  outline-offset: -3px;
}

/* Midlertidig beste forslag (grå forhåndsvisning) */
.cell.preview { background: var(--color-preview); }
.cell.preview .letter,
.cell.preview .points { color: var(--color-text-muted); }
.cell.preview.blocked { background: var(--color-text-muted); }

.results {
  border: 1px solid var(--color-border-light);
  border-radius: 16px;
  padding: 14px;
  background: var(--color-white);
  max-width: 980px;
  margin: 0 auto;
}
.results h2 { margin: 0 0 8px; font-size: 16px; }
.words { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.chip { display: inline-flex; gap: 6px; align-items: baseline; }
.chip .w { font-weight: 800; }
.chip .p { font-size: 12px; opacity: .75; }


.solver-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.solver-text { font-size: 14px; }

.stats-row {
  display: none;
  justify-content: space-between;
  align-items: baseline;
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  margin: var(--vgap) auto 0;
  padding: 0 var(--align-inset);
  box-sizing: border-box;
}
.stats-row.visible {
  display: flex;
}


.stats-label {
  font-size: calc(var(--cell) * 0.55);
  font-weight: bold;
  text-align: left;
  opacity: 0;
  line-height: 1;
}

.stats-label.visible {
  opacity: 1;
}

.stats-bars {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  background: transparent;
}

/* Stat-brikker: nøyaktig samme størrelse som rutenett-celler */
.stat-tile {
  height: var(--cell);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  background: transparent;
  border: none;
  font-size: calc(var(--cell) * 0.55);
  font-weight: bold;
  opacity: 0;
}

.stat-tile.complete {
  opacity: 1;
}

#scoreValue {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}


.stat-tile-black {
  background: #000;
  color: #fff;
}

.stat-tile-wide {
  width: calc(var(--cell) * 2 + var(--gap));
  font-size: calc(var(--cell) * 0.4);
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.score-left {
  display: flex;
  align-items: center;
  justify-content: center;
}

.score-right {
  display: flex;
  align-items: center;
  justify-content: center;
}

.score-slash {
  position: absolute;
  top: 25%;
  bottom: 25%;
  left: 50%;
  width: 2px;
  background: #000;
  transform: rotate(20deg);
}

.tile-counter {
  position: absolute;
  right: var(--align-inset);
  top: 0;
  text-align: right;
  font-size: calc(var(--cell) * 0.3);
  font-weight: normal;
  line-height: 1;
}

.tile-points {
  right: auto;
  left: var(--align-inset);
  text-align: left;
}

.action-buttons {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  margin: calc(var(--gap) + var(--vgap) + 4px) auto 0;
}


.share-row {
  display: flex;
  justify-content: flex-end;
  width: calc(var(--cols) * var(--cell) + (var(--cols) + 1) * var(--gap));
  margin: var(--gap) auto 0;
  padding-right: var(--gap);
}

.action-btn {
  width: var(--cell);
  height: var(--cell);
  border: 1px solid #000;
  border-radius: 50%;
  background: var(--color-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--color-text-muted);
}

.action-btn-wide {
  width: calc(var(--cell) * 2 + var(--gap));
}

.action-btn svg {
  width: calc(var(--cell) * 0.5);
  height: calc(var(--cell) * 0.5);
}

.action-btn:disabled {
  cursor: not-allowed;
}

.action-btn.active {
  cursor: pointer;
}

#btnLockGame {
  background: rgba(76, 175, 80, 0.4);
  color: var(--color-bg);
}
#btnLockGame.active {
  background: var(--color-green);
  color: var(--color-bg);
}
#btnLockGame.blinking {
  animation: button-pulse 1s ease-in-out infinite;
}

#btnShareMain {
  background: rgba(255, 165, 0, 0.5);
}
#btnShareMain.active {
  background: var(--color-orange);
  color: var(--color-white);
}

.close-btn {
  position: absolute;
  top: var(--pad);
  right: var(--pad);
  width: calc(var(--cell) * 0.5);
  height: calc(var(--cell) * 0.5);
  border-radius: 50%;
  background: tomato;
  color: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn svg {
  width: 50%;
  height: 50%;
}

/* Bekreft-overlay */
.game-overlay {
  position: fixed;
  inset: 0;
  z-index: 1010;
  background: var(--color-bg);
  overflow: hidden auto;
  overscroll-behavior: none;
  animation: overlay-fade-in 0.3s ease;
}

@keyframes overlay-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.welcome-content {
  max-width: 500px;
  margin: 0 auto;
  padding: calc(var(--cell) * 1) calc(var(--pad) + 16px) var(--pad);
  text-align: center;
}
#helpAnimWrap + .welcome-content {
  padding-top: 0;
  padding-bottom: calc(var(--pad) + 2em);
  margin-top: 1em;
}
.welcome-content h2 {
  text-align: center;
  margin-bottom: 1em;
}
.welcome-content p {
  margin-bottom: 1em;
  line-height: 1.5;
  font-size: 1em;
}
#welcomeAnimSlot {
  margin-top: 1.5em;
}
.welcome-btn {
  display: block;
  margin: 1.5em auto 0;
  padding: 12px 40px;
  font-size: 1.1em;
  font-weight: 700;
  border: 1px solid var(--color-border-dark);
  border-radius: 12px;
  background: var(--color-white);
  cursor: pointer;
}

.overlay-header-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--pad) + var(--cell) * 0.15 + var(--cell) * 1.2 + 8px);
  background: var(--color-bg);
  z-index: 1001;
}

.overlay-close {
  position: fixed;
  top: calc(var(--pad) + var(--cell) * 0.15);
  right: calc((100vw - 5 * var(--cell) - 4 * var(--gap)) / 2 + var(--align-inset));
  z-index: 1003;
  width: calc(var(--cell) * 0.5);
  height: calc(var(--cell) * 0.5);
  border: none;
  border-radius: 50%;
  background: tomato;
  color: var(--color-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.overlay-close svg {
  width: 75%;
  height: 75%;
  stroke: var(--color-bg);
}

.overlay-content {
  max-width: 500px;
  margin: 0 auto;
  padding: calc(var(--cell) + var(--pad)) var(--pad) var(--pad);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.overlay-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.overlay-label {
  font-size: calc(var(--cell) * 0.3);
  font-weight: bold;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.overlay-board {
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  background: var(--color-dark);
  width: fit-content;
}

.overlay-board .cell {
  width: var(--cell);
  height: var(--cell);
  border: none;
  display: grid;
  place-items: center;
  background: var(--color-white);
  position: relative;
  overflow: hidden;
}

.overlay-board .cell.blocked {
  background: var(--color-blocked);
}

.overlay-board .cell.blocked .letter,
.overlay-board .cell.blocked .points {
  color: var(--color-white);
  opacity: 0.5;
}

.overlay-text {
  text-align: center;
  font-size: calc(var(--cell) * 0.3);
  line-height: 1.5;
  max-width: 400px;
  margin: 0;
}

.overlay-btn {
  padding: 12px 24px;
  border: 1px solid var(--color-border-dark);
  border-radius: 12px;
  background: var(--color-white);
  cursor: pointer;
  font-size: calc(var(--cell) * 0.3);
  font-weight: bold;
}


.overlay-stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: calc(var(--cell) * 0.28);
  margin-top: 8px;
}

/* Spillerstatistikk */
.player-stats {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: calc(var(--cols) * var(--cell) + (var(--cols) + 1) * var(--gap));
  margin: 8px auto 0;
  font-size: calc(var(--cell) * 0.28);
}

.player-stats-title {
  font-weight: bold;
  font-size: calc(var(--cell) * 0.32);
}

.player-stats-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.player-stat-line {
  color: var(--color-text-muted);
}

.player-stat-line span {
  font-weight: bold;
  color: var(--color-text);
}

/* Delemelding */
#shareMessage {
  display: none;
  color: var(--color-blue);
  font-size: 14px;
  margin-left: 8px;
}
#shareMessage.error {
  color: var(--color-red);
}

/* Drag-klone farge */
.cell-drag-clone {
  background: #c3d1b6;
  border: 1px solid #000 !important;
}

/* Felles stiler for alle sider */
.back-link {
  display: inline-block;
  margin-bottom: 16px;
  color: var(--color-blue);
  text-decoration: none;
  font-size: 14px;
}
.back-link:hover {
  text-decoration: underline;
}

.center {
  text-align: center;
}

/* Forside */
.front-intro {
  text-align: center;
  padding: 0 12px;
  max-width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  margin: 0 auto;
}

.front-title {
  font-size: calc(var(--cell) * 0.55);
  font-weight: bold;
  margin: 0 0 16px;
}

.front-desc {
  font-size: calc(var(--cell) * 0.3);
  font-weight: normal;
  margin: 0 0 0;
  line-height: 1.4;
}

.box-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr 1fr 1fr;
  gap: 1px;
  margin: 0 auto;
  max-width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  aspect-ratio: 5 / 5;
  background: #000;
  border: 1px solid #000;
}

.daily-box {
  text-align: center;
  padding: 16px;
  background: var(--color-white);
  color: #000;
  box-sizing: border-box;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Daily-boks (nr + dato): col 1-3, row 2-3 */
.box-daily {
  grid-column: 1 / 4;
  grid-row: 2 / 4;
  aspect-ratio: auto;
  background: var(--color-white);
  color: #000;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

.daily-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 4px;
  box-sizing: border-box;
}

/* Play-knapp */
.box-play {
  width: calc(var(--cell) * 2 + var(--gap));
  height: calc(var(--cell) * 2 + var(--gap));
  margin: var(--vgap) auto 0;
  background: var(--color-bg);
  text-decoration: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-circle {
  width: 75%;
  height: 75%;
  border-radius: 50%;
  border: 1px solid #000;
  background: #498360;
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-circle svg {
  width: 63%;
  height: 63%;
  fill: var(--color-bg);
}

.box-play.played .play-circle {
  background: #a7cda9;
}

/* Score-boks: col 4-5, row 2-3 */
.box-score {
  grid-column: 4 / 6;
  grid-row: 1 / 3;
  aspect-ratio: auto;
  background: #000;
  color: #b8d4e3;
  padding: 0 16px;
}

/* Språkvalg: rad 1, full bredde */
.box-lang {
  grid-column: 1 / 4;
  grid-row: 1 / 2;
  display: flex;
  align-items: center;
  background: var(--color-white);
  position: relative;
}

.box-lang::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 52px;
  width: 34px;
  pointer-events: none;
  background: linear-gradient(to right, rgba(255, 255, 255, 0), var(--color-white));
}

/* Distribusjonskart: rad 6-7, full bredde */
.box-distribution {
  aspect-ratio: auto;
  background: var(--color-white);
  padding: 0;
  position: relative;
  overflow: hidden;
  align-items: stretch;
}

.box-distribution .distribution-chart {
  flex: 1;
}

.distribution-chart {
  display: flex;
  align-items: flex-end;
  height: 100%;
  width: 100%;
  position: relative;
  gap: 0;
  margin-right: -1px;
}

.distribution-bar {
  flex: 1 0 0;
  background: #b2aca7;
  min-height: 1px;
  min-width: 0;
  margin-right: -1px;
  transform-origin: bottom;
  animation: bar-grow 0.5s ease-out both;
  transition: height 0.4s ease-out, background-color 0.4s ease-out;
}

@keyframes bar-grow {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

.distribution-median-line {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 3px;
  background: #E88F87;
  transform: translateX(-50%);
  transform-origin: bottom;
  animation: bar-grow 0.5s ease-out both;
  transition: height 0.4s ease-out;
  z-index: 2;
}

.distribution-median {
  position: absolute;
  top: 20%;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: var(--color-bg);
  transform: translateX(-50%);
  z-index: 1;
  transition: left 0.6s ease;
}

.distribution-median-label {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: bold;
  color: var(--color-bg);
  white-space: nowrap;
  padding-bottom: 2px;
}

.box-stat-val {
  aspect-ratio: auto;
  background: #000;
  font-size: 22px;
  font-weight: bold;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  flex-direction: column;
}

#percentileBox {
  background: #b8d4e3;
  color: #000;
}

#medianBox {
  background: #E88F87;
  color: #000;
}


/* Leader-boks: col 3-5, row 5 */
.box-leader {
  grid-column: 1 / 3;
  grid-row: 4 / 5;
  aspect-ratio: auto;
  font-size: 18px;
  line-height: 1.4;
  justify-content: center;
  background: #f1b266;
  padding: 16px 21px 16px 11px;
}

/* Next-boks: col 5, row 6-7 */
.box-next {
  grid-column: 1 / 3;
  grid-row: 5 / 6;
  aspect-ratio: auto;
  background: var(--color-white);
  color: #000;
  padding: 0 12px;
  border: none;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.stats-title {
  font-size: 22px;
  font-weight: bold;
}

/* Score-boks: stor poengsum, sentrert */
.score-label {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 0;
}

.score-value {
  font-size: 72px;
  font-weight: bold;
  line-height: 1;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}



.next-icon {
  display: flex;
  align-items: center;
}

.next-icon svg {
  width: calc(var(--cell) * 0.28);
  height: calc(var(--cell) * 0.28);
}

.next-countdown {
  font-size: calc(var(--cell) * 0.25);
  font-weight: 400;
  display: flex;
  gap: 4px;
}

.next-countdown > div {
  width: 2ch;
  text-align: center;
}


.daily-date {
  font-size: 17px;
  font-weight: normal;
  text-align: center;
  white-space: nowrap;
}

.daily-number {
  font-size: calc(var(--cell) * 0.6);
  font-weight: bold;
}

.daily-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: none;
  color: #000;
  padding: 0;
}

.daily-nav-btn svg {
  width: 26px;
  height: 18px;
  stroke-width: 1.5;
}

#frontPrevDayBtn svg {
  transform: rotate(90deg);
}

#frontNextDayBtn svg {
  transform: rotate(-90deg);
}

.daily-nav-btn:disabled {
  opacity: 0.45;
  cursor: default;
}




.front-practice {
  text-align: center;
  margin: 16px auto;
  max-width: calc(var(--cell) * 4 + var(--gap) * 3);
}

.front-practice p {
  font-size: calc(var(--cell) * 0.36);
  margin: 0;
}

.practice-link {
  color: var(--color-green-link);
  text-decoration: underline;
}

.front-lang {
  display: none;
}

.lang-dropdown {
  padding: 0 24px;
  font-size: calc(var(--cell) * 0.3);
  font-weight: bold;
  height: 100%;
  border: none !important;
  border-radius: 0 !important;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  background: var(--color-white);
  color: #000;
  appearance: none;
  -webkit-appearance: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='12' viewBox='0 0 14 8'%3E%3Cpath d='M13 1L7 7L1 1' fill='none' stroke='%23000000' stroke-width='2.5' stroke-linejoin='miter' stroke-miterlimit='10'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 24px center;
  padding-right: 52px;
}

/* Statistikk */
.stats-container {
  max-width: 100%;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  margin-bottom: 2px;
}
.stat-card {
  background: var(--color-surface);
  border: none;
  border-radius: 0;
  padding: 16px;
  text-align: center;
}
.stat-value {
  font-size: 28px;
  font-weight: bold;
  color: var(--color-text);
}
.stat-label {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 4px;
}
.history-section h2 {
  font-size: 16px;
  margin-bottom: 12px;
}
.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--color-surface);
  border: none;
  border-radius: 0;
  margin-bottom: 2px;
  font-size: 14px;
}
.no-data {
  text-align: center;
  color: var(--color-text-faint);
  padding: 32px;
  font-size: 14px;
}

/* Øvemodus */
.practice-container {
  max-width: 100%;
}
.practice-container > p {
  font-size: 14px;
  color: var(--color-text-muted);
  margin: 0 0 16px;
}
.practice-grid {
  display: grid;
  gap: 2px;
}
.practice-card {
  display: block;
  background: var(--color-surface);
  border: none;
  border-radius: 0;
  padding: 16px;
  text-decoration: none;
  color: inherit;
}
.practice-card:hover {
  background: var(--color-surface-hover);
}
.practice-card h2 {
  margin: 0 0 4px;
  font-size: 16px;
}
.practice-card p {
  margin: 0;
  font-size: 13px;
  color: var(--color-text-muted);
}
.size-options {
  margin-top: 24px;
}
.size-options h2 {
  font-size: 14px;
  margin-bottom: 12px;
}
.size-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}
.size-btn {
  padding: 12px 8px;
  border: none;
  border-radius: 0;
  background: var(--color-surface);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  color: inherit;
}
.size-btn:hover {
  background: var(--color-surface-hover);
}
.size-btn .size {
  font-size: 16px;
  font-weight: bold;
}
.size-btn .label {
  font-size: 10px;
  color: var(--color-text-muted);
}
.custom-size {
  margin-top: 2px;
  padding: 16px;
  background: var(--color-surface);
  border: none;
  border-radius: 0;
}
.custom-size h3 {
  margin: 0 0 12px;
  font-size: 14px;
}
.custom-inputs {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.custom-inputs label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}
.custom-inputs input {
  width: 50px;
  padding: 8px;
  border: 1px solid var(--color-border);
  border-radius: 0;
  font-size: 14px;
}
.custom-inputs button {
  padding: 10px 16px;
  background: var(--color-close);
  color: var(--color-white);
  border: none;
  border-radius: 0;
  cursor: pointer;
  font-size: 14px;
}

/* Kontrollbar mobil */
#controlBar {
  font-size: 12px;
}
#controlBar button {
  padding: 8px 10px;
  font-size: 12px;
}
#controlBar .pill {
  font-size: 11px;
  padding: 3px 6px;
}
#controlBar input {
  width: 48px !important;
  padding: 3px 4px !important;
  font-size: 12px;
}
#controlBar select {
  padding: 3px 4px !important;
  font-size: 12px;
}

/* Kontrollbar input/select styling */
#controlBar input[type="number"],
#controlBar select {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-white);
}

@media (min-width: 700px){
  :root{
    --gap: 1px;
    --pad: 24px;
    --cell: min(var(--maxCell), calc((700px - (2 * var(--pad)) - ((var(--cols) - 1) * var(--gap))) / var(--cols)), calc((100dvh - 155px) / 8));
  }
  h1 { font-size: 22px; }

  .date-game-selector select {
    font-size: 14px;
    padding: 4px 6px;
  }

  .hero h1 { font-size: 48px; }
  .hero p { font-size: 18px; }
  .hero { padding: 40px 20px; }

  .nav-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
  .nav-card {
    padding: 20px;
  }
  .nav-card h2 { font-size: 18px; }
  .nav-card p { font-size: 14px; }
  .nav-card .icon { font-size: 32px; }

  .stats-grid { gap: 16px; }
  .stat-value { font-size: 36px; }
  .stat-label { font-size: 14px; }

  #controlBar {
    font-size: 14px;
  }
  #controlBar button {
    padding: 10px 12px;
    font-size: 14px;
  }
  #controlBar .pill {
    font-size: 12px;
    padding: 4px 8px;
  }
  #controlBar input {
    width: 56px !important;
    padding: 4px 6px !important;
    font-size: 14px;
  }
  #controlBar select {
    padding: 4px 6px !important;
    font-size: 14px;
  }
}

/* Hjem-knapp */
.home-btn {
  position: fixed;
  top: calc(var(--pad) + var(--cell) * 0.15);
  left: calc((100vw - 5 * var(--cell) - 4 * var(--gap)) / 2 + var(--align-inset) - var(--cell) * 0.075);
  z-index: 1003;
  width: calc(var(--cell) * 0.5);
  height: calc(var(--cell) * 0.5);
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #000;
  opacity: 0;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.home-btn svg {
  width: 60%;
  height: 60%;
}
.home-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Stats-knapp (ved siden av hjelp) */
.stats-btn {
  position: fixed;
  top: calc(var(--pad) + var(--cell) * 0.15);
  right: calc((100vw - 5 * var(--cell) - 4 * var(--gap)) / 2 + var(--align-inset) + var(--cell) * 0.5 + 12px);
  z-index: 1003;
  width: calc(var(--cell) * 0.5);
  height: calc(var(--cell) * 0.5);
  border: none;
  border-radius: 50%;
  background: #000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #b8d4e3;
}
.stats-btn svg {
  width: 60%;
  height: 60%;
}
.stats-icon-close {
  display: none;
}
.stats-btn.active .stats-icon-person {
  display: none;
}
.stats-btn.active .stats-icon-close {
  display: block;
  width: 75%;
  height: 75%;
}
.stats-btn.active {
  background: #000;
  color: #b8d4e3;
}

/* Hjelp-knapp */
.help-btn {
  position: fixed;
  top: calc(var(--pad) + var(--cell) * 0.15);
  right: calc((100vw - 5 * var(--cell) - 4 * var(--gap)) / 2 + var(--align-inset));
  z-index: 999;
  width: calc(var(--cell) * 0.5);
  height: calc(var(--cell) * 0.5);
  border: none;
  border-radius: 50%;
  background: tomato;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.38);
  font-weight: 300;
  color: var(--color-bg);
  padding: 0;
}

/* Hjelp-overlay */
.help-section {
  --help-cell: clamp(38px, 13vw, 56px);
}

.help-board {
  display: grid;
  grid-template-columns: repeat(5, var(--help-cell));
  grid-template-rows: repeat(5, var(--help-cell));
  gap: var(--gap);
  padding: var(--gap);
  background: #000;
  width: fit-content;
  margin: 0 auto;
}

.help-board .cell {
  width: var(--help-cell);
  height: var(--help-cell);
}

.help-board .cell .letter {
  font-size: calc(var(--help-cell) * 0.6);
}

.help-board .cell .points {
  font-size: calc(var(--help-cell) * 0.18);
  right: 3px;
  bottom: 2px;
}

/* Hånd: matcher spillets tile-row nøyaktig */
.help-tile-row {
  display: flex;
  justify-content: space-between;
  width: calc(5 * var(--help-cell) + 4 * var(--gap) + 2 * var(--gap) - 2px);
  margin: 8px auto 0;
}

.help-tile {
  width: calc(var(--help-cell) + 2px);
  height: var(--help-cell);
  background: #feefc0;
  border: none;
  outline: 1px solid #000;
  display: grid;
  place-items: center;
  position: relative;
  user-select: none;
}

.help-tile .letter {
  font-size: calc(var(--help-cell) * 0.6);
  font-weight: 900;
  line-height: 1;
}

.help-tile .points {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: calc(var(--help-cell) * 0.18);
  font-weight: 800;
  opacity: .85;
}

.help-tile.empty {
  background: #f0e4d0;
  outline: none;
  box-shadow: inset 0 0 0 1px var(--color-bg);
  z-index: 0;
}

.help-tile:not(.empty) {
  z-index: 1;
}

.help-group {
  padding: 32px var(--pad);
  margin: 0 calc(-1 * var(--pad));
}

.help-group + .help-group {
  position: relative;
}

.help-group + .help-group::before {
  display: none;
}

.help-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.help-section + .help-section {
  margin-top: 48px;
}

.help-confirm {
  width: var(--help-cell);
  height: var(--help-cell);
  border-radius: 50%;
  background: var(--color-green);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  color: var(--color-bg);
}

.help-confirm svg {
  width: calc(var(--help-cell) * 0.5);
  height: calc(var(--help-cell) * 0.5);
}

.help-stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: calc(5 * var(--help-cell) + 4 * var(--gap) + 2 * var(--gap));
  margin-top: 8px;
}

.help-stats-label,
.help-stats-value {
  font-size: calc(var(--help-cell) * 0.5);
  font-weight: bold;
}

#helpBoard20 .cell.invalid {
  background: #8fa8b8;
}

.help-board .cell.steelblue {
  background: #d6e8f2;
}

.help-board .cell.darkblue {
  background: #8fa8b8;
}

.help-board .cell.diagonal {
  background: linear-gradient(to bottom right, #8fa8b8 50%, #d6e8f2 50%);
}


.help-board-wrap {
  position: relative;
  display: inline-block;
}

.help-x2 {
  position: absolute;
  font-size: calc(var(--help-cell) * 0.38);
  font-weight: bold;
  color: #000;
}

.help-x2.help-x1-left-row5,
.help-x2.help-x1-right-row3,
.help-x2.help-x1-top-col5 {
  color: #000;
}

.help-x2-row1 {
  left: calc(5 * var(--help-cell) + 6 * var(--gap) + 4px);
  top: calc(var(--gap) + var(--help-cell) / 2);
  transform: translateY(-50%);
}

.help-x2-top-col1 {
  left: calc(var(--gap) + var(--help-cell) * 0.2);
  top: calc(-1 * var(--help-cell) * 0.45);
}

.help-x2-top-col3 {
  left: calc(var(--gap) + 2 * var(--help-cell) + 2 * var(--gap) + var(--help-cell) * 0.2);
  top: calc(-1 * var(--help-cell) * 0.45);
}

.help-x1-left-row5 {
  left: calc(-1 * var(--help-cell) * 0.45);
  bottom: calc(var(--gap) + var(--help-cell) / 2);
  transform: translateY(50%);
}

.help-x1-right-row3 {
  left: calc(5 * var(--help-cell) + 6 * var(--gap) + 4px);
  top: calc(var(--gap) + 2 * var(--help-cell) + 2 * var(--gap) + var(--help-cell) / 2);
  transform: translateY(-50%);
}

.help-x1-top-col5 {
  right: calc(var(--gap) + var(--help-cell) * 0.2);
  top: calc(-1 * var(--help-cell) * 0.45);
}

/* ===== Help animation (replaces old static help boards) ===== */
#helpAnimWrap {
  --help-cell: clamp(44px, 15vw, 64px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2em 0.5em;
  transform: scale(0.9);
  transform-origin: top center;
  border: 1px solid #000;
  max-width: min(400px, calc(100% - 2 * var(--pad)));
  margin: 0 auto -40px;
  box-sizing: border-box;
}
#helpMidSection {
  height: calc(var(--help-cell) + 10px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  position: relative;
}
#helpTileArea { transition: opacity 0.3s; }
#helpStatsRow {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  width: calc(5 * var(--help-cell) + 4 * var(--gap) + 2 * var(--gap));
  padding-right: calc(var(--help-cell) * 0.1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
#helpStatsRow.visible { opacity: 1; pointer-events: auto; }
#helpActionRow {
  display: flex;
  justify-content: center;
  align-items: center;
  width: calc(5 * var(--help-cell) + 4 * var(--gap) + 2 * var(--gap));
  margin: 8px auto 0;
  position: relative;
  height: var(--help-cell);
}
#helpFinalizedRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: absolute;
  inset: 0;
  padding: 0 calc(var(--help-cell) * 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
#helpFinalizedRow.visible { opacity: 1; }
#helpAnimWrap .demo-final-btn {
  width: var(--help-cell);
  height: var(--help-cell);
  border: 1px solid #000;
  border-radius: 50%;
  background: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--help-cell) * 0.4);
  font-weight: bold;
}
#helpAnimWrap .help-board-wrap { transition: opacity 0.5s ease; }
#helpAnimWrap .help-board-wrap.fade-out { opacity: 0; }
#helpAnimWrap .cell { transition: none; }
#helpAnimWrap .cell .letter,
#helpAnimWrap .cell .points { transition: none; }
#helpAnimWrap .help-tile { transition: none; }
#helpAnimWrap .help-x2 { opacity: 0; transition: opacity 0.4s; font-weight: normal; }
#helpAnimWrap .help-x2.visible { opacity: 1; }
#helpAnimWrap .help-confirm { opacity: 0.4; transition: opacity 0.3s ease; }
#helpAnimWrap .help-confirm.active { opacity: 1; }
#helpAnimWrap .help-confirm.pop { animation: btn-pop 0.35s ease-out; }
@keyframes btn-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
#helpTimeline {
  width: calc(5 * var(--help-cell) + 4 * var(--gap) + 2 * var(--gap));
  margin: 16px auto 0;
  position: relative;
  height: 32px;
  display: flex;
  align-items: center;
  touch-action: none;
}
.ha-track {
  position: absolute;
  left: 0; right: 0;
  height: 1px;
  background: #000;
}
.ha-ball {
  position: absolute;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: tomato;
  border: 1px solid #000;
  cursor: pointer;
  transform: translateX(-50%);
  z-index: 2;
  transition: left 0.35s ease;
}
.ha-ball::before {
  content: '';
  position: absolute;
  inset: -12px;
  border-radius: 50%;
}
.ha-ball {
  display: flex;
  align-items: center;
  justify-content: center;
}
.ha-ball.dragging { transition: none; cursor: grabbing; }
.ha-play { width: 97%; height: 97%; pointer-events: none; margin-left: -1px; }
.ha-pause { width: 77%; height: 77%; pointer-events: none; }
.float-tile {
  position: fixed;
  background: #feefc0;
  box-shadow: inset 0 0 0 1px #000, 0 4px 12px rgba(0,0,0,0.3);
  display: grid;
  place-items: center;
  z-index: 10000;
  pointer-events: none;
  font-family: 'Gabarito', system-ui, sans-serif;
}
.float-tile .letter {
  font-size: clamp(23px, 9vw, 40px);
  font-weight: 900;
}
.float-tile .points {
  position: absolute;
  right: 3px; bottom: 2px;
  font-size: clamp(8px, 2.8vw, 14px);
  font-weight: 800;
  opacity: 0.85;
}

/* Reklame-overlay */
#adOverlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.ad-placeholder {
  background: var(--color-white, #fffcf5);
  border-radius: 12px;
  padding: 24px;
  min-width: 300px;
  min-height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-slot {
  color: var(--color-text-muted, #666);
  font-size: 14px;
  text-align: center;
}

@keyframes adOverlayFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

.ad-overlay-fade-out {
  animation: adOverlayFadeOut 0.3s ease-out forwards;
}

