:root {
  --bg: #0e1627;
  --bg-glow: #1b2a4a;
  --tile: #16213a;
  --tile-border: #2a3a5e;
  --tile-filled: #6f84b3;
  --key: #26365a;
  --text: #eaf0ff;
  --muted: #8d9bc0;
  --correct: #22c3a0;
  --present: #f5a524;
  --absent: #3b4768;
  --accent: #8b6cff;
  --hint: #ffd166;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  font-family: "Outfit", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(900px 500px at 50% -10%, var(--bg-glow), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 1000px;
  padding: 20px 14px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* Header */
.top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
h1 { margin: 0; font-size: 2rem; font-weight: 800; letter-spacing: 0.04em; line-height: 1; }
.tagline { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; }

.chip {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s;
}
.chip:hover { background: rgba(255, 255, 255, 0.14); }

button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Hint bar */
.hint-bar {
  width: min(100%, 340px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hint-slots { display: flex; gap: 6px; }

.slot {
  width: 34px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  text-transform: uppercase;
  border-radius: 8px;
  border: 2px dashed var(--tile-border);
  color: transparent;
}
.slot.revealed {
  border: 2px solid var(--hint);
  background: rgba(255, 209, 102, 0.14);
  color: var(--hint);
  animation: pop 0.25s ease;
}

.hint-btn {
  font: inherit;
  font-weight: 600;
  color: #3a2a00;
  background: var(--hint);
  border: 0;
  border-radius: 999px;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.1s, filter 0.15s;
}
.hint-btn:hover:not(:disabled) { filter: brightness(1.06); }
.hint-btn:active:not(:disabled) { transform: scale(0.96); }
.hint-btn:disabled { background: var(--absent); color: var(--muted); cursor: not-allowed; }

/* Board */
.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 7px;
  width: min(100%, 340px);
}
.row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }

.tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--tile);
  border: 2px solid var(--tile-border);
  border-radius: 10px;
  user-select: none;
}
.tile.filled { border-color: var(--tile-filled); animation: pop 0.12s ease; }
.tile.correct, .tile.present, .tile.absent { color: #fff; border-color: transparent; }
.tile.correct { background: var(--correct); }
.tile.present { background: var(--present); }
.tile.absent  { background: var(--absent); }
.tile.flip { animation: flip 0.5s ease forwards; }

.row.shake { animation: shake 0.4s ease; }
.row.win .tile { animation: bounce 0.6s ease; animation-delay: calc(var(--i) * 0.08s); }

@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes bounce { 40% { transform: translateY(-14px); } 70% { transform: translateY(2px); } }

/* Layout: board on the left, small keyboard on the right */
.play {
  display: grid;
  grid-template-columns: 1fr 340px 1fr;
  align-items: center;
  width: 100%;
}
.left { grid-column: 2; }
.keyboard { grid-column: 3; justify-self: end; }
.left { display: flex; flex-direction: column; align-items: center; gap: 16px; }

/* Keyboard */
.keyboard { width: 292px; flex-shrink: 0; display: flex; flex-direction: column; gap: 5px; }
.krow { display: flex; justify-content: center; gap: 4px; }

.key {
  flex: 1;
  max-width: 26px;
  height: 36px;
  font: inherit;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text);
  background: var(--key);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  transition: transform 0.08s, filter 0.15s;
}
.key.wide { max-width: 42px; font-size: 0.6rem; }
.key:hover { filter: brightness(1.15); }
.key:active { transform: scale(0.94); }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent {
  background: #080d18;
  color: #56648a;
  text-decoration: line-through;
  box-shadow: inset 0 0 0 1px #1b2640;
  opacity: 0.75;
}
.key.absent:hover { filter: none; }

/* Toast */
.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: #fff;
  color: #1a2340;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
  max-width: 92vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Result modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 9, 20, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.modal.hidden { display: none; }

.modal-card {
  background: #18254a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 30px 24px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: rise 0.25s ease;
}
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }

.result-badge {
  width: 64px;
  height: 64px;
  margin: -62px auto 12px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: var(--badge, #26365a);
  border: 4px solid #18254a;
}
.modal-card { position: relative; margin-top: 32px; }

/* Won */
.modal-card.win {
  --badge: var(--correct);
  border-color: var(--correct);
  box-shadow: 0 0 0 1px var(--correct), 0 24px 60px rgba(34, 195, 160, 0.25);
}
.modal-card.win .result-title { color: var(--correct); font-weight: 700; }
.modal-card.win .result-word { color: #7ff0d6; }

/* Lost */
.modal-card.lose {
  --badge: #ff6b6b;
  border-color: #ff6b6b;
  box-shadow: 0 0 0 1px #ff6b6b, 0 24px 60px rgba(255, 107, 107, 0.22);
}
.modal-card.lose .result-title { color: #ff8e8e; font-weight: 700; }
.modal-card.lose .result-word { color: #ffb0b0; }

.result-title { margin: 0 0 6px; font-weight: 500; color: var(--muted); }
.result-word { margin: 0; font-size: 2.6rem; font-weight: 800; text-transform: capitalize; letter-spacing: 0.03em; }
.result-pos {
  display: inline-block;
  margin: 8px 0 14px;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(139, 108, 255, 0.22);
  color: #c9bbff;
  font-size: 0.85rem;
  font-weight: 600;
}
.result-pos:empty { display: none; }
.result-meaning { margin: 0 0 24px; line-height: 1.6; font-size: 1.05rem; color: #dbe4ff; }

.primary {
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  padding: 12px 28px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.primary:hover { filter: brightness(1.1); }
.primary:active { transform: scale(0.97); }

/* Narrow screens: keyboard drops below the board */
@media (max-width: 960px) {
  .play { display: flex; flex-direction: column; align-items: center; gap: 18px; }
  .keyboard { width: 100%; max-width: 380px; justify-self: auto; }
  .key { max-width: 34px; height: 44px; font-size: 0.9rem; }
  .key.wide { max-width: 52px; font-size: 0.7rem; }
}

@media (max-width: 420px) {
  .tile { font-size: 1.6rem; }
  .tagline { font-size: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.retry {
  font: inherit;
  font-weight: 600;
  color: var(--hint);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}
