/* Sanapyramidi: pyramidi, laatat ja loppuruutu. Rivien värit ovat sivuston omat
   (huippu kulta, sitten vihreä, sininen, violetti ja ruskea – samat kuin jakotekstin
   ruuduissa 🟨🟩🟦🟪🟫). Valkoisen tekstin kontrasti riveillä on vähintään 4,5:1. */

.sanapyramidi-page {
  --pyr-huippu: #e2b844;
  --pyr-kaksi: #2e7d47;
  --pyr-kolme: #2a68b3;
  --pyr-nelja: #7445b0;
  --pyr-viisi: #85552c;
}

.sanapyramidi-page .game-stage-bar {
  align-items: center;
}

.pyr-nav {
  min-height: 36px;
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.pyr-nav-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  color: #ffd25e;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.pyr-nav-link:hover {
  border-color: #ffd25e;
}

.pyr-nav-link[hidden] {
  display: none;
}

.pyr-app {
  max-width: 640px;
  margin: 0 auto;
  color: var(--on-dark);
}

.pyr-head {
  margin: 0 0 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 12px;
}

.pyr-title {
  margin: 0;
  color: #fff;
  font-size: 18px;
  font-weight: 800;
}

.pyr-number {
  color: var(--pyr-huippu);
}

.pyr-date {
  min-height: 1.4em;
  margin: 0;
  color: var(--on-dark-muted);
  font-size: 14px;
}

.pyr-date::first-letter {
  text-transform: uppercase;
}

/* ---------- Pyramidi */
.pyr-board {
  margin: 0 auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  list-style: none;
}

.pyr-row {
  width: 100%;
  min-height: 50px;
  margin: 0;
  display: flex;
  justify-content: center;
  gap: 5px;
  border-radius: 10px;
}

.pyr-row-1 { width: 36%; }
.pyr-row-2 { width: 52%; }
.pyr-row-3 { width: 68%; }
.pyr-row-4 { width: 84%; }

.pyr-slot {
  flex: 1;
  border: 2px dashed rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.pyr-row.is-solved {
  padding: 6px 10px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--pyr-c);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  color: #fff;
  text-align: center;
}

.pyr-c-huippu { --pyr-c: var(--pyr-huippu); }
.pyr-c-kaksi { --pyr-c: var(--pyr-kaksi); }
.pyr-c-kolme { --pyr-c: var(--pyr-kolme); }
.pyr-c-nelja { --pyr-c: var(--pyr-nelja); }
.pyr-c-viisi { --pyr-c: var(--pyr-viisi); }

.pyr-row.pyr-c-huippu {
  color: #1d1604;
}

/* Hävityssä näytetyt rivit: raidat erottavat ne itse ratkaistuista. */
.pyr-row.is-revealed {
  background-image: repeating-linear-gradient(135deg, rgba(0, 0, 0, 0.22) 0 6px, transparent 6px 12px);
}

.pyr-theme {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
}

.pyr-words {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.03em;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.pyr-row-1.is-solved .pyr-theme {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pyr-row-1.is-solved .pyr-words {
  font-size: 14px;
  font-weight: 800;
}

.pyr-row.is-new {
  animation: pyr-pop 0.45s ease-out;
}

@keyframes pyr-pop {
  0% { transform: scale(0.92); opacity: 0.4; }
  60% { transform: scale(1.03); opacity: 1; }
  100% { transform: scale(1); }
}

/* ---------- Viesti */
.pyr-message {
  min-height: 2.8em;
  margin: 10px 0;
  color: var(--on-dark-muted);
  font-size: 15px;
  font-weight: 650;
  line-height: 1.4;
  text-align: center;
}

.pyr-message.is-good { color: #9be3b1; }
.pyr-message.is-bad { color: #ffb4aa; }
.pyr-message.is-warn,
.pyr-message.is-hint { color: #ffd25e; }

/* ---------- Laatat */
.pyr-tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.pyr-tiles[hidden] {
  display: none;
}

.pyr-tile {
  position: relative;
  min-width: 0;
  min-height: 54px;
  margin: 0;
  padding: 6px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  background: #fbf7ee;
  box-shadow: inset 0 -3px 0 rgba(20, 35, 58, 0.16);
  color: var(--ink);
  font: 800 15px/1.15 var(--font-sans);
  letter-spacing: 0.02em;
  text-align: center;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.12s ease, transform 0.1s ease;
}

.pyr-tile.is-long { font-size: 13px; }
.pyr-tile.is-xlong { font-size: 11.5px; letter-spacing: 0; }

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

.pyr-tile:disabled {
  cursor: default;
  opacity: 0.6;
}

.pyr-tile.is-selected {
  background: var(--accent);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
  color: var(--accent-ink);
}

.pyr-tile.is-hinted {
  outline: 2px dashed #ffd25e;
  outline-offset: 2px;
}

.pyr-tile.is-hinted::after {
  content: "vihje";
  position: absolute;
  top: 3px;
  right: 5px;
  color: #8a6a10;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pyr-tile.is-selected.is-hinted::after {
  color: var(--accent-ink);
}

.pyr-tile:focus-visible,
.pyr-btn:focus-visible,
.pyr-nav-link:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.pyr-tile.is-wrong {
  animation: pyr-shake 0.4s ease;
}

@keyframes pyr-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

/* ---------- Virheet, vihjeet ja painikkeet */
.pyr-meta {
  margin: 14px 0 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  color: var(--on-dark-muted);
  font-size: 14px;
  font-weight: 650;
}

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

.pyr-dots {
  display: inline-flex;
  gap: 6px;
}

.pyr-dots i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
}

.pyr-dots i.is-used {
  background: #e0574a;
  box-shadow: 0 0 0 2px rgba(224, 87, 74, 0.35);
}

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

.pyr-btn {
  min-height: 46px;
  margin: 0;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font: 750 16px/1.2 var(--font-sans);
  cursor: pointer;
}

.pyr-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.pyr-btn-main {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.pyr-btn-main:hover:not(:disabled) {
  background: var(--accent-hover);
}

.pyr-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.pyr-app.is-done .pyr-meta,
.pyr-app.is-done .pyr-controls {
  display: none;
}

/* ---------- Loppuruutu */
.pyr-end {
  margin: 14px 0 0;
  padding: 18px 16px;
  border: 1px solid var(--board-line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.2);
  text-align: center;
}

.pyr-end[hidden] {
  display: none;
}

.pyr-end-title {
  margin: 0 0 6px;
  color: #fff;
  font-family: var(--font-serif);
  font-size: 22px;
}

.pyr-end-text {
  margin: 0 0 14px;
  color: var(--on-dark);
}

.pyr-stats {
  margin: 0 0 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.pyr-stats div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.pyr-stats dt {
  color: var(--on-dark-muted);
  font-size: 12px;
  font-weight: 650;
}

.pyr-stats dd {
  margin: 2px 0 0;
  color: #fff;
  font-size: 22px;
  font-weight: 800;
}

.pyr-next,
.pyr-end-links {
  margin: 6px 0 0;
  color: var(--on-dark-muted);
}

.pyr-end a {
  color: #ffd25e;
  font-weight: 700;
}

.pyr-noscript {
  margin: 12px 0 0;
  text-align: center;
}

/* ---------- Arkisto */
.pyr-archive {
  margin-top: 0;
}

.pyr-archive-list {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  columns: 1;
}

.pyr-archive-list li {
  padding: 5px 0;
  break-inside: avoid;
  border-bottom: 1px solid var(--line);
}

.pyr-archive-list li[aria-current] {
  font-weight: 800;
}

.pyr-archive-list a {
  display: inline-block;
  min-width: 3.4em;
  color: var(--link);
  font-weight: 750;
}

.pyr-archive-date {
  color: var(--ink-2);
}

.pyr-archive-status {
  color: var(--muted);
  font-size: 14px;
}

@media (min-width: 600px) {
  .pyr-tiles {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .pyr-tile.is-long { font-size: 14px; }
  .pyr-tile.is-xlong { font-size: 13px; }

  .pyr-row {
    min-height: 56px;
  }

  .pyr-theme { font-size: 14px; }
  .pyr-words { font-size: 13px; }

  .pyr-controls {
    display: flex;
    justify-content: center;
  }

  .pyr-btn-main {
    min-width: 140px;
  }

  .pyr-archive-list {
    columns: 2;
    column-gap: 32px;
  }
}

@media (max-width: 380px) {
  .pyr-tile { font-size: 14px; }
  .pyr-tile.is-long { font-size: 12px; }
  .pyr-tile.is-xlong { font-size: 10.5px; }
  .pyr-stats dd { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  .pyr-row.is-new,
  .pyr-tile.is-wrong {
    animation: none;
  }

  .pyr-tile {
    transition: none;
  }
}
