/* Ink Budget (public/ink-budget.js). A sheet of dotted paper on an easel, an ink meter under it, and
   beside it the word, the room's guesses and your guess box. Every screen fits the window
   (style.css caps the match area): the paper is the largest 4:3 sheet that fits what's left. */
.ib { --ib-green: #2c9a5e; --ib-red: #e0472a; --ib-blue: #3b4bd1; display: flex; flex-direction: column; flex: 0 1 auto; min-height: 0; }
.ib > * { flex: none; }
.ib .gd-bar { flex-wrap: nowrap; margin-bottom: .85rem; }
.ib .gd-bar .gd-hint { min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib .gd-kicker.ib-twist-tag { background: #ffb3cf; }

/* ---- The stage: paper on the left, the word and the guesses on the right. ---- */
.ib-stage {
  display: flex; justify-content: center; gap: 1.3rem; flex: 0 1 auto; height: clamp(17rem, 62vh, 32rem); min-height: 0;
}
/* The paper's column is as wide as the sheet can be at this height (--paper-w, from the script),
   giving way first when the side needs room. */
.ib-left { display: flex; flex-direction: column; flex: 0 1 var(--paper-w, 60%); gap: .55rem; min-width: 0; min-height: 0; }
.ib-left > * { flex: none; }
.ib-easel { display: grid; place-items: end center; flex: 1 1 0; min-width: 0; min-height: 0; padding: 4px 10px 10px 4px; }
.ib-paper {
  position: relative; overflow: hidden; border-radius: 12px; user-select: none; -webkit-user-select: none;
  background: radial-gradient(circle at 1.5px 1.5px, #1b11401f 1.5px, transparent 0) 0 0 / 16px 16px, #fffdf8;
  box-shadow: 0 0 0 3px var(--gd-ink), 6px 6px 0 3px var(--gd-ink);
}
.ib-canvas { display: block; width: 100%; height: 100%; }
.ib-paper.is-artist, .ib-paper.is-artist .ib-canvas { cursor: crosshair; touch-action: none; }
/* Shrinking Canvas: the edge of the paper you can still draw on; outside it is shaded. */
.ib-bounds {
  position: absolute; border: 2.5px dashed var(--ib-red); border-radius: 6px; box-shadow: 0 0 0 100vmax #1b114026; pointer-events: none;
  transition: left .2s linear, top .2s linear, width .2s linear, height .2s linear;
}
.ib-stamp {
  position: absolute; right: .55rem; top: .55rem; padding: .12rem .55rem .16rem; color: var(--ib-red); background: #fffaf3;
  border: 3px solid currentColor; border-radius: 9px; rotate: 6deg; font: 800 .86rem/1.1 var(--font); letter-spacing: .07em;
  text-transform: uppercase; pointer-events: none; animation: ib-stamp .45s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes ib-stamp { from { opacity: 0; scale: 2; } }
/* Blind: where the pen is, though its lines stay hidden. */
.ib-nib {
  position: absolute; left: 0; top: 0; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; pointer-events: none;
  background: var(--ib-red); box-shadow: 0 0 0 3px #fffdf8, 0 0 0 5px var(--gd-ink);
}

/* The ink meter. */
.ib-meter { display: flex; align-items: center; gap: .55rem; width: calc(100% - 14px); min-width: 0; margin-left: 4px; color: var(--text, inherit); font: 800 .8rem/1 var(--font); letter-spacing: .05em; text-transform: uppercase; }
.ib-meter-track { flex: 1 1 auto; height: .95rem; overflow: hidden; background: #fffaf3; border: 2.5px solid var(--gd-ink); border-radius: 999px; }
.ib-meter-fill {
  display: block; height: 100%; background: var(--ib-blue); transform-origin: 0 50%; border-right: 2.5px solid var(--gd-ink);
  transition: transform .2s linear, background .4s;
}
.ib-meter[data-level="half"] .ib-meter-fill { background: #f5a524; }
.ib-meter[data-level="low"] .ib-meter-fill { background: var(--ib-red); }
.ib-meter[data-level="empty"] .ib-meter-fill { border-right: 0; }
.ib-meter[data-level="low"] .ib-meter-count { color: var(--ib-red); }
.ib-meter-count { min-width: 2.6rem; text-align: right; font-variant-numeric: tabular-nums; letter-spacing: 0; }

/* The side: the word, who has it, the feed and the guess box. */
.ib-side { display: flex; flex-direction: column; flex: 0 0 clamp(15rem, 30%, 22rem); gap: .6rem; min-width: 0; min-height: 0; }
.ib-chip { display: none; }
.ib-side > * { flex: none; }
.ib-word {
  display: grid; gap: .3rem; padding: .5rem .8rem .6rem; color: var(--gd-ink); background: var(--gd-paper);
  border: 3px solid var(--gd-ink); border-radius: 14px; box-shadow: 4px 4px 0 var(--gd-ink); rotate: -.6deg;
}
.ib-word.is-known { background: #e8f8c8; }
.ib-word-label { color: var(--gd-muted); font: 800 .7rem/1.1 var(--font); letter-spacing: .08em; text-transform: uppercase; }
.ib-word-text { font: 800 clamp(1.35rem, 2.4vw, 1.7rem)/1.05 var(--font); letter-spacing: -.02em; overflow-wrap: anywhere; }
.ib-tiles { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .3rem .7rem; min-width: 0; margin: 0; }
.ib-tile-word { display: flex; align-items: flex-end; gap: .2rem; min-width: 0; max-width: 100%; }
.ib-tile { display: grid; place-items: end center; flex: 0 1 1.05rem; min-width: .45rem; height: 1.45rem; border-bottom: 3px solid var(--gd-ink); font: 800 1rem/1.1 var(--font); }
.ib-tile.is-filled { color: #1d6e3e; }
.ib-tile-mark { font: 800 1rem/1.1 var(--font); }
.ib-status { margin: 0; color: var(--gd-muted); font: 800 .82rem/1.2 var(--font); }
.ib-status:empty { display: none; }
.ib-status.is-all { color: var(--ib-green); }
.ib-feed {
  display: flex; flex-direction: column; justify-content: flex-end; gap: .3rem; flex: 1 1 0; min-height: 2.2rem; margin: 0; padding: 0;
  overflow: hidden; list-style: none; mask-image: linear-gradient(to bottom, transparent, #000 1.4rem);
}
.ib-line {
  display: flex; align-items: baseline; gap: .45rem; flex: none; min-width: 0; padding: .22rem .6rem .26rem .5rem; color: var(--gd-ink);
  background: var(--gd-paper); border: 2px solid var(--gd-ink); border-left: 6px solid var(--c, var(--gd-butter)); border-radius: 10px;
  font-weight: 700; animation: ib-line .3s ease-out both;
}
@keyframes ib-line { from { opacity: 0; translate: 0 .5rem; } }
.ib-who { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }
.ib-said { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-line.is-got { background: #e8f8c8; }
.ib-line.is-got .ib-said { color: #1d6e3e; font-weight: 800; }
.ib-line.is-mine { background: #fff1c9; }
.ib-line.is-got.is-mine { background: #c9f0a0; }
.ib-form { display: flex; gap: .5rem; min-width: 0; }
.ib-field { flex: 1 1 auto; min-width: 0; }
.ib input.ib-input {
  width: 100%; min-height: 3rem; margin: 0; padding: .2rem .8rem; color: var(--gd-ink); background: #fff; border: 3px solid var(--gd-ink) !important;
  border-radius: 12px; box-shadow: 3px 3px 0 var(--gd-ink); font: 800 1.05rem/1.1 var(--font);
}
.ib input.ib-input::placeholder { color: #1b11404d; font-weight: 700; }
.ib input.ib-input:focus-visible { border-color: var(--ib-red) !important; box-shadow: 3px 3px 0 var(--gd-ink), inset 0 0 0 2px var(--ib-red); outline: none; }
.ib .ib-send { min-height: 3rem; padding-inline: 1.15rem; font-size: 1rem; }
.ib-note { margin: 0; color: var(--muted); font-weight: 750; }
.ib-note:empty { display: none; }
.ib-note.is-close { color: #d18b0e; }
.ib-note.is-good { color: var(--ib-green); }

/* ---- Stage 1: picking the word. ---- */
.ib-pick-body { display: grid; justify-items: center; gap: 1rem; padding: .5rem 0 .3rem; text-align: center; }
.ib-ask { margin: 0; font: 800 clamp(1.6rem, 3vw, 2.2rem)/1.05 var(--font); letter-spacing: -.04em; }
.ib-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 15rem)); gap: 1.1rem; width: 100%; justify-content: center; }
.ib-choice {
  display: grid; justify-items: center; gap: .35rem; min-width: 0; min-height: 0; padding: .9rem .9rem 1rem; color: var(--gd-ink);
  background: var(--gd-paper); border: 3px solid var(--gd-ink); border-radius: 18px; box-shadow: 5px 5px 0 var(--gd-ink); font: inherit;
  cursor: pointer; rotate: -1deg; transition: translate .2s, box-shadow .2s, background .2s, rotate .3s, opacity .2s;
}
.ib-choice:nth-child(2) { rotate: 1deg; }
.ib-choice:not(:disabled):hover { translate: 0 -3px; box-shadow: 6px 8px 0 var(--gd-ink); }
.ib-choice:not(:disabled):active { translate: 2px 2px; box-shadow: 2px 2px 0 var(--gd-ink); }
.ib-choice:disabled:not(.is-picked) { opacity: .55; }
.ib-choice.is-picked { rotate: 0deg; background: var(--gd-butter); }
.ib-choice-level {
  padding: .1rem .5rem .14rem; background: #e8f8c8; border: 2px solid var(--gd-ink); border-radius: 999px;
  font: 800 .7rem/1.1 var(--font); letter-spacing: .08em; text-transform: uppercase;
}
.ib-choice[data-level="medium"] .ib-choice-level { background: #fff1c9; }
.ib-choice[data-level="hard"] .ib-choice-level { background: #ffd6c9; }
.ib-choice-word { max-width: 100%; font: 800 clamp(1.3rem, 2.6vw, 1.7rem)/1.1 var(--font); letter-spacing: -.02em; overflow-wrap: anywhere; }
.ib-choice-ink { color: var(--gd-muted); font-weight: 750; font-size: .9rem; }
.ib-tip { max-width: 34rem; margin: 0; color: var(--muted); font-weight: 650; }
.ib-up { display: flex; align-items: center; gap: .9rem; }
.ib-up .sb-face { width: 3.6rem; height: 3.6rem; font-size: 1.3rem; }
.ib-up-text { margin: 0; font: 800 clamp(1.3rem, 2.6vw, 1.8rem)/1.1 var(--font); letter-spacing: -.02em; text-align: left; }
.ib-twist {
  display: grid; gap: .15rem; max-width: 30rem; margin: .2rem 0 0; padding: .55rem .9rem .6rem; color: var(--gd-ink); background: #ffe1ec;
  border: 3px solid var(--gd-ink); border-radius: 14px; box-shadow: 4px 4px 0 var(--gd-ink); rotate: -1deg; font-weight: 700;
}
.ib-twist strong { font: 800 .8rem/1.1 var(--font); letter-spacing: .08em; text-transform: uppercase; color: #b1245c; }
.ib-pick .ib-note { color: var(--ib-red); }

/* ---- Stage 4: the reveal. ---- */
.ib-reveal .ib-side { flex-basis: clamp(16rem, 34%, 24rem); }
.ib-answer {
  display: grid; gap: .15rem; padding: .55rem .9rem .65rem; color: var(--gd-ink); background: #e8f8c8; border: 3px solid var(--gd-ink);
  border-radius: 14px; box-shadow: 4px 4px 0 var(--gd-ink); opacity: 0; translate: 0 10px; scale: .94; rotate: -1deg;
  transition: opacity .3s, translate .45s cubic-bezier(.2, 1.4, .4, 1), scale .45s cubic-bezier(.2, 1.4, .4, 1);
}
.is-told .ib-answer { opacity: 1; translate: none; scale: 1; }
.ib-answer-word { font: 800 clamp(1.5rem, 2.8vw, 2.1rem)/1.2 var(--font); letter-spacing: -.03em; overflow-wrap: anywhere; }
.ib-results { display: grid; flex: 0 1 auto; align-content: start; gap: .4rem; min-height: 0; margin: 0; padding: 0 4px 4px 0; overflow: hidden; list-style: none; }
.ib-result {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .55rem; min-width: 0; padding: .28rem .6rem .28rem .32rem;
  color: var(--gd-ink); background: var(--gd-paper); border: 2.5px solid var(--gd-ink); border-radius: 12px; box-shadow: 3px 3px 0 var(--gd-ink);
  opacity: 0; translate: 14px 0; transition: opacity .3s, translate .4s cubic-bezier(.2, 1.4, .4, 1);
}
.ib-result.is-in { opacity: 1; translate: none; }
.ib-result.is-missed.is-in { opacity: .78; }
.ib-result.is-artist { background: #fff1c9; }
.ib-result.is-mine { box-shadow: 3px 3px 0 var(--gd-ink), 0 0 0 3px var(--gd-butter); }
.ib-result .sb-face { width: 1.9rem; height: 1.9rem; border-width: 2px; font-size: .72rem; }
.ib-result-text { display: grid; min-width: 0; }
.ib-result-name, .ib-result-detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-result-name { font: 800 .95rem/1.15 var(--font); }
.ib-result-detail { color: var(--gd-muted); font-size: .78rem; font-weight: 700; }
.ib-result-points { font: 800 1.05rem/1 var(--font); font-variant-numeric: tabular-nums; }
.ib-many .ib-results { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem .45rem; }
.ib-many .ib-result { gap: .4rem; padding-right: .45rem; }
.ib-many .ib-result .sb-face { width: 1.6rem; height: 1.6rem; }
.ib-many .ib-result-name { font-size: .86rem; }
.ib-many .ib-result-points { font-size: .92rem; }
.ib-reveal > .gd-you { margin-top: .8rem; opacity: 0; translate: 0 -6px; transition: opacity .4s, translate .4s; }
.ib .gd-hint.ib-score {
  flex: none; margin-left: auto; padding: .1rem .6rem .14rem; color: var(--gd-ink); background: #fffaf3; border: 2px solid var(--gd-ink);
  border-radius: 999px; font-weight: 800; animation: ib-line .35s ease-out both;
}
.ib .gd-hint.ib-score.good { background: #e8f8c8; }
@media (min-width: 46.01rem) { .ib-reveal > .gd-you { display: none; } }
@media (max-width: 46rem) { .ib .ib-score { display: none; } }
.ib-reveal > .gd-you:empty { display: none; }
.ib-reveal.is-scored > .gd-you { opacity: 1; translate: none; }

/* ---- Laptop heights: gaps and the bar give way first. ---- */
@media (min-width: 46.01rem) and (max-height: 50rem) {
  .ib .gd-bar { margin-bottom: .6rem; }
  .ib-stage { height: clamp(15rem, 60vh, 28rem); gap: 1.1rem; }
  .ib-side { gap: .5rem; }
  .ib input.ib-input, .ib .ib-send { min-height: 2.7rem; }
  .ib-pick-body { gap: .8rem; }
  .ib-reveal > .gd-you { margin-top: .55rem; }
}
@media (min-width: 46.01rem) and (max-height: 38rem) {
  .ib-stage { height: clamp(13rem, 58vh, 22rem); }
  .ib-word { padding-block: .4rem .45rem; }
  .ib-word .ib-word-label { display: none; }
  .ib-tip { display: none; }
  .ib-result { padding-block: .18rem; }
  .ib-result .sb-face { width: 1.55rem; height: 1.55rem; }
  .ib-result-detail { display: none; }
}

/* ---- A phone (either way up): the round fills the screen. ---- */
@media (max-width: 46rem), (max-height: 30rem) {
  .ib { flex: 1 1 0; }
  .ib .gd-bar { margin-bottom: .5rem; }
  .ib .gd-bar .gd-hint { font-size: .84rem; }
  .ib-stage { flex: 1 1 0; height: auto; }
  .ib-word-label { display: none; }
  .ib input.ib-input, .ib .ib-send { min-height: 2.7rem; }
  .ib-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
  .ib-choice { padding: .7rem .6rem .8rem; }
  .ib-pick-body { gap: .8rem; }
}
/* Upright: the word, the paper, the ink and the guesses in one column. */
@media (max-width: 46rem) and (min-height: 30.01rem) {
  .ib-stage { display: flex; flex-direction: column; gap: .45rem; }
  .ib-left, .ib-side { display: contents; }
  .ib-word { order: 1; display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .6rem; padding: .35rem .7rem .4rem; }
  .ib-word-text { font-size: 1.3rem; }
  .ib-status { margin-left: auto; }
  .ib-meter { align-self: center; width: min(100% - 11px, var(--paper-w, 100%) - 11px); margin-left: 0; }
  .ib-easel { order: 3; flex: 1 1 0; padding: 3px 8px 8px 3px; }
  .ib-meter { order: 4; font-size: .72rem; }
  .ib-meter-track { height: .8rem; }
  .ib-feed { order: 5; flex: none; height: 3.45rem; min-height: 0; gap: .25rem; }
  /* The bar steps aside for the paper; a chip in the word's row names the twist or the last call. */
  :is(.ib-draw, .ib-reveal) > .gd-bar { display: none; }
  .ib-chip {
    display: inline-block; padding: .08rem .45rem .12rem; background: #ffb3cf; border: 2px solid var(--gd-ink); border-radius: 999px;
    font: 800 .66rem/1.1 var(--font); letter-spacing: .07em; text-transform: uppercase;
  }
  .ib-line { padding-block: .12rem .16rem; font-size: .88rem; }
  .ib-form { order: 6; }
  .ib-note { order: 7; font-size: .86rem; }
  .ib-tile { flex-basis: .95rem; height: 1.3rem; font-size: .92rem; }
  /* The reveal: the word, the replay, then everyone as compact chips. */
  .ib-reveal .ib-answer { order: 1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 .6rem; padding-block: .35rem .45rem; }
  .ib-reveal .ib-answer .ib-word-label { display: inline; }
  .ib-reveal .ib-answer-word { font-size: 1.45rem; }
  .ib-reveal .ib-easel { order: 2; }
  .ib-reveal .ib-results { order: 3; display: flex; flex-wrap: wrap; gap: .35rem; overflow: visible; }
  .ib-reveal .ib-result { gap: .3rem; padding: .15rem .45rem .15rem .2rem; border-width: 2px; box-shadow: 2px 2px 0 var(--gd-ink); }
  .ib-reveal .ib-result .sb-face { width: 1.4rem; height: 1.4rem; }
  .ib-reveal .ib-result-detail { display: none; }
  .ib-reveal .ib-result-name { max-width: 5.5rem; font-size: .8rem; }
  .ib-reveal .ib-result-points { font-size: .84rem; }
  /* Your chip says your points, so the reveal's own line steps aside for the drawing. */
  .ib-reveal > .gd-you { display: none; }
  .ib-reveal .ib-results { gap: .3rem; }
  .ib-pick-body { flex: 1 1 0; align-content: center; padding-bottom: 2rem; }
}
/* Sideways: the paper on the left, everything else beside it. */
@media (max-height: 30rem) {
  .ib .gd-bar { display: none; }
  .ib-stage { gap: .8rem; }
  .ib-side, .ib-reveal .ib-side { flex: 1 1 0; min-width: 13rem; }
  .ib-left { gap: .35rem; }
  .ib-easel { padding: 3px 8px 8px 3px; }
  .ib-side { gap: .4rem; }
  .ib-word { padding: .3rem .6rem .35rem; display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .5rem; }
  .ib-word-text { font-size: 1.15rem; }
  .ib-feed { min-height: 1.6rem; }
  .ib-line { padding-block: .1rem .14rem; font-size: .84rem; }
  .ib-tile { flex-basis: .9rem; height: 1.2rem; font-size: .88rem; }
  .ib-answer { padding-block: .3rem .4rem; }
  .ib-answer-word { font-size: 1.3rem; }
  .ib-results { grid-template-columns: repeat(auto-fill, minmax(7.2rem, 1fr)); gap: .3rem; }
  .ib-result { padding: .08rem .4rem .08rem .15rem; gap: .3rem; border-width: 2px; box-shadow: 2px 2px 0 var(--gd-ink); }
  .ib-result .sb-face { width: 1.2rem; height: 1.2rem; }
  .ib-result-points { font-size: .8rem; }
  .ib-result-detail { display: none; }
  .ib-result-name { font-size: .8rem; }
  .ib-reveal > .gd-you { display: none; }
  .ib-pick-body { gap: .5rem; padding: 0; }
  .ib-ask { font-size: 1.4rem; }
  .ib-tip { display: none; }
  .ib-choice { padding: .5rem .6rem .6rem; }
}
