:root {
  color: #f5efe6;
  background: #100f0e;
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(205, 171, 111, 0.09), transparent 42%),
    linear-gradient(145deg, #171411 0%, #100f0e 55%, #0d0c0b 100%);
  overflow-x: hidden;
}

.game {
  position: relative;
  width: min(520px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 22px 0 18px;
}

.topbar {
  position: relative;
  width: 100%;
  padding-bottom: 14px;
  margin-bottom: 18px;
  text-align: center;
  border-bottom: 1px solid rgba(229, 196, 137, 0.12);
}
.topbar h1 {
  margin: 0;
  color: #f7f0df;
  letter-spacing: 0.12em;
  padding-left: 0.12em;
  font-size: clamp(1.15rem, 4vw, 2rem);
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
}
.board {
  --tile-size: calc((min(330px, 78vw) - 28px) / 5);
}
.extended-letter {
  width: var(--tile-size);
  height: var(--tile-size);
  display: grid;
  place-items: center;
  border: 1px solid #4d463b;
  border-radius: 7px;
  color: #dcbf7d;
  background: rgba(216, 190, 127, 0.07);
  font-size: clamp(1.1rem, 5vw, 1.5rem);
  font-weight: 700;
  animation: tile-in 160ms ease-out both;
}

.instructions {
  margin: 10px 0 0;
  color: #9e9589;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
}

.board {
  display: grid;
  gap: 7px;
  width: min(330px, 78vw);
}
.board-row { display: grid; grid-template-columns: repeat(5, var(--tile-size)); gap: 7px; }
.tile {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid #3d3934;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.025);
  color: #f5efe6;
  font-size: clamp(1.45rem, 7vw, 1.9rem);
  font-weight: 700;
  text-transform: uppercase;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.025);
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    color 180ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}
.tile:not(:empty) {
  border-color: #777067;
  background: rgba(255, 255, 255, 0.055);
  transform: scale(1);
  animation: tile-in 160ms ease-out;
}
.tile.correct {
  border-color: #65b77a;
  background: linear-gradient(145deg, #3e9858, #287344);
  color: #f3fff5;
  box-shadow: 0 5px 18px rgba(56, 160, 88, 0.2);
  animation: tile-reveal 520ms ease both;
}
.tile.present {
  border-color: #d9b84e;
  background: linear-gradient(145deg, #bb9635, #967322);
  color: #fff9e8;
  animation: tile-reveal 520ms ease both;
}
.tile.absent {
  border-color: #35332f;
  background: #292825;
  color: #aaa49b;
  animation: tile-reveal 520ms ease both;
}

.status {
  min-height: 24px;
  margin: 12px 0 10px;
  text-align: center;
  color: #c8bda9;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.status[data-tone="error"] { color: #c97970; }
.status[data-tone="success"] { color: #dfc47e; }

.keyboard { width: 100%; display: grid; gap: 7px; margin-top: auto; }
.keyboard-row { display: flex; justify-content: center; gap: 5px; }
.key {
  min-width: 28px;
  height: 50px;
  padding: 0 6px;
  border: 1px solid #46413b;
  border-radius: 6px;
  background: #242220;
  color: #ede6da;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.16);
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 100ms ease;
}
.key-action {
  min-width: 50px;
  color: #d8caa9;
  border-color: #5a5143;
  background: #302d28;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
}
.key:active { transform: translateY(1px) scale(0.97); }
.key.correct {
  border-color: #65b77a;
  background: #37844e;
  color: #f3fff5;
}
.key.present {
  border-color: #d9b84e;
  background: #997826;
  color: #fff9e8;
}
.key.absent {
  border-color: #363431;
  background: #292825;
  color: #858078;
}
.key:focus-visible { outline: 2px solid #dac587; outline-offset: 3px; }

.shimmer .tile:not(:empty) {
  border-color: rgba(218, 197, 135, 0.7);
  box-shadow: 0 0 10px rgba(218, 197, 135, 0.08);
}
.shimmer .extended-letter {
  border-color: rgba(218, 197, 135, 0.7);
  box-shadow: 0 0 10px rgba(218, 197, 135, 0.12);
  animation: letter-shimmer 700ms ease-in-out infinite alternate;
}

@keyframes tile-in {
  0% { transform: scale(0.94); }
  100% { transform: scale(1); }
}
@keyframes letter-shimmer {
  0% { filter: brightness(0.9); }
  100% { filter: brightness(1.3); }
}

@keyframes tile-reveal {
  0% { filter: brightness(0.72); transform: scaleY(0.82); }
  55% { filter: brightness(1.12); transform: scaleY(1.02); }
  100% { filter: brightness(1); transform: scaleY(1); }
}

.effect-layer { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
.effect-layer.active {
  pointer-events: auto;
  background: rgba(8, 7, 6, 0.68);
  backdrop-filter: blur(5px);
}

.victory {
  position: fixed;
  left: 50%;
  top: 50%;
  margin: 0;
  padding: 0;
  max-width: none;
  max-height: none;
  width: min(390px, calc(100% - 40px));
  min-height: 220px;
  transform: translate(-50%, -50%);
  display: grid;
  place-content: center;
  gap: 18px;
  border: 1px solid rgba(255, 183, 86, 0.42);
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 100%, rgba(255, 91, 24, 0.22), transparent 48%),
    linear-gradient(145deg, rgba(51, 31, 20, 0.97), rgba(18, 13, 10, 0.98));
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.65),
    0 0 35px rgba(255, 120, 38, 0.16),
    inset 0 1px rgba(255, 219, 158, 0.12);
  text-align: center;
  animation: victory-in 420ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.victory::backdrop {
  background: rgba(8, 7, 6, 0.72);
  backdrop-filter: blur(5px);
}
.victory-close {
  position: absolute;
  z-index: 1;
  right: 12px;
  top: 12px;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 216, 156, 0.18);
  border-radius: 50%;
  color: #f8ddb1;
  background: rgba(255, 255, 255, 0.04);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.victory-close:focus-visible { outline: 2px solid #ffd49a; outline-offset: 3px; }
.victory-text {
  color: #fff2d2;
  font-size: clamp(2.1rem, 10vw, 4.3rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
  text-shadow:
    0 0 7px #ffd06a,
    0 0 18px #ff7b24,
    0 4px 12px #c92a10;
  animation: fire-pulse 1.1s ease-in-out infinite alternate;
}
.victory-counter {
  color: #cbb99a;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
@keyframes victory-in {
  0% { opacity: 0; transform: translate(-50%, -48%) scale(0.92); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes fire-pulse {
  0% { filter: brightness(0.92); transform: scale(0.985); text-shadow: 0 0 5px #ffd06a, 0 0 12px #ff7b24, 0 3px 8px #c92a10; }
  100% { filter: brightness(1.12); transform: scale(1.015); text-shadow: 0 0 9px #ffe199, 0 0 24px #ff7820, 0 5px 16px #d83a12; }
}

.diabetes {
  position: absolute;
  left: 50%;
  bottom: -15vh;
  transform: translateX(-50%);
  color: #f7b8ce;
  font-size: clamp(3rem, 12vw, 10rem);
  font-weight: 900;
  text-shadow: 4px 4px 0 #8d1f52;
  animation: pop-diabetes 1.6s ease-out both;
}
@keyframes pop-diabetes {
  0% { bottom: -15vh; opacity: 0; }
  18%, 75% { bottom: 12%; opacity: 1; }
  100% { bottom: 18%; opacity: 0; }
}

.beer-can {
  position: absolute;
  top: 20%;
  left: -180px;
  font-size: clamp(5rem, 12vw, 10rem);
  animation: float-can 3.2s linear both;
}
@keyframes float-can {
  from { left: -180px; transform: rotate(0); }
  to { left: calc(100% + 180px); transform: rotate(720deg); }
}

.julistaja {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  background: radial-gradient(circle, rgba(218, 190, 127, 0.12), rgba(8, 7, 6, 0.5));
  font-size: clamp(4rem, 13vw, 12rem);
  font-weight: 900;
  text-shadow: 0 10px 38px rgba(0, 0, 0, 0.8), 0 0 40px rgba(218, 190, 127, 0.65);
  animation: surprise 2.6s ease-out both;
}
@keyframes surprise {
  0%, 100% { opacity: 0; }
  12%, 80% { opacity: 1; }
}

.secret-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(390px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  gap: 14px;
  padding: 30px 20px 20px;
  border: 1px solid rgba(216, 190, 127, 0.28);
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(45, 40, 34, 0.98), rgba(17, 16, 14, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
  animation: victory-in 420ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.spotify-link {
  pointer-events: auto;
  padding: 14px 18px;
  border-radius: 8px;
  background: #1db954;
  color: #0b2413;
  font-weight: 900;
  text-decoration: none;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
.secret-close {
  min-width: 88px;
  min-height: 40px;
  border: 1px solid rgba(216, 190, 127, 0.24);
  border-radius: 8px;
  color: #f5efe6;
  background: #292724;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.secret-close:focus-visible {
  outline: 2px solid #dac587;
  outline-offset: 3px;
}

.enforcer {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  padding: clamp(16px, 4vw, 36px);
  border: 3px dashed #f7eadf;
  color: #f7eadf;
  background: #6a3024;
  font-size: clamp(2.5rem, 9vw, 9rem);
  font-weight: 900;
  animation: float-placeholder 2.6s ease-in-out both;
}
@keyframes float-placeholder {
  50% { transform: translate(-50%, -70%) rotate(3deg); }
}

@media (max-width: 420px) {
  .game { width: calc(100% - 20px); padding-top: 16px; }
  .topbar { margin-bottom: 12px; padding-bottom: 12px; }
  .topbar h1 {
    max-width: 100%;
    margin: 0 auto;
    font-size: clamp(1rem, 5vw, 1.25rem);
    letter-spacing: 0.1em;
    padding-left: 0.1em;
  }
  .board {
    --tile-size: calc((min(290px, 78vw) - 24px) / 5);
    width: min(290px, 78vw);
    gap: 6px;
  }
  .board.has-overflow {
    width: calc(100vw - 20px);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .board.has-overflow::-webkit-scrollbar { display: none; }
  .board-row { gap: 6px; }
  .keyboard-row { gap: 3px; }
  .keyboard { gap: 8px; }
  .key {
    min-width: clamp(22px, 6.5vw, 28px);
    height: 52px;
    padding: 0 2px;
    font-size: 0.75rem;
  }
  .key-action {
    min-width: clamp(34px, 10vw, 42px);
    font-size: 0.62rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
