/* ccccdle: Wordle palette and feel. */

:root {
  --bg: #ffffff;
  --text: #1a1a1b;
  --text-muted: #787c7e;
  --tile-border: #d3d6da;
  --tile-border-filled: #878a8c;
  --key-bg: #d3d6da;
  --key-text: #1a1a1b;
  --modal-bg: #ffffff;
  --modal-shadow: rgba(0, 0, 0, 0.25);
  --divider: #d3d6da;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --on-colour: #ffffff;
  --toast-bg: #1a1a1b;
  --toast-text: #ffffff;
  --accent: #6aaa64;

  --cols: 11;
  --gap: 3px;
  --row-gap: 10px;
  --gutter: 16px;
  --tile-max: 52px;
  --flip-ms: 250ms;
  --stagger-ms: 15ms;
}

:root[data-theme="dark"] {
  --bg: #121213;
  --text: #d7dadc;
  --text-muted: #818384;
  --tile-border: #3a3a3c;
  --tile-border-filled: #565758;
  --key-bg: #818384;
  --key-text: #d7dadc;
  --modal-bg: #121213;
  --modal-shadow: rgba(0, 0, 0, 0.6);
  --divider: #3a3a3c;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --toast-bg: #d7dadc;
  --toast-text: #1a1a1b;
  --accent: #538d4e;
}

:root[data-contrast="high"] {
  --correct: #f5793a;
  --present: #85c0f9;
  --accent: #f5793a;
}

:root[data-motion="reduce"] * {
  animation-duration: 0.01ms !important;
  animation-delay: 0ms !important;
  transition-duration: 0.01ms !important;
}

@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) * {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1400px;
  margin: 0 auto;
}

/* Header */

.header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 52px;
  padding: 0 var(--gutter);
  border-bottom: 1px solid var(--divider);
  flex: 0 0 auto;
}

.header-group { display: flex; gap: 2px; }
.header-group:last-child { justify-content: flex-end; }

.title {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-align: center;
  line-height: 1;
  font-family: "Karnak Condensed", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.title::first-letter { }

.icon-btn {
  background: none;
  border: 0;
  color: var(--text);
  width: 36px;
  height: 36px;
  padding: 6px;
  border-radius: 4px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover { background: rgba(128, 128, 128, 0.15); }

/* Board */

.game {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 10px var(--gutter);
}

.board {
  display: flex;
  flex-direction: column;
  gap: var(--row-gap);
  margin: auto 0;
  width: 100%;
  max-width: calc(var(--cols) * var(--tile-max) + (var(--cols) - 1) * var(--gap));
}

.row {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: var(--gap);
  position: relative;
}

.row.shake { animation: shake 600ms; }

.tile {
  aspect-ratio: 1;
  border: 2px solid var(--tile-border);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: clamp(10px, 4.2cqw, 28px);
  text-transform: lowercase;
  line-height: 1;
  user-select: none;
  color: var(--text);
  position: relative;
}

.row { container-type: inline-size; }
.tile { font-size: clamp(10px, calc(60cqw / var(--cols)), 30px); }

.tile.filled { border-color: var(--tile-border-filled); animation: pop 100ms; }
.tile.pid::after {
  content: "";
  position: absolute;
  left: 20%; right: 20%; bottom: -1px;
  height: 2px;
  background: var(--tile-border-filled);
  opacity: 0.5;
}
.tile.correct, .tile.present, .tile.absent {
  border-color: transparent;
  color: var(--on-colour);
}
.tile.correct { background: var(--correct); }
.tile.present { background: var(--present); }
.tile.absent { background: var(--absent); }
.tile.correct.pid::after, .tile.present.pid::after, .tile.absent.pid::after { display: none; }

.tile.flip { animation: flip var(--flip-ms) ease-in both; animation-delay: var(--delay, 0ms); }
.tile.bounce { animation: bounce 1000ms ease-in-out; animation-delay: var(--delay, 0ms); }

@keyframes pop {
  from { transform: scale(0.8); opacity: 0; }
  40% { transform: scale(1.1); opacity: 1; }
  to { transform: scale(1); }
}
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
@keyframes bounce {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-30px); }
  50% { transform: translateY(5px); }
  60% { transform: translateY(-15px); }
  80% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

/* Keyboard */

.keyboard {
  flex: 0 0 auto;
  padding: 8px var(--gutter) max(8px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}
.key-row { display: flex; gap: 6px; justify-content: center; }
.key {
  flex: 1;
  height: 52px;
  border: 0;
  border-radius: 4px;
  background: var(--key-bg);
  color: var(--key-text);
  font-family: inherit;
  font-weight: 700;
  font-size: 1.1rem;
  text-transform: lowercase;
  cursor: pointer;
  display: grid;
  place-items: center;
  user-select: none;
  transition: background-color 200ms;
  transition-delay: var(--key-delay, 0ms);
}
.key.wide { flex: 1.6; font-size: 0.75rem; text-transform: uppercase; }
.key.correct, .key.present, .key.absent { color: var(--on-colour); }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent { background: var(--absent); }
.key svg { width: 22px; height: 22px; }

/* Toasts */

.toasts {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
}
.toast {
  background: var(--toast-bg);
  color: var(--toast-text);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 12px 16px;
  border-radius: 4px;
  animation: toast-in 150ms ease-out;
}
.toast.out { animation: toast-out 300ms ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; } }
@keyframes toast-out { to { opacity: 0; } }

/* Modals */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  z-index: 40;
  padding: var(--gutter);
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--modal-bg);
  color: var(--text);
  border-radius: 8px;
  box-shadow: 0 4px 23px var(--modal-shadow);
  width: 100%;
  min-width: 0;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 24px 24px 20px;
  position: relative;
  animation: modal-in 200ms ease-out;
}
@keyframes modal-in { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none;
  border: 0;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  width: 36px; height: 36px;
}
.modal h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}
.modal h3 {
  margin: 20px 0 8px;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
}
.modal p { line-height: 1.5; margin: 8px 0; font-size: 0.95rem; }
.muted { color: var(--text-muted); }
.small { font-size: 0.8rem; }
.modal code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(128, 128, 128, 0.15);
  padding: 1px 4px;
  border-radius: 3px;
}

.example { margin: 12px 0; }
.example-row {
  display: grid;
  grid-template-columns: repeat(6, 40px);
  gap: 4px;
  margin-bottom: 6px;
}
.example-row .tile { font-size: 1.4rem; }

.stats-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 8px 0;
}
.stat { text-align: center; flex: 1; }
.stat-num { font-size: 2.2rem; font-weight: 400; line-height: 1.1; }
.stat-label { font-size: 0.75rem; line-height: 1.2; color: var(--text); }

.distribution { display: flex; flex-direction: column; gap: 4px; }
.dist-row { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.dist-bar {
  background: var(--absent);
  color: var(--on-colour);
  font-weight: 700;
  min-width: 22px;
  padding: 2px 6px;
  text-align: right;
  height: 20px;
  line-height: 16px;
}
.dist-bar.highlight { background: var(--correct); }

.answer-reveal { text-align: center; margin: 16px 0 0; }
.answer-reveal code { display: inline-block; margin-top: 6px; word-break: break-all; font-size: 0.85rem; }

.stats-footer {
  display: flex;
  margin-top: 20px;
  padding-top: 16px;
  gap: 16px;
}
.countdown { flex: 1; text-align: center; border-right: 1px solid var(--divider); }
.countdown-num { font-size: 2rem; font-weight: 400; letter-spacing: 0.02em; }
.share-btn {
  flex: 1;
  align-self: center;
  background: var(--accent);
  color: var(--on-colour);
  border: 0;
  border-radius: 4px;
  font-family: inherit;
  font-weight: 700;
  font-size: 1.1rem;
  text-transform: uppercase;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}
.share-btn svg { width: 22px; height: 22px; }

.setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--divider);
  gap: 16px;
  cursor: pointer;
}
.setting-name { font-size: 1rem; }
.setting-desc { font-size: 0.75rem; color: var(--text-muted); }
.switch {
  appearance: none;
  width: 32px; height: 20px;
  border-radius: 10px;
  background: var(--absent);
  position: relative;
  cursor: pointer;
  flex: 0 0 auto;
  margin: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 150ms;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(12px); }

/* Breakpoints: columns per guess row. 44 tiles wrap into 4, 2 or 1 sub-rows. */
@media (min-width: 640px) { :root { --cols: 22; --tile-max: 40px; --gap: 4px; } }
@media (min-width: 1240px) { :root { --cols: 44; --tile-max: 28px; --gap: 3px; } }
@media (max-width: 400px) { .key { height: 46px; } .title { font-size: 28px; } }
