:root {
  color-scheme: light;
  --ink: #29271f;
  --paper: #f3ead6;
  --paper-light: #fffaf0;
  --red: #d85845;
  --blue: #4e7d8d;
  --yellow: #e2b845;
  --muted: #777164;
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; }

body {
  color: var(--ink);
  background: #d9cfbb;
  background-image: radial-gradient(#5c554915 1px, transparent 1px);
  background-size: 7px 7px;
}

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

.page {
  width: min(100%, 980px);
  min-height: 100dvh;
  margin: auto;
  background:
    linear-gradient(90deg, transparent 46px, #d36a5d33 47px, transparent 48px),
    repeating-linear-gradient(0deg, transparent 0 32px, #638ca31d 33px 34px),
    var(--paper);
  box-shadow: 0 0 50px #514a3e40;
}

.topbar {
  min-height: 66px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 8px clamp(14px, 4vw, 34px);
  border-bottom: 3px solid var(--ink);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(27px, 5vw, 39px);
  line-height: 1;
  letter-spacing: -.08em;
  transform: rotate(-1.5deg);
}

.home-link, .text-button {
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.home-link { justify-self: start; }
.topbar nav { justify-self: end; display: flex; align-items: center; gap: 13px; }

.text-button {
  padding: 3px 1px;
  border: 0;
  border-bottom: 2px solid currentColor;
  background: none;
  cursor: pointer;
}

.share-button { color: #a43e31; }

.game {
  min-height: calc(100dvh - 66px);
  display: grid;
  grid-template-columns: minmax(260px, .85fr) minmax(400px, 1.15fr);
  align-items: stretch;
}

.drawing-panel {
  position: relative;
  min-height: 510px;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 48px 30px 28px;
  border-right: 3px solid var(--ink);
  background: #fffaf0b8;
}

.paper-tape {
  position: absolute;
  z-index: 2;
  top: 13px;
  left: 50%;
  width: 91px;
  height: 27px;
  background: #d9c58fc7;
  box-shadow: 0 1px 2px #493f2b2b;
  transform: translateX(-50%) rotate(-3deg);
}

.drawing { min-height: 0; display: grid; place-items: center; }
.drawing svg { width: min(100%, 310px); height: min(52vh, 420px); overflow: visible; }
.drawing path { fill: var(--ink); transition: opacity .22s ease, transform .22s ease; transform-origin: center; }
.drawing path.stroke-hidden { opacity: 0; transform: scale(.96); }
.drawing path.stroke-shown { animation: draw-in .28s ease both; }

.miss-count {
  width: fit-content;
  margin: 12px auto 0;
  padding: 5px 12px 3px;
  border: 2px solid var(--ink);
  border-radius: 47% 53% 51% 49%;
  background: var(--paper);
  font-size: 12px;
  font-weight: 700;
  transform: rotate(1deg);
}

.play-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 34px clamp(22px, 5vw, 58px);
}

.game-label, .kicker {
  margin: 0 0 15px;
  color: var(--red);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.word {
  width: 100%;
  min-height: 69px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 9px 7px;
  padding: 4px;
}

.letter-slot {
  width: clamp(25px, 5vw, 38px);
  height: 50px;
  display: grid;
  place-items: end center;
  border-bottom: 3px solid var(--ink);
  font-family: ui-monospace, "Courier New", monospace;
  font-size: clamp(27px, 5vw, 38px);
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.letter-slot.revealed { animation: pop-in .25s ease both; }
.letter-slot.lost { color: var(--red); }

.message {
  min-height: 24px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

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

.keyboard {
  width: min(100%, 480px);
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 7px;
  padding: 5px 0 23px;
}

.key {
  position: relative;
  aspect-ratio: 1 / 1.06;
  min-width: 0;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 46% 54% 43% 57% / 55% 42% 58% 45%;
  background: var(--paper-light);
  box-shadow: 2px 3px 0 var(--ink);
  font-family: ui-monospace, "Courier New", monospace;
  font-size: clamp(15px, 3vw, 21px);
  font-weight: 900;
  cursor: pointer;
  transform: rotate(var(--tilt));
}

.key:nth-child(3n) { --tilt: 1.5deg; }
.key:nth-child(3n + 1) { --tilt: -1deg; }
.key:nth-child(3n + 2) { --tilt: .4deg; }
.key:hover:not(:disabled) { background: #f1d36d; transform: translateY(-2px) rotate(var(--tilt)); }
.key:active:not(:disabled) { box-shadow: 0 1px 0 var(--ink); transform: translate(2px, 2px) rotate(var(--tilt)); }
.key:disabled { cursor: default; box-shadow: none; transform: translate(2px, 3px) rotate(var(--tilt)); }
.key.correct { border-color: #477b54; color: #2f653d; background: #b9d3a9; }
.key.wrong { color: #8f8980; background: #ded6c8; }
.key.wrong::after {
  content: "";
  position: absolute;
  top: 48%;
  left: 7%;
  width: 88%;
  height: 2px;
  background: var(--red);
  transform: rotate(-39deg);
}

.primary-button, .secondary-button {
  border: 2px solid var(--ink);
  border-radius: 49% 51% 46% 54% / 52% 46% 54% 48%;
  padding: 10px 20px;
  background: var(--yellow);
  box-shadow: 3px 4px 0 var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.primary-button:hover { background: #efc95d; }
.primary-button:active, .secondary-button:active { box-shadow: 1px 1px 0 var(--ink); transform: translate(2px, 3px); }
.secondary-button { margin-top: 18px; background: var(--paper-light); }
.wide { width: 100%; }

.dialog {
  width: min(92vw, 440px);
  max-height: 90dvh;
  padding: 31px;
  overflow: auto;
  border: 3px solid var(--ink);
  border-radius: 5px 13px 7px 11px;
  color: var(--ink);
  background: var(--paper-light);
  box-shadow: 8px 9px 0 #29271f80;
  transform: rotate(-.3deg);
}

.dialog::backdrop { background: #29271fb8; backdrop-filter: blur(2px); }
.dialog h2 { margin: 0 35px 20px 0; font-size: 30px; line-height: 1; letter-spacing: -.05em; }
.dialog ol { margin: 0 0 25px; padding-left: 24px; color: #5e594f; font-size: 14px; line-height: 1.8; }
.close-button { position: absolute; top: 13px; right: 15px; border: 0; background: none; font-size: 30px; line-height: 1; cursor: pointer; }

.share-dialog label, .share-dialog legend { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 800; }
.share-dialog input[type="password"], .link-row input {
  width: 100%;
  height: 46px;
  border: 2px solid var(--ink);
  border-radius: 5px 8px 4px 7px;
  padding: 8px 11px;
  color: var(--ink);
  background: white;
  font-family: ui-monospace, "Courier New", monospace;
  font-size: 17px;
}

.field-note { margin: 5px 0 20px; color: var(--muted); font-size: 10px; }
.share-dialog fieldset { min-width: 0; margin: 0 0 18px; padding: 0; border: 0; }
.art-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.art-choice { position: relative; cursor: pointer; }
.art-choice input { position: absolute; opacity: 0; pointer-events: none; }
.art-choice span { aspect-ratio: 1; display: grid; place-items: center; border: 2px solid #a9a294; border-radius: 5px; background: var(--paper); }
.art-choice img { width: 78%; height: 78%; object-fit: contain; }
.art-choice input:checked + span { border: 3px solid var(--red); background: #f3d9c7; transform: rotate(-2deg); }
.art-choice input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }
.form-error { min-height: 18px; margin: -7px 0 7px; color: var(--red); font-size: 11px; font-weight: 700; }
.share-result { text-align: center; }
.link-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.link-row input { min-width: 0; font-size: 12px; }

@keyframes draw-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@keyframes pop-in { 50% { transform: translateY(-5px) rotate(-4deg) scale(1.15); } }

@media (max-width: 720px) {
  .topbar { min-height: 58px; grid-template-columns: auto 1fr auto; padding: 7px 12px; }
  .topbar h1 { justify-self: center; font-size: 27px; }
  .home-link { font-size: 0; }
  .home-link::first-letter { font-size: 22px; }
  .topbar nav { gap: 9px; }
  .text-button { font-size: 10px; }
  .game { min-height: calc(100dvh - 58px); grid-template-columns: 1fr; grid-template-rows: minmax(210px, 38dvh) 1fr; }
  .drawing-panel { min-height: 0; padding: 29px 18px 11px; border-right: 0; border-bottom: 3px solid var(--ink); }
  .paper-tape { top: 7px; width: 70px; height: 20px; }
  .drawing svg { width: min(55vw, 220px); height: min(29dvh, 230px); }
  .miss-count { position: absolute; right: 12px; bottom: 10px; margin: 0; font-size: 10px; }
  .play-panel { justify-content: flex-start; padding: 20px 13px 25px; }
  .game-label { margin-bottom: 6px; }
  .word { min-height: 55px; gap: 7px 5px; }
  .letter-slot { width: clamp(21px, 7vw, 31px); height: 39px; font-size: 26px; }
  .message { margin: 11px 0 9px; font-size: 12px; }
  .keyboard { width: min(100%, 430px); gap: 6px; padding-bottom: 17px; }
  .key { border-width: 1.5px; box-shadow: 2px 2px 0 var(--ink); }
}

@media (max-width: 420px) {
  .share-button { max-width: 48px; line-height: 1.05; }
  .dialog { padding: 27px 22px; }
}

@media (max-height: 700px) and (max-width: 720px) {
  .game { grid-template-rows: minmax(170px, 31dvh) 1fr; }
  .drawing svg { height: 23dvh; }
  .play-panel { padding-top: 11px; }
  .game-label { display: none; }
  .word { min-height: 47px; }
  .message { margin: 6px 0; }
  .keyboard { padding-bottom: 10px; }
  #new-game { padding-block: 7px; }
}

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