:root {
  --bg: #121213;
  --bg-raised: #1c1c1e;
  --text: #e7e7e9;
  --text-dim: #818384;
  --border: #3a3a3c;
  --border-active: #565758;
  --green: #538d4e;
  --yellow: #b59f3b;
  --gray: #3a3a3c;
  --key: #818384;
  --key-text: #e7e7e9;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* ------------------------------------------------------------------ header */

header {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.header-side {
  display: flex;
  gap: 4px;
  flex: 1;
}

.header-right {
  justify-content: flex-end;
}

.header-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

h1 {
  font-size: clamp(1.15rem, 4.5vw, 1.6rem);
  letter-spacing: 0.14em;
  font-weight: 800;
}

.puzzle-number {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.practice-badge {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--bg);
  background: var(--text-dim);
  border-radius: 3px;
  padding: 1px 6px;
  margin-top: 3px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  padding: 6px 4px;
}

.text-btn:hover {
  color: var(--text);
}

/* ------------------------------------------------------------------- board */

main {
  width: 100%;
  max-width: 500px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
}

.board {
  position: relative;
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  gap: 5px;
  padding: 6px 0;
  flex: 1;
  max-height: min(52vh, 380px);
  aspect-ratio: 1 / 1;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  font-size: clamp(1.1rem, 5.5vmin, 2rem);
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
  aspect-ratio: 1;
  transition: transform 0.08s ease;
}

.tile.filled {
  border-color: var(--border-active);
}

.tile.pop {
  animation: pop 0.09s ease;
}

@keyframes pop {
  50% { transform: scale(1.08); }
}

.tile.flip {
  animation: flip 0.52s ease;
}

@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}

.tile[data-state] {
  border-color: transparent;
  color: #fff;
}

.tile[data-state="green"] { background: var(--green); }
.tile[data-state="yellow"] { background: var(--yellow); }
.tile[data-state="gray"] { background: var(--gray); }

/* A rare, almost imperceptible twitch. Nothing is wrong. */
.row:nth-child(2) .tile:nth-child(4)[data-state],
.row:nth-child(4) .tile:nth-child(2)[data-state] {
  animation: twitch 53s linear infinite;
}

@keyframes twitch {
  0%, 97.2%, 98%, 100% { transform: none; filter: none; }
  97.4% { transform: translateX(0.7px) rotate(0.35deg); filter: brightness(1.12); }
  97.7% { transform: translateX(-0.4px); }
}

.row.shake {
  animation: shake 0.5s ease;
}

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

/* -------------------------------------------------------------------- cats */

.cat {
  position: fixed;
  z-index: 10;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.cat svg,
.cat img {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

/* Walking: a little bob, and flip when heading left */
.cat.walking {
  animation: cat-bob 0.4s ease-in-out infinite;
}

@keyframes cat-bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -3px; }
}

.cat.facing-left svg,
.cat.facing-left img {
  transform: scaleX(-1);
}

.cat.walking .cat-leg-a {
  animation: cat-step 0.4s ease-in-out infinite;
}

.cat.walking .cat-leg-b {
  animation: cat-step 0.4s ease-in-out infinite reverse;
}

@keyframes cat-step {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

/* Getting comfy: kneading wiggle, then slow loaf breathing */
.cat.kneading {
  animation: cat-knead 0.45s ease-in-out infinite;
}

@keyframes cat-knead {
  0%, 100% { transform: rotate(-2deg) scale(1); }
  50% { transform: rotate(2deg) scale(0.97, 1.02); }
}

.cat.comfy {
  animation: cat-breathe 3.2s ease-in-out infinite;
}

@keyframes cat-breathe {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.02, 0.965); }
}

/* Occasional slow blink for drawn eyes */
.cat .cat-eyes {
  animation: cat-blink 7s linear infinite;
}

@keyframes cat-blink {
  0%, 95.5%, 98.5%, 100% { opacity: 1; }
  96.5%, 97.5% { opacity: 0; }
}

/* Being carried: dangling, slightly swinging, very tolerant */
.cat.carried {
  cursor: grabbing;
  z-index: 18;
  animation: cat-dangle 1.6s ease-in-out infinite;
}

@keyframes cat-dangle {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

/* ---------------------------------------------------------------- keyboard */

.keyboard {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0 10px;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  flex: 1;
  max-width: 44px;
  height: 54px;
  border: none;
  border-radius: 4px;
  background: var(--key);
  color: var(--key-text);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease 0.05s;
}

.key:active {
  filter: brightness(1.25);
}

.key-wide {
  flex: 1.6;
  max-width: 72px;
  font-size: 0.65rem;
}

.key[data-state="green"] { background: var(--green); }
.key[data-state="yellow"] { background: var(--yellow); }
.key[data-state="gray"] { background: var(--gray); color: var(--text-dim); }

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 10px 16px;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}

.toast.show {
  opacity: 1;
}

/* ------------------------------------------------------------------ modals */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  position: relative;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  animation: modal-in 0.22s ease;
}

@keyframes modal-in {
  from { transform: translateY(14px) scale(0.98); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.modal h2 {
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}

.modal p {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text);
}

.intro-text {
  letter-spacing: 0.02em;
  margin-bottom: 22px;
}

.end-word {
  margin-bottom: 4px;
}

.end-count {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.modal-btn {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 28px;
  cursor: pointer;
}

.modal-btn:hover {
  filter: brightness(1.1);
}

.modal-x {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.modal-x:hover {
  color: var(--text);
}

@media (max-width: 420px) {
  .text-btn { font-size: 0.62rem; padding: 6px 2px; }
  .key { height: 48px; }
}
