/* Page: green table on every width; the clip grows with the game instead of keeping 4:3,
   and "Spiel vergrößern" zooms less than elsewhere, so that the whole game stays in the window. */

.page-hangman .game-section {
  background: #005000;
}

.page-hangman .game-clip {
  aspect-ratio: auto;
}

.page-hangman .game-clip--large .game-inner {
  zoom: 1.3;
}

@media (max-width: 850px) {
  .page-hangman .game-section {
    padding: 20px 5px;
  }
}

/* Game */

#hm-app {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* Width from the window, not from the content: a word slot sizes its letters from the space it gets. */
#hm-game {
  --hm-draw: clamp(110px, calc(100vh - 460px), 200px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "modes new" "score score" "drawing drawing" "category category" "word word" "enter enter" "status status" "keys keys";
  justify-items: center;
  gap: 10px 8px;
  box-sizing: border-box;
  width: min(480px, calc(100vw - 20px));
  max-width: 100%;
  padding: 16px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  color: #1f2d1f;
  font-family: 'Inter', system-ui, sans-serif;
  text-transform: uppercase;
  user-select: none;
}

/* Buttons do not inherit the capitals on their own (the browser sets text-transform: none on them). */
#hm-game button {
  text-transform: inherit;
}

/* The levels and "Zwei Spieler" as one row of buttons; the one in play is lit. */
#hm-modes {
  grid-area: modes;
  justify-self: stretch;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #edf1ed;
  border: 1px solid #d6ded6;
  border-radius: 8px;
}

#hm-modes button {
  flex: 1 1 auto;
  min-width: 0;
  padding: 5px 9px;
  font: 600 13px 'Inter', system-ui, sans-serif;
  color: #556355;
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#hm-modes button.hm-on {
  color: #005000;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  cursor: default;
}

#hm-modes button[data-mode="pvp"] {
  flex: 0 0 auto;
}

#hm-modes svg {
  display: block;
  width: 20px;
  height: 18px;
}

#hm-new {
  grid-area: new;
  align-self: stretch;
  padding: 7px 14px;
  font: 600 13px 'Inter', system-ui, sans-serif;
  color: #fff;
  background: #00b050;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

#hm-new.hm-pulse {
  animation: hm-pulse 1.2s ease-in-out infinite;
}

#hm-score {
  grid-area: score;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
}

.hm-score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 6px 2px;
  background: #f1f4f1;
  border-radius: 8px;
  box-shadow: inset 0 -3px 0 transparent;
  transition: box-shadow 0.2s;
}

.hm-score-box.hm-active {
  box-shadow: inset 0 -3px 0 #00b050;
}

.hm-score-label {
  font-size: 12px;
  color: #556355;
  white-space: nowrap;
}

.hm-score-value {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.1;
}

/* The gallows and the figure: a part is hidden until it stands. Parts already standing at the start
   of a round appear at once, a part added by a wrong letter is drawn in. */
#hm-drawing {
  grid-area: drawing;
  display: block;
  height: var(--hm-draw);
  width: calc(var(--hm-draw) * 200 / 220);
}

#hm-drawing [data-part] {
  fill: none;
  stroke: #3c4a3c;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  visibility: hidden;
  transition: stroke 0.3s;
}

#hm-drawing [data-part="5"],
#hm-drawing [data-part="6"],
#hm-drawing [data-part="7"],
#hm-drawing [data-part="8"],
#hm-drawing [data-part="9"],
#hm-drawing [data-part="10"] {
  stroke: #1f2d1f;
}

#hm-drawing .hm-pre,
#hm-drawing .hm-on {
  visibility: visible;
}

#hm-drawing .hm-on {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: hm-draw 0.3s ease-out forwards;
}

#hm-drawing.hm-lost [data-part] {
  stroke: #c9443e;
}

#hm-drawing.hm-won [data-part] {
  stroke: #9aa79a;
}

#hm-category {
  grid-area: category;
  margin: 0;
  font-size: 14px;
  color: #556355;
}

/* One slot per letter; the letters shrink with the space, long words included. */
#hm-word {
  grid-area: word;
  container-type: inline-size;
  display: flex;
  justify-content: center;
  gap: 3px;
  width: 100%;
}

/* Each slot has the height of a letter from the start, so the first hit does not push anything around. */
#hm-word span {
  flex: 0 1 34px;
  height: 1.6em;
  min-width: 0;
  font-size: min(26px, calc(100cqw / var(--n) * 0.7));
  font-weight: 600;
  line-height: 1.6;
  text-align: center;
  border-bottom: 3px solid #3c4a3c;
  transition: color 0.3s;
}

#hm-word span.hm-missed {
  color: #c9443e;
}

#hm-word span.hm-solved {
  color: #00a050;
}

#hm-word[hidden],
#hm-keyboard[hidden],
#hm-enter[hidden] {
  display: none;
}

/* Two players: one types the word, the other looks away. */
#hm-enter {
  grid-area: enter;
  width: 100%;
  margin: 0;
}

#hm-enter label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  text-align: center;
}

.hm-enter-row {
  display: flex;
  gap: 8px;
}

#hm-secret {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  font: 600 16px 'Inter', system-ui, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #1f2d1f;
  background: #f1f4f1;
  border: 1px solid #c3cfc3;
  border-radius: 6px;
  -webkit-text-security: disc;
}

#hm-secret:focus {
  outline: 2px solid #00b050;
  outline-offset: 0;
}

#hm-enter button {
  padding: 7px 18px;
  font: 600 14px 'Inter', system-ui, sans-serif;
  color: #fff;
  background: #00b050;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

#hm-enter-error {
  min-height: 1.3em;
  margin: 4px 0 0;
  font-size: 13px;
  color: #c9443e;
  text-align: center;
}

#hm-status {
  grid-area: status;
  min-height: 1.4em;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}

/* QWERTZ in a grid of eleven equal columns; the third row starts one key in. */
#hm-keyboard {
  grid-area: keys;
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  gap: 6px 5px;
  width: 100%;
}

.hm-row {
  display: contents;
}

.hm-row:last-child > :first-child {
  grid-column-start: 3;
}

#hm-keyboard button {
  height: 42px;
  min-width: 0;
  padding: 0;
  font: 600 16px 'Inter', system-ui, sans-serif;
  color: #1f2d1f;
  background: #edf1ed;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#hm-keyboard button:disabled {
  cursor: default;
}

#hm-keyboard button.hm-hit {
  color: #fff;
  background: #00b050;
}

#hm-keyboard button.hm-miss {
  color: #a9b3a9;
  background: #f6f8f6;
}

#hm-keyboard button:focus-visible,
#hm-modes button:focus-visible,
#hm-new:focus-visible {
  outline: 3px solid #00b050;
  outline-offset: 1px;
}

/* Hover only where there is a mouse: after a tap on a phone it would stick to the key. */
@media (hover: hover) {
  #hm-modes button:not(.hm-on):hover {
    color: #1f2d1f;
    background: rgba(0, 0, 0, 0.05);
  }

  #hm-new:hover,
  #hm-enter button:hover {
    background: #00c45a;
  }

  #hm-keyboard button:not(:disabled):hover {
    background: #dde7dd;
  }
}

@keyframes hm-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes hm-pulse {
  50% { box-shadow: 0 0 0 4px rgba(0, 176, 80, 0.35); }
}

/* Phones: the mode buttons take the whole top row, "Neues Wort" sits beside the score. */
@media (max-width: 480px) {
  #hm-game {
    grid-template-areas: "modes modes" "score new" "drawing drawing" "category category" "word word" "enter enter" "status status" "keys keys";
  }

  #hm-keyboard {
    gap: 5px 4px;
  }

  #hm-keyboard button {
    height: 40px;
    font-size: 15px;
  }
}

/* The narrowest phones: a little less padding, so that all four mode buttons fit. */
@media (max-width: 360px) {
  #hm-game {
    padding: 12px;
  }

  #hm-modes button {
    padding: 5px 6px;
    font-size: 12px;
  }

  #hm-new {
    padding: 7px 10px;
  }
}

/* Phones held sideways: drawing and word on the left, buttons and keyboard on the right. */
@media (orientation: landscape) and (max-height: 500px) {
  #hm-game {
    --hm-draw: clamp(80px, calc(100vh - 270px), 160px);
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    grid-template-areas:
      "drawing modes modes"
      "drawing score new"
      "category keys keys"
      "word keys keys"
      "enter keys keys"
      "status keys keys";
    align-items: start;
    width: min(760px, calc(100vw - 20px));
  }

  #hm-keyboard button {
    height: 34px;
  }
}
