/* Думоплет — NYT Games visual language: white chrome, hairline rules,
   Karnak-style slab display (Roboto Slab), Franklin-style UI text
   (Helvetica stack), and the exact Wordle / Spelling Bee palette. */

@font-face {
  font-family: 'Roboto Slab';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/robotoslab-700-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: 'Roboto Slab';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/robotoslab-700-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}

:root {
  --white: #ffffff;
  --ink: #1a1a1b;
  --gray-text: #787c7e;
  --hairline: #e3e3e1;
  --card-line: #dfdfdf;

  /* wordle */
  --green: #6aaa64;
  --yellow: #c9b458;
  --absent: #787c7e;
  --tile-line: #d3d6da;
  --tile-line-filled: #878a8c;
  --key: #d3d6da;

  /* our games */
  --brown: #7b5b3a;
  --red: #d0342c;

  /* spelling bee */
  --bee-yellow: #f7da21;
  --bee-gray: #e6e6e6;

  --focus: #2b5faa;

  --display: 'Roboto Slab', Georgia, serif;
  --body: 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--white);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

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

.topbar {
  display: flex;
  align-items: center;
  max-width: 100%;
  height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--hairline);
}

.topnav { flex: 1; display: flex; gap: 16px; }
.topnav.right { justify-content: flex-end; }

.wordmark {
  font-family: var(--display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.2px;
  color: var(--ink);
  text-decoration: none;
}

.topnav a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  padding: 4px 2px;
  border-bottom: 2px solid transparent;
}

.topnav a.active { border-bottom-color: var(--ink); }
.topnav a:hover { border-bottom-color: var(--tile-line); }

/* ---------- layout ---------- */

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.page-note { color: var(--gray-text); text-align: center; }

.page-head { margin: 4px 0 18px; }

.page-head h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 32px;
  margin: 0 0 2px;
}

.page-head .sub {
  color: var(--gray-text);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge-archive {
  background: var(--ink);
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.game-head {
  position: relative;
  text-align: center;
  margin-bottom: 8px;
}

.game-head .sub { justify-content: center; }

.head-actions { position: absolute; right: 0; top: 6px; }

/* ---------- home ---------- */

.today-line {
  color: var(--gray-text);
  font-size: 14px;
  margin: 2px 0 18px;
}

.cards { display: grid; grid-template-columns: 1fr; gap: 12px; }

@media (min-width: 560px) {
  .cards { grid-template-columns: 1fr 1fr; }
}

.card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  border: 1px solid var(--card-line);
  border-radius: 8px;
  background: var(--white);
  padding: 16px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.card:hover { box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); }

.card h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 21px;
  margin: 0 0 3px;
}

.card p { margin: 0; color: var(--gray-text); font-size: 13px; line-height: 1.45; }

.card-status { margin-top: 8px; font-size: 13px; font-weight: 700; }
.card-status.won { color: var(--green); }
.card-status.lost { color: var(--red); }
.card-status.progress { color: var(--gray-text); }

/* NYT-style flat game icons */
.card-icon {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 6px;
  display: grid;
  place-items: center;
}

.icon-wordle {
  background: var(--green);
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 9px;
}

.icon-wordle span {
  background: var(--white);
  border-radius: 2px;
}

.icon-wordle span:nth-child(2) { background: var(--yellow); }

.icon-wordle500 {
  background: var(--yellow);
  color: var(--white);
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
}

.icon-poople { background: var(--brown); font-size: 26px; }

.icon-bee { background: var(--bee-yellow); }

.icon-bee::before {
  content: '';
  width: 26px;
  height: 28px;
  background: var(--ink);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}

/* ---------- shared game bits ---------- */

.board { display: grid; gap: 5px; justify-content: center; margin: 16px 0; }

.row { display: flex; gap: 5px; align-items: center; }

.tile {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  font-family: var(--body);
  font-weight: 700;
  font-size: 32px;
  line-height: 1;
  text-transform: uppercase;
  border: 2px solid var(--tile-line);
  background: var(--white);
  color: var(--ink);
}

@media (max-width: 380px) {
  .tile { width: 52px; height: 52px; font-size: 26px; }
}

.tile.filled { border-color: var(--tile-line-filled); }
.tile.correct { background: var(--green); border-color: var(--green); color: #fff; }
.tile.present { background: var(--yellow); border-color: var(--yellow); color: #fff; }
.tile.absent { background: var(--absent); border-color: var(--absent); color: #fff; }
.tile.neutral { background: var(--absent); border-color: var(--absent); color: #fff; }
.tile.target { background: var(--brown); border-color: var(--brown); color: #fff; }

/* typing pop — the quick scale NYT tiles do when a letter lands */
.tile.pop { animation: pop-in 0.1s ease; }

@keyframes pop-in {
  0% { transform: scale(0.8); }
  40% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* NYT-style reveal: each tile flips on its X axis and swaps to its
   result color edge-on, staggered left to right via --i. */
.tile.correct { --to-bg: var(--green); --to-bd: var(--green); --to-fg: #fff; }
.tile.present { --to-bg: var(--yellow); --to-bd: var(--yellow); --to-fg: #fff; }
.tile.absent { --to-bg: var(--absent); --to-bd: var(--absent); --to-fg: #fff; }
.tile.neutral { --to-bg: var(--absent); --to-bd: var(--absent); --to-fg: #fff; }
.tile.target { --to-bg: var(--brown); --to-bd: var(--brown); --to-fg: #fff; }

.reveal .tile.correct, .reveal .tile.present, .reveal .tile.absent,
.reveal .tile.neutral, .reveal .tile.target {
  animation: flip 0.5s ease both;
  animation-delay: calc(var(--i, 0) * 0.25s);
}

@keyframes flip {
  0% {
    transform: rotateX(0);
    background: var(--white);
    border-color: var(--tile-line-filled);
    color: var(--ink);
  }
  49.99% {
    transform: rotateX(-90deg);
    background: var(--white);
    border-color: var(--tile-line-filled);
    color: var(--ink);
  }
  50% {
    transform: rotateX(-90deg);
    background: var(--to-bg);
    border-color: var(--to-bd);
    color: var(--to-fg);
  }
  100% {
    transform: rotateX(0);
    background: var(--to-bg);
    border-color: var(--to-bd);
    color: var(--to-fg);
  }
}

/* winning row hop, staggered like NYT */
.bounce .tile {
  animation: bounce 0.9s ease;
  animation-delay: calc(var(--i, 0) * 0.1s);
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-24px); }
  55% { transform: translateY(4px); }
  75% { transform: translateY(-8px); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
  .reveal .tile, .row.shake, .tile.pop, .bounce .tile, .reveal .chips { animation: none; }
}

/* wordle-500 score chips */
.chips { display: flex; gap: 4px; margin-left: 10px; min-width: 114px; }

.chip {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  font-weight: 700;
  font-size: 17px;
}

.chip.green { background: var(--green); color: #fff; }
.chip.gold { background: var(--yellow); color: #fff; }
.chip.red { background: var(--red); color: #fff; }
.chip.ghost { background: transparent; }

/* chips hold back until their row finishes flipping */
.reveal .chips {
  animation: chips-in 0.25s ease both;
  animation-delay: 1.3s;
}

@keyframes chips-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

.keyboard { max-width: 520px; margin: 14px auto 0; user-select: none; }

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

.key {
  flex: 1;
  max-width: 44px;
  height: 58px;
  border: 0;
  border-radius: 4px;
  background: var(--key);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
}

.key:active { transform: translateY(1px); }
.key.wide { max-width: 68px; flex: 1.6; font-size: 12px; }
.key.correct { background: var(--green); color: #fff; }
.key.present { background: var(--yellow); color: #fff; }
.key.absent { background: var(--absent); color: #fff; }

/* ---------- poople ---------- */

.ladder-meta {
  display: flex;
  justify-content: center;
  gap: 18px;
  font-size: 14px;
  color: var(--gray-text);
  margin-bottom: 4px;
}

.ladder-meta b { color: var(--ink); }

.poople-target-label {
  text-align: center;
  font-size: 13px;
  color: var(--gray-text);
  margin-top: 10px;
}

/* ---------- spelling bee ---------- */

.bee-wrap { display: grid; gap: 18px; justify-items: center; }

@media (min-width: 640px) {
  .bee-wrap { grid-template-columns: 1fr 1fr; align-items: start; }
}

.bee-input {
  min-height: 44px;
  font-family: var(--body);
  font-size: 28px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-align: center;
  min-width: 240px;
  padding: 4px 8px;
}

.bee-input .center-letter { color: var(--bee-yellow); filter: brightness(0.82); }

.bee-input .caret {
  display: inline-block;
  width: 2px;
  height: 30px;
  background: var(--bee-yellow);
  vertical-align: -4px;
  animation: blink 1s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) { .bee-input .caret { animation: none; } }

.hive {
  position: relative;
  width: 300px;
  height: 284px;
}

.hex {
  position: absolute;
  width: 96px;
  height: 104px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--bee-gray);
  border: 0;
  font-family: var(--body);
  font-size: 28px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
  transition: transform 0.05s ease;
}

.hex:active { transform: scale(0.92); }
.hex.center { background: var(--bee-yellow); }

.bee-controls { display: flex; gap: 10px; justify-content: center; }

.bee-panel { width: 100%; max-width: 320px; }

.bee-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.bee-rank { font-weight: 700; font-size: 15px; white-space: nowrap; }

.bee-bar { flex: 1; height: 6px; background: var(--bee-gray); border-radius: 999px; overflow: hidden; }

.bee-bar span { display: block; height: 100%; background: var(--bee-yellow); }

.bee-score { font-weight: 700; font-size: 15px; min-width: 34px; text-align: right; }

.found-count { font-size: 13px; color: var(--gray-text); margin: 6px 0; }

.found-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.found-words li {
  border-bottom: 1px solid var(--hairline);
  padding: 3px 8px;
  font-size: 14px;
  background: var(--white);
}

.found-words li.pangram {
  background: var(--bee-yellow);
  border-radius: 4px;
  border-bottom-color: transparent;
  font-weight: 700;
}

/* ---------- buttons ---------- */

.btn {
  border: 1px solid var(--gray-text);
  border-radius: 999px;
  background: var(--white);
  color: var(--ink);
  font-family: var(--body);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 22px;
  cursor: pointer;
}

.btn:hover { background: #f4f4f4; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: var(--white); border-color: var(--ink); }
.btn.primary:hover { background: #000; }
.btn.small { padding: 5px 14px; font-size: 13px; }

/* ---------- archive ---------- */

.archive-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.archive-tabs .btn { text-decoration: none; }
.archive-tabs .btn.active { background: var(--ink); color: var(--white); border-color: var(--ink); }

.archive-list { display: grid; gap: 0; list-style: none; margin: 0; padding: 0; }

.archive-list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--hairline);
  padding: 12px 4px;
  text-decoration: none;
  color: var(--ink);
  background: var(--white);
}

.archive-list a:hover { background: #fafafa; }

.archive-date { font-weight: 500; }
.archive-num { color: var(--gray-text); font-size: 13px; }
.archive-state { font-size: 13px; font-weight: 700; }
.archive-state.won { color: var(--green); }
.archive-state.lost { color: var(--red); }

.lock-note {
  border: 1px solid var(--card-line);
  border-radius: 8px;
  padding: 28px;
  text-align: center;
  color: var(--gray-text);
}

.lock-note .btn { text-decoration: none; display: inline-block; margin-top: 8px; }

/* ---------- result banner ---------- */

.banner {
  text-align: center;
  margin: 14px auto;
  max-width: 420px;
  border: 1px solid var(--card-line);
  border-radius: 8px;
  padding: 16px;
  background: var(--white);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.banner h3 { font-family: var(--display); font-weight: 700; font-size: 20px; margin: 0 0 6px; }
.banner p { margin: 0 0 12px; color: var(--gray-text); font-size: 14px; }

/* ---------- toast & modal ---------- */

.toast[hidden], .modal-backdrop[hidden] { display: none; }

.toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--white);
  font-weight: 700;
  font-size: 14px;
  padding: 12px 16px;
  border-radius: 4px;
  z-index: 30;
  max-width: 90vw;
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.6);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 16px;
}

.modal {
  position: relative;
  background: var(--white);
  border: 1px solid var(--card-line);
  border-radius: 8px;
  box-shadow: 0 4px 23px rgba(0, 0, 0, 0.2);
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow: auto;
  padding: 24px 28px;
}

.modal h2 {
  font-family: var(--display);
  font-weight: 700;
  margin: 0 0 10px;
}

.modal p, .modal li { font-size: 14px; line-height: 1.55; color: var(--ink); }
.modal .example { display: flex; gap: 4px; margin: 8px 0; align-items: center; }
.modal .example .tile { width: 36px; height: 36px; font-size: 18px; }

/* ---------- auth ---------- */

.auth-box { max-width: 360px; margin: 0 auto; }

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 18px;
}

.auth-tabs button {
  flex: 1;
  padding: 10px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  font-family: var(--body);
  font-size: 15px;
  font-weight: 700;
  color: var(--gray-text);
  cursor: pointer;
}

.auth-tabs button.active { border-bottom-color: var(--ink); color: var(--ink); }

.field { margin-bottom: 12px; }

.field label {
  display: block;
  font-size: 12px;
  color: var(--gray-text);
  margin-bottom: 4px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--tile-line);
  border-radius: 4px;
  font-family: var(--body);
  font-size: 15px;
}

.auth-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--gray-text);
  font-size: 12px;
  margin: 16px 0;
}

.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--hairline);
}

.btn.block { display: block; width: 100%; text-align: center; margin-bottom: 10px; }
.btn.oauth { display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn.oauth svg { flex: 0 0 auto; }

.account-email { font-weight: 700; }

.stats-grid { display: flex; gap: 24px; margin: 16px 0 12px; }

.stat { text-align: center; }

.stat b {
  display: block;
  font-size: 32px;
  font-weight: 400;
  line-height: 1.1;
}

.stat span { font-size: 12px; color: var(--gray-text); }

.stats-extra { color: var(--gray-text); font-size: 13px; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: none;
  font-size: 26px;
  cursor: pointer;
  color: var(--ink);
  line-height: 1;
}

/* ---------- archive calendar ---------- */

.cal-nav { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 6px 0 14px; }

.cal-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  min-width: 180px;
  text-align: center;
  text-transform: capitalize;
}

.cal-arrow {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--gray-text);
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink);
  font-size: 18px;
}

.cal-arrow.disabled { opacity: 0.3; }

.cal { display: grid; grid-template-columns: repeat(7, 52px); gap: 8px; justify-content: center; }

.cal-head {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-text);
  padding-bottom: 2px;
  border-bottom: 1px solid var(--hairline);
}

.cal-cell { text-align: center; }

.cal-day {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border: 2px solid var(--tile-line);
  border-radius: 6px;
  background: var(--white);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.cal-day.won { background: var(--green); border-color: var(--green); }
.cal-day.lost { background: var(--absent); border-color: var(--absent); }
.cal-day.progress { background: var(--yellow); border-color: var(--yellow); color: var(--ink); }
.cal-day.today { box-shadow: 0 0 0 2px var(--ink); }
.cal-day.out { border-style: dashed; opacity: 0.35; pointer-events: none; }

.cal-num { font-size: 12px; color: var(--ink); margin-top: 4px; }
.cal-num.dim { color: var(--gray-text); }

@media (max-width: 430px) {
  .cal { grid-template-columns: repeat(7, 40px); gap: 6px; }
  .cal-day { width: 36px; height: 36px; font-size: 15px; }
}
