/* Hangman — scoped to .hm-page; respects theme tokens */

.hm-page {
  --hm-purple: var(--color-secondary);
  --hm-purple-content: var(--color-secondary-content);
  --hm-cyan: color-mix(in oklch, var(--color-info) 70%, var(--color-primary) 30%);
  --hm-miss: color-mix(in oklch, var(--color-error) 75%, oklch(45% 0.08 40));
  --hm-miss-border: color-mix(in oklch, var(--color-error) 55%, transparent);
  --hm-surface: var(--color-base-100);
  --hm-raised: var(--color-base-200);
  --hm-border: color-mix(in oklch, var(--hm-cyan) 45%, var(--color-base-300));
  --hm-muted: color-mix(in oklch, var(--color-base-content) 62%, transparent);
  --hm-glow: color-mix(in oklch, var(--hm-purple) 35%, transparent);
  --hm-tile: clamp(1.85rem, 7.2vw, 2.55rem);
  --hm-key: clamp(2.45rem, 11vw, 2.85rem);
  --hm-safe-bottom: env(safe-area-inset-bottom, 0px);
  max-width: 42rem;
  margin-inline: auto;
  padding: 0.75rem 0.85rem calc(1.25rem + var(--hm-safe-bottom));
  color: var(--color-base-content);
}

@media (min-width: 768px) {
  .hm-page {
    padding: 1.25rem 1.25rem 2rem;
  }
}

.hm-page * {
  box-sizing: border-box;
}

.hm-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* —— Hero —— */
.hm-hero {
  text-align: center;
  margin-bottom: 0.85rem;
}

.hm-hero__title {
  margin: 0;
  font-size: clamp(2rem, 8vw, 2.85rem);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.02em;
  line-height: 1.05;
  color: var(--color-base-content);
  text-shadow: 0 0 18px var(--hm-glow);
}

.hm-hero__sub {
  margin: 0.35rem 0 0;
  font-size: 0.95rem;
  color: var(--hm-muted);
}

/* —— Source segment —— */
.hm-sources {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
  padding: 0.3rem;
  border-radius: 0.95rem;
  background: color-mix(in oklch, var(--hm-raised) 88%, transparent);
  border: 1px solid color-mix(in oklch, var(--hm-cyan) 28%, var(--color-base-300));
  margin-bottom: 0.65rem;
}

.hm-source {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 0.7rem;
  min-height: 2.65rem;
  padding: 0.45rem 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.15;
  background: transparent;
  color: color-mix(in oklch, var(--color-base-content) 78%, transparent);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.hm-source:hover,
.hm-source:focus-visible {
  outline: none;
  border-color: color-mix(in oklch, var(--hm-cyan) 50%, transparent);
  color: var(--color-base-content);
}

.hm-source:focus-visible {
  box-shadow: 0 0 0 2px color-mix(in oklch, var(--hm-cyan) 45%, transparent);
}

.hm-source[aria-pressed="true"] {
  background: var(--hm-purple);
  color: var(--hm-purple-content);
  border-color: color-mix(in oklch, var(--hm-purple) 80%, white 10%);
  box-shadow: 0 0 14px var(--hm-glow);
}

@media (min-width: 420px) {
  .hm-source {
    font-size: 0.88rem;
  }
}

/* —— Summary + settings —— */
.hm-summary-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.hm-summary {
  flex: 1 1 10rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.55rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid color-mix(in oklch, var(--hm-cyan) 35%, var(--color-base-300));
  background: color-mix(in oklch, var(--hm-surface) 92%, transparent);
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--color-base-content);
}

.hm-summary__icon {
  color: var(--hm-cyan);
  flex-shrink: 0;
}

.hm-settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.55rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid color-mix(in oklch, var(--hm-cyan) 45%, var(--color-base-300));
  background: transparent;
  color: var(--color-base-content);
  font-weight: 650;
  font-size: 0.88rem;
  cursor: pointer;
}

.hm-settings-btn:hover,
.hm-settings-btn:focus-visible {
  outline: none;
  background: color-mix(in oklch, var(--hm-cyan) 12%, transparent);
  box-shadow: 0 0 0 2px color-mix(in oklch, var(--hm-cyan) 35%, transparent);
}

.hm-manual {
  margin-bottom: 0.75rem;
}

.hm-manual__input {
  width: 100%;
  min-height: 2.75rem;
  border-radius: 0.75rem;
  border: 1px solid color-mix(in oklch, var(--hm-cyan) 35%, var(--color-base-300));
  background: var(--hm-surface);
  color: var(--color-base-content);
  padding: 0.55rem 0.85rem;
  font-size: 1rem;
}

.hm-manual__input:focus-visible {
  outline: 2px solid color-mix(in oklch, var(--hm-purple) 55%, transparent);
  outline-offset: 1px;
}

.hm-manual__hint {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--hm-muted);
}

.hm-category {
  margin: -0.25rem 0 0.75rem;
  text-align: center;
}

.hm-category__badge {
  display: inline-block;
  max-width: 100%;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid color-mix(in oklch, var(--hm-cyan) 40%, transparent);
  background: color-mix(in oklch, var(--hm-raised) 85%, transparent);
  color: var(--hm-cyan);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  word-break: break-word;
}

/* —— Game card —— */
.hm-card {
  border-radius: 1.15rem;
  border: 1px solid var(--hm-border);
  background:
    linear-gradient(
      165deg,
      color-mix(in oklch, var(--hm-surface) 94%, var(--hm-purple) 6%),
      var(--hm-surface)
    );
  box-shadow:
    0 0 0 1px color-mix(in oklch, var(--hm-cyan) 12%, transparent),
    0 10px 28px color-mix(in oklch, var(--color-base-content) 8%, transparent);
  padding: 0.9rem 0.85rem 1rem;
}

@media (min-width: 768px) {
  .hm-card {
    padding: 1.15rem 1.25rem 1.25rem;
  }
}

.hm-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.55rem;
}

.hm-card__heading {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--hm-cyan);
}

.hm-misses-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  min-height: 1.7rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  border: 1px solid color-mix(in oklch, var(--hm-cyan) 45%, transparent);
  background: color-mix(in oklch, var(--hm-raised) 80%, transparent);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-base-content);
  white-space: nowrap;
}

.hm-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
}

@media (min-width: 900px) {
  .hm-stage {
    display: grid;
    grid-template-columns: minmax(0, 11rem) minmax(0, 1fr);
    align-items: center;
    gap: 1rem 1.25rem;
  }

  .hm-stage__figure {
    grid-row: 1 / span 2;
  }

  .hm-stage__puzzle {
    align-self: center;
  }
}

.hm-figure {
  width: min(100%, 11.5rem);
  aspect-ratio: 200 / 220;
  display: grid;
  place-items: center;
}

.hm-figure__svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.hm-gallows {
  stroke: var(--hm-purple);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  filter: drop-shadow(0 0 4px var(--hm-glow));
}

.hm-part {
  stroke: var(--hm-purple);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  opacity: 0;
  visibility: hidden;
  filter: drop-shadow(0 0 3px var(--hm-glow));
}

.hm-part--visible {
  opacity: 1;
  visibility: visible;
}

.hm-part--draw.hm-part--visible {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: hm-draw 0.85s ease-out forwards;
}

.hm-part--fill.hm-part--visible {
  fill: none;
}

@keyframes hm-draw {
  to {
    stroke-dashoffset: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hm-part--draw.hm-part--visible {
    animation: none;
    stroke-dasharray: none;
    stroke-dashoffset: 0;
  }

  .hm-figure--sway .hm-body-group,
  .hm-page--shake .hm-figure {
    animation: none;
  }
}

.hm-figure--sway .hm-body-group {
  transform-origin: 150px 50px;
  animation: hm-sway 2.5s ease-in-out infinite;
}

@keyframes hm-sway {
  0%,
  100% {
    transform: rotate(-3deg);
  }
  50% {
    transform: rotate(3deg);
  }
}

.hm-page--shake .hm-figure {
  animation: hm-shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes hm-shake {
  10%,
  90% {
    transform: translate3d(-1px, 0, 0);
  }
  20%,
  80% {
    transform: translate3d(2px, 0, 0);
  }
  30%,
  50%,
  70% {
    transform: translate3d(-3px, 0, 0);
  }
  40%,
  60% {
    transform: translate3d(3px, 0, 0);
  }
}

/* Miss progress dots */
.hm-miss-track {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.hm-miss-dot {
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 999px;
  border: 1.5px solid color-mix(in oklch, var(--hm-cyan) 55%, transparent);
  background: transparent;
  display: grid;
  place-items: center;
  font-size: 0.55rem;
  font-weight: 800;
  color: transparent;
  line-height: 1;
}

.hm-miss-dot--used {
  background: color-mix(in oklch, var(--hm-miss) 85%, transparent);
  border-color: var(--hm-miss-border);
  color: oklch(98% 0.01 80);
}

/* Puzzle tiles */
.hm-puzzle {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 0.55rem 0.85rem;
  min-height: 3.25rem;
}

.hm-word {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.28rem;
  max-width: 100%;
}

.hm-tile {
  width: var(--hm-tile);
  height: calc(var(--hm-tile) * 1.15);
  border-radius: 0.45rem;
  display: grid;
  place-items: end center;
  padding-bottom: 0.28rem;
  font-size: calc(var(--hm-tile) * 0.48);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
  border: 1px solid color-mix(in oklch, var(--hm-cyan) 28%, var(--color-base-300));
  background: color-mix(in oklch, var(--hm-raised) 90%, transparent);
  color: var(--color-base-content);
}

.hm-tile--blank {
  color: color-mix(in oklch, var(--color-base-content) 45%, transparent);
}

.hm-tile--blank::after {
  content: "_";
  font-weight: 700;
}

.hm-tile--letter {
  place-items: center;
  padding-bottom: 0;
  background: var(--hm-purple);
  border-color: color-mix(in oklch, var(--hm-purple) 70%, white 15%);
  color: var(--hm-purple-content);
  box-shadow: 0 0 10px var(--hm-glow);
}

.hm-tile--punct {
  place-items: center;
  padding-bottom: 0;
  background: transparent;
  border-color: transparent;
  color: var(--hm-muted);
  width: auto;
  min-width: calc(var(--hm-tile) * 0.55);
  font-size: calc(var(--hm-tile) * 0.42);
}

.hm-tile--revealed-loss {
  place-items: center;
  padding-bottom: 0;
  background: color-mix(in oklch, var(--hm-miss) 22%, var(--hm-raised));
  border-color: color-mix(in oklch, var(--hm-miss) 45%, transparent);
  color: var(--color-base-content);
  box-shadow: none;
  font-style: italic;
}

.hm-status {
  min-height: 2.75rem;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-align: center;
}

.hm-status__msg {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.25;
}

.hm-status__msg--win {
  color: var(--color-success);
}

.hm-status__msg--loss {
  color: var(--color-error);
}

.hm-status__msg--info {
  color: var(--hm-muted);
  font-weight: 600;
  font-style: italic;
}

.hm-status__link {
  color: var(--hm-cyan);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* —— Keyboard —— */
.hm-keys-block {
  margin-top: 1rem;
}

.hm-keys-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.75rem;
  margin-bottom: 0.55rem;
}

.hm-keys-label {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.hm-legend {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  font-size: 0.7rem;
  color: var(--hm-muted);
  font-weight: 600;
}

.hm-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}

.hm-legend__swatch {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  border: 1px solid color-mix(in oklch, var(--color-base-content) 20%, transparent);
}

.hm-legend__swatch--correct {
  background: var(--hm-purple);
  border-color: var(--hm-purple);
}

.hm-legend__swatch--miss {
  background: var(--hm-miss);
  border-color: var(--hm-miss-border);
}

.hm-legend__swatch--unused {
  background: var(--hm-raised);
}

.hm-keyboard {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.35rem;
  width: 100%;
  max-width: 28rem;
  margin-inline: auto;
}

@media (max-width: 379px) {
  .hm-keyboard {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .hm-key--tail {
    /* no special centering needed on 6-col */
  }
}

@media (min-width: 380px) {
  .hm-key--tail-start {
    grid-column: 2;
  }
}

.hm-key {
  appearance: none;
  position: relative;
  min-height: var(--hm-key);
  min-width: 0;
  border-radius: 0.55rem;
  border: 1px solid color-mix(in oklch, var(--hm-cyan) 32%, var(--color-base-300));
  background: color-mix(in oklch, var(--color-base-200) 92%, transparent);
  color: var(--color-base-content);
  -webkit-text-fill-color: var(--color-base-content);
  font-size: clamp(0.85rem, 3.6vw, 1rem);
  font-weight: 800;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.hm-key:hover:not(:disabled),
.hm-key:focus-visible:not(:disabled) {
  outline: none;
  border-color: color-mix(in oklch, var(--hm-cyan) 65%, transparent);
  box-shadow: 0 0 0 2px color-mix(in oklch, var(--hm-cyan) 30%, transparent);
}

.hm-key--correct {
  background: var(--hm-purple);
  border-color: color-mix(in oklch, var(--hm-purple) 70%, white 12%);
  color: var(--hm-purple-content);
  box-shadow: 0 0 10px var(--hm-glow);
}

.hm-key--miss {
  background: color-mix(in oklch, var(--hm-miss) 55%, var(--hm-raised));
  border-color: var(--hm-miss-border);
  color: oklch(97% 0.01 80);
}

.hm-key--miss::before {
  content: "×";
  position: absolute;
  top: 0.05rem;
  right: 0.28rem;
  font-size: 0.7rem;
  font-weight: 900;
  color: color-mix(in oklch, var(--hm-miss) 30%, white 70%);
  line-height: 1;
}

.hm-key:disabled {
  cursor: default;
  opacity: 0.92;
}

.hm-key:disabled:not(.hm-key--correct):not(.hm-key--miss) {
  opacity: 0.45;
}

/* —— Actions —— */
.hm-actions {
  display: grid;
  gap: 0.55rem;
  margin-top: 1rem;
}

@media (min-width: 480px) {
  .hm-actions {
    grid-template-columns: 1fr 1fr;
  }
}

.hm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.85rem;
  padding: 0.55rem 1rem;
  border-radius: 0.85rem;
  font-weight: 750;
  font-size: 0.95rem;
  cursor: pointer;
  border: 1px solid transparent;
}

.hm-btn:focus-visible {
  outline: 2px solid color-mix(in oklch, var(--hm-cyan) 55%, transparent);
  outline-offset: 2px;
}

.hm-btn--primary {
  background: var(--hm-purple);
  color: var(--hm-purple-content);
  box-shadow: 0 0 16px var(--hm-glow);
}

.hm-btn--primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.hm-btn--primary:disabled {
  opacity: 0.65;
  cursor: wait;
}

.hm-btn--ghost {
  background: transparent;
  border-color: color-mix(in oklch, var(--color-base-content) 28%, transparent);
  color: var(--color-base-content);
}

.hm-btn--ghost:hover {
  background: color-mix(in oklch, var(--color-base-content) 8%, transparent);
}

.hm-btn--loading::after {
  content: "";
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  border: 2px solid color-mix(in oklch, var(--hm-purple-content) 35%, transparent);
  border-top-color: var(--hm-purple-content);
  animation: hm-spin 0.7s linear infinite;
}

@keyframes hm-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .hm-btn--loading::after {
    animation: none;
    opacity: 0.7;
  }
}

/* —— Settings dialog (daisyUI modal + opaque sheet) —— */
.hm-settings.modal {
  padding: 0;
}

.hm-settings.modal[open] {
  display: grid;
}

.hm-settings__sheet.modal-box {
  width: min(100vw - 1rem, 26rem);
  max-height: min(92dvh, 40rem);
  overflow: auto;
  border-radius: 1.15rem;
  border: 1px solid var(--hm-border);
  background: var(--color-base-100) !important;
  color: var(--color-base-content);
  padding: 1rem 1rem calc(1rem + var(--hm-safe-bottom));
  box-shadow: 0 12px 36px color-mix(in oklch, oklch(10% 0.02 260) 40%, transparent);
}

@media (max-width: 639px) {
  .hm-settings.modal[open] {
    align-items: end;
  }

  .hm-settings__sheet.modal-box {
    width: 100%;
    max-width: none;
    margin: 0;
    border-radius: 1.15rem 1.15rem 0 0;
  }
}

.hm-settings__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.hm-settings__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
}

.hm-settings__close {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  border: none;
  background: color-mix(in oklch, var(--color-base-content) 8%, transparent);
  color: var(--color-base-content);
  font-size: 1.1rem;
  cursor: pointer;
}

.hm-settings__close:focus-visible {
  outline: 2px solid var(--hm-cyan);
}

.hm-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

.hm-field__label {
  font-size: 0.8rem;
  font-weight: 700;
}

.hm-field__control {
  min-height: 2.55rem;
  border-radius: 0.65rem;
  border: 1px solid color-mix(in oklch, var(--hm-cyan) 30%, var(--color-base-300));
  background-color: var(--color-base-200);
  color: var(--color-base-content);
  padding: 0.4rem 0.65rem;
  font-size: 0.95rem;
}

.hm-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.hm-settings__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid color-mix(in oklch, var(--color-base-content) 12%, transparent);
}

.hm-confirm.modal {
  padding: 0;
}

.hm-confirm.modal[open] {
  display: grid;
}

.hm-confirm__box.modal-box {
  width: min(100vw - 1.5rem, 22rem);
  border-radius: 1rem;
  border: 1px solid var(--hm-border);
  background: var(--color-base-100) !important;
  color: var(--color-base-content);
  padding: 1.1rem;
  box-shadow: 0 12px 36px color-mix(in oklch, oklch(10% 0.02 260) 45%, transparent);
}

.hm-confirm__title {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  font-weight: 800;
}

.hm-confirm__text {
  margin: 0 0 0.9rem;
  font-size: 0.9rem;
  color: var(--hm-muted);
}

.hm-actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.85rem;
  padding: 0.55rem 1rem;
  border-radius: 0.85rem;
  font-weight: 750;
  font-size: 0.95rem;
  background: transparent;
  border: 1px solid color-mix(in oklch, var(--color-base-content) 28%, transparent);
  color: var(--color-base-content);
}

.hm-actions .btn:hover {
  background: color-mix(in oklch, var(--color-base-content) 8%, transparent);
}

.hm-actions .btn:focus-visible {
  outline: 2px solid color-mix(in oklch, var(--hm-cyan) 55%, transparent);
  outline-offset: 2px;
}
