:root {
  color-scheme: light;
  --ink: #15202a;
  --ink-soft: #45515d;
  --paper: rgba(252, 248, 238, 0.86);
  --paper-solid: #f7f0df;
  --line: rgba(21, 32, 42, 0.16);
  --line-strong: rgba(21, 32, 42, 0.28);
  --green: #247d59;
  --green-bright: #4fb27d;
  --gold: #c88a24;
  --coral: #cc624b;
  --cyan: #287d91;
  --absent: #33404b;
  --shadow: 0 24px 80px rgba(18, 24, 28, 0.22);
  --tile-size: clamp(2.65rem, min(6.4vw, 6.7vh), 3.65rem);
  font-family:
    Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 20rem;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: #cabfa9 url("./assets/letter-table.png") center / cover fixed;
  touch-action: manipulation;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(120deg, rgba(22, 31, 37, 0.52), rgba(247, 240, 223, 0.18) 42%, rgba(20, 38, 47, 0.44)),
    radial-gradient(circle at 50% 32%, rgba(255, 252, 243, 0.64), rgba(255, 252, 243, 0) 40%);
  content: "";
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  letter-spacing: 0;
  touch-action: manipulation;
}

button:not(:disabled) {
  cursor: pointer;
}

.app {
  width: min(100% - 2rem, 72rem);
  min-height: 100vh;
  margin: 0 auto;
  padding: 1.25rem 0 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.44);
  border-radius: 8px;
  background: rgba(255, 248, 235, 0.7);
  box-shadow: 0 12px 42px rgba(18, 24, 28, 0.14);
  backdrop-filter: blur(1rem);
}

.brand,
.topbar-actions,
.round-strip,
.rail-actions,
.modal-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 0.45rem;
  min-width: 0;
}

.brand-tile {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid rgba(21, 32, 42, 0.12);
  border-radius: 7px;
  color: #fff7e8;
  background: var(--ink);
  box-shadow: inset 0 -0.18rem rgba(0, 0, 0, 0.18);
  font-weight: 800;
  place-items: center;
}

.brand-tile-accent {
  background: var(--coral);
}

.brand-name {
  overflow: hidden;
  margin-left: 0.35rem;
  font-size: clamp(1.15rem, 2vw, 1.55rem);
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.utility-button,
.ghost-button,
.primary-button,
.mode-button,
.close-button {
  min-height: 2.7rem;
  border-radius: 8px;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.utility-button,
.ghost-button {
  border: 1px solid var(--line);
  background: rgba(255, 250, 238, 0.72);
}

.utility-button {
  padding: 0 0.9rem;
}

.utility-button:hover,
.ghost-button:hover,
.mode-button:hover,
.close-button:hover {
  border-color: var(--line-strong);
  background: rgba(255, 252, 244, 0.96);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(18rem, 31rem) minmax(16rem, 20rem);
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 3vw, 2.4rem);
  min-height: calc(100vh - 6.5rem);
  padding: clamp(1.1rem, 3vw, 2.5rem) 0;
}

.game-stage,
.control-rail {
  border: 1px solid rgba(255, 255, 255, 0.46);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(1.15rem);
}

.game-stage {
  display: grid;
  justify-items: center;
  gap: clamp(0.8rem, 2vh, 1.1rem);
  padding: clamp(0.9rem, 2.2vw, 1.35rem);
}

.round-strip {
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
}

.eyebrow {
  margin: 0 0 0.3rem;
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  margin-bottom: 0;
  letter-spacing: 0;
  line-height: 1.08;
}

h1 {
  font-size: clamp(1.55rem, 3vw, 2.35rem);
}

h2 {
  font-size: clamp(1.35rem, 2.5vw, 1.9rem);
}

.round-meta {
  display: grid;
  justify-items: end;
  gap: 0.18rem;
  max-width: 10rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
  text-align: right;
}

.round-meta strong {
  color: var(--ink);
  font-size: 0.78rem;
  line-height: 1.22;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, var(--tile-size));
  grid-template-rows: repeat(6, var(--tile-size));
  gap: clamp(0.28rem, 0.8vw, 0.42rem);
  width: max-content;
}

.tile {
  display: grid;
  width: var(--tile-size);
  height: var(--tile-size);
  border: 2px solid rgba(21, 32, 42, 0.18);
  border-radius: 8px;
  background: rgba(255, 252, 244, 0.64);
  color: var(--ink);
  font-size: clamp(1.55rem, 5vw, 2.35rem);
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
  box-shadow: inset 0 -0.3rem rgba(21, 32, 42, 0.05);
  place-items: center;
  transform-style: preserve-3d;
}

.tile.is-filled {
  border-color: rgba(21, 32, 42, 0.42);
  animation: pop 150ms ease both;
}

.tile.is-current {
  border-color: var(--cyan);
}

.tile.correct,
.tile.present,
.tile.absent {
  border-color: transparent;
  color: #fff8eb;
  animation: reveal 560ms ease both;
}

.tile.correct {
  background: linear-gradient(150deg, var(--green-bright), var(--green));
}

.tile.present {
  background: linear-gradient(150deg, #e1b03a, var(--gold));
}

.tile.absent {
  background: linear-gradient(150deg, #556470, var(--absent));
}

.board.is-shaking .tile.is-current,
.board.is-shaking .tile.pending {
  animation: shake 420ms ease;
}

.keyboard {
  display: grid;
  gap: 0.42rem;
  width: min(100%, 28rem);
}

.key-row {
  display: grid;
  gap: 0.34rem;
  grid-template-columns: repeat(var(--keys), minmax(0, 1fr));
}

.key-row:last-child {
  grid-template-columns: 1.45fr repeat(9, minmax(0, 1fr)) 1.35fr;
}

.key {
  min-width: 0;
  min-height: clamp(2.15rem, 5vh, 2.9rem);
  border: 1px solid rgba(21, 32, 42, 0.14);
  border-radius: 7px;
  background: rgba(255, 250, 238, 0.86);
  color: var(--ink);
  font-size: clamp(0.8rem, 1.8vw, 1rem);
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: inset 0 -0.18rem rgba(21, 32, 42, 0.08);
  transition:
    transform 120ms ease,
    background 160ms ease,
    color 160ms ease;
}

.key:hover {
  background: #fffaf0;
}

.key:active,
.utility-button:active,
.ghost-button:active,
.primary-button:active,
.mode-button:active {
  transform: translateY(1px);
}

.key.wide {
  font-size: 0.76rem;
}

.key.correct,
.key.present,
.key.absent {
  color: #fff8eb;
}

.key.correct {
  background: var(--green);
}

.key.present {
  background: var(--gold);
}

.key.absent {
  background: var(--absent);
}

.control-rail {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 3vw, 1.4rem);
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 40, 49, 0.08);
}

.mode-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 900;
}

.mode-button.is-active {
  border-color: rgba(255, 255, 255, 0.54);
  color: #fff8eb;
  background: var(--ink);
}

.rail-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  width: 100%;
}

.metric {
  min-width: 0;
  min-height: 4.35rem;
  padding: 0.75rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 251, 241, 0.56);
}

.metric span,
.metric strong {
  display: block;
}

.metric span {
  overflow-wrap: anywhere;
  color: var(--ink-soft);
  font-size: 0.76rem;
}

.metric strong {
  margin-top: 0.35rem;
  font-size: clamp(1rem, 2vw, 1.4rem);
}

.rail-actions,
.modal-actions {
  gap: 0.55rem;
}

.primary-button,
.ghost-button {
  flex: 1 1 0;
  padding: 0 0.9rem;
  font-weight: 900;
}

.primary-button {
  border: 1px solid rgba(36, 125, 89, 0.28);
  color: #fff8eb;
  background: linear-gradient(135deg, var(--green), #186858);
}

.primary-button:hover {
  background: linear-gradient(135deg, #2d9568, #186858);
}

.ghost-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.status-line {
  min-height: 3.4rem;
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.45;
}

.account-card {
  display: grid;
  align-items: center;
  gap: 0.7rem;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 251, 241, 0.56);
}

.account-copy {
  min-width: 0;
}

.account-copy .eyebrow {
  margin-bottom: 0.16rem;
}

.account-copy strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.telegram-login {
  min-height: 0;
  overflow: hidden;
}

.telegram-login iframe {
  max-width: 100%;
}

.account-logout {
  width: 100%;
}

.toast {
  position: fixed;
  right: 50%;
  bottom: 1rem;
  z-index: 5;
  max-width: min(90vw, 28rem);
  padding: 0.8rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  color: #fff8eb;
  background: rgba(21, 32, 42, 0.92);
  box-shadow: 0 18px 48px rgba(18, 24, 28, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translate(50%, 1rem);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

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

.modal {
  width: min(100% - 1.5rem, 32rem);
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
}

.modal::backdrop {
  background: rgba(10, 17, 21, 0.56);
  backdrop-filter: blur(0.35rem);
}

.modal-shell {
  position: relative;
  display: grid;
  gap: 1rem;
  max-height: min(88vh, 44rem);
  overflow: auto;
  margin: 0;
  padding: clamp(1rem, 4vw, 1.6rem);
  border: 1px solid rgba(255, 255, 255, 0.54);
  border-radius: 8px;
  background: var(--paper-solid);
  box-shadow: var(--shadow);
}

.modal-shell > p {
  margin-bottom: 0;
  line-height: 1.5;
}

.close-button {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  min-height: 2.2rem;
  padding: 0 0.72rem;
  border: 1px solid var(--line);
  background: rgba(255, 250, 238, 0.8);
  color: var(--ink-soft);
  font-size: 0.84rem;
}

.example-row {
  display: grid;
  grid-template-columns: repeat(5, 2.7rem);
  gap: 0.35rem;
}

.sample {
  display: grid;
  width: 2.7rem;
  height: 2.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff8ea;
  font-size: 1.3rem;
  font-weight: 950;
  place-items: center;
}

.sample.correct,
.sample.present,
.sample.absent {
  border-color: transparent;
  color: #fff8eb;
}

.sample.correct {
  background: var(--green);
}

.sample.present {
  background: var(--gold);
}

.sample.absent {
  background: var(--absent);
}

.legend {
  display: grid;
  gap: 0.55rem;
}

.legend p {
  margin-bottom: 0;
}

.field {
  display: grid;
  gap: 0.36rem;
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 800;
}

.field input {
  width: 100%;
  min-height: 3rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: none;
  padding: 0 0.85rem;
  color: var(--ink);
  background: rgba(255, 251, 241, 0.94);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-transform: none;
}

#challengeWord {
  text-transform: lowercase;
}

.field input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 0.2rem rgba(40, 125, 145, 0.16);
}

.modal-submit {
  width: 100%;
}

.link-result {
  display: grid;
  gap: 0.65rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.telegram-challenge-actions {
  align-items: stretch;
}

.leaderboard-list {
  display: grid;
  gap: 0.42rem;
}

.leader-row,
.leader-empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 251, 241, 0.7);
}

.leader-row {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.55rem;
  min-height: 3.4rem;
  padding: 0.55rem;
}

.leader-rank {
  color: var(--coral);
  font-weight: 950;
  text-align: center;
}

.leader-player {
  min-width: 0;
}

.leader-player strong,
.leader-player span,
.leader-score strong,
.leader-score span {
  display: block;
}

.leader-player strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leader-player span,
.leader-score span {
  color: var(--ink-soft);
  font-size: 0.76rem;
}

.leader-score {
  min-width: 3.4rem;
  text-align: right;
}

.leader-empty {
  padding: 0.9rem;
  color: var(--ink-soft);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
}

.stats-grid div {
  min-height: 4.9rem;
  padding: 0.65rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 238, 0.76);
  text-align: center;
}

.stats-grid strong,
.stats-grid span {
  display: block;
}

.stats-grid strong {
  font-size: clamp(1.2rem, 4vw, 1.8rem);
}

.stats-grid span {
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.distribution {
  display: grid;
  gap: 0.42rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 1rem 1fr;
  align-items: center;
  gap: 0.45rem;
}

.bar-track {
  min-height: 1.7rem;
  overflow: hidden;
  border-radius: 6px;
  background: rgba(21, 32, 42, 0.09);
}

.bar-fill {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 2rem;
  height: 100%;
  padding: 0 0.45rem;
  border-radius: inherit;
  color: #fff8eb;
  background: var(--cyan);
  font-size: 0.82rem;
  font-weight: 900;
}

.result-banner {
  display: grid;
  gap: 0.28rem;
  padding: 0.8rem;
  border: 1px solid rgba(204, 98, 75, 0.22);
  border-radius: 8px;
  background: rgba(204, 98, 75, 0.11);
}

.result-banner .eyebrow {
  margin-bottom: 0;
  color: var(--coral);
}

.result-banner strong {
  font-size: 1.2rem;
}

@keyframes pop {
  0% {
    transform: scale(0.92);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes reveal {
  0% {
    transform: rotateX(0);
  }

  48% {
    transform: rotateX(88deg);
  }

  100% {
    transform: rotateX(0);
  }
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-0.28rem);
  }

  40%,
  80% {
    transform: translateX(0.28rem);
  }
}

@media (max-width: 50rem) {
  .app {
    width: 100%;
    padding: 0 0 1rem;
  }

  body {
    background-image: none;
    background-color: #e8ddc7;
  }

  body::before {
    background:
      linear-gradient(180deg, rgba(255, 250, 239, 0.86), rgba(225, 213, 188, 0.56)),
      linear-gradient(135deg, rgba(40, 125, 145, 0.1), rgba(204, 98, 75, 0.08));
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: grid;
    gap: 0.42rem;
    padding: 0.48rem 0.5rem 0.52rem;
    border-radius: 0;
    border-width: 0 0 1px;
    background: rgba(250, 244, 229, 0.94);
  }

  .brand {
    gap: 0.28rem;
  }

  .brand-tile {
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 6px;
    font-size: 0.86rem;
  }

  .brand-name {
    margin-left: 0.18rem;
    font-size: 1rem;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.3rem;
    width: 100%;
  }

  .utility-button,
  .ghost-button,
  .primary-button,
  .mode-button {
    min-height: 2.8rem;
  }

  .utility-button {
    min-width: 0;
    padding: 0 0.42rem;
    font-size: 0.81rem;
    line-height: 1.08;
    white-space: normal;
  }

  .game-layout {
    grid-template-columns: 1fr;
    align-items: start;
    min-height: auto;
    gap: 0.45rem;
    padding: 0;
  }

  .game-stage,
  .control-rail {
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .game-stage {
    gap: 0.42rem;
    padding: 0.48rem 0.5rem 0.55rem;
    border-width: 0 0 1px;
    background: rgba(251, 246, 235, 0.9);
  }

  .round-strip {
    gap: 0.38rem;
    align-items: end;
  }

  .eyebrow {
    margin-bottom: 0.12rem;
    font-size: 0.64rem;
  }

  h1 {
    font-size: clamp(1.2rem, 5vw, 1.55rem);
  }

  .round-meta {
    max-width: 7.6rem;
    font-size: 0.78rem;
    line-height: 1.2;
  }

  .round-meta strong {
    font-size: 0.67rem;
  }

  .board {
    gap: 0.22rem;
  }

  .tile {
    border-radius: 7px;
    font-size: clamp(1.35rem, 7vw, 2rem);
  }

  .keyboard {
    gap: 0.34rem;
    width: 100%;
  }

  .key-row {
    gap: 0.2rem;
  }

  .key {
    min-height: clamp(2.72rem, 6.2vh, 3.18rem);
    border-radius: 6px;
    font-size: 0.9rem;
  }

  .key.wide {
    font-size: 0.8rem;
  }

  .control-rail {
    gap: 0.45rem;
    padding: 0.5rem;
    border-width: 1px 0 0;
    background: rgba(251, 246, 235, 0.82);
  }

  .mode-switch {
    order: 1;
    padding: 0.18rem;
  }

  .rail-actions {
    order: 2;
    gap: 0.42rem;
  }

  .metric {
    min-height: 2.62rem;
    padding: 0.38rem;
  }

  .metric span {
    font-size: 0.68rem;
  }

  .metric strong {
    margin-top: 0.14rem;
  }

  .account-card {
    order: 5;
    gap: 0.42rem;
    padding: 0.5rem;
  }

  .status-line {
    order: 3;
    min-height: 0;
    font-size: 0.84rem;
    line-height: 1.2;
  }
}

@media (max-width: 33rem) {
  :root {
    --tile-size: min(12.7vw, 7.2vh, 3.35rem);
  }

  .rail-actions,
  .modal-actions {
    align-items: stretch;
  }

  .utility-button {
    flex: 0 1 auto;
  }

  .topbar-actions #rulesButton,
  .topbar-actions #statsButton {
    padding-inline: 0.32rem;
  }

  .modal-actions {
    flex-direction: column;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .brand-tile {
    width: 2rem;
    height: 2rem;
  }
}
