/* Wright Words — clean Wordle-style UI */
:root {
  --bg: #ffffff;
  --text: #1a1a1b;
  --muted: #787c7e;
  --border: #d3d6da;
  --border-strong: #878a8c;
  --tile-empty-border: #d3d6da;
  --tile-filled-border: #878a8c;
  --key-bg: #d3d6da;
  --key-text: #1a1a1b;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --tone-text: #ffffff;
  --modal-bg: #ffffff;
  --overlay: rgba(255, 255, 255, 0.5);
  --shadow: 0 4px 23px 0 rgba(0, 0, 0, 0.2);
  --header-h: 52px;
  --maxw: 500px;
  font-family: "Helvetica Neue", Helvetica, Arial, "Clear Sans", "Segoe UI", sans-serif;
  color-scheme: light;
}

html.dark {
  --bg: #121213;
  --text: #ffffff;
  --muted: #818384;
  --border: #3a3a3c;
  --border-strong: #565758;
  --tile-empty-border: #3a3a3c;
  --tile-filled-border: #565758;
  --key-bg: #818384;
  --key-text: #ffffff;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --modal-bg: #121213;
  --overlay: rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

html.high-contrast {
  --correct: #f5793a;
  --present: #85c0f9;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: var(--maxw);
  margin: 0 auto;
}

/* boot splash */
.boot { height: 100%; display: grid; place-items: center; }
.boot-tiles { display: flex; gap: 5px; }
.boot-tiles span {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 2px solid var(--border); border-radius: 3px;
  font-weight: 700; animation: bootpulse 1.2s infinite ease-in-out;
}
.boot-tiles span:nth-child(2) { animation-delay: .1s; }
.boot-tiles span:nth-child(3) { animation-delay: .2s; }
.boot-tiles span:nth-child(4) { animation-delay: .3s; }
.boot-tiles span:nth-child(5) { animation-delay: .4s; }
.boot-tiles span:nth-child(6) { animation-delay: .5s; }
@keyframes bootpulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }

/* header */
header.bar {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.bar .group { display: flex; align-items: center; gap: 2px; min-width: 96px; }
.bar .group.right { justify-content: flex-end; }
.bar h1 {
  margin: 0;
  font-weight: 700;
  font-size: clamp(1.4rem, 6vw, 2.1rem);
  letter-spacing: 0.01em;
  text-transform: uppercase;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}
.icon-btn {
  background: none; border: none; color: var(--text);
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; padding: 0;
}
.icon-btn:hover { background: rgba(120, 124, 126, 0.18); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; }

/* main / board */
main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}
.banner {
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.banner button {
  background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: 4px; padding: 4px 10px; font-size: 0.78rem; font-weight: 600;
}
.board-wrap { flex: 1 1 auto; display: grid; place-items: center; width: 100%; padding: 10px 0; min-height: 0; }
.board { display: grid; grid-template-rows: repeat(6, 1fr); gap: 5px; padding: 8px; box-sizing: border-box; height: min(420px, 100%); aspect-ratio: 5 / 6; }
.brow { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.tile {
  display: grid; place-items: center;
  border: 2px solid var(--tile-empty-border);
  font-size: 2rem; font-weight: 700; text-transform: uppercase;
  line-height: 1; user-select: none; color: var(--text);
  width: 100%; aspect-ratio: 1 / 1;
}
.tile.filled { border-color: var(--tile-filled-border); animation: pop 0.1s ease; }
.tile.correct { background: var(--correct); border-color: var(--correct); color: var(--tone-text); }
.tile.present { background: var(--present); border-color: var(--present); color: var(--tone-text); }
.tile.absent { background: var(--absent); border-color: var(--absent); color: var(--tone-text); }
.tile.reveal { animation: flip 0.5s ease forwards; }
.brow.shake { animation: shake 0.5s; }
.brow.win .tile { animation: bounce 1s ease; }

@keyframes pop { 0% { transform: scale(0.92); } 100% { transform: scale(1); } }
@keyframes flip {
  0% { transform: rotateX(0); }
  45% { transform: rotateX(-90deg); }
  55% { 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(-26px); }
  50% { transform: translateY(4px); }
  60% { transform: translateY(-12px); }
  80% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

/* keyboard */
.keyboard { flex: 0 0 auto; width: 100%; max-width: 484px; margin: 0 auto; padding: 0 6px 8px; }
.krow { display: flex; justify-content: center; gap: 6px; margin-bottom: 6px; touch-action: manipulation; }
.key {
  height: 58px; flex: 1 1 0; min-width: 0;
  border: none; border-radius: 4px;
  background: var(--key-bg); color: var(--key-text);
  font-weight: 700; font-size: 0.86rem; text-transform: uppercase;
  display: grid; place-items: center; padding: 0;
  transition: background 0.1s ease;
}
.key.wide { flex: 1.5 1 0; font-size: 0.72rem; }
.key.spacer { flex: 0.5 1 0; background: none; pointer-events: none; }
.key svg { width: 22px; height: 22px; fill: currentColor; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent { background: var(--absent); color: #fff; }
html.dark .key.absent { background: #3a3a3c; }

/* toast */
.toast-wrap {
  position: fixed; top: calc(var(--header-h) + 12px); left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  font-weight: 600; font-size: 0.9rem;
  padding: 12px 16px; border-radius: 4px;
  box-shadow: var(--shadow);
  animation: toastin 0.1s ease;
}
@keyframes toastin { from { opacity: 0; } to { opacity: 1; } }
.toast.fade { animation: toastout 0.3s ease forwards; }
@keyframes toastout { to { opacity: 0; } }

/* modals */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--overlay);
  display: grid; place-items: center; padding: 16px;
  animation: toastin 0.12s ease;
}
.modal {
  background: var(--modal-bg); color: var(--text);
  width: min(500px, 100%); max-height: 92vh; overflow-y: auto;
  border-radius: 8px; box-shadow: var(--shadow);
  padding: 16px 20px 28px; position: relative;
  animation: modalin 0.18s ease;
}
@keyframes modalin { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal .close {
  position: absolute; top: 10px; right: 10px;
  background: none; border: none; color: var(--text);
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
}
.modal .close:hover { background: rgba(120,124,126,0.18); }
.modal h2 { text-align: center; text-transform: uppercase; letter-spacing: 0.06em; font-size: 1rem; margin: 6px 0 16px; }
.modal h3 { font-size: 0.95rem; margin: 18px 0 8px; }
.modal p { line-height: 1.5; font-size: 0.95rem; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* how to play */
.example { display: flex; gap: 4px; margin: 8px 0; }
.example .tile { width: 38px; aspect-ratio: 1; font-size: 1.5rem; border-width: 2px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* stats */
.stat-row { display: flex; justify-content: center; gap: 6px; margin: 4px 0 18px; }
.stat-box { flex: 1 1 0; text-align: center; }
.stat-box .num { font-size: 2.1rem; font-weight: 400; line-height: 1; }
.stat-box .lbl { font-size: 0.72rem; line-height: 1.1; margin-top: 4px; }
.dist { margin: 0 0 14px; }
.dist-row { display: flex; align-items: center; gap: 6px; height: 20px; margin-bottom: 4px; font-size: 0.82rem; }
.dist-row .d-idx { width: 10px; text-align: center; }
.dist-bar {
  background: var(--absent); color: #fff; text-align: right;
  padding: 2px 8px; min-width: 22px; font-weight: 700; border-radius: 2px;
}
.dist-bar.cur { background: var(--correct); }
.share-area { display: flex; align-items: center; gap: 16px; justify-content: center; }
.countdown { text-align: center; }
.countdown .lbl { font-size: 0.72rem; text-transform: uppercase; }
.countdown .clock { font-size: 1.9rem; font-variant-numeric: tabular-nums; font-weight: 500; }
.share-btn {
  background: var(--correct); color: #fff; border: none; border-radius: 4px;
  font-weight: 700; text-transform: uppercase; font-size: 1rem; letter-spacing: 0.03em;
  padding: 14px 22px; display: inline-flex; align-items: center; gap: 8px;
}
.share-btn svg { width: 20px; height: 20px; fill: currentColor; }
.vsep { width: 1px; align-self: stretch; background: var(--border); }

/* settings rows */
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); }
.set-row .info .t { font-size: 1rem; }
.set-row .info .d { font-size: 0.78rem; color: var(--muted); }
.switch { position: relative; width: 42px; height: 22px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--muted); border-radius: 22px; transition: 0.2s; }
.slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--correct); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* forms / buttons */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%; padding: 11px 12px; font-size: 1rem;
  border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--bg); color: var(--text);
}
.btn {
  width: 100%; padding: 13px; border: none; border-radius: 4px;
  background: var(--text); color: var(--bg); font-weight: 700; font-size: 1rem;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.btn:disabled { opacity: 0.5; }
.btn.outline { background: none; color: var(--text); border: 1px solid var(--border-strong); }
.linkish { background: none; border: none; color: var(--text); text-decoration: underline; font-weight: 600; padding: 0; font-size: inherit; }
.formerr { color: #c0392b; font-size: 0.85rem; margin: 4px 0 10px; min-height: 1em; }
html.dark .formerr { color: #ff7b6b; }

/* leaderboard */
.lb-tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px; }
.lb-tabs button { background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 999px; padding: 6px 12px; font-size: 0.78rem; font-weight: 600; }
.lb-tabs button.active { color: var(--text); border-color: var(--text); }
.lb-row { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.lb-row .rk { color: var(--muted); font-weight: 700; text-align: center; }
.lb-empty { text-align: center; color: var(--muted); padding: 24px 0; }

@media (max-height: 680px) {
  .key { height: 48px; }
  .tile { font-size: 1.6rem; }
}
@media (max-width: 380px) {
  .key { font-size: 0.74rem; }
  .bar h1 { font-size: 1.25rem; }
}
