:root {
  --ink: #15171c;
  --ink-raised: #20232b;
  --ink-line: #33373f;
  --paper: #f3ead8;
  --paper-dim: #d9cdb6;
  --on-paper: #24201a;
  --on-paper-soft: #6d6353;
  --text: #f1ece2;
  --text-soft: #a5a29b;
  --red: #d6402b;
  --red-soft: #f08a78;
  --gold: #e3b34c;
  --hanzi: "Songti SC", "Noto Serif SC", "STSong", serif;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--ui);
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

h1, h2, h3, p, ul, dl, dd { margin: 0; padding: 0; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

button { font: inherit; color: inherit; cursor: pointer; }

.button {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--ink-line);
  border-radius: 8px;
  background: var(--ink-raised);
  font-weight: 600;
  font-size: 17px;
}

.button.primary { border-color: var(--red); background: var(--red); color: #fff; }
.button:disabled { opacity: .4; cursor: default; }

.link { border: 0; background: none; color: var(--text-soft); font-size: 15px; padding: 10px 0; }

/* Главная */

.home { align-items: center; justify-content: center; gap: 12px; text-align: center; }

.seal {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  margin-bottom: 6px;
  border-radius: 10px;
  background: var(--red);
  color: #fff;
  font: 700 48px/1 var(--hanzi);
}

h1 { font-size: 34px; letter-spacing: .01em; }
.tagline { color: var(--text-soft); font-size: 16px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  margin: 18px 0 2px;
  border-top: 1px solid var(--ink-line);
  border-bottom: 1px solid var(--ink-line);
}

.stats > div { padding: 14px 4px; }
.stats dd { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats dt { order: 2; color: var(--text-soft); font-size: 13px; }
.stats > div { display: flex; flex-direction: column; gap: 2px; }

.best { min-height: 20px; color: var(--gold); font-size: 14px; }

.sync-status { min-height: 18px; margin-bottom: 8px; color: var(--text-soft); font-size: 13px; }

.login-form { display: grid; gap: 10px; width: 100%; margin-top: 16px; }

.login-form input {
  width: 100%;
  min-height: 52px;
  padding: 0 12px;
  border: 1px solid var(--ink-line);
  border-radius: 8px;
  outline: none;
  background: var(--ink-raised);
  color: var(--text);
  font: 20px var(--ui);
  text-align: center;
}

.login-form input:focus { border-color: var(--gold); }

/* Словарик */

.dict { gap: 12px; }

.bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 48px;
}

.bar .link { justify-self: start; }
.bar h2 { font-size: 17px; }
.count { justify-self: end; color: var(--text-soft); font-size: 14px; font-variant-numeric: tabular-nums; }

.word-form { display: grid; gap: 10px; }
.word-form label { display: grid; gap: 4px; color: var(--text-soft); font-size: 13px; }

.word-form input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--ink-line);
  border-radius: 8px;
  outline: none;
  background: var(--ink-raised);
  color: var(--text);
  font: 17px var(--ui);
}

.word-form input:focus { border-color: var(--gold); }
.word-form input::placeholder { color: #6e6c67; }
.form-error { color: var(--red-soft); font-size: 14px; }
.form-error:empty { display: none; }
.form-actions { display: flex; gap: 10px; }

.word-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  -webkit-overflow-scrolling: touch;
}

.word-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--ink-line);
}

.word-row .main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-width: 0; border: 0; padding: 0; background: none; text-align: left; }
.word-row .hanzi { font: 600 22px var(--hanzi); }
.word-row .pinyin { color: var(--gold); font-size: 15px; }
.word-row .ru { flex-basis: 100%; color: var(--text-soft); font-size: 14px; overflow-wrap: anywhere; }
.word-row .delete { width: 40px; height: 40px; border: 0; background: none; color: var(--text-soft); font-size: 18px; }

.dots { display: flex; gap: 3px; flex-basis: 100%; margin-top: 4px; }
.dots i { width: 14px; height: 3px; background: var(--ink-line); }
.dots i.on { background: var(--gold); }

.empty { padding: 24px 12px; color: var(--text-soft); text-align: center; line-height: 1.45; }

/* Игра */

.game { padding-left: 0; padding-right: 0; touch-action: none; user-select: none; -webkit-user-select: none; }

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 48px;
  padding: 0 12px;
}

.lives { display: flex; gap: 6px; }
.lives i { width: 14px; height: 14px; border-radius: 3px; background: var(--red); }
.lives i.lost { background: var(--ink-line); }
.score { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.icon-button { justify-self: end; width: 44px; height: 44px; border: 0; background: none; color: var(--text-soft); font-size: 13px; }

.field {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-bottom: 2px solid var(--red);
}

.card {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: calc(33.333% - 6px);
  min-height: 72px;
  padding: 8px 4px;
  border-radius: 6px;
  background: var(--paper);
  color: var(--on-paper);
  text-align: center;
  will-change: transform;
}

.card .hanzi { font: 700 28px/1.15 var(--hanzi); overflow-wrap: anywhere; }
.card .pinyin { margin-top: 2px; color: #a8331f; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.card .ru { margin-top: 2px; color: var(--on-paper-soft); font-size: 13px; line-height: 1.2; overflow-wrap: anywhere; }
.card.ru-only .ru { color: var(--on-paper); font-size: 16px; font-weight: 600; }

.card.locked { box-shadow: 0 0 0 3px var(--gold); }
.card.shake { animation: shake .24s; }

.card.cleared {
  background: var(--gold);
  opacity: 0;
  transition: opacity .32s ease-out;
}

.reveal {
  position: absolute;
  right: 8px;
  bottom: 8px;
  left: 8px;
  z-index: 2;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--red);
  color: #fff;
  font-size: 15px;
  text-align: center;
}

.reveal b { font: 700 19px var(--hanzi); }

.typed {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 46px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .04em;
}

.typed.shake { animation: shake .24s; color: var(--red-soft); }
.caret { width: 2px; height: 22px; margin-left: 2px; background: var(--gold); animation: blink 1s steps(2) infinite; }

.keyboard { display: grid; gap: 7px; padding: 0 3px 6px; }
.keyboard .row { display: flex; justify-content: center; gap: 4px; }

.key {
  position: relative;
  flex: 0 1 9.4%;
  min-width: 0;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: #3a3e47;
  color: var(--text);
  font-size: 19px;
  touch-action: none;
}

.key.wide { flex-basis: 15%; background: #2a2d34; font-size: 17px; }
.key.down { background: var(--gold); color: var(--on-paper); }
.key small { position: absolute; top: 2px; right: 3px; color: var(--gold); font-size: 10px; }
.key.down small { color: var(--on-paper); }

@media (hover: hover) and (pointer: fine) {
  .keyboard { display: none; }
  .typed { height: 60px; }
}

@media (max-height: 640px) {
  .key { height: 40px; }
  .card .hanzi { font-size: 24px; }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  background: rgba(21, 23, 28, .92);
}

.overlay h2 { margin-bottom: 12px; font-size: 26px; }

/* Итоги */

.result { gap: 8px; padding-top: calc(env(safe-area-inset-top) + 32px); padding-bottom: calc(env(safe-area-inset-bottom) + 16px); text-align: center; }
.result h2 { font-size: 22px; }
.result-score { font-size: 60px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.result h3 { margin: 16px 0 4px; color: var(--text-soft); font-size: 14px; font-weight: 600; text-align: left; }
#result-missed-block { display: flex; flex: 1; flex-direction: column; min-height: 0; text-align: left; }
.result-actions { display: grid; gap: 10px; margin-top: auto; padding-top: 12px; }

@keyframes shake {
  25% { translate: -5px 0; }
  75% { translate: 5px 0; }
}

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

@media (prefers-reduced-motion: reduce) {
  .card.shake, .typed.shake { animation: none; }
  .caret { animation: none; }
}
