:root {
  --app-height: 100vh;
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #202124;
  --muted: #6f7378;
  --border: #d3d6da;
  --key: #d3d6da;
  --key-text: #202124;
  --empty: #ffffff;
  --filled-border: #878a8c;
  --absent: #787c7e;
  --present: #c9b458;
  --correct: #6aaa64;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
    "Segoe UI Symbol", "Noto Color Emoji";
  line-height: 1.5;
}

body.dark {
  --bg: #121213;
  --panel: #1f2023;
  --text: #f5f5f5;
  --muted: #a7a9ac;
  --border: #3a3a3c;
  --key: #818384;
  --key-text: #f5f5f5;
  --empty: #121213;
  --filled-border: #565758;
  --absent: #3a3a3c;
}

body.colorblind {
  --present: #85c0f9;
  --correct: #f5793a;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  width: min(100%, 28rem);
  height: var(--app-height);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

.topbar {
  width: 100%;
  min-height: 56px;
  display: grid;
  grid-template-columns: 32px 32px 32px 1fr 32px 32px 32px;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  overflow: hidden;
  text-align: center;
  text-transform: uppercase;
  text-overflow: clip;
  white-space: nowrap;
  font-size: 24px;
  font-weight: 800;
  line-height: 32px;
  letter-spacing: 1.2px;
}

.icon-button {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  line-height: 1;
}

.icon-button:nth-of-type(1),
.icon-button:nth-of-type(2),
.icon-button:nth-of-type(3) {
  justify-self: start;
}

.icon-button:nth-of-type(4),
.icon-button:nth-of-type(5),
.icon-button:nth-of-type(6) {
  justify-self: end;
}

.icon-button svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
}

.language-button {
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 24px;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: color-mix(in srgb, var(--key) 42%, transparent);
  outline: none;
}

.game {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 0;
  padding: 0 10px max(12px, env(safe-area-inset-bottom));
}

.timed-hud {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transform: translateX(-50%);
  padding: 4px 9px;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  color: var(--text);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
  font-size: 13px;
  font-weight: 800;
  line-height: 16px;
  pointer-events: none;
}

.timed-hud[hidden] {
  display: none;
}

.timed-hud span:first-child::after {
  content: "с";
  margin-left: 1px;
  color: var(--muted);
}

.timed-hud span:last-child::before {
  content: "×";
  margin-right: 2px;
  color: var(--muted);
}

.board {
  width: min(336px, calc(100vw - 24px));
  height: min(456px, calc(var(--app-height) - 217px));
  align-self: center;
  justify-self: center;
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 4px;
  transform: translateY(-1.5px);
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.tile {
  position: relative;
  width: 100%;
  height: 100%;
  display: inline-grid;
  place-items: center;
  border: 2px solid var(--border);
  background: var(--empty);
  color: var(--text);
  text-transform: uppercase;
  font-size: 36px;
  font-weight: 700;
  line-height: 40px;
  overflow: hidden;
  user-select: none;
}

body.accessible .tile.revealed::after {
  content: attr(data-mark);
  position: absolute;
  right: 3px;
  bottom: 2px;
  padding: 1px 2px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.3);
  color: #ffffff;
  font-size: 8px;
  font-weight: 900;
  line-height: 1;
}

.tile.filled {
  border-color: var(--filled-border);
}

.tile.revealed {
  border-color: transparent;
  color: #ffffff;
}

.tile.legacy-reveal {
  overflow: visible;
  border: 0;
  background: transparent;
}

.tile.pulse-present {
  animation: pulse-present 0.36s ease-out both;
}

.tile.pulse-correct {
  animation: pulse-correct 0.36s ease-out both;
}

.tile.revealed.settled,
.tile.revealed.settled.legacy-reveal,
.tile.revealed.settled.pulse-present,
.tile.revealed.settled.pulse-correct {
  animation: none;
}

.tile.correct {
  background: var(--correct);
}

.tile.present {
  background: var(--present);
}

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

.tile.legacy-reveal.correct,
.tile.legacy-reveal.present,
.tile.legacy-reveal.absent {
  background: transparent;
}

.react-card-flip,
.react-card-back {
  position: absolute;
  inset: 0;
}

.react-card-flip {
  perspective: 1000px;
}

.react-card-flipper {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.react-card-front,
.react-card-back {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 2px solid transparent;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.react-card-front {
  position: relative;
  z-index: 2;
  transform: rotateX(0deg);
  transition: transform 0.6s;
  border-color: var(--filled-border);
  background: var(--empty);
  color: var(--text);
}

.react-card-back {
  transform: rotateX(-180deg);
  transition: transform 0.9s;
  color: #ffffff;
}

.react-card-flipper.flipped .react-card-front {
  transform: rotateX(180deg);
}

.react-card-flipper.flipped .react-card-back {
  transform: rotateX(0deg);
}

.react-card-flipper.settled .react-card-front,
.react-card-flipper.settled .react-card-back {
  transition: none;
}

.react-card-back.correct {
  background: var(--correct);
}

.react-card-back.present {
  background: var(--present);
}

.react-card-back.absent {
  background: var(--absent);
}

.react-card-content {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.tile.pop {
  animation: pop 0.08s ease-out;
}

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

.keyboard {
  width: min(100%, 428px, calc(100vw - 20px));
  align-self: end;
  justify-self: center;
  display: grid;
  gap: 8px;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.key {
  min-width: 0;
  height: 56px;
  flex: 1 1 0;
  border: 0;
  border-radius: 4px;
  padding: 0 2px;
  background: var(--key);
  color: var(--key-text);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
  line-height: 16px;
}

.key.hint {
  background:
    linear-gradient(
      to top,
      rgb(37 99 235 / var(--hint-strength, 0.28)) 0%,
      rgb(37 99 235 / calc(var(--hint-strength, 0.28) * 0.55)) 42%,
      rgb(37 99 235 / 0) 100%
    ),
    var(--key);
}

.key.wide {
  flex: 1.6 1 0;
  font-size: 12px;
}

.key-icon {
  width: 24px;
  height: 24px;
  display: block;
  margin: 0 auto;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.key[data-key="kana-toggle"] {
  flex: 0 0 48px;
  font-size: 12px;
}

.key[data-key="backspace"] {
  flex: 0 0 44px;
}

.key[data-key="enter"] {
  flex: 0 0 50px;
}

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

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

.key.correct.hint {
  background:
    linear-gradient(
      to top,
      rgb(37 99 235 / var(--hint-strength, 0.28)) 0%,
      rgb(37 99 235 / calc(var(--hint-strength, 0.28) * 0.55)) 42%,
      rgb(37 99 235 / 0) 100%
    ),
    var(--correct);
}

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

.key.present.hint {
  background:
    linear-gradient(
      to top,
      rgb(37 99 235 / var(--hint-strength, 0.28)) 0%,
      rgb(37 99 235 / calc(var(--hint-strength, 0.28) * 0.55)) 42%,
      rgb(37 99 235 / 0) 100%
    ),
    var(--present);
}

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

.info-band {
  display: none;
}

.info-band h2 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 18px;
}

.info-band p {
  margin: 0;
}

.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  z-index: 20;
  max-width: min(92vw, 420px);
  transform: translateX(-50%) translateY(-10px);
  padding: 10px 14px;
  border-radius: 4px;
  background: #202124;
  color: #ffffff;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal {
  width: min(92vw, 450px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(17, 24, 39, 0.72);
}

.modal-panel {
  max-height: min(88vh, calc(var(--app-height) - 38px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
  background: color-mix(in srgb, var(--key) 16%, var(--panel));
}

.modal-header h2 {
  margin: 0;
  text-transform: uppercase;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0;
}

.modal-body {
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
}

.modal-body p {
  margin: 0 0 14px;
}

.rules-content {
  overflow-wrap: anywhere;
}

.rules-section + .rules-section {
  margin-top: 18px;
}

.rules-section h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 800;
  line-height: 20px;
  text-transform: uppercase;
}

.rules-section ul {
  margin: 0 0 14px;
  padding-left: 18px;
}

.rules-section li {
  margin: 0 0 8px;
}

.example-row {
  display: grid;
  grid-template-columns: repeat(5, 44px);
  gap: 5px;
  margin: 10px 0 16px;
}

.example-row .tile {
  font-size: 24px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: center;
}

.stats-grid strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}

.stats-grid span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.stats-chart-section {
  margin-top: 18px;
}

.stats-chart-section h3 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 20px;
}

.stats-mode-switch {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.stats-mode-switch:hover,
.stats-mode-switch:focus-visible {
  color: var(--text);
  outline: none;
}

.stats-chart {
  display: grid;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.timed-bars,
.timed-breakdown,
.normal-distribution {
  display: grid;
  gap: 6px;
}

.timed-bar-row,
.normal-bar-row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) 24px;
  gap: 8px;
  align-items: center;
}

.timed-bar-label,
.timed-bucket-detail strong,
.normal-bar-label {
  color: var(--text);
}

.timed-bar-track,
.normal-bar-track {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--key) 55%, transparent);
}

.timed-bar-fill,
.normal-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  min-width: 0;
  border-radius: inherit;
  background: var(--correct);
}

.normal-bar-fill.best {
  background: var(--present);
}

.timed-bar-count,
.normal-bar-count {
  text-align: right;
  color: var(--text);
  font-weight: 700;
}

.timed-bucket-detail {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

@media (max-width: 380px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .example-row {
    grid-template-columns: repeat(5, 36px);
    gap: 4px;
  }

  .example-row .tile {
    font-size: 20px;
  }

  .timed-bar-row,
  .normal-bar-row,
  .timed-bucket-detail {
    grid-template-columns: 76px minmax(0, 1fr) 22px;
    gap: 6px;
  }

  .timed-bucket-detail {
    grid-template-columns: 76px minmax(0, 1fr);
  }
}

.bar-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 8px;
}

.bar {
  min-width: 28px;
  padding: 3px 6px;
  background: var(--absent);
  color: #ffffff;
  text-align: right;
  font-size: 12px;
  font-weight: 800;
}

.bar.best {
  background: var(--correct);
}

.settings-list {
  display: grid;
  gap: 14px;
}

.settings-separator {
  height: 1px;
  margin: 2px 0;
  background: var(--border);
}

.setting-icon-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.setting-enter-icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.switch-row input {
  position: relative;
  width: 36px;
  height: 20px;
  flex: 0 0 auto;
  appearance: none;
  border: 0;
  border-radius: 9999px;
  background: #404040;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.switch-row input::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 9999px;
  background: #ffffff;
  transition: transform 0.15s ease;
}

.switch-row input:checked {
  background: #3b82f6;
}

.switch-row input:checked::before {
  transform: translateX(16px);
}

.switch-row input:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 14px;
}

.field input {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--empty);
  color: var(--text);
  text-transform: uppercase;
  font-size: 24px;
  font-weight: 800;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.primary-button,
.secondary-button,
.qa-button {
  min-height: 42px;
  flex: 1 1 160px;
  border: 0;
  border-radius: 4px;
  padding: 10px 14px;
  color: #ffffff;
  font-weight: 800;
}

.primary-button {
  background: #2563eb;
}

.secondary-button {
  background: var(--correct);
}

.qa-button {
  background: var(--absent);
}

.share-preview {
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--key) 18%, var(--panel));
  color: var(--text);
  white-space: pre-wrap;
  font: inherit;
}

.solution-line,
.timer-line,
.friend-link {
  color: var(--muted);
  overflow-wrap: anywhere;
}

@keyframes pop {
  from {
    transform: scale(0.92);
  }
  to {
    transform: scale(1);
  }
}

@keyframes pulse-present {
  0%,
  100% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.09);
  }
}

@keyframes pulse-correct {
  0%,
  100% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.14);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  .tile.pulse-present,
  .tile.pulse-correct,
  .tile.pop,
  .row.shake {
    animation: none !important;
  }

  .tile.legacy-reveal .react-card-front,
  .tile.legacy-reveal .react-card-back {
    transition: none !important;
  }

  .tile.legacy-reveal .react-card-front {
    transform: rotateX(180deg);
  }

  .tile.legacy-reveal .react-card-back {
    transform: rotateX(0deg);
  }
}

@media (max-width: 700px) {
  .topbar h1 {
    font-size: 20px;
    line-height: 28px;
    letter-spacing: 1px;
  }
}

@media (max-width: 480px) and (min-width: 381px) {
  .topbar {
    grid-template-columns: 24px 24px 24px 1fr 24px 24px 24px;
  }

  .topbar h1 {
    font-size: 16px;
    line-height: 24px;
    letter-spacing: 0.8px;
  }
}

@media (max-width: 380px) {
  .topbar {
    grid-template-columns: 24px 24px 24px 1fr 24px 24px 24px;
    min-height: 40px;
    padding: 0 8px;
  }

  .topbar h1 {
    font-size: clamp(12px, 4vw, 16px);
    line-height: 24px;
    letter-spacing: 0.4px;
  }

  .icon-button:nth-of-type(3) {
    justify-self: start;
  }

  .game {
    padding: 0 0 max(12px, env(safe-area-inset-bottom));
  }

  .board,
  .row {
    gap: 4px;
  }

  .keyboard,
  .key-row {
    gap: 4px;
  }

  .key {
    height: 48px;
  }

  .key[data-key="backspace"] {
    flex: 0 0 36px;
  }

  .key[data-key="enter"] {
    flex: 0 0 42px;
  }
}

@media (max-width: 349px) {
  .key {
    height: 40px;
  }

  .keyboard {
    gap: 8px;
  }
}
