* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: radial-gradient(circle at center, #1b2735, #090a0f);
  color: #f5f5f5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
}

/* Intro splash */

#introSplash {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  overflow: hidden;
}

.container {
  position: relative;
  width: 400px;
  height: 200px;
  color: gold;
  font-family: 'Arial Black', Arial, sans-serif;
}

.container.fade-out {
  animation: fadeOut 0.5s forwards;
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

.top-text {
  position: absolute;
  top: 50px;
  width: 100%;
  text-align: center;
  font-size: 60px;
  color: gold;
  filter: drop-shadow(0 0 10px gold);
  opacity: 0.8;
  transition: filter 1s ease, opacity 1s ease;
}

.top-text.clear {
  filter: none;
  opacity: 1;
  animation: wave 3s infinite ease-in-out;
}

.bottom-text {
  position: absolute;
  bottom: 20px;
  width: 100%;
  text-align: center;
  font-size: 28px;
  color: gold;
  filter: drop-shadow(0 0 8px gold);
}

.letter {
  display: inline-block;
  position: relative;
  color: gold;
  filter: drop-shadow(0 0 8px gold);
  white-space: pre;
}

.star-shape {
  position: absolute;
  width: 12px;
  height: 12px;
  background: gold;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  pointer-events: none;
}

/* Main app */

#mainApp {
  display: none;
  width: 100%;
  max-width: 600px;
  padding: 10px 10px 60px;
}

/* Title */

h1 {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 8px 0;
  font-size: clamp(2rem, 6vw, 2.6rem);
  color: #ffd700;
  text-shadow: 1px 1px 5px rgba(255, 255, 255, 0.4);
  user-select: none;
}

.title {
  white-space: nowrap;
}

.arrow, #scoreLink {
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #1b2735;
  box-shadow: 0 0 5px rgba(0, 255, 255, 0.3);
  cursor: pointer;
  transition: transform 0.3s ease;
}

.arrow {
  font-size: 1.6rem;
}

.arrow.rotating {
  animation: spinArrow 0.4s ease forwards;
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.6);
}

#scoreLink {
  color: #ffd700;
}

#scoreLink:hover {
  transform: scale(1.1);
}

/* Status bar */

#statusBar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  width: min(94vw, 500px);
  margin: 10px auto 20px;
}

#livesContainer {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  padding-left: 12px;
}

#timer {
  font-weight: bold;
  color: #ffd700;
  font-size: 1.2rem;
  text-align: center;
  white-space: nowrap;
  padding-right: 12px;
}

/* Board */

#board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(94vw, 500px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border: 3px solid #ffd700;
  background: #121b22;
  border-radius: 10px;
  box-shadow: 0 0 20px rgba(0, 255, 255, 0.25);
  gap: 2px;
  user-select: none;
  position: relative;
}

input.cell {
  width: 100%;
  height: 100%;
  font-size: clamp(1.6rem, 5vmin, 2.5rem);
  text-align: center;
  border: none;
  background: linear-gradient(to bottom, #34495e, #22313f);
  color: #f0f0f0;
  font-weight: bold;
  border-radius: 6px;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  caret-color: transparent;
  pointer-events: auto;
}

input.cell:focus,
input.cell:hover {
  background: #1d2d3a;
  outline: 3px solid #00e6e6;
  box-shadow: 0 0 5px rgba(0, 255, 255, 0.3);
  caret-color: #ffd700;
}

input.cell.fixed {
  background: #1d2d3a;
  color: #a0a0a0;
  cursor: default;
  pointer-events: none;
  caret-color: transparent;
}

input.cell.invalid {
  background-color: #c0392b !important;
  color: #fff;
  border: 2px solid #e74c3c !important;
  border-radius: 6px;
  box-shadow: 0 0 5px #e74c3c;
}

.error-pulse {
  animation: errorPulse 0.9s infinite;
  font-weight: bold;
  color: #ff4d4d;
}

@keyframes errorPulse {
  0%, 100% { color: #ff4d4d; }
  50% { color: #fff; }
}

input.cell.inactive {
  opacity: 0.3;
  cursor: default;
}

input.cell[data-top] { border-top: 3px solid #ffd700; }
input.cell[data-left] { border-left: 3px solid #ffd700; }
input.cell[data-right] { border-right: 3px solid #ffd700; }
input.cell[data-bottom] { border-bottom: 3px solid #ffd700; }

/* Keyboard */

.keyboard {
  position: relative;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(94vw, 500px);
  display: flex;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 5px;
  z-index: 100;
}

.key {
  width: calc((100% - 8 * 2px) / 9);
  aspect-ratio: 1 / 1;
  font-size: clamp(1.8rem, 5vmin, 2.6rem);
  font-weight: bold;
  font-family: 'Segoe UI', 'Roboto', sans-serif;
  text-align: center;
  background: linear-gradient(to bottom, #34495e, #22313f);
  color: #f0f0f0;
  border-radius: 6px;
  border: none;
  transition: all 0.2s ease;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
  caret-color: transparent;
}

.key:hover, .key.active {
  background: #2c3e50;
  outline: 3px solid #00e6e6;
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.3);
  transform: scale(1.04);
}

/* Modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  overflow-y: auto;
}

.modal-content {
  background: linear-gradient(to bottom, #121b22, #22313f);
  color: #ffd700;
  padding: clamp(20px, 5vw, 30px);
  border-radius: 16px;
  box-shadow: 0 0 16px rgba(0, 255, 255, 0.3);
  text-align: center;
  width: clamp(260px, 90vw, 400px);
  border: 2px solid #ffd700;
  animation: fadeIn 0.3s ease;
  user-select: none;
  margin: 0 auto;
}

.modal-content h2 {
  margin-top: 0;
  font-weight: 700;
  font-size: clamp(1.3rem, 2.5vw, 1.6rem);
  color: #ffd700;
  text-shadow: 1px 1px 3px rgba(255, 255, 255, 0.3);
}

.modal-content label {
  display: block;
  margin-top: 15px;
  font-weight: 600;
  text-align: left;
  color: #f0f0f0;
  font-size: clamp(0.9rem, 2.2vw, 1rem);
}

.modal-content select,
.modal-content input[type=number],
.modal-content button {
  width: 100%;
  padding: 10px 14px;
  font-size: clamp(1rem, 2.5vw, 1.1rem);
  border-radius: 8px;
  border: none;
  margin-top: 6px;
  background: #34495e;
  color: #ffd700;
  box-shadow: 0 0 5px rgba(0, 255, 255, 0.2);
}

.modal-content input[type=number] {
  text-align: center;
}

.modal-content button {
  width: auto;
  min-width: 140px;
  max-width: 240px;
  display: block;
  margin: 20px auto 0;
  text-align: center;
  padding: 10px 16px;
  font-size: 1rem;
  background: #ffd700;
  color: #003344;
  border-radius: 8px;
  border: none;
  box-shadow: 0 0 5px rgba(0, 255, 255, 0.2);
  cursor: pointer;
  font-weight: 600;
}

.modal-content button:hover {
  background-color: #00e6e6;
  transform: scale(1.02);
}

/* Stats tab */

#statsTab {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #121b22;
  border: 2px solid #ffd700;
  border-radius: 12px;
  box-shadow: 0 0 16px rgba(0, 255, 255, 0.3);
  z-index: 1001;
  max-width: 400px;
  width: 90vw;
  padding: 20px;
  display: none;
  animation: fadeIn 0.3s ease;
}

#statsTab h2 {
  margin-top: 0;
  font-size: 1.4rem;
  color: #ffd700;
}

#statsContent {
  font-family: sans-serif;
  font-size: 14px;
  background: #f9f9f9;
  color: #333;
  border: 1px solid #ccc;
  padding: 10px;
  max-width: 100%;
  margin-top: 10px;
  border-radius: 8px;
}

#statsTab button {
  margin-top: 15px;
  padding: 8px 16px;
  font-size: 1rem;
  background: #ffd700;
  color: #003344;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 0 5px rgba(0, 255, 255, 0.2);
}

#statsTab button:hover {
  background-color: #00e6e6;
  transform: scale(1.02);
}

/* Animations */

@keyframes wave {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(5px, 5px); }
}

@keyframes moveUp {
  0% { bottom: 20px; opacity: 1; }
  80% { bottom: 110px; opacity: 1; }
  100% { bottom: 110px; opacity: 0; }
}

@keyframes spinArrow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* Cookie banner */

.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #222;
  color: #fff;
  padding: 15px;
  text-align: center;
  font-size: 14px;
  display: none;
  z-index: 9999;
}

.cookie-banner button {
  margin-left: 10px;
  padding: 6px 14px;
  background: #4CAF50;
  color: white;
  border: none;
  cursor: pointer;
  border-radius: 3px;
}

/* Footer */

#footer {
  width: 100%;
  padding: 10px 0;
  text-align: center;
  font-size: 12px;
  color: #ddd;
  background: #05070b;
  border-top: 1px solid #222;
  position: relative;
  margin-top: auto;
}

.footer-content a {
  color: #ffd700;
  text-decoration: none;
}

.footer-content a:hover {
  text-decoration: underline;
}
