:root {
  --paper: #faf7f2;
  --paper-2: #f2ede4;
  --card: #ffffff;
  --ink: #24211c;
  --ink-soft: #6b6459;
  --line: #e6ddd0;
  --green: #6aaa64;
  --green-dark: #4a8a44;
  --yellow: #c9b458;
  --gray: #787c7e;
  --danger: #d64545;
  --key: #e8e2d7;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over any `display` rule below (same lesson
   as in the amr app: author display rules override the UA default). */
[hidden] { display: none !important; }

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1rem 1rem 0.75rem;
}

/* --- header --- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
}
.title { text-align: center; }
.title h1 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.title p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.hdr-btn {
  flex: none;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-soft);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.hdr-btn:hover {
  color: var(--green-dark);
  border-color: var(--green);
  transform: translateY(-1px);
}

/* --- toast --- */
.toast {
  position: fixed;
  top: 4.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  border-radius: 10px;
  box-shadow: 0 10px 24px -10px rgba(36, 33, 28, 0.5);
  z-index: 60;
  white-space: nowrap;
}
.toast.error { background: var(--danger); color: white; }

/* --- board --- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  width: min(330px, 100%);
}
.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.row.shake { animation: shake 0.5s; }

.tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  font-weight: 800;
  text-transform: uppercase;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  user-select: none;
  transition: transform 0.08s ease;
}
.tile.filled {
  border-color: var(--ink-soft);
  animation: pop 0.1s ease;
}
.tile.flip { animation: flip 0.5s ease forwards; }
.tile.correct, .tile.present, .tile.absent {
  border-color: transparent;
  color: white;
}
.tile.correct { background: var(--green); }
.tile.present { background: var(--yellow); }
.tile.absent  { background: var(--gray); }
.tile.win { animation: bounce 0.9s ease; }

/* small tiles in the help modal */
.tile.small {
  width: 2.1rem;
  aspect-ratio: 1;
  font-size: 1.1rem;
  display: inline-flex;
  border-radius: 6px;
}

/* --- reveal (loss) banner --- */
.reveal {
  background: rgba(214, 69, 69, 0.1);
  border: 1px solid rgba(214, 69, 69, 0.35);
  color: var(--danger);
  border-radius: 12px;
  padding: 0.5rem 1.1rem;
  font-size: 0.95rem;
}
.reveal strong { text-transform: uppercase; letter-spacing: 0.06em; }

/* --- keyboard --- */
.keyboard {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 0.5rem;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}
.key {
  flex: 1;
  max-width: 44px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: var(--key);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: filter 0.1s ease;
  padding: 0;
}
.key:active { filter: brightness(0.9); }
.key.wide {
  flex: 1.6;
  max-width: 72px;
  font-size: 0.72rem;
}
.key.correct { background: var(--green); color: white; }
.key.present { background: var(--yellow); color: white; }
.key.absent  { background: var(--gray); color: white; }

/* --- footer --- */
footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0 0.4rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
footer a { color: var(--ink-soft); text-decoration: none; }
footer a:hover { color: var(--ink); }

/* --- modals --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(36, 33, 28, 0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: max(1.5rem, 6vh) 1.5rem 1.5rem;
  z-index: 50;
}
.modal {
  position: relative;
  background: var(--card);
  border-radius: 18px;
  padding: 1.75rem;
  width: 100%;
  max-width: 26rem;
  margin: auto;
  box-shadow: 0 24px 60px -20px rgba(36, 33, 28, 0.4);
}
.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  border-radius: 9px;
  color: var(--ink-soft);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: var(--paper-2); color: var(--ink); }
.modal h2 { margin: 0 0 0.6rem; font-size: 1.3rem; letter-spacing: -0.01em; }
.modal h3 { margin: 1.25rem 0 0.5rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
.modal .muted { margin: 0 0 1rem; color: var(--ink-soft); font-size: 0.9rem; }

.example { border-top: 1px solid var(--line); padding-top: 1rem; }
.example p { margin: 0.4rem 0 1rem; font-size: 0.85rem; color: var(--ink-soft); }
.ex-row { display: flex; gap: 4px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  text-align: center;
}
.stat { display: flex; flex-direction: column; }
.stat-num { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.7rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }

.dist { display: flex; flex-direction: column; gap: 4px; }
.dist-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.dist-row .n { width: 0.8rem; color: var(--ink-soft); font-weight: 700; }
.dist-bar {
  min-width: 1.4rem;
  padding: 0.1rem 0.5rem;
  border-radius: 5px;
  background: var(--gray);
  color: white;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.dist-bar.hit { background: var(--green); }

.btn.share {
  display: block;
  width: 100%;
  margin-top: 1.25rem;
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1.1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(155deg, var(--green), var(--green-dark));
  color: white;
}
.btn.share:hover { filter: brightness(1.05); }

/* --- animations --- */
@keyframes pop {
  50% { transform: scale(1.1); }
}
@keyframes flip {
  0%   { transform: rotateX(0); }
  50%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}
@keyframes bounce {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-24px); }
  55% { transform: translateY(4px); }
  70% { transform: translateY(-12px); }
  82% { transform: translateY(2px); }
  92% { transform: translateY(-4px); }
  100% { transform: translateY(0); }
}

@media (max-width: 380px) {
  .tile { font-size: 1.5rem; }
  .key { height: 50px; }
}
