﻿:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #1c1a17;
  --muted: #5c564c;
  --panel: #fffdf8;
  --line: #d9d1c3;
  --focus: #0b5cab;
  --correct: #0f6b3c;
  --correct-ink: #ffffff;
  --present: #8a4b08;
  --present-ink: #ffffff;
  --absent: #5e6570;
  --absent-ink: #ffffff;
  --tile: clamp(2.15rem, 12vw, 3.5rem);
  --guess: #0e8f86;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  font-size: 1.05rem;
  line-height: 1.45;
}

.game {
  width: min(40rem, calc(100% - 2rem));
  margin: 0 auto;
  flex: 1;
  padding: 1.5rem 0 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1rem;
}

h1,
h1 a {
  display: flex;
  justify-content: center;
  width: 100%;
  margin: 0;
}

.logo {
  display: block;
  width: min(28rem, 100%);
  height: auto;
}

.how-to-line {
  margin: 0;
}

.length-label {
  margin: 0.35rem 0 0;
  width: 100%;
  font-size: 0.95rem;
  color: var(--muted);
}

.length-name {
  position: relative;
  display: inline-block;
}

.length-name .points {
  position: absolute;
  left: calc(100% + 0.45rem);
  top: 50%;
  margin: 0;
  transform: translateY(-50%);
  color: var(--correct);
  font-weight: 750;
  white-space: nowrap;
}

.extra-buy {
  flex: 0 0 100%;
  display: flex;
  justify-content: center;
}

.copyright {
  margin: 0;
  padding: 0 1rem 1.25rem;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}

#extra-count {
  width: 4.5rem;
  min-height: 2.75rem;
  font: inherit;
  text-align: center;
  border: 2px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--ink);
}

dialog {
  border: 2px solid var(--line);
  border-radius: 0.75rem;
  padding: 1.25rem 1.4rem;
  max-width: 36rem;
  width: calc(100% - 2rem);
  color: var(--ink);
  background: var(--panel);
  text-align: left;
}

dialog::backdrop {
  background: rgba(28, 26, 23, 0.45);
}

dialog h2 {
  margin: 0 0 0.75rem;
  text-align: center;
}

dialog p {
  margin: 0 0 0.75rem;
}

dialog button {
  display: block;
  margin: 0.5rem auto 0;
}

.score-line,
.actions,
.offer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.75rem 1rem;
}

.offer {
  flex-direction: column;
}

select,
button,
.tile-input {
  font: inherit;
}

select {
  min-height: 2.75rem;
  min-width: 10rem;
  padding: 0.35rem 0.6rem;
  border: 2px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--ink);
}

.status,
.score-line,
.result {
  margin: 0;
}

.status {
  font-size: 1.65rem;
  font-weight: 750;
}

.status.game-over {
  font-size: 4em;
  line-height: 1.05;
  text-shadow: 2px 2px 0 #ff0000, 4px 4px 0 #0000ff;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.score-line {
  font-size: 1.85rem;
  font-weight: 750;
}

.flip-score {
  display: inline-flex;
  gap: 0.16rem;
  margin-left: 0.35rem;
  vertical-align: middle;
}

.flap {
  position: relative;
  display: inline-grid;
  place-items: center;
  min-width: 0.92em;
  height: 1.35em;
  padding: 0 0.08em;
  border-radius: 0.16em;
  background: linear-gradient(#314056 0 49.5%, #1b2636 50.5% 100%);
  color: #f6f0e4;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  box-shadow: 0 0.12em 0 #0c121a, inset 0 1px 0 rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.flap::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% - 1px);
  height: 2px;
  background: #0b1016;
  z-index: 1;
}

.flap.turning .flap-num {
  animation: flap-drop 0.42s ease-out;
  transform-origin: center top;
}

@keyframes flap-drop {
  0% { transform: rotateX(-88deg); }
  100% { transform: rotateX(0); }
}

.board {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
}

.row,
.guess-form {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 0.35rem;
  width: 100%;
}

.guess-form {
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.row {
  align-items: center;
}

.letters {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.multiplier {
  position: absolute;
  left: calc(100% + 0.55rem);
  top: 50%;
  transform: translateY(-50%);
  color: var(--guess);
  font-size: 1.25rem;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
}

.tile-slot {
  font: inherit;
  cursor: text;
  appearance: none;
}

.guess-capture {
  position: absolute;
  z-index: 2;
  margin: 0;
}

.cost {
  position: absolute;
  left: calc(100% + 0.55rem);
  top: 50%;
  transform: translateY(-50%);
  color: #c62828;
  font-size: 1.25rem;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
}

.tile {
  position: relative;
  cursor: help;
}

.tile:hover::after {
  content: attr(data-worth);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.3rem);
  transform: translateX(-50%);
  padding: 0.2rem 0.45rem;
  border-radius: 0.35rem;
  background: #243044;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  z-index: 3;
  pointer-events: none;
}

.tile,
.tile-input,
.tile-slot {
  width: var(--tile);
  min-height: 2.75rem;
  margin: 0;
  padding: 0.2rem 0.1rem 0.3rem;
  border: 2px solid var(--line);
  border-radius: 0.45rem;
  background: var(--panel);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.tile-input {
  text-align: center;
  text-transform: uppercase;
  font-size: clamp(1.15rem, 4vw, 1.6rem);
  font-weight: 750;
}

.tile-letter {
  font-size: clamp(1.15rem, 4vw, 1.6rem);
  font-weight: 750;
  line-height: 1;
}

.tile-state {
  margin-top: 0.15rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.1;
  text-transform: lowercase;
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: var(--correct-ink);
}

.tile.hint {
  z-index: 1;
  animation: hint-throb 1.15s ease-in-out infinite;
}

@keyframes hint-throb {
  0%,
  100% {
    box-shadow: 0 0 0.15rem rgba(255, 214, 0, 0.35);
  }
  50% {
    box-shadow: 0 0 0.25rem 0.45rem rgba(255, 214, 0, 0.95), 0 0 1.35rem 0.15rem rgba(255, 190, 0, 0.8);
  }
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: var(--present-ink);
}

.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: var(--absent-ink);
}

button {
  min-height: 2.75rem;
  padding: 0.45rem 1rem;
  border: 2px solid transparent;
  border-radius: 0.5rem;
  background: #243044;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button.secondary {
  background: var(--panel);
  color: var(--ink);
  border-color: #243044;
}

#submit-guess {
  background: var(--guess);
  border-color: var(--guess);
  color: #fff;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.actions .result {
  flex-basis: 100%;
  font-size: 1.25rem;
  font-weight: 750;
}

.result.winner {
  font-size: clamp(2rem, 8vw, 3.1rem);
  font-weight: 800;
  letter-spacing: 0.14em;
}

.result.winner span {
  display: inline-block;
  animation: prism 1.8s ease-in-out infinite alternate;
  animation-delay: calc(var(--i) * 0.14s);
}

@keyframes prism {
  0% { color: hsl(0, 92%, 52%); }
  16% { color: hsl(28, 96%, 50%); }
  33% { color: hsl(52, 95%, 46%); }
  50% { color: hsl(145, 75%, 38%); }
  66% { color: hsl(200, 90%, 46%); }
  83% { color: hsl(265, 85%, 58%); }
  100% { color: hsl(325, 90%, 54%); }
}

.notice {
  flex: 0 0 100%;
  margin: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (min-width: 40rem) {
  :root {
    --tile: clamp(2.75rem, 8vw, 3.5rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
    transition: none;
  }

  .result.winner span,
  .status.game-over {
    animation: none;
  }

  .result.winner span:nth-child(1) { color: hsl(0, 92%, 52%); }
  .result.winner span:nth-child(2) { color: hsl(28, 96%, 50%); }
  .result.winner span:nth-child(3) { color: hsl(52, 95%, 46%); }
  .result.winner span:nth-child(4) { color: hsl(145, 75%, 38%); }
  .result.winner span:nth-child(5) { color: hsl(200, 90%, 46%); }
  .result.winner span:nth-child(6) { color: hsl(265, 85%, 58%); }
  .result.winner span:nth-child(7) { color: hsl(325, 90%, 54%); }

  .tile.hint {
    animation: none;
    box-shadow: 0 0 0.55rem 0.2rem rgba(255, 214, 0, 0.9);
  }

  .flap.turning .flap-num {
    animation: none;
  }
}
