/* ───────────────────────────── базовые стили ───────────────────────────── */
:root {
  --cream: #fbf6ea;
  --cream-2: #f6eeda;
  --green-bg: #d9edd6;
  --green-bg-2: #e4f0dc;
  --ink: #1e2a1d;
  --ink-soft: rgba(30, 42, 29, 0.6);
  --white: #ffffff;
  --accent: #e8664a;
  --radius-card: 22px;
  --pill-green: linear-gradient(96deg, #79c088 0%, #b9e2bf 100%);
  --pill-yellow: linear-gradient(96deg, #efbc81 0%, #f9dfb3 100%);
  --pill-red: linear-gradient(96deg, #e79181 0%, #f4c3b9 100%);
  --pill-gray: linear-gradient(96deg, #e6e1d2 0%, #f1ede2 100%);
  --shadow: 0 2px 12px rgba(70, 58, 30, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--cream);
  display: flex;
  flex-direction: column;
}

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(20px + var(--safe-bottom));
}

.screen[hidden] {
  display: none;
}

@media (min-width: 560px) {
  body {
    background: radial-gradient(circle at 50% 0%, #f3ead6 0%, #e9e0ca 100%);
    padding: 18px 0;
  }
  #app {
    border-radius: 34px;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(60, 48, 20, 0.16);
    min-height: calc(100dvh - 36px);
  }
  .screen {
    min-height: calc(100dvh - 36px);
  }
}

/* ───────────────────────────── шапка ───────────────────────────── */
.topbar {
  background: var(--green-bg);
  border-radius: 0 0 26px 26px;
  padding: max(12px, env(safe-area-inset-top)) 10px 16px;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: 0 1px 0 rgba(30, 42, 29, 0.04);
}

.topbar-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
}

.game-title {
  position: absolute;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  pointer-events: none;
  font-size: clamp(17px, 5.2vw, 24px);
  font-weight: 800;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.game-sub {
  margin: 2px 0 0;
  text-align: center;
  font-size: 15px;
  color: rgba(30, 42, 29, 0.72);
  min-height: 20px;
}

.icon-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s;
}

.icon-btn:active {
  background: rgba(30, 42, 29, 0.08);
}

.icon-btn.ghost {
  pointer-events: none;
}

.eye-btn {
  margin-left: auto;
}

.eye-btn .eye-off {
  display: none;
}

.eye-btn.off .eye-on {
  display: none;
}

.eye-btn.off .eye-off {
  display: block;
}

/* слово скрыто, но плашка, порядок и число остались */
.word.blurred {
  filter: blur(7px);
  opacity: 0.55;
  user-select: none;
  pointer-events: none;
}

/* ───────────────────────────── контент ───────────────────────────── */
.content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 14px 8px;
}

.card {
  background: var(--white);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 9px;
}

.card-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #79c088;
  flex: 0 0 auto;
}

.link-btn {
  margin-left: auto;
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 14px;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  padding: 4px;
}

.link-btn svg {
  transition: transform 0.2s;
}

.link-btn.collapsed svg {
  transform: rotate(-90deg);
}

/* ───────────────────────────── ввод слова ───────────────────────────── */
.custom-secret {
  text-align: center;
  font-size: 16px;
  color: var(--ink);
  margin: -2px 0 2px;
}

.custom-secret b {
  font-weight: 700;
}

.custom-secret[hidden] {
  display: none;
}

.guess-form {
  position: relative;
  display: flex;
  align-items: center;
}

.guess-input {
  width: 100%;
  height: 54px;
  border-radius: 999px;
  border: 1.6px solid var(--ink);
  background: var(--white);
  padding: 0 58px 0 20px;
  font-size: 17px;
  font-family: inherit;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.guess-input::placeholder {
  color: rgba(30, 42, 29, 0.45);
}

.guess-input:focus {
  box-shadow: 0 0 0 4px rgba(121, 192, 136, 0.22);
}

.send-btn {
  position: absolute;
  right: 7px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s;
}

.send-btn:active {
  transform: scale(0.9);
  background: rgba(30, 42, 29, 0.07);
}

.tries {
  text-align: center;
  font-size: 16px;
  margin-top: -2px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ───────────────────────────── лидеры ───────────────────────────── */
.leaders {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-top: 15px;
  scrollbar-width: none;
}

.leaders::-webkit-scrollbar {
  display: none;
}

.leaders.collapsed {
  display: none;
}

.leader {
  flex: 0 0 auto;
  width: 64px;
  text-align: center;
}

.leader-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  margin: 0 auto;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  letter-spacing: -0.2px;
  background: var(--pill-green);
  color: var(--ink);
}

.leader-circle.yellow {
  background: var(--pill-yellow);
}

.leader-circle.red {
  background: var(--pill-red);
}

.leader-circle.empty {
  background: #f0ece0;
  color: rgba(30, 42, 29, 0.35);
}

.leader-name {
  margin-top: 6px;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 64px;
  color: var(--ink);
}

.leader.me .leader-name {
  font-weight: 700;
}

.leader.me .leader-circle {
  box-shadow: 0 0 0 2.5px var(--ink);
}

/* ───────────────────────────── подсказки ───────────────────────────── */
.hint-text {
  margin: 0;
  font-size: 17px;
  line-height: 1.38;
}

.rules-card[hidden] {
  display: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
  font-size: 13px;
  color: rgba(30, 42, 29, 0.72);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.green { background: #79c088; }
.legend-dot.yellow { background: #efbc81; }
.legend-dot.red { background: #e79181; }

/* ───────────────────── последнее введённое слово ───────────────────── */
/* Оформление то же, что у обычной плашки: размер, отступы, шрифт. */
.guess.last-card {
  /* отделяем от списка примерно на треть высоты плашки (54 / 3 = 18px) */
  margin-bottom: 8px;
  /* базовая анимация .guess здесь не нужна: иначе она перезапускается
     при снятии класса .pop */
  animation: none;
}

.last-card[hidden] {
  display: none;
}

.last-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

.last-card.pop {
  animation: last-pop 0.42s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes last-pop {
  0% { transform: scale(0.98); opacity: 0.7; }
  100% { transform: none; opacity: 1; }
}

/* ───────────────────────────── список попыток ───────────────────────────── */
.guesses {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guess {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 15px 20px;
  border-radius: 999px;
  font-size: 17px;
  color: var(--ink);
  animation: slide-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  border: 1px solid rgba(30, 42, 29, 0.05);
}

.guess.green { background: var(--pill-green); }
.guess.yellow { background: var(--pill-yellow); }
.guess.red { background: var(--pill-red); }

.guess.gray {
  background: var(--pill-gray);
}

.guess .score.unknown {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
  color: rgba(30, 42, 29, 0.55);
}

.guess .word {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guess .score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.guess.fresh {
  animation: slide-in 0.3s cubic-bezier(0.22, 1, 0.36, 1), glow 1s ease 0.3s;
}

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

@keyframes glow {
  0% { box-shadow: 0 0 0 0 rgba(30, 42, 29, 0.2); }
  100% { box-shadow: 0 0 0 14px rgba(30, 42, 29, 0); }
}

.list-tail {
  height: 8px;
}

/* ───────────────────────────── победа ───────────────────────────── */
.solved-card {
  text-align: center;
}

.solved-card .solved-emoji {
  font-size: 46px;
  line-height: 1;
  margin-bottom: 6px;
}

.solved-card h2 {
  font-size: 22px;
  margin-bottom: 6px;
}


.solved-card .primary-btn {
  margin-bottom: 8px;
}

.ghost-btn {
  border: 1.6px solid var(--ink);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  height: 44px;
  padding: 0 18px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.ghost-btn.small {
  height: 38px;
  padding: 0 14px;
  font-size: 14px;
  margin-left: auto;
  flex: 0 0 auto;
}

.ghost-btn.wide {
  width: 100%;
  height: 48px;
}

.new-round-chip {
  align-self: center;
  margin-top: -4px;
  border: 1.5px solid #4e8f5e;
  background: #eef7ec;
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}

.new-round-chip[hidden] {
  display: none;
}

/* ───────────────────────────── приветственный экран ───────────────────────────── */
.field-label {
  display: block;
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.text-input {
  width: 100%;
  height: 52px;
  border-radius: 16px;
  border: 1.5px solid #e2dbc9;
  background: #fcfaf3;
  padding: 0 16px;
  font-size: 17px;
  font-family: inherit;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.text-input:focus {
  border-color: #79c088;
  box-shadow: 0 0 0 4px rgba(121, 192, 136, 0.2);
}

.seg {
  display: flex;
  gap: 4px;
  background: #f6f1e4;
  border-radius: 14px;
  padding: 4px;
  margin-top: 10px;
}

.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: 11px;
  padding: 11px 6px;
  font-size: 14.5px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}

.seg-btn.active {
  background: #d9edd6;
  box-shadow: 0 1px 4px rgba(60, 50, 30, 0.1);
  font-weight: 600;
}

.seg-hint {
  margin: 10px 2px 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink-soft);
}

.primary-btn {
  width: 100%;
  height: 56px;
  border-radius: 18px;
  border: none;
  background: #2e5b42;
  color: #fff;
  font-size: 17px;
  font-family: inherit;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s;
  box-shadow: 0 8px 20px rgba(46, 91, 66, 0.24);
}

.primary-btn:active {
  transform: scale(0.985);
  background: #264d37;
}

.primary-btn:disabled {
  opacity: 0.6;
}

.join-row {
  display: flex;
  gap: 8px;
}

.code-input {
  text-transform: lowercase;
  letter-spacing: 2px;
  font-weight: 600;
}

.footnote {
  margin: 4px 6px 10px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-soft);
  text-align: center;
}

/* ───────────────────────────── модальные окна ───────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(30, 42, 29, 0.42);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 20px;
  animation: fade 0.2s ease;
  backdrop-filter: blur(3px);
}

.modal[hidden] {
  display: none;
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: #fff;
  border-radius: 26px;
  padding: 24px 20px 20px;
  width: 100%;
  max-width: 340px;
  animation: rise 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 21px;
}

.modal-sub {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--ink-soft);
}

.modal-card .text-input {
  margin-bottom: 14px;
}

.modal-card .primary-btn {
  height: 52px;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.modal.sheet {
  align-items: end;
  padding: 0;
}

.sheet-card {
  background: #fff;
  border-radius: 26px 26px 0 0;
  padding: 10px 16px calc(20px + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  animation: slide-up 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: none; }
}

.sheet-grip {
  width: 42px;
  height: 5px;
  border-radius: 999px;
  background: #e4ddcb;
  margin: 4px auto 14px;
}

.sheet-card h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.sheet-code {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 3px;
  margin-bottom: 16px;
  text-transform: lowercase;
}

.sheet-row {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: #faf7ee;
  border-radius: 14px;
  padding: 16px 18px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  margin-bottom: 8px;
}

.sheet-row:active {
  background: #f0ebdc;
}

.sheet-row.muted {
  color: #b04a3a;
  background: #fdf3f0;
}

/* ───────────────────────────── тосты и конфетти ───────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 14px);
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  padding: 11px 20px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 70;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 65;
  overflow: hidden;
}

.confetti i {
  position: absolute;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation: fall 2.4s ease-in forwards;
}

@keyframes fall {
  0% { opacity: 1; transform: translateY(-10vh) rotate(0); }
  100% { opacity: 0; transform: translateY(105vh) rotate(540deg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
