:root {
  --ink: #141414;
  --paper: #ffffff;
  --pink: #ec5aa0;
  --blue: #2fb6ec;
  --orange: #f59a23;
  --green: #36b45a;
  --soft: #f2f2f2;
  --marker: "Permanent Marker", "Marker Felt", "Comic Sans MS", cursive;
  --word: "Kalam", "Marker Felt", "Comic Sans MS", cursive;
  --hand: "Gochi Hand", "Bradley Hand", "Comic Sans MS", cursive;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 18px;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.screen {
  max-width: 34rem;
  margin: 0 auto;
  padding: max(0.8rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}

/* ---------- Ribbons ---------- */

.ribbon {
  position: relative;
  display: inline-block;
  padding: 0.28rem 1.1rem 0.34rem;
  color: #fff;
  font-family: var(--marker);
  font-weight: 400;
  line-height: 1.1;
  background: var(--pink);
  clip-path: polygon(0 6%, 4% 0, 96% 4%, 100% 0, 97% 50%, 100% 100%, 95% 96%, 3% 100%, 0 94%, 3% 50%);
  transform: rotate(-1.2deg);
}

.ribbon > span {
  display: block;
  text-shadow: 0 2px 0 rgb(0 0 0 / 0.12);
}

.ribbon.blue {
  background: var(--blue);
  transform: rotate(1deg);
}

.ribbon.small {
  margin: 0 0 0.6rem;
  font-size: 1.15rem;
}

/* ---------- Home ---------- */

.back {
  display: inline-block;
  color: var(--ink);
  font-size: 1.1rem;
  text-decoration: none;
  padding: 0.2rem 0;
}

.home-top {
  display: grid;
  justify-items: center;
  text-align: center;
  margin-top: 0.6rem;
}

.home-mark {
  width: 7rem;
  height: 7rem;
  transform: rotate(-4deg);
  filter: drop-shadow(0 6px 0 rgb(0 0 0 / 0.12));
}

.home-title {
  margin: 0.4rem 0 0;
  font-family: var(--marker);
  font-weight: 400;
  font-size: clamp(3rem, 15vw, 4.4rem);
  line-height: 1;
  transform: rotate(-2deg);
}

.home-tag {
  margin: 0.3rem 0 0;
  font-size: 1.3rem;
  color: #555;
}

.play {
  display: block;
  width: min(100%, 19rem);
  margin: 1.4rem auto 0;
  padding: 0.75rem 1rem 0.85rem;
  border: 3px solid var(--ink);
  border-radius: 1.1rem;
  background: var(--blue);
  color: #fff;
  font-family: var(--marker);
  font-size: 2rem;
  letter-spacing: 0.02em;
  box-shadow: 0 6px 0 var(--ink);
  transform: rotate(-1deg);
}

.play:active {
  transform: rotate(-1deg) translateY(4px);
  box-shadow: 0 2px 0 var(--ink);
}

.home-note {
  max-width: 22rem;
  margin: 1rem auto 0;
  text-align: center;
  font-size: 1.15rem;
  line-height: 1.3;
}

.board-wrap {
  margin: 1.8rem auto 0;
  max-width: 24rem;
  text-align: center;
}

.board {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0.9rem;
  border: 3px dashed var(--ink);
  border-radius: 1rem;
  text-align: left;
}

.board li {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.35rem 0;
  font-size: 1.25rem;
}

.board li + li {
  border-top: 2px dotted #bbb;
}

.board .rank {
  width: 1.6rem;
  font-family: var(--marker);
}

.board .who {
  flex: 1;
}

.board .num {
  font-family: var(--marker);
  font-size: 1.4rem;
}

.board .plays {
  color: #777;
  font-size: 1rem;
}

.board-empty {
  margin: 0;
  color: #666;
}

.credits {
  margin: 2rem auto 0;
  max-width: 24rem;
  text-align: center;
  color: #888;
  font-family: system-ui, sans-serif;
  font-size: 0.72rem;
  line-height: 1.4;
}

/* ---------- Game ---------- */

.game {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-bottom: max(0.6rem, env(safe-area-inset-bottom));
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

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

.player {
  min-width: 0;
}

.player-name {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.95rem;
  line-height: 1.2;
}

.player-box {
  position: relative;
  aspect-ratio: 1 / 1.05;
  margin-top: 0.7rem;
  border: 2.5px dashed var(--ink);
  border-radius: 0.6rem;
  background: #fff;
}

.player-box canvas {
  position: absolute;
  inset: 12% 8% 6%;
  width: 84%;
  height: 82%;
}

.player-score {
  position: absolute;
  top: -0.65rem;
  left: 50%;
  min-width: 1.9rem;
  padding: 0 0.35rem;
  transform: translateX(-50%);
  border-radius: 0.35rem;
  background: var(--ink);
  color: #fff;
  text-align: center;
  font-family: var(--marker);
  font-size: 1rem;
  line-height: 1.35;
}

.player.me .player-box {
  margin-top: 0.7rem;
  border: none;
  background: var(--ink);
  display: grid;
  place-items: center;
}

.player.me .player-score {
  position: static;
  transform: none;
  background: none;
  font-size: clamp(2.2rem, 11vw, 3rem);
  line-height: 1;
}

.player.me .pencil {
  position: absolute;
  right: 0.3rem;
  bottom: 0.3rem;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 0.3rem;
  background: #fff;
  padding: 0.15rem;
}

.player-bot {
  font-size: 0.75rem;
  color: #888;
}

.bump {
  animation: bump 0.45s cubic-bezier(0.3, 1.8, 0.5, 1);
}

@keyframes bump {
  40% {
    transform: translateX(-50%) scale(1.5);
  }
}

.player.me .bump {
  animation-name: bump-me;
}

@keyframes bump-me {
  40% {
    transform: scale(1.35);
  }
}

.timebar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.55rem 0 0.2rem;
}

.scribble {
  flex: 1;
  height: 0.55rem;
  background: repeating-linear-gradient(100deg, var(--ink) 0 2px, transparent 2px 4px), repeating-linear-gradient(80deg, #555 0 1px, transparent 1px 5px);
  border-radius: 0.3rem;
  opacity: 0.9;
}

.clock {
  padding: 0.05rem 0.55rem;
  border: 2.5px solid var(--ink);
  border-radius: 0.55rem;
  font-family: var(--marker);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.clock.hurry {
  background: var(--ink);
  color: #fff;
}

.ribbon-row {
  text-align: center;
}

.draw-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 11rem;
  margin: 0.2rem auto 0.1rem;
  font-family: var(--marker);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.draw-label::before,
.draw-label::after {
  content: "";
  flex: 1;
  height: 2px;
  background: var(--ink);
}

.choices {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.choices .ribbon {
  font-family: var(--word);
  font-weight: 700;
  flex: 1 1 0;
  min-width: 0;
  max-width: 14rem;
  font-size: clamp(1.05rem, 5.4vw, 1.5rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.choices .ribbon.got {
  background: var(--green);
}

.or {
  font-size: 1rem;
}

.guess {
  display: grid;
  justify-items: center;
  margin: 0.45rem 0 0;
  padding: 0.1rem 0.6rem 0.25rem;
  border: 3px dotted var(--ink);
  border-radius: 1.1rem;
}

.is-it {
  font-size: 0.95rem;
  line-height: 1.1;
}

.guess-word {
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: var(--word);
  font-size: clamp(1.8rem, 9.5vw, 2.6rem);
  line-height: 1.15;
}

.guess-word.right {
  color: var(--orange);
  animation: pop 0.5s cubic-bezier(0.3, 1.8, 0.5, 1);
}

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

.pad {
  position: relative;
  flex: 1;
  min-height: 12rem;
  margin-top: 0.4rem;
}

.pad canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.pad-tool {
  position: absolute;
  top: 0.2rem;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 0.05rem;
  padding: 0.2rem 0.3rem;
  border: none;
  background: none;
  font-family: var(--marker);
  font-size: 0.95rem;
  text-transform: uppercase;
}

.pad-tool svg {
  width: 2.6rem;
  height: 2.2rem;
}

.pad-tool.clear {
  left: 0;
}

.pad-tool.skip {
  right: 0;
}

.skip-icon {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.skip-icon svg {
  width: 2rem;
}

.skip-count {
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 0.85rem;
}

.pad-tool:disabled {
  opacity: 0.3;
}

.banner {
  position: absolute;
  left: 50%;
  bottom: 0.4rem;
  z-index: 3;
  margin: 0;
  padding: 0.5rem 1.6rem 0.6rem;
  transform: translateX(-50%) rotate(-1.5deg);
  white-space: nowrap;
  color: #fff;
  font-family: var(--marker);
  font-size: clamp(1.6rem, 8vw, 2.2rem);
  background: var(--blue);
  clip-path: polygon(0 0, 100% 4%, 94% 50%, 100% 100%, 2% 96%, 6% 50%);
  pointer-events: none;
}

.banner.pink {
  background: var(--pink);
}

.banner.show {
  animation: slide 0.35s cubic-bezier(0.3, 1.5, 0.5, 1);
}

@keyframes slide {
  0% {
    transform: translateX(-50%) translateY(140%) rotate(-1.5deg);
  }
}

/* ---------- Results ---------- */

.results-title {
  margin: 0.8rem 0 0;
  text-align: center;
  font-family: var(--marker);
  font-weight: 400;
  font-size: clamp(2.6rem, 13vw, 3.6rem);
  transform: rotate(-2deg);
}

.results-line {
  margin: 0.2rem 0 0;
  text-align: center;
  font-size: 1.3rem;
}

.podium {
  list-style: none;
  margin: 1rem auto 1.4rem;
  padding: 0;
  max-width: 22rem;
}

.podium li {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.5rem;
  padding: 0.45rem 0.8rem;
  border: 3px dashed var(--ink);
  border-radius: 0.9rem;
  font-size: 1.3rem;
}

.podium li.me {
  border-style: solid;
  background: var(--ink);
  color: #fff;
}

.podium .place {
  width: 2.2rem;
  font-family: var(--marker);
  font-size: 1.5rem;
}

.podium .who {
  flex: 1;
}

.podium .num {
  font-family: var(--marker);
  font-size: 1.6rem;
}

#results .ribbon.small {
  display: table;
  margin: 0 auto 0.7rem;
}

.sketchbook {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.4rem, 1fr));
  gap: 0.6rem;
  margin: 0;
  padding: 0;
}

.sketchbook li {
  position: relative;
  border: 2.5px dashed var(--ink);
  border-radius: 0.7rem;
  padding: 0.3rem;
  text-align: center;
}

.sketchbook canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
}

.sketchbook .label {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 1rem;
}

.sketchbook .mark {
  position: absolute;
  top: -0.6rem;
  right: -0.4rem;
  display: grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  color: #fff;
  font-family: var(--marker);
  font-size: 0.9rem;
  background: var(--green);
}

.sketchbook .miss .mark {
  background: #999;
}

.sketchbook-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: #666;
  border: none !important;
}

.save-note {
  min-height: 1.4rem;
  margin: 0.9rem 0 0;
  text-align: center;
  color: #555;
}

.results-actions {
  display: grid;
  justify-items: center;
  gap: 0.4rem;
  padding-bottom: 1rem;
}

.results-actions .play {
  margin-top: 0.4rem;
}

.plain {
  padding: 0.5rem 1.4rem;
  border: none;
  background: none;
  font-size: 1.3rem;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

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