/* Wordle clone — palette follows the original's light and dark values. */

:root {
  --bg: #ffffff;
  --fg: #1a1a1b;
  --muted: #727271;
  --line: #d3d6da;
  --tile-bg: transparent;
  --key-bg: #dadbde;
  --key-fg: #1a1a1b;
  --card: #ffffff;
  --overlay: rgba(255, 255, 255, .96);
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --tile: 62px;
  --gap: 5px;
  --radius: 6px;
}

[data-theme="dark"] {
  --bg: #212121;
  --fg: #ffffff;
  --muted: #b0b0b1;
  --line: #3a3a3c;
  --key-bg: #818384;
  --key-fg: #ffffff;
  --card: #2a2a2b;
  --overlay: rgba(33, 33, 33, .97);
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
}

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

.bar {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.tools { display: flex; gap: 6px; }

.tool {
  width: 34px;
  height: 34px;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--fg);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  cursor: pointer;
}
.tool:hover { border-color: var(--line); }
.tool[aria-pressed="true"] {
  color: var(--correct);
  border-color: var(--correct);
  font-weight: 700;
}

.source {
  margin: 8px 0 0;
  min-height: 1em;
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}
.source.is-fallback { color: #d97706; font-weight: 700; }

main {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 12px;
}

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

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: var(--gap);
}

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

.tile {
  width: var(--tile);
  height: var(--tile);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--tile-bg);
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--fg);
  user-select: none;
}

.tile.filled {
  border-color: var(--muted);
  animation: pop .12s ease;
}

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

.tile.flip { animation: flip .5s ease forwards; }

.tile.bounce { animation: bounce .9s ease; }

@keyframes pop {
  from { transform: scale(.85); }
  to   { transform: scale(1); }
}

/* Color is swapped at the midpoint by the script, so only the fold is here. */
@keyframes flip {
  0%   { transform: rotateX(0deg); }
  49%  { transform: rotateX(90deg); }
  50%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

@keyframes bounce {
  0%, 20%  { transform: translateY(0); }
  40%      { transform: translateY(-24px); }
  60%      { transform: translateY(-6px); }
  80%      { transform: translateY(-12px); }
  100%     { transform: translateY(0); }
}

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

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

.notice { min-height: 1.15em; margin: 0; font-size: .8rem; color: var(--muted); }

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

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  max-width: 530px;
}
.keyboard .krow { display: flex; justify-content: center; gap: 7px; }

.key {
  flex: 1;
  min-width: 34px;
  height: 54px;
  padding: 0 4px;
  border: 0;
  border-radius: 5px;
  background: var(--key-bg);
  color: var(--key-fg);
  font-size: .95rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}
.key:hover { filter: brightness(.95); }
.key.wide { flex: 1.6; font-size: .8rem; text-transform: none; }
.key.correct { background: var(--correct); color: #fff; }
.key.present  { background: var(--present); color: #fff; }
.key.absent   { background: var(--absent);  color: #fff; opacity: .85; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: 5px;
  background: #1a1a1b;
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
  animation: fade .35s ease;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: var(--overlay);
  z-index: 40;
}
.modal[hidden] { display: none; }

.modal-card {
  position: relative;
  width: min(440px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  padding: 26px 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  text-align: center;
}

.modal-x {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--fg);
  font-size: 1rem;
  cursor: pointer;
}

.modal-card h2 { margin: 0 0 14px; font-size: 1.15rem; }
.modal-card h3 { margin: 20px 0 8px; font-size: .95rem; }
.modal-card p { margin: 8px 0; font-size: .9rem; line-height: 1.5; color: var(--fg); }
.modal-card .sub { color: var(--muted); font-size: .8rem; }

.rules { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.rules .row-demo { display: grid; grid-template-columns: repeat(5, 34px); gap: 4px; }
.rules .row-demo .demo {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem; font-weight: 700; text-transform: uppercase; color: #fff;
  border: 2px solid var(--line); color: var(--fg);
}
.rules .demo.correct { background: var(--correct); border-color: transparent; color: #fff; }
.rules .demo.present { background: var(--present); border-color: transparent; color: #fff; }
.rules .demo.absent  { background: var(--absent);  border-color: transparent; color: #fff; }

.share-grid {
  display: inline-grid;
  grid-template-rows: repeat(var(--rows, 6), 20px);
  grid-auto-flow: column;
  grid-template-columns: repeat(5, 20px);
  gap: 4px;
  margin: 12px 0;
}
.share-grid i {
  width: 20px; height: 20px; border-radius: 3px;
  background: var(--line);
}
.share-grid i.correct { background: var(--correct); }
.share-grid i.present { background: var(--present); }

button.primary {
  margin-top: 12px;
  padding: 12px 18px;
  min-width: 190px;
  border: 0;
  border-radius: 6px;
  background: var(--correct);
  color: #fff;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
}
button.primary:disabled { opacity: .55; cursor: default; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 16px 0;
}
.stat-grid .stat strong { display: block; font-size: 1.5rem; }
.stat-grid .stat span { font-size: .7rem; color: var(--muted); }

.dist { display: flex; flex-direction: column; gap: 5px; }
.dist .bar-row { display: flex; align-items: center; gap: 8px; font-size: .8rem; }
.dist .bar-label { width: 12px; text-align: right; }
.dist .bar-track { flex: 1; display: block; }
.dist .bar {
  height: 20px;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 3px;
  background: var(--line);
  color: var(--fg);
  line-height: 20px;
  font-size: .75rem;
  font-weight: 700;
  transition: width .3s ease;
}
.dist .bar.current { background: var(--correct); color: #fff; }

@media (max-width: 420px) {
  :root { --tile: 54px; }
  .tile { font-size: 1.7rem; }
  .key { height: 48px; min-width: 26px; font-size: .82rem; }
}

@media (prefers-reduced-motion: reduce) {
  .tile, .row, .toast { animation: none !important; }
}
