:root {
  color-scheme: dark;
  --background: #1c1c1e;
  --surface: #2b2b2b;
  --tile-empty: #333335;
  --tile-absent: #4d4d4d;
  --yellow: #fedd2c;
  --white: #ffffff;
  --text: #f5f5f5;
  --muted: #b6b6b6;
  --line: #444444;
  --key-height: 52px;
  --key-gap: 6px;
  --board-gap: 7px;
  font-family: Arial, Helvetica, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  min-width: 280px;
  min-height: 100%;
  background: var(--background);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--text);
  background: var(--background);
  overflow-x: hidden;
}

button {
  padding: 0;
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 4px;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: min(100%, 520px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  margin-bottom: 26px;
}

.wordmark {
  display: flex;
  flex: 0 0 auto;
  gap: 2px;
  user-select: none;
}

.wordmark span {
  display: grid;
  width: 31px;
  height: 33px;
  place-items: center;
  border-radius: 4px;
  color: #242424;
  background: var(--yellow);
  font-size: 26px;
  font-weight: 500;
  font-style: normal;
  line-height: 1;
}

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

.icon-button {
  display: grid;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 10px;
  color: #e5e5e5;
  background: transparent;
}

.icon-button svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:active { background: #333333; }

.screen { width: 100%; }

.screen--game {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--board-gap);
  width: min(100%, calc((100svh - 310px) * 0.825));
  max-width: 480px;
  margin: auto 0;
}

.board-row { display: contents; }

.board:focus { outline: none; }

.tile {
  display: grid;
  min-width: 0;
  aspect-ratio: 1;
  place-items: center;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: clamp(6px, 2vw, 10px);
  color: var(--text);
  background: var(--tile-empty);
  font-size: clamp(24px, min(9vw, calc((100svh - 310px) * 0.08)), 48px);
  font-weight: 400;
  line-height: 1;
  user-select: none;
}

.tile--correct,
.tile[data-state="correct"] {
  color: #282828;
  background: var(--yellow);
}

.tile--present,
.tile[data-state="present"] {
  color: #262626;
  background: var(--white);
}

.tile--absent,
.tile[data-state="absent"] { background: var(--tile-absent); }

.tile--active { border-color: #6b6b6b; }

.tile--reveal {
  backface-visibility: hidden;
  animation: reveal 500ms cubic-bezier(0.45, 0, 0.35, 1) both;
  animation-delay: var(--tile-delay, 0ms);
}

.board--shake { animation: shake 240ms ease-in-out; }

.tile--invalid {
  color: #ef7373;
  animation: invalid-word 460ms ease-in-out;
}

.keyboard {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  user-select: none;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: var(--key-gap);
}

.keyboard-row:nth-child(2) { padding: 0 calc((100% - 11 * var(--key-gap)) / 24); }

.key {
  display: grid;
  flex: 1 1 0;
  min-width: 0;
  height: var(--key-height);
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: #f0f0f0;
  background: transparent;
  font-size: clamp(15px, 4.25vw, 23px);
  font-weight: 400;
  line-height: 1;
  transition: filter 100ms ease, transform 100ms ease;
}

.key svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.key--correct,
.key[data-state="correct"],
.key--enter {
  border-color: var(--yellow);
  color: #262626;
  background: var(--yellow);
}

.key--present,
.key[data-state="present"],
.key--delete {
  border-color: var(--white);
  color: #262626;
  background: var(--white);
}

.key--absent,
.key[data-state="absent"] {
  border-color: var(--tile-absent);
  background: var(--tile-absent);
}

.key--enter,
.key--delete { flex-grow: 1.45; }

.key--enter svg { width: 27px; height: 27px; }

.key:active {
  filter: brightness(0.8);
  transform: translateY(1px);
}

.page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 22px;
}

.page-heading h1 {
  margin: 0;
  font-size: 25px;
  font-weight: 600;
  line-height: 1.25;
}

.heading-spacer { flex: 0 0 40px; width: 40px; }

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

.stat-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 96px;
  padding: 12px 5px;
  border: 1px solid #3a3a3a;
  border-radius: 14px;
  background: #292929;
  text-align: center;
}

.stat-value {
  color: var(--yellow);
  font-size: clamp(20px, 6vw, 28px);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat-label {
  max-width: 100%;
  color: #c2c2c2;
  font-size: 12px;
  line-height: 1.3;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.distribution-section { margin-top: 32px; }

.distribution-section h2 {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
  text-transform: uppercase;
}

.distribution {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.distribution-row {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 29px;
}

.distribution-label {
  flex: 0 0 14px;
  font-size: 17px;
  font-weight: 500;
  text-align: center;
}

.distribution-track { flex: 1 1 auto; min-width: 0; }

.distribution-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 29px;
  height: 29px;
  padding: 0 10px;
  border-radius: 18px;
  color: #272727;
  background: var(--yellow);
}

.distribution-value {
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.distribution-bar--empty,
.distribution-bar[data-empty="true"] {
  justify-content: center;
  width: 29px;
  padding: 0;
  color: var(--text);
  background: #656565;
}

.screen--settings,
.screen--rules {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
}

.settings-block {
  width: 100%;
  padding: 25px 24px;
  border-radius: 26px;
  background: var(--surface);
}

.reminder-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.reminder-heading h2 { margin: 0; font-size: 25px; font-weight: 400; }

.reminder-switch {
  flex: 0 0 60px;
  width: 60px;
  height: 35px;
  padding: 3px;
  border-radius: 24px;
  background: #4c4c4c;
  cursor: default;
}

.reminder-switch span {
  display: block;
  width: 29px;
  height: 29px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 5px #00000026;
}

.next-word-countdown {
  display: block;
  margin-top: 22px;
  font-size: clamp(36px, 10vw, 46px);
  font-weight: 500;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.reminder-caption {
  margin: 12px 0 0;
  color: #929292;
  font-size: 17px;
  line-height: 1.3;
  text-align: center;
}

.rules-link {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
  margin-top: 22px;
  padding-right: 52px;
  text-align: left;
}

.rules-link-title { font-size: 27px; line-height: 1.2; }
.rules-link-caption { color: #929292; font-size: 17px; line-height: 1.3; }

.rules-link svg {
  position: absolute;
  top: 50%;
  right: 22px;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: #a1a1a1;
  stroke-width: 1.35;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: translateY(-50%);
}

.rules-link:active { background: #343434; }

.rules-content {
  padding: 25px 22px 28px;
  border-radius: 24px;
  background: var(--surface);
}

.rules-content h2 { margin: 0 0 20px; font-size: 24px; font-weight: 400; line-height: 1.3; }
.rules-content p { margin: 0 0 25px; color: #e2e2e2; font-size: 18px; line-height: 1.45; }
.rules-content p:last-child { margin-bottom: 0; }
.rules-content hr { height: 1px; margin: 29px 0; border: 0; background: #585858; }

.rules-example { display: flex; gap: 7px; margin: 27px 0 18px; }

.rule-tile {
  display: grid;
  flex: 1 1 0;
  min-width: 0;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 7px;
  font-size: clamp(24px, 7.2vw, 38px);
  font-weight: 400;
  line-height: 1;
}

.rule-tile--correct { color: #282828; background: var(--yellow); }
.rule-tile--present { color: #262626; background: var(--white); }
.rule-tile--absent { color: var(--text); background: var(--tile-absent); }

.screen--summary {
  padding-top: 25px;
  text-align: center;
}

.summary-title { margin: 0 0 14px; font-size: 30px; font-weight: 500; line-height: 1.25; }
.summary-text { min-height: 24px; margin: 0; color: #bcbcbc; font-size: 18px; line-height: 1.4; }

.progress-chain {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 36px -4px 32px;
}

.progress-node {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  gap: 13px;
}

.progress-node:not(:first-child)::before {
  position: absolute;
  z-index: 0;
  top: 26px;
  left: -50%;
  width: 100%;
  height: 3px;
  background: #3c3c3c;
  content: "";
}

.progress-node.is-complete::before { background: var(--yellow); }

.progress-point {
  position: relative;
  z-index: 1;
  display: grid;
  width: 55px;
  max-width: calc(100% - 9px);
  height: auto;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  color: #818181;
  background: #2d2d2d;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.progress-node.is-complete .progress-point { color: #242424; background: var(--yellow); }
.progress-point svg { width: 29px; height: 29px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.progress-word { min-height: 17px; max-width: 100%; color: #aaa; font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }
.progress-node.is-complete .progress-word { color: #e7e7e7; }

.primary-button.replay-button { min-height: 65px; border-radius: 22px; font-size: 21px; font-weight: 400; }

.attempts-card {
  margin-top: 29px;
  padding: 27px 20px 32px;
  border-radius: 26px;
  background: var(--surface);
}

.attempts-card p { margin: 0 0 19px; color: #c4c4c4; font-size: 20px; line-height: 1.4; }
.attempts-value { font-size: 70px; font-weight: 400; line-height: 1; font-variant-numeric: tabular-nums; }
.attempts-value strong { color: var(--yellow); font-weight: 400; }
.attempts-value span { color: #707070; }

.screen--closed {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding-bottom: 70px;
  text-align: center;
}

.screen--closed p { color: var(--muted); font-size: 22px; }
.screen--closed .primary-button { max-width: 290px; }
.app-shell--closed .app-header { visibility: hidden; }

.toast {
  position: fixed;
  z-index: 30;
  top: 92px;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 36px);
  padding: 13px 17px;
  border: 1px solid #555555;
  border-radius: 12px;
  color: var(--text);
  background: #303030;
  box-shadow: 0 6px 24px #00000040;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -6px);
  transition: opacity 150ms ease, transform 150ms ease;
}

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

.toast--word-error {
  top: var(--toast-y, 270px);
  left: var(--toast-x, 50%);
  width: 216px;
  max-width: calc(100% - 28px);
  padding: 20px 16px;
  border: 0;
  border-radius: 12px;
  color: #494949;
  background: var(--white);
  font-size: 18px;
  line-height: 1.35;
  transform: translate(-50%, 5px);
}

.toast--word-error::before { position: absolute; top: -10px; left: 28px; width: 20px; height: 20px; border-radius: 3px; background: var(--white); content: ""; transform: rotate(45deg); }
.toast--word-error.is-visible { transform: translate(-50%, 0); }

.confetti { position: fixed; z-index: 50; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-piece { position: absolute; top: -20px; left: var(--confetti-x, 50%); width: 8px; height: 13px; border-radius: 2px; background: var(--confetti-color, var(--yellow)); animation: confetti-fall var(--confetti-duration, 2600ms) linear var(--confetti-delay, 0ms) both; }

.primary-button {
  width: 100%;
  min-height: 49px;
  padding: 12px 18px;
  border-radius: 12px;
  color: #242424;
  background: var(--yellow);
  font-size: 16px;
  font-weight: 600;
}

.primary-button:active { filter: brightness(0.9); }

@media (hover: hover) {
  .icon-button:hover { background: #303030; }
  .key:hover { filter: brightness(1.17); }
}

@media (min-width: 600px) {
  .stat-card { min-height: 105px; }
}

@media (max-width: 300px) {
  .stat-value { font-size: 17px; }
}

@media (max-height: 700px) {
  :root { --key-height: 40px; }
  .app-shell { padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .app-header { min-height: 36px; margin-bottom: 18px; }
  .icon-button { height: 36px; }
  .wordmark span { width: 28px; height: 30px; font-size: 24px; }
  .screen--game { gap: 18px; }
  .board { width: min(100%, calc((100svh - 242px) * 0.825)); }
  .tile { font-size: clamp(22px, min(9vw, calc((100svh - 242px) * 0.08)), 42px); }
  .keyboard { gap: 6px; }
  .key svg { width: 22px; height: 22px; }
  .toast { top: 75px; }
}

@media (max-width: 350px) {
  :root { --key-gap: 4px; --board-gap: 6px; }
  .app-shell { padding-left: 14px; padding-right: 14px; }
  .header-actions { gap: 2px; }
  .header-actions .icon-button { flex-basis: 34px; width: 34px; }
  .wordmark span { width: 27px; height: 30px; font-size: 24px; }
  .stat-label { font-size: 11px; }
  .page-heading h1 { font-size: 23px; }
  .settings-block { padding: 22px 20px; }
  .reminder-heading h2 { font-size: 23px; }
  .rules-content { padding-right: 18px; padding-left: 18px; }
  .rules-content p { font-size: 17px; }
  .progress-node:not(:first-child)::before { top: 22px; }
  .progress-point { font-size: 20px; }
  .progress-word { font-size: 11px; }
  .summary-title { font-size: 27px; }
}

@media (orientation: landscape) and (max-height: 480px) {
  .screen--game { gap: 24px; }
  .board {
    width: min(100%, 280px);
    margin: 8px auto 0;
  }
  .tile { font-size: 28px; }
}

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

@keyframes reveal {
  0% { transform: perspective(500px) rotateX(0); }
  50% { transform: perspective(500px) rotateX(90deg); }
  100% { transform: perspective(500px) rotateX(0); }
}

@keyframes invalid-word {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-3px) rotate(-1deg); }
  40%, 80% { transform: translateX(3px) rotate(1deg); }
}

@keyframes confetti-fall {
  0% { opacity: 1; transform: translate(0, -20px) rotate(0deg); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--confetti-drift, 40px), 110svh) rotate(var(--confetti-rotation, 540deg)); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%, 75% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
}
