:root {
  --bg: #ffffff;
  --ink: #121212;
  --muted: #727272;
  --grid-border: #121212;
  --cell-bg: #ffffff;
  --block-bg: #121212;
  --accent: #d81b60;
  --highlight-selected: #ffd700;
  --highlight-word: #a7d8ff;
  --shadow: rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 32px 48px;
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e0e0e0;
}

.timer {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.5px;
}

.masthead h1 {
  font-family: "Chomsky", "Playfair Display", Georgia, serif;
  font-weight: 700;
  margin: 0 0 8px;
  font-size: 42px;
  letter-spacing: -0.5px;
}

.meta {
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 16px;
}

.board {
  display: grid;
  grid-template-columns: minmax(400px, 600px) 1fr;
  gap: 40px;
  align-items: start;
}

.grid {
  display: grid;
  grid-template-columns: repeat(15, minmax(18px, 1fr));
  width: 100%;
  max-width: 600px;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--grid-border);
  background: var(--grid-border);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.cell {
  position: relative;
  background: var(--cell-bg);
  border: 1px solid var(--grid-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-transform: uppercase;
  text-align: center;
  font-size: clamp(16px, 2.8vw, 26px);
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #5a94d5;
  caret-color: transparent;
  cursor: pointer;
}

.cell input::selection {
  background: transparent;
}

.cell input:focus {
  outline: none;
}

.cell.block {
  background: var(--block-bg);
}

.cell.block input {
  display: none;
}

.cell .number {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 9px;
  color: var(--ink);
  font-weight: 600;
  pointer-events: none;
}

.cell.correct input {
  color: #5a94d5;
  font-weight: 700;
}

.cell.incorrect input {
  color: var(--ink);
  font-weight: 700;
}

.cell.incorrect::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to top right,
    transparent 0%,
    transparent calc(50% - 1px),
    #d32f2f calc(50% - 1px),
    #d32f2f calc(50% + 1px),
    transparent calc(50% + 1px),
    transparent 100%
  );
  pointer-events: none;
}

.cell.selected {
  background: var(--highlight-selected) !important;
}

.cell.highlighted {
  background: var(--highlight-word) !important;
}

.grid.lit .cell.theme-lit {
  background: #d81b60 !important;
  animation: darkPinkFill 0.4s ease-out forwards;
  box-shadow: 0 4px 20px rgba(216, 27, 96, 0.5);
  position: relative;
  z-index: 100;
}

.grid.lit .cell.theme-lit input {
  color: white !important;
}

.grid.lit .cell.theme-flying {
  animation: letterFlyOut 0.8s ease-in forwards;
}

.grid.fading {
  animation: fadeToRomantic 0.8s ease-out forwards;
}

@keyframes fadeToRomantic {
  to {
    opacity: 0.2;
    filter: blur(3px);
    transform: scale(0.98);
  }
}

@keyframes darkPinkFill {
  0% {
    background: white;
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    background: #d81b60;
    transform: scale(1);
  }
}

@keyframes letterFlyOut {
  0% {
    transform: scale(1) translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: scale(0.5) translateY(-80vh) rotate(360deg);
    opacity: 0;
  }
}

@keyframes glowPulse {
  0%, 100% {
    background: #ffe4f1;
    box-shadow: 0 0 12px rgba(216, 27, 96, 0.5);
    transform: scale(1);
  }
  50% {
    background: #ffc0e0;
    box-shadow: 0 0 24px rgba(216, 27, 96, 0.8);
    transform: scale(1.05);
  }
}


.clues {
  background: #fafafa;
  border-radius: 0;
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  position: sticky;
  top: 20px;
  border: 1px solid #e0e0e0;
}

.clue-group h2 {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink);
}

.clue-group ol {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 15px;
  line-height: 1.9;
}

.clue-group li {
  margin-bottom: 10px;
  display: flex;
  gap: 10px;
  color: var(--muted);
  padding: 6px 8px;
  margin-left: -8px;
  margin-right: -8px;
  border-radius: 4px;
  transition: background-color 0.2s ease, color 0.2s ease;
  cursor: pointer;
}

.clue-group li:hover {
  background-color: #f0f0f0;
}

.clue-group li.active-clue {
  background-color: #ffd700;
  color: var(--ink);
  font-weight: 600;
}

.clue-group li.active-clue .clue-number {
  color: var(--ink);
}

.clue-number {
  font-weight: 700;
  color: var(--ink);
  min-width: 32px;
  flex-shrink: 0;
}

.completion-message {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
  z-index: 1000;
}

.completion-message.show {
  opacity: 1;
  pointer-events: all;
}

.completion-card {
  background: linear-gradient(135deg, #fff 0%, #ffe9f3 100%);
  border: 2px solid var(--accent);
  padding: 60px 80px;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(216, 27, 96, 0.4);
  text-align: center;
  animation: completionBounce 0.6s ease-out;
  max-width: 90vw;
}

@keyframes completionBounce {
  0% {
    transform: scale(0.3) translateY(-100px);
    opacity: 0;
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.completion-title {
  font-family: "Chomsky", Georgia, serif;
  font-size: 48px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 24px;
}

.completion-text {
  font-family: Georgia, serif;
  font-size: 32px;
  margin-bottom: 16px;
  color: var(--ink);
}

.completion-subtitle {
  font-size: 24px;
  color: var(--accent);
  font-weight: 600;
}

.message-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255, 182, 193, 0.15) 0%, rgba(255, 218, 224, 0.2) 100%);
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 2000;
}

.message-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.grid.lit .cell.theme-flying {
  animation: letterFlyOut 1s ease-in forwards;
}

@keyframes letterFlyOut {
  0% {
    transform: scale(1) translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: scale(0.3) translateY(-100vh) rotate(720deg);
    opacity: 0;
  }
}

.scrabble-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  justify-content: center;
}

.scrabble-tile {
  position: fixed;
  width: 50px;
  height: 50px;
  background: #d81b60;
  border: 2px solid #c2185b;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 8px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  left: var(--start-x);
  top: var(--start-y);
  opacity: 0;
  transform: translate(-50%, -50%) rotate(0deg);
}

.scrabble-container.animate .scrabble-tile {
  animation: percyJacksonScramble 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes percyJacksonScramble {
  0% {
    left: var(--scramble-x);
    top: var(--scramble-y);
    transform: translate(-50%, -50%) rotate(0deg) scale(0.5);
    opacity: 0;
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(720deg) scale(0.8);
  }
  70% {
    transform: translate(-50%, -50%) rotate(360deg) scale(1.1);
  }
  85% {
    transform: translate(-50%, -50%) rotate(0deg) scale(0.95);
  }
  100% {
    left: var(--final-x);
    top: var(--final-y);
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
    opacity: 1;
  }
}

.tile-letter {
  font-size: 32px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.button-container {
  position: fixed;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 30px;
  z-index: 3000;
  animation: fadeInButtons 0.5s ease-in forwards;
}

@keyframes fadeInButtons {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.response-btn {
  padding: 16px 40px;
  font-size: 24px;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.yes-btn {
  background: linear-gradient(135deg, #ff6b9d 0%, #c44569 100%);
  color: white;
}

.yes-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(255, 107, 157, 0.5);
}

.no-btn {
  background: linear-gradient(135deg, #666 0%, #444 100%);
  color: white;
}

.no-btn:hover {
  transform: scale(1.05);
}

.celebration {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 3000;
  opacity: 0;
  animation: fadeIn 0.4s ease-out forwards;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

.video-container {
  position: relative;
  width: 560px;
  max-width: 90vw;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.video-container iframe {
  display: block;
}

.celebration-text {
  font-size: 36px;
  margin-top: 20px;
  color: #d81b60;
  font-weight: 600;
  text-align: center;
}

@media (max-width: 980px) {
  .board {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .grid {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
  }

  .clues {
    grid-template-columns: 1fr;
    max-height: none;
    position: static;
  }

  .masthead h1 {
    font-size: 28px;
  }

  .masthead {
    padding: 16px;
  }
}

/* iPhone 14 and similar devices */
@media (max-width: 430px) {
  body {
    font-size: 14px;
  }

  .page {
    padding: 12px;
  }

  .masthead {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .masthead h1 {
    font-size: 24px;
  }

  .grid {
    width: 100%;
    max-width: 100vw;
    aspect-ratio: 1;
  }

  .cell {
    min-width: 0;
    font-size: 14px;
  }

  .cell input {
    font-size: 16px;
  }

  .cell .number {
    font-size: 7px;
  }

  .clue-group {
    padding: 12px;
  }

  .clue-group h2 {
    font-size: 12px;
  }

  .clue-group li {
    font-size: 13px;
    line-height: 1.6;
  }

  /* Mobile buttons */
  .button-container {
    bottom: 10%;
    gap: 20px;
    flex-direction: column;
    width: 80%;
  }

  .response-btn {
    width: 100%;
    padding: 16px 32px;
    font-size: 18px;
  }

  /* Mobile tiles */
  .scrabble-tile {
    width: 40px;
    height: 40px;
  }

  .tile-letter {
    font-size: 24px;
  }

  /* Video on mobile */
  .video-container {
    width: 90vw;
    max-width: 100%;
  }

  .video-container iframe {
    width: 100%;
    height: 50vh;
  }

  .celebration-text {
    font-size: 24px;
    padding: 0 20px;
  }
}
