:root {
  --color-correct: #538d4e;
  --color-present: #b59f3b;
  --color-absent: #3a3a3c;
  --color-absent-key: #3a3a3c;
  --color-bg: #121213;
  --color-surface: #1a1a1b;
  --color-text: #ffffff;
  --color-text-subtle: #818384;
  --color-border: #3a3a3c;
  --color-border-active: #565758;
  --color-key-bg: #818384;
  --color-key-text: #ffffff;
  --modal-bg: rgba(0, 0, 0, 0.75);
  --tile-size: 62px;
  --font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
}

[data-theme="light"] {
  --color-correct: #6aaa64;
  --color-present: #c9b458;
  --color-absent: #787c7e;
  --color-absent-key: #787c7e;
  --color-bg: #ffffff;
  --color-surface: #f6f7f8;
  --color-text: #1a1a1b;
  --color-text-subtle: #787c7e;
  --color-border: #d3d6da;
  --color-border-active: #878a8c;
  --color-key-bg: #d3d6da;
  --color-key-text: #1a1a1b;
  --modal-bg: rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-family);
  transition: background-color 0.3s ease, color 0.3s ease;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 0 10px 10px 10px;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 52px;
  border-bottom: 1px solid var(--color-border);
  padding: 0 8px;
}

.header-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  user-select: none;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--color-text);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, transform 0.1s;
}

.icon-btn:hover {
  background-color: var(--color-border);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* Toasts */
#toast-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background-color: var(--color-text);
  color: var(--color-bg);
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: fadeInOut 2s ease forwards;
  pointer-events: auto;
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateY(-10px); }
  10% { opacity: 1; transform: translateY(0); }
  85% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* Board */
#board-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-grow: 1;
  padding: 10px 0;
  width: 100%;
}

#board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  grid-gap: 6px;
  width: 100%;
  max-width: 350px;
  aspect-ratio: 5 / 6;
}

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

.tile {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--color-border);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2rem;
  font-weight: 800;
  text-transform: uppercase;
  user-select: none;
  background-color: transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
  perspective: 1000px;
}

.tile[data-state="active"] {
  border-color: var(--color-border-active);
  animation: popIn 0.1s ease-in-out;
}

.tile[data-state="correct"] {
  background-color: var(--color-correct) !important;
  border-color: var(--color-correct) !important;
  color: #ffffff;
}

.tile[data-state="present"] {
  background-color: var(--color-present) !important;
  border-color: var(--color-present) !important;
  color: #ffffff;
}

.tile[data-state="absent"] {
  background-color: var(--color-absent) !important;
  border-color: var(--color-absent) !important;
  color: #ffffff;
}

@keyframes popIn {
  0% { transform: scale(0.85); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Flip animation */
.tile.flip {
  animation: flipTile 0.5s ease forwards;
}

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

/* Shake row animation */
.row.shake {
  animation: shakeRow 0.5s ease-in-out;
}

@keyframes shakeRow {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
  90% { transform: translateX(2px); }
}

/* Win bounce animation */
.tile.bounce {
  animation: bounceWin 0.6s ease;
}

@keyframes bounceWin {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-24px); }
  50% { transform: translateY(0); }
  60% { transform: translateY(-10px); }
  80% { transform: translateY(0); }
  100% { transform: translateY(0); }
}

/* Keyboard */
#keyboard {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  user-select: none;
}

.keyboard-row {
  display: flex;
  width: 100%;
  touch-action: manipulation;
  gap: 6px;
}

.keyboard-row:nth-child(2) {
  padding: 0 4%;
}

.key {
  font-family: inherit;
  font-weight: 700;
  font-size: 1.1rem;
  border: 0;
  padding: 0;
  height: 58px;
  border-radius: 4px;
  background-color: var(--color-key-bg);
  color: var(--color-key-text);
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.08s ease;
}

.key:hover {
  opacity: 0.9;
}

.key:active {
  transform: scale(0.95);
}

.key.wide-key {
  flex: 1.5;
  font-size: 0.85rem;
}

.key[data-state="correct"] {
  background-color: var(--color-correct) !important;
  color: #ffffff !important;
}

.key[data-state="present"] {
  background-color: var(--color-present) !important;
  color: #ffffff !important;
}

.key[data-state="absent"] {
  background-color: var(--color-absent-key) !important;
  color: #ffffff !important;
  opacity: 0.6;
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--modal-bg);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  padding: 16px;
  backdrop-filter: blur(3px);
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: 12px;
  padding: 24px;
  max-width: 440px;
  width: 100%;
  position: relative;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: modalScaleUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScaleUp {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--color-text-subtle);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
}

.modal-close:hover {
  color: var(--color-text);
  background-color: var(--color-border);
}

.modal-title {
  text-align: center;
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 18px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Stats Modal */
.stats-grid {
  display: flex;
  justify-content: space-around;
  margin-bottom: 24px;
  text-align: center;
}

.stat-item .stat-num {
  font-size: 2rem;
  font-weight: 800;
}

.stat-item .stat-label {
  font-size: 0.72rem;
  color: var(--color-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.distribution-title {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.dist-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 24px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
}

.dist-bar-container {
  flex-grow: 1;
  background-color: transparent;
  display: flex;
}

.dist-bar {
  background-color: var(--color-border-active);
  color: #ffffff;
  padding: 2px 8px;
  border-radius: 3px;
  min-width: 22px;
  text-align: right;
  font-size: 0.8rem;
  transition: width 0.4s ease;
}

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

.modal-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.primary-btn {
  background-color: var(--color-correct);
  color: #ffffff;
  border: none;
  font-weight: 700;
  font-size: 1rem;
  padding: 12px 28px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: filter 0.15s ease, transform 0.1s ease;
}

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

.primary-btn:active {
  transform: scale(0.96);
}

/* Help Modal Examples */
.example-word {
  display: flex;
  gap: 6px;
  margin: 10px 0 6px 0;
}

.example-tile {
  width: 40px;
  height: 40px;
  font-size: 1.4rem;
  font-weight: 800;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 2px solid var(--color-border);
}

.help-desc {
  font-size: 0.9rem;
  color: var(--color-text-subtle);
  margin-bottom: 14px;
  line-height: 1.4;
}

/* Canvas Confetti */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1500;
}

@media (max-height: 700px) {
  header { height: 44px; }
  .header-title { font-size: 1.6rem; }
  .key { height: 48px; font-size: 0.95rem; }
  #board { max-width: 300px; }
  .tile { font-size: 1.7rem; }
}
