:root {
  /* #6aaa64 on #121213 bg: ~4.5:1 contrast ratio — passes WCAG AA for normal text.
     #b59f3b on #121213 bg: ~3.8:1 — passes WCAG AA for large/bold text (tiles are 2rem bold). */
  --color-correct: #6aaa64;
  --color-present: #b59f3b;
  --color-absent: #3a3a3c;
  --color-border: #565758;
  --color-border-active: #999;
  --color-bg: #121213;
  --color-text: #ffffff;
  --color-key-bg: #818384;
  --color-key-text: #ffffff;
  --color-header-border: #3a3a3c;
}

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

html, body {
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 500px;
  margin: 0 auto;
}

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

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

#mode-indicator {
  font-size: 0.75rem;
  color: #aaa;
}

#btn-help, #btn-stats, #btn-mode {
  background: none;
  border: 1px solid #555;
  color: var(--color-text);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.8rem;
}

#btn-help {
  font-weight: bold;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  padding: 0;
}

main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  min-height: 0;
}

#board {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.row {
  display: flex;
  gap: 5px;
}

.tile {
  width: 62px;
  height: 62px;
  border: 2px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  transition: border-color 0.1s;
}

/* Scale tiles on small screens */
@media (max-width: 360px) {
  .tile { width: 52px; height: 52px; font-size: 1.6rem; }
}
@media (max-width: 320px) {
  .tile { width: 46px; height: 46px; font-size: 1.4rem; }
}

.tile[data-letter] {
  border-color: var(--color-border-active);
}

/* Tile state colors (applied after evaluation) */
.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; }

/* Reveal — tile pops to color instantly, then scale-bounces back */
.tile.flip-reveal {
  animation: tileReveal 0.2s ease forwards;
}

@keyframes tileReveal {
  0%   { transform: scale(0.9); }
  60%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* Pop animation on letter entry */
.tile.pop {
  animation: pop 0.1s ease-in-out;
}

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

/* Shake animation for invalid guess */
.row.shake {
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 50%, 90% { transform: translateX(-4px); }
  30%, 70% { transform: translateX(4px); }
}

/* Bounce animation for win */
.tile.bounce {
  animation: bounce 1s ease forwards;
}

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

/* Keyboard */
#keyboard {
  width: 100%;
  padding: 8px 6px;
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  flex-shrink: 0;
}

.key-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  justify-content: center;
}

.key {
  flex: 1;
  height: 68px;
  background: var(--color-key-bg);
  color: var(--color-key-text);
  border: none;
  border-radius: 4px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  min-width: 0;
  padding: 0;
  touch-action: manipulation;
}

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

.key[data-state="correct"] { background: var(--color-correct); color: #fff; }
.key[data-state="present"] { background: var(--color-present); color: #fff; }
.key[data-state="absent"]  { background: var(--color-absent);  color: #fff; }
.key[aria-disabled="true"] { opacity: 0.6; pointer-events: none; }

.key:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

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

.toast {
  background: var(--color-text);
  color: var(--color-bg);
  padding: 10px 20px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.9rem;
  animation: fadeInOut 1.6s ease forwards;
  pointer-events: none;
}

.toast.persist {
  animation: fadeIn 0.2s ease forwards;
}

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateY(-4px); }
  15%  { opacity: 1; transform: translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal.hidden { display: none; }

.modal-content {
  background: #1a1a1b;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 24px;
  max-width: 380px;
  width: 90%;
  position: relative;
  max-height: 90%;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--color-text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
}

.modal-content h2 {
  text-align: center;
  font-size: 1rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.modal-content h3 {
  text-align: center;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 16px 0 8px;
}

/* Stats */
.stats-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 50px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  text-align: center;
}

/* Distribution bars */
.dist-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 0.8rem;
}

.dist-label { width: 12px; text-align: right; flex-shrink: 0; }

.dist-bar-wrap {
  flex: 1;
  height: 22px;
  display: flex;
  align-items: center;
}

.dist-bar {
  height: 100%;
  background: var(--color-absent);
  min-width: 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  font-weight: 700;
  font-size: 0.8rem;
  transition: width 0.3s ease;
}

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

/* Share button */
.btn-primary {
  display: block;
  margin: 16px auto 0;
  padding: 12px 28px;
  background: var(--color-correct);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.05em;
}

.btn-primary.hidden { display: none; }

/* Help modal examples */
.example-row {
  display: flex;
  gap: 4px;
  margin: 8px 0 4px;
}

.example-tile {
  width: 42px;
  height: 42px;
  font-size: 1.4rem;
}

/* Share fallback textarea */
#share-text {
  width: 100%;
  min-height: 100px;
  background: #2a2a2b;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 8px;
  font-family: monospace;
  font-size: 1.2rem;
  resize: none;
  margin-top: 12px;
}

/* Private mode banner */
#private-mode-banner {
  background: #3a3a0a;
  color: #ffdd44;
  text-align: center;
  padding: 6px 12px;
  font-size: 0.8rem;
  width: 100%;
  flex-shrink: 0;
}

/* Responsive adjustments for very small screens */
@media (max-width: 340px) {
  .key { height: 50px; font-size: 0.75rem; }
  #keyboard { padding: 6px 4px; padding-bottom: max(16px, env(safe-area-inset-bottom, 16px)); }
  .key-row { gap: 4px; margin-bottom: 4px; }
}
