/* Adam Asmaca: dark theme, mobile first (phone portrait, phone landscape, desktop). */

:root {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --surface-3: #475569;
  --line: rgba(148, 163, 184, 0.16);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #a3e635;
  --accent-hover: #bef264;
  --accent-ink: #0f172a;
  --danger: #f87171;
  --danger-soft: #fca5a5;
  --warn: #fbbf24;
  --warn-soft: #fcd34d;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 18px 40px -22px rgba(0, 0, 0, 0.8), 0 2px 8px -2px rgba(0, 0, 0, 0.35);
  --fast: 150ms;
  --mid: 200ms;
  --slow: 250ms;
  --ease: cubic-bezier(0.22, 0.8, 0.3, 1);
  --gutter: clamp(10px, 3.2vw, 24px);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1100px 520px at 50% -240px, rgba(163, 230, 53, 0.1), transparent 70%) no-repeat,
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
select {
  font: inherit;
  color: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Header and footer ---------- */

.site-header {
  padding: 10px var(--gutter) 6px;
}

.bar {
  max-width: 1040px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 9px;
  box-shadow: 0 6px 18px -8px rgba(163, 230, 53, 0.45);
}

.header-actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.site-footer {
  padding: 4px var(--gutter) 10px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 4px;
  color: var(--text);
  text-decoration-color: rgba(163, 230, 53, 0.55);
  text-underline-offset: 3px;
  transition: color var(--fast) ease;
}

.site-footer a:hover {
  color: var(--accent);
}

.site-footer a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Buttons and the word-list select ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 40px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.95rem;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  transition:
    background-color var(--fast) ease,
    border-color var(--fast) ease,
    color var(--fast) ease,
    transform var(--fast) var(--ease),
    opacity var(--fast) ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.98);
}

.btn:focus-visible,
.select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-square {
  width: 40px;
  padding: 0;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 8px 22px -12px rgba(163, 230, 53, 0.7);
}

.btn-hint .cost {
  color: var(--warn-soft);
  font-size: 0.78rem;
  font-weight: 700;
}

.btn-hint .icon {
  color: var(--warn);
}

.btn-wide {
  width: 100%;
  min-height: 46px;
  margin-top: 10px;
}

@media (hover: hover) {
  .btn:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: rgba(148, 163, 184, 0.3);
  }

  .btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
  }
}

.field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.field-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.select {
  appearance: none;
  min-height: 40px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 10px center / 14px;
  font-size: 0.95rem;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color var(--fast) ease, background-color var(--fast) ease;
}

.select:hover {
  border-color: rgba(148, 163, 184, 0.35);
}

/* ---------- Game layout (phone portrait first) ---------- */

.game {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 4px var(--gutter) 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stats {
  display: flex;
  gap: 4px;
  margin: 0;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 40px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stat dt {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.2;
  text-transform: uppercase;
}

.stat dd {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

/* ---------- Stage: category, misses and the drawing ---------- */

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 140px;
  max-height: 440px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(120% 90% at 70% 0%, rgba(163, 230, 53, 0.06), transparent 60%),
    var(--surface);
  box-shadow: var(--shadow);
}

.stage-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.category {
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(163, 230, 53, 0.12);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.misses {
  display: flex;
  gap: 4px;
}

.miss {
  display: grid;
  place-items: center;
  width: 22px;
  height: 24px;
  border: 1.5px dashed var(--surface-3);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1;
}

.miss[data-kind="wrong"] {
  border: 1.5px solid rgba(248, 113, 113, 0.55);
  background: rgba(248, 113, 113, 0.14);
  color: var(--danger-soft);
  animation: pop var(--slow) var(--ease);
}

.miss[data-kind="hint"] {
  border: 1.5px solid rgba(251, 191, 36, 0.55);
  background: rgba(251, 191, 36, 0.14);
  color: var(--warn-soft);
  animation: pop var(--slow) var(--ease);
}

.gallows {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  margin-top: 4px;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ground {
  fill: rgba(2, 6, 23, 0.45);
}

.frame path {
  stroke: #64748b;
  stroke-width: 8;
  stroke-dasharray: 1;
  animation: draw 480ms var(--ease) both;
  animation-delay: calc(var(--i) * 110ms + 60ms);
}

.frame .rope {
  stroke: var(--muted);
  stroke-width: 4;
}

.figure {
  stroke: var(--text);
  stroke-width: 6;
  transition: stroke var(--slow) ease;
}

.part {
  visibility: hidden;
  stroke-dasharray: 1;
}

.part.is-drawn {
  visibility: visible;
  animation: draw 420ms var(--ease) both;
}

.stage.is-intro .part.is-drawn {
  animation-delay: calc(var(--p) * 140ms + 640ms);
}

.face {
  opacity: 0;
  stroke-width: 3.5;
  transition: opacity var(--slow) ease;
}

.face-won circle {
  fill: var(--accent);
  stroke: none;
}

.stage[data-face="lost"] .face-lost,
.stage[data-face="won"] .face-won {
  opacity: 1;
}

.stage[data-status="won"] .figure {
  stroke: var(--accent);
}

.stage[data-status="lost"] .figure {
  stroke: var(--danger);
}

/* ---------- The hidden word ---------- */

.word {
  --slot-gap: 6px;
  container-type: inline-size;
  display: flex;
  justify-content: center;
  gap: var(--slot-gap);
}

.slot {
  --size: min(52px, calc((100cqi - (var(--n) - 1) * var(--slot-gap)) / var(--n)));
  display: grid;
  place-items: center;
  width: var(--size);
  height: calc(var(--size) * 1.12 + 6px);
  padding-bottom: 3px;
  border-bottom: 3px solid var(--surface-3);
  border-radius: 2px;
  color: var(--text);
  font-size: calc(var(--size) * 0.64);
  font-weight: 800;
  line-height: 1;
  transition: border-color var(--mid) ease, color var(--mid) ease;
}

.slot.is-revealed {
  border-bottom-color: var(--accent);
  animation: pop var(--slow) var(--ease);
}

.slot.is-hinted {
  border-bottom-color: var(--warn);
  color: var(--warn-soft);
}

.slot.is-missed {
  border-bottom-color: var(--danger);
  color: var(--danger);
  animation: fade-in var(--slow) ease both;
  animation-delay: calc(var(--i) * 40ms);
}

.word.is-won .slot {
  color: var(--accent);
  animation: wave 520ms var(--ease) both;
  animation-delay: calc(var(--i) * 60ms);
}

/* ---------- Status line and actions ---------- */

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
}

.status {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.3;
  transition: color var(--fast) ease;
}

.status[data-tone="good"] {
  color: var(--accent);
}

.status[data-tone="bad"] {
  color: var(--danger-soft);
}

.status[data-tone="warn"] {
  color: var(--warn-soft);
}

/* ---------- On-screen keyboard ---------- */

/* The play area: quick taps here never pan or zoom the page; everywhere else scrolls normally. */
.keyboard {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

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

.key {
  position: relative;
  flex: 0 0 min(56px, calc(100% / var(--cols, 10)));
  height: 48px;
  padding: 2.5px;
  border: 0;
  background: none;
  cursor: pointer;
}

.key-face {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  background: var(--surface-2);
  box-shadow: inset 0 -2px 0 rgba(2, 6, 23, 0.35), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  color: var(--text);
  font-size: 1.12rem;
  font-weight: 750;
  line-height: 1;
  transition:
    background-color var(--fast) ease,
    color var(--fast) ease,
    opacity var(--fast) ease,
    transform var(--fast) var(--ease);
}

.key:focus-visible {
  outline: none;
}

.key:focus-visible .key-face {
  outline: 3px solid var(--text);
  outline-offset: 1px;
}

.key[data-state="correct"] .key-face {
  background: var(--accent);
  box-shadow: none;
  color: var(--accent-ink);
}

.key[data-state="hinted"] .key-face {
  background: var(--warn);
  box-shadow: none;
  color: var(--accent-ink);
}

.key[data-state="wrong"] .key-face {
  background: rgba(248, 113, 113, 0.1);
  box-shadow: inset 0 0 0 1px rgba(248, 113, 113, 0.25);
  color: var(--danger);
  opacity: 0.8;
}

.keyboard[data-over] .key[data-state="unused"] .key-face {
  opacity: 0.4;
}

.key[aria-disabled="true"] {
  cursor: default;
}

@media (hover: hover) {
  .keyboard:not([data-over]) .key[data-state="unused"]:hover .key-face {
    background: var(--surface-3);
  }
}

.key:active .key-face {
  transform: scale(0.94);
}

/* A finger or pen press lifts the key so the letter shows above the fingertip. */
.key.is-pressed {
  z-index: 2;
}

.key.is-pressed .key-face {
  transform: translateY(-58%) scale(1.25);
  box-shadow: 0 12px 24px -8px rgba(2, 6, 23, 0.9);
}

/* ---------- Result dialog ---------- */

.result {
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px -24px rgba(0, 0, 0, 0.85);
}

.result[open] {
  animation: dialog-in var(--slow) var(--ease);
}

.result::backdrop {
  background: rgba(2, 6, 23, 0.68);
  backdrop-filter: blur(3px);
}

.result-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 22px 20px 20px;
  text-align: center;
}

.result-body p {
  margin: 0;
}

.result-icon {
  width: 52px;
  height: 52px;
  fill: none;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.result-icon circle {
  fill: rgba(163, 230, 53, 0.14);
}

.result-icon path {
  stroke: var(--accent);
}

.result[data-status="lost"] .result-icon circle {
  fill: rgba(248, 113, 113, 0.14);
}

.result[data-status="lost"] .result-icon path {
  stroke: var(--danger);
}

.result .icon-lost,
.result[data-status="lost"] .icon-won {
  display: none;
}

.result[data-status="lost"] .icon-lost {
  display: inline;
}

.result-title {
  margin: 10px 0 12px;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.result-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.result-word {
  max-width: 100%;
  font-size: clamp(1.5rem, 7.5vw, 2.1rem);
  font-weight: 850;
  letter-spacing: 0.08em;
  line-height: 1.25;
  color: var(--accent);
  overflow-wrap: anywhere;
}

.result[data-status="lost"] .result-word {
  color: var(--danger-soft);
}

.result-category {
  color: var(--muted);
  font-size: 0.85rem;
}

.result-body .result-points {
  margin-top: 10px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  font-weight: 750;
}

.result[data-status="won"] .result-points {
  background: rgba(163, 230, 53, 0.14);
  color: var(--accent);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  margin: 16px 0 0;
}

.result-stats div {
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.5);
}

.result-stats dt {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.result-stats dd {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- Animations ---------- */

@keyframes draw {
  from {
    stroke-dashoffset: 1;
  }

  to {
    stroke-dashoffset: 0;
  }
}

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

  70% {
    transform: scale(1.12);
    opacity: 1;
  }

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

@keyframes wave {
  0%,
  100% {
    transform: translateY(0);
  }

  40% {
    transform: translateY(-10px);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Phones: the word-list label is left to screen readers, so the toolbar fits in one row ---------- */

@media (max-width: 399px) {
  .field-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* ---------- Narrow phones ---------- */

@media (max-width: 359px) {
  .brand-mark,
  .stat-best {
    display: none;
  }

  .brand {
    font-size: 1.05rem;
  }

  .btn {
    padding: 0 10px;
  }

  /* New game becomes icon-only so the title is not cut off; the hidden label stays its accessible name. */
  #new-game span {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* ---------- Landscape phones: a compact result card that fits without scrolling ---------- */

@media (max-height: 420px) {
  .result-body {
    padding: 12px 18px 14px;
  }

  .result-icon {
    width: 34px;
    height: 34px;
  }

  .result-title {
    margin: 4px 0 6px;
    font-size: 1.2rem;
  }

  .result-body .result-points {
    margin-top: 6px;
  }

  .result-stats {
    margin-top: 10px;
  }

  .result-stats div {
    padding: 4px;
  }
}

/* ---------- Short phone screens: tighter spacing and the drawing beside its labels keep the keyboard in view ---------- */

@media (max-width: 559px) and (max-height: 639px) {
  .site-header {
    padding-top: 6px;
    padding-bottom: 2px;
  }

  .game {
    gap: 8px;
    padding-top: 2px;
    padding-bottom: 4px;
  }

  .stage {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    min-height: 108px;
    padding: 8px;
  }

  .stage-top {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: flex-start;
  }

  .gallows {
    align-self: stretch;
    width: auto;
    min-width: 0;
    margin-top: 0;
  }

  .slot {
    --size: min(38px, calc((100cqi - (var(--n) - 1) * var(--slot-gap)) / var(--n)));
  }

  .key {
    height: 40px;
    padding: 2px;
  }

  .site-footer {
    padding-top: 0;
    padding-bottom: 4px;
  }
}

/* ---------- Phones in landscape: drawing beside the keyboard ---------- */

@media (orientation: landscape) and (max-height: 520px) and (min-width: 560px) {
  .site-header {
    padding-top: 6px;
    padding-bottom: 2px;
  }

  .game {
    display: grid;
    grid-template-columns: minmax(150px, 30%) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "stage toolbar"
      "stage word"
      "stage status"
      "stage keys";
    align-content: start;
    column-gap: 16px;
    row-gap: 6px;
    padding-top: 2px;
    padding-bottom: 2px;
  }

  .toolbar {
    grid-area: toolbar;
  }

  .stage {
    grid-area: stage;
    min-height: 0;
    max-height: none;
  }

  .word {
    grid-area: word;
  }

  .slot {
    --size: min(40px, calc((100cqi - (var(--n) - 1) * var(--slot-gap)) / var(--n)));
    height: calc(var(--size) + 4px);
  }

  .status-row {
    grid-area: status;
  }

  .keyboard {
    grid-area: keys;
  }

  .key {
    height: 40px;
    padding: 2px;
  }

  .site-footer {
    padding-top: 0;
    padding-bottom: 0;
  }
}

/* ---------- Desktop: drawing on the left, word and keyboard on the right ---------- */

@media (min-width: 860px) {
  .site-header {
    padding-top: 18px;
    padding-bottom: 8px;
  }

  .brand {
    gap: 10px;
    font-size: 1.4rem;
  }

  .btn {
    padding: 0 14px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .game {
    display: grid;
    grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
    grid-template-rows: auto minmax(120px, 1fr) auto auto;
    grid-template-areas:
      "stage toolbar"
      "stage word"
      "stage status"
      "stage keys";
    flex: none;
    margin-top: auto;
    margin-bottom: auto;
    column-gap: 40px;
    row-gap: 16px;
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .toolbar {
    grid-area: toolbar;
  }

  .stage {
    grid-area: stage;
    min-height: clamp(400px, 58vh, 560px);
    max-height: none;
    padding: 16px;
  }

  .miss {
    width: 28px;
    height: 30px;
    font-size: 0.85rem;
  }

  .category {
    font-size: 0.78rem;
  }

  .word {
    grid-area: word;
    align-self: center;
    --slot-gap: 8px;
  }

  .slot {
    --size: min(60px, calc((100cqi - (var(--n) - 1) * var(--slot-gap)) / var(--n)));
  }

  .status-row {
    grid-area: status;
  }

  .status {
    font-size: 0.98rem;
  }

  .keyboard {
    grid-area: keys;
  }

  .key {
    height: 56px;
  }

  .key-face {
    font-size: 1.25rem;
  }

  .site-footer {
    padding-bottom: 16px;
  }
}

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

  .key.is-pressed .key-face {
    transform: none;
    background: var(--surface-3);
  }
}
