:root {
  color-scheme: light;
  --paper: #fff;
  --ink: #080808;
  --green: #179a42;
  --red: #d02424;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Trebuchet MS", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
}

.phone-game,
.phone-game *,
.stats-modal,
.stats-modal * {
  font-family: "Trebuchet MS", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.page-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(0.35rem, 2.5vw, 0.75rem);
}

.phone-game {
  width: min(100%, 24rem);
  display: flex;
  flex-direction: column;
  padding: clamp(0.7rem, 3vw, 1rem) clamp(0.65rem, 3vw, 0.9rem) 0.8rem;
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: 28px;
  box-shadow: 8px 10px 0 var(--ink);
  overflow: hidden;
}

.site-header {
  text-align: center;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1;
  font-weight: 900;
}

.intro {
  margin: 0.35rem auto 0;
  font-size: 0.9rem;
  line-height: 1.2;
}

.hangman-wrap {
  width: min(100%, 18.25rem);
  margin: 0.5rem auto 0;
}

.hangman {
  width: 100%;
  height: auto;
  display: block;
}

.gallows,
.part {
  fill: none;
  stroke: var(--ink);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 6.5;
}

.part {
  opacity: 0;
}

.part.visible {
  opacity: 1;
}

.part-head {
  fill: var(--paper);
}

.part-left-eye,
.part-right-eye,
.part-sad-mouth {
  stroke-width: 4.5;
}

.word-slots {
  display: flex;
  justify-content: center;
  gap: clamp(0.32rem, 1.6vw, 0.5rem);
  margin: 0.15rem 0 0.25rem;
  flex-wrap: wrap;
}

.slot {
  width: clamp(1.75rem, 8.6vw, 2.15rem);
  min-height: clamp(2.25rem, 10vw, 2.8rem);
  display: grid;
  place-items: center;
  border-bottom: 5px solid var(--ink);
  color: var(--green);
  font-size: clamp(1.85rem, 9vw, 2.25rem);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  transform: rotate(-1deg);
}

.slot:nth-child(2n) {
  transform: rotate(1.5deg);
}

.misses-panel {
  min-height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  margin: 0.05rem 0 0.2rem;
}

.misses-label {
  font-size: 0.9rem;
  font-weight: 900;
}

.misses {
  min-width: 6rem;
  color: var(--red);
  font-size: clamp(1.1rem, 5vw, 1.35rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.answer {
  min-height: 1.35rem;
  margin: 0.1rem 0 0.35rem;
  color: var(--red);
  font-size: clamp(1rem, 4.3vw, 1.2rem);
  font-weight: 900;
  text-align: center;
}

.keyboard {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: clamp(0.28rem, 1.8vw, 0.42rem);
  margin: 0 auto;
}

.key {
  min-width: 0;
  min-height: 44px;
  border: 4px solid var(--ink);
  border-radius: 8px 11px 7px 10px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-size: clamp(1.05rem, 5.2vw, 1.3rem);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  transform: rotate(-1deg);
}

.key:nth-child(3n) {
  transform: rotate(1.5deg);
}

.key:nth-child(4n) {
  transform: rotate(-2deg);
}

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

.key.wrong {
  border-color: var(--red);
  color: var(--red);
}

.key:disabled {
  cursor: not-allowed;
}

.status-panel {
  min-height: 3.8rem;
  margin-top: 0.45rem;
  padding-top: 0.2rem;
  text-align: center;
}

.date-label {
  margin: 0;
  font-size: 0.8rem;
}

.message {
  margin: 0.2rem 0 0;
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1.15;
}

.message.win {
  color: var(--green);
}

.message.lose {
  color: var(--red);
}

.actions,
.stats-footer {
  text-align: center;
}

.share-button {
  min-height: 44px;
  padding: 0 1rem;
  border: 4px solid var(--ink);
  border-radius: 10px 8px 12px 9px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 900;
  transform: rotate(1deg);
}

.danger-button {
  color: var(--red);
  border-color: var(--red);
}

.share-status {
  min-height: 1.1rem;
  margin: 0.4rem 0 0;
  font-size: 0.82rem;
  white-space: pre-wrap;
}

.stats-modal[hidden] {
  display: none;
}

.stats-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.78);
}

.stats-card {
  position: relative;
  width: min(22rem, 94vw);
  max-height: min(44rem, calc(100vh - 2rem));
  max-height: min(44rem, calc(100svh - 2rem));
  overflow: auto;
  padding: 1rem;
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: 24px;
  box-shadow: 8px 10px 0 var(--ink);
}

.stats-close {
  position: absolute;
  top: 0.6rem;
  right: 0.75rem;
  width: 2.3rem;
  height: 2.3rem;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  cursor: pointer;
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 1;
}

.stats-card h2,
.stats-card h3 {
  margin: 0;
  text-align: center;
}

.stats-card h2 {
  font-size: 1.5rem;
}

.stats-card h3 {
  margin-top: 1rem;
  font-size: 1rem;
}

.stats-result {
  min-height: 1.5rem;
  margin: 0.45rem 0 0.8rem;
  text-align: center;
  color: var(--red);
  font-weight: 900;
}

.stats-result.win {
  color: var(--green);
}

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

.stat-tile {
  min-height: 4rem;
  display: grid;
  place-items: center;
  padding: 0.35rem;
  border: 3px solid var(--ink);
  border-radius: 10px 8px 12px 9px;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 900;
}

.stat-label {
  display: block;
  font-size: 0.72rem;
}

.guess-distribution {
  display: grid;
  gap: 0.28rem;
  margin-top: 0.55rem;
}

.distribution-row {
  display: grid;
  grid-template-columns: 1.4rem 1fr 2rem;
  align-items: center;
  gap: 0.4rem;
}

.distribution-label,
.distribution-count {
  font-weight: 900;
}

.bar-track {
  min-height: 1.25rem;
  border: 2px solid var(--ink);
  border-radius: 8px;
  overflow: hidden;
}

.bar-fill {
  min-width: 0.45rem;
  height: 100%;
  background: var(--ink);
}

.distribution-row.today .bar-fill {
  background: var(--green);
}

.distribution-row.missed.today .bar-fill {
  background: var(--red);
}

.recent-results {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.recent-result {
  min-width: 2.25rem;
  padding: 0.25rem 0.35rem;
  border: 3px solid var(--ink);
  border-radius: 8px 11px 7px 10px;
  text-align: center;
  font-weight: 900;
}

.recent-result.win {
  color: var(--green);
}

.recent-result.loss {
  color: var(--red);
}

.recent-helper {
  display: block;
  font-size: 0.01rem;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.stats-footer {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  margin-top: 1rem;
}

.stats-footer .share-button {
  width: min(100%, 13rem);
}

@media (max-width: 22rem) {
  .phone-game {
    border-width: 4px;
    box-shadow: 5px 7px 0 var(--ink);
    padding-inline: 0.65rem;
  }

  .slot {
    width: 1.85rem;
    font-size: 2rem;
  }

  .key {
    min-height: 44px;
    border-width: 3px;
    font-size: 1.1rem;
  }

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

/* Stats modal repair: keep this fixed over the page, not inside the phone layout. */
#statsModal.stats-modal,
.stats-modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  width: 100vw;
  min-height: 100vh;
  min-height: 100svh;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.84);
}

#statsModal.stats-modal[hidden],
.stats-modal[hidden] {
  display: none;
}

#statsModal .stats-card,
.stats-card {
  position: relative;
  width: min(22rem, calc(100vw - 1.5rem));
  max-height: calc(100vh - 1.5rem);
  max-height: calc(100svh - 1.5rem);
  overflow-y: auto;
  padding: 1.05rem;
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: 22px 25px 20px 24px;
  box-shadow: 8px 10px 0 var(--ink);
}

#statsModal .stats-card::before,
.stats-card::before {
  content: "";
  display: block;
  height: 4px;
  margin: 2.15rem 0 0.85rem;
  background: var(--ink);
  border-radius: 999px;
}

#statsTitle {
  position: absolute;
  top: 1rem;
  left: 1rem;
  margin: 0;
  font-size: 1.35rem;
  line-height: 1;
  text-align: left;
}

#statsCloseButton.stats-close,
.stats-close {
  position: absolute;
  top: 0.65rem;
  right: 0.75rem;
  width: 2.45rem;
  height: 2.45rem;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 2rem;
  font-weight: 400;
  line-height: 1;
}

#statsResult.stats-result,
.stats-result {
  min-height: 2.75rem;
  display: grid;
  place-items: center;
  margin: 0 0 1rem;
  padding: 0.45rem 0.6rem;
  border: 3px solid var(--ink);
  border-radius: 8px 10px 7px 11px;
  color: var(--red);
  font-size: 1rem;
  font-weight: 900;
  text-align: center;
}

#statsResult.stats-result.win,
.stats-result.win {
  color: var(--green);
}

#statsTiles.stats-tiles,
.stats-tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.stat-tile {
  min-height: 4.25rem;
  display: grid;
  place-items: center;
  padding: 0.35rem 0.2rem;
  border: 3px solid var(--ink);
  border-radius: 9px 11px 8px 10px;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 900;
  line-height: 1;
}

.stat-label {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.65rem;
  font-weight: 900;
  text-transform: uppercase;
}

.stats-card h3 {
  margin: 0.9rem 0 0.55rem;
  font-size: 0.95rem;
  line-height: 1;
  text-align: left;
  text-transform: uppercase;
}

#guessDistribution.guess-distribution,
.guess-distribution {
  display: grid;
  gap: 0.42rem;
}

.distribution-row {
  display: grid;
  grid-template-columns: 1.35rem minmax(0, 1fr) 1.6rem;
  align-items: center;
  gap: 0.45rem;
}

.distribution-label,
.distribution-count {
  font-weight: 900;
  line-height: 1;
}

.distribution-count {
  text-align: right;
}

.bar-track {
  min-width: 0;
  min-height: 1.35rem;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: #f5f5f5;
  overflow: hidden;
}

.bar-fill {
  display: block;
  min-width: 0.45rem;
  height: 1.35rem;
  background: var(--ink);
}

.distribution-row.today {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: 4px;
}

.distribution-row.today .bar-fill {
  background: var(--green);
}

.distribution-row.missed.today {
  outline-color: var(--red);
}

.distribution-row.missed.today .bar-fill {
  background: var(--red);
}

#recentResults.recent-results,
.recent-results {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-start;
  min-height: 2.35rem;
  margin: 0.45rem 0 1rem;
}

.recent-result {
  min-width: 2.1rem;
  min-height: 2.1rem;
  display: grid;
  place-items: center;
  padding: 0.2rem 0.35rem;
  border: 3px solid var(--ink);
  border-radius: 7px 10px 8px 9px;
  font-weight: 900;
}

.recent-result.win {
  border-color: var(--green);
  color: var(--green);
}

.recent-result.loss {
  border-color: var(--red);
  color: var(--red);
}

.recent-text {
  margin-left: 0.2rem;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 700;
}

.recent-helper {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.stats-footer {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  padding-top: 0.85rem;
  border-top: 3px solid var(--ink);
}

.stats-footer .share-button {
  width: min(100%, 13rem);
}

#statsShareStatus {
  max-width: 100%;
}

@media (max-width: 22rem) {
  #statsTiles.stats-tiles,
  .stats-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #statsModal .stats-card,
  .stats-card {
    padding: 0.85rem;
  }
}

.stats-modal,
.stats-modal * {
  font-family: "Trebuchet MS", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
