/* ===== Worldle Custom Styles ===== */

/* ---- CSS Variables ---- */
:root {
  --tile-size: clamp(48px, 12vw, 60px);
  --tile-gap: 5px;
  --tile-font: clamp(1.4rem, 4vw, 2rem);
  --kb-key-size: clamp(28px, 8vw, 44px);
  --kb-key-font: clamp(0.7rem, 2vw, 0.95rem);
  --kb-gap: 4px;

  --color-correct: #6aaa64;
  --color-present: #c9b458;
  --color-absent: #787c7e;
  --color-tile-border: #d3d6da;
  --color-tile-border-filled: #878a8c;
  --color-tile-bg: #ffffff;
  --color-key-bg: #d3d6da;
  --color-key-text: #1a1a1b;
  --color-key-correct: #6aaa64;
  --color-key-present: #c9b458;
  --color-key-absent: #787c7e;

  --flip-duration: 0.3s;
  --flip-stagger: 0.1s;
}

/* ---- Welcome Overlay ---- */
.welcome-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--bg, #f6f1ea);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.welcome-overlay.hidden {
  display: none;
}

.welcome-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.welcome-icon {
  font-size: 4rem;
  margin-bottom: 4px;
}

.welcome-title {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin: 0 0 2px;
  color: var(--ink);
}

.welcome-subtitle {
  font-size: 1rem;
  color: var(--soft);
  margin: 0 0 28px;
}

.welcome-tiles {
  display: flex;
  gap: 6px;
  margin-bottom: 32px;
}

.welcome-tile {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
}

.welcome-tile.wc1 { background: #6aaa64; }
.welcome-tile.wc2 { background: #c9b458; }
.welcome-tile.wc3 { background: #787c7e; }
.welcome-tile.wc4 { background: #6aaa64; }
.welcome-tile.wc5 { background: #c9b458; }

.btn-begin {
  font-size: 1.2rem;
  padding: 14px 48px;
  border-radius: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ---- Header ---- */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 500px;
  margin: 0 auto 12px;
  padding: 0 4px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.game-title {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--ink);
  user-select: none;
}

.header-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--soft);
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}
.header-btn:hover {
  background: var(--line);
  color: var(--ink);
}

/* ---- Game Main ---- */
.game-main {
  max-width: 500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* ---- Tile Grid ---- */
.grid {
  display: grid;
  grid-template-rows: repeat(6, var(--tile-size));
  grid-template-columns: repeat(5, var(--tile-size));
  gap: var(--tile-gap);
  justify-content: center;
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--tile-font);
  font-weight: 700;
  text-transform: uppercase;
  border-radius: 4px;
  user-select: none;
  transition: transform 0.1s;
}

/* Empty tile */
.tile.empty {
  background: var(--color-tile-bg);
  border: 2px solid var(--color-tile-border);
  color: transparent;
}

/* Filled unsubmitted tile */
.tile.filled {
  background: var(--color-tile-bg);
  border: 2px solid var(--color-tile-border-filled);
  color: var(--ink);
}

/* Current row highlight — subtle pulse on the empty tile being typed */
.tile.current-empty {
  border-color: var(--accent);
  border-width: 2px;
}

/* Submitted tile colors */
.tile.correct {
  background: var(--color-correct);
  border-color: var(--color-correct);
  color: #fff;
}
.tile.present {
  background: var(--color-present);
  border-color: var(--color-present);
  color: #fff;
}
.tile.absent {
  background: var(--color-absent);
  border-color: var(--color-absent);
  color: #fff;
}

/* ---- Flip Animation ---- */
.tile.flip {
  animation: flipIn var(--flip-duration) ease forwards;
}

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

/* Pop animation on letter entry */
.tile.pop {
  animation: popIn 0.08s ease;
}
@keyframes popIn {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Shake animation for invalid word */
.tile.shake {
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ---- Endgame Area ---- */
.endgame {
  text-align: center;
  min-height: 60px;
}
.endgame-message {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 10px;
  color: var(--ink);
}
.endgame-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---- On-Screen Keyboard (3D Feather) ---- */
.keyboard {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--kb-gap) + 4px);
  margin-top: 8px;
  touch-action: manipulation;
  perspective: 600px;
}

.kb-row {
  display: flex;
  gap: calc(var(--kb-gap) + 2px);
  justify-content: center;
  width: 100%;
}

/* ── 3D Feather Key ── */
.kb-key {
  height: var(--kb-key-size);
  min-width: var(--kb-key-size);
  padding: 0 4px;
  border: none;
  border-radius: 8px;
  color: var(--color-key-text);
  font-size: var(--kb-key-font);
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;

  /* ── 3D Feather base look ── */
  position: relative;
  transform-style: preserve-3d;
  transform:
    rotateX(15deg)
    translateY(0px);
  transition:
    transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.18s ease,
    filter 0.15s ease;

  /* Soft feather-like gradient: light top, slightly darker bottom */
  background:
    linear-gradient(
      180deg,
      #f0ebe0 0%,
      #e8e0d3 30%,
      #dbd2c4 60%,
      #cbc2b3 100%
    );

  /* Multi-layered shadow for 3D depth */
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.6) inset,
    0 -1px 0 0 rgba(0,0,0,0.06) inset,
    0 3px 0 0 #b8afa0,
    0 4px 6px rgba(0,0,0,0.12),
    0 6px 12px rgba(0,0,0,0.06);

  /* Subtle feather texture via pseudo-element */
  overflow: hidden;
}

/* Feather texture overlay */
.kb-key::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 3px,
      rgba(255,255,255,0.08) 3px,
      rgba(255,255,255,0.08) 4px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 6px,
      rgba(0,0,0,0.02) 6px,
      rgba(0,0,0,0.02) 7px
    );
  pointer-events: none;
  z-index: 1;
}

/* Subtle top highlight sheen */
.kb-key::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 4px;
  right: 4px;
  height: 40%;
  border-radius: 6px 6px 50% 50%;
  background: linear-gradient(
    180deg,
    rgba(255,255,255,0.45) 0%,
    rgba(255,255,255,0.1) 60%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 2;
}

/* Hover: key lifts up like a feather floating */
.kb-key:hover {
  transform:
    rotateX(10deg)
    translateY(-4px);
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.6) inset,
    0 -1px 0 0 rgba(0,0,0,0.06) inset,
    0 5px 0 0 #b8afa0,
    0 8px 10px rgba(0,0,0,0.14),
    0 12px 20px rgba(0,0,0,0.08);
}

/* Active: key presses down */
.kb-key:active {
  transform:
    rotateX(5deg)
    translateY(2px);
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.4) inset,
    0 -1px 0 0 rgba(0,0,0,0.04) inset,
    0 1px 0 0 #b8afa0,
    0 2px 4px rgba(0,0,0,0.1);
  transition:
    transform 0.06s ease,
    box-shadow 0.06s ease;
}

.kb-key.wide {
  min-width: calc(var(--kb-key-size) * 1.6);
  font-size: calc(var(--kb-key-font) * 0.85);
}

/* ── Color states with feather-appropriate gradients ── */

/* Correct (green) — warm earthy green */
.kb-key.key-correct {
  color: #fff;
  background:
    linear-gradient(
      180deg,
      #7dbf73 0%,
      #6aaa64 30%,
      #5a9a54 60%,
      #4a8a44 100%
    );
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.35) inset,
    0 -1px 0 0 rgba(0,0,0,0.1) inset,
    0 3px 0 0 #3d7038,
    0 4px 6px rgba(0,0,0,0.12),
    0 6px 12px rgba(0,0,0,0.06);
}
.kb-key.key-correct:hover {
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.35) inset,
    0 -1px 0 0 rgba(0,0,0,0.1) inset,
    0 5px 0 0 #3d7038,
    0 8px 10px rgba(0,0,0,0.14),
    0 12px 20px rgba(0,0,0,0.08);
}
.kb-key.key-correct:active {
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.25) inset,
    0 -1px 0 0 rgba(0,0,0,0.08) inset,
    0 1px 0 0 #3d7038,
    0 2px 4px rgba(0,0,0,0.1);
}

/* Present (yellow) — warm golden */
.kb-key.key-present {
  color: #fff;
  background:
    linear-gradient(
      180deg,
      #dcc870 0%,
      #c9b458 30%,
      #b9a448 60%,
      #a99438 100%
    );
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.35) inset,
    0 -1px 0 0 rgba(0,0,0,0.1) inset,
    0 3px 0 0 #8a7a2e,
    0 4px 6px rgba(0,0,0,0.12),
    0 6px 12px rgba(0,0,0,0.06);
}
.kb-key.key-present:hover {
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.35) inset,
    0 -1px 0 0 rgba(0,0,0,0.1) inset,
    0 5px 0 0 #8a7a2e,
    0 8px 10px rgba(0,0,0,0.14),
    0 12px 20px rgba(0,0,0,0.08);
}
.kb-key.key-present:active {
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.25) inset,
    0 -1px 0 0 rgba(0,0,0,0.08) inset,
    0 1px 0 0 #8a7a2e,
    0 2px 4px rgba(0,0,0,0.1);
}

/* Absent (gray) — muted slate */
.kb-key.key-absent {
  color: #fff;
  background:
    linear-gradient(
      180deg,
      #94989a 0%,
      #787c7e 30%,
      #686c6e 60%,
      #585c5e 100%
    );
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.25) inset,
    0 -1px 0 0 rgba(0,0,0,0.12) inset,
    0 3px 0 0 #4a4e50,
    0 4px 6px rgba(0,0,0,0.12),
    0 6px 12px rgba(0,0,0,0.06);
}
.kb-key.key-absent:hover {
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.25) inset,
    0 -1px 0 0 rgba(0,0,0,0.12) inset,
    0 5px 0 0 #4a4e50,
    0 8px 10px rgba(0,0,0,0.14),
    0 12px 20px rgba(0,0,0,0.08);
}
.kb-key.key-absent:active {
  box-shadow:
    0 1px 0 0 rgba(255,255,255,0.15) inset,
    0 -1px 0 0 rgba(0,0,0,0.1) inset,
    0 1px 0 0 #4a4e50,
    0 2px 4px rgba(0,0,0,0.1);
}

/* ---- Toast Notifications ---- */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  animation: toastIn 0.25s ease forwards;
  pointer-events: auto;
  white-space: nowrap;
}

.toast.out {
  animation: toastOut 0.3s ease forwards;
}

.toast.error {
  background: #d9534f;
}
.toast.success {
  background: #5cb85c;
}
.toast.info {
  background: #5bc0de;
}

@keyframes toastIn {
  0% { opacity: 0; transform: translateY(-20px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-20px); }
}

/* ---- Modal Overlay ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

/* Override the class display:flex when hidden attribute is present,
   so the overlay truly vanishes and stops intercepting clicks. */
.modal-overlay[hidden] {
  display: none;
}

@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.modal {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 24px 24px;
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  0% { opacity: 0; transform: scale(0.92) translateY(10px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--soft);
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
.modal-close:hover {
  background: var(--line);
  color: var(--ink);
}

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.stat-item {
  text-align: center;
}
.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.1;
}
.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--soft);
  margin-top: 2px;
}

/* ---- Guess Distribution ---- */
.distribution {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dist-label {
  width: 20px;
  text-align: right;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--soft);
  flex-shrink: 0;
}

.dist-bar-wrap {
  flex: 1;
  height: 22px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.dist-bar {
  height: 100%;
  background: var(--color-absent);
  border-radius: 4px;
  min-width: 0;
  transition: width 0.4s ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
}

.dist-bar.highlight {
  background: var(--color-correct);
}

.dist-count {
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  min-width: 16px;
  text-align: right;
}

/* ---- Help Modal ---- */
.help-content p {
  margin: 0 0 12px;
  font-size: 0.95rem;
}

.help-examples {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.help-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.help-tile {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  border-radius: 4px;
  border: 2px solid var(--color-tile-border);
  background: #fff;
  color: var(--ink);
  flex-shrink: 0;
}

.help-tile.correct {
  background: var(--color-correct);
  border-color: var(--color-correct);
  color: #fff;
}
.help-tile.present {
  background: var(--color-present);
  border-color: var(--color-present);
  color: #fff;
}
.help-tile.absent {
  background: var(--color-absent);
  border-color: var(--color-absent);
  color: #fff;
}

.help-label {
  font-size: 0.85rem;
  color: var(--ink);
  margin-left: 4px;
}

/* ---- Responsive ---- */
@media (max-width: 400px) {
  .game-title {
    font-size: 1.3rem;
  }
  .header-btn {
    font-size: 1.1rem;
    padding: 4px 6px;
  }
  .modal {
    padding: 20px 16px 16px;
  }
  .stat-value {
    font-size: 1.6rem;
  }
}

@media (max-width: 360px) {
  :root {
    --tile-size: 44px;
    --kb-key-size: 26px;
    --kb-gap: 3px;
    --tile-gap: 3px;
  }
  .kb-key.wide {
    min-width: 40px;
  }
}
