/* ---------------------------------------------------------------------------
 * Hold the Line — the playable hero.
 *
 * Two palettes meet here on purpose. The chrome around the screen (HUD, build
 * panel, overlays, scoreboard) is drawn from the studio's own tokens so the
 * game sits *in* the page rather than on top of it. Everything inside the
 * canvas is CropCorp's own palette, painted in JS from CCBlocks.h.
 *
 * Mobile first: the build panel is a horizontal strip under the screen and
 * moves to the left of it from 720px up. Everything is scoped under .htl.
 * ------------------------------------------------------------------------- */

.htl {
  --htl-coin: var(--amb);
  max-width: 880px;
  margin: 38px auto 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.htl-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-family: var(--fm);
  font-size: .7rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--dim);
}
.htl-label b { color: var(--g); font-weight: 700; }

.htl-cab {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* --- HUD ---------------------------------------------------------------- */
.htl-hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  font-family: var(--fm);
  font-variant-numeric: tabular-nums;
}
.htl-stat {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.htl-stat .k { font-size: .55rem; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.htl-stat .v { font-size: clamp(.95rem, 3.2vw, 1.16rem); font-weight: 700; color: var(--tx); }
.htl-stat .v.gold { color: var(--htl-coin); }
.htl-stat .v.crop { color: #e07a3a; }
.htl-stat .v.low  { color: #ff6b6b; }
.htl-stat.flash { animation: htl-pop .4s ease; }
@keyframes htl-pop { 0%,100% { transform: none; } 30% { transform: translateY(-3px) scale(1.04); } }

/* --- main: screen + panel ---------------------------------------------- */
.htl-main { display: grid; grid-template-columns: 1fr; gap: 9px; }
.htl-screen { order: 1; position: relative; border-radius: 10px; overflow: hidden; background: #0d1a24; }
.htl-panel  { order: 2; }
.htl-screen canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  touch-action: none;
}

/* --- build panel -------------------------------------------------------- */
.htl-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  font-family: var(--fm);
  min-width: 0;
}
.htl-panel-title { display: none; }
.htl-tool {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 2px;
  padding: 7px 4px 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--tx);
  cursor: pointer;
  text-align: center;
  font: inherit;
  min-width: 0;
  transition: border-color .12s ease, background .12s ease;
}
.htl-tool canvas { width: 36px; height: 36px; image-rendering: pixelated; display: block; }
.htl-tool .nm { font-size: .6rem; font-weight: 700; letter-spacing: .03em; line-height: 1.15; }
.htl-tool .cost { font-size: .62rem; color: var(--htl-coin); font-weight: 700; }
.htl-tool .tip { display: none; font-size: .58rem; color: var(--dim); line-height: 1.35; }
.htl-tool .key { display: none; }
.htl-tool:hover { border-color: var(--line2); background: var(--bg3); }
.htl-tool.on { border-color: var(--g); background: rgba(46, 224, 122, .08); box-shadow: inset 0 0 0 1px var(--g); }
.htl-tool.poor .cost { color: #ff8b8b; }
.htl-tool.poor canvas { opacity: .55; }
.htl-tool:disabled { opacity: .5; cursor: default; }
.htl-tool:focus-visible { outline: 2px solid var(--g); outline-offset: 2px; }

.htl-sel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 5px 8px;
  padding: 7px 9px;
  background: var(--bg);
  border: 1px solid var(--line2);
  border-radius: 9px;
}
.htl-sel[hidden] { display: none; }
.htl-sel .nm { grid-column: 1 / -1; font-size: .68rem; font-weight: 700; color: var(--tx); }
.htl-sel .info { grid-column: 1 / -1; font-size: .6rem; color: var(--dim); }
.htl-sel .htl-btn { padding: 8px 10px; font-size: .62rem; }

.htl-wave {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px;
  background: var(--g);
  color: #04140a;
  border: 0; border-radius: 9px;
  font: inherit; font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  cursor: pointer;
}
.htl-wave:hover { filter: brightness(1.08); }
.htl-wave:disabled { background: var(--bg3); color: var(--mut); cursor: default; filter: none; }
.htl-wave .t { font-weight: 600; opacity: .8; text-transform: none; letter-spacing: 0; }
.htl-wave:focus-visible { outline: 2px solid var(--g); outline-offset: 3px; }

/* --- overlays ----------------------------------------------------------- */
.htl-over {
  position: absolute; inset: 0; z-index: 3;
  display: grid; place-content: center; align-content: safe center; gap: 12px;
  text-align: center; padding: 18px;
  background: rgba(10, 12, 16, .9);
  backdrop-filter: blur(3px);
  overflow: auto;
}
.htl-over[hidden] { display: none; }

/* On a phone the little screen is ~210px tall and the cards are taller. While
   a card is up, let the card set the height and stretch the field behind it,
   instead of clipping the title off the top. */
@media (max-width: 719px) {
  .htl-screen:has(.htl-over:not([hidden])) canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
  .htl-screen:has(.htl-over:not([hidden])) .htl-over { position: relative; aspect-ratio: 480 / 300; overflow: visible; }
  .htl-over { gap: 9px; padding: 14px; }
  .htl-keys { display: none; }
  .htl-board th, .htl-board td { padding: 6px 7px; }
}
.htl-over h3 { margin: 0; font-size: clamp(1.25rem, 4.4vw, 1.8rem); color: var(--tx); letter-spacing: -.01em; }
.htl-over p { margin: 0; color: var(--mut); font-size: clamp(.82rem, 2.6vw, .95rem); line-height: 1.5; max-width: 36ch; }
.htl-over p b { color: var(--tx); }
.htl-over .warn { color: #ff8b8b; }
.htl-keys { font-family: var(--fm); font-size: .66rem; color: var(--dim); }
.htl-keys kbd {
  background: var(--bg3); border: 1px solid var(--line2); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; color: var(--tx); font: inherit; font-size: .62rem;
}

.htl-tally { font-family: var(--fm); font-variant-numeric: tabular-nums; display: grid; gap: 3px; }
.htl-tally .big { font-size: clamp(1.9rem, 8vw, 2.8rem); font-weight: 800; color: var(--htl-coin); line-height: 1; }
.htl-tally .sub { font-size: .76rem; color: var(--mut); }
.htl-tally .best { font-size: .68rem; color: var(--dim); }
.htl-tally .best.new { color: var(--g); }
.htl-tally .rank { font-size: .8rem; font-weight: 700; color: var(--tx); min-height: 1.2em; margin-top: 4px; }
.htl-tally .rank.good { color: var(--g); }
.htl-tally .rank.gold { color: var(--htl-coin); }

.htl-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; align-items: center; }
.htl-name {
  font: inherit; font-family: var(--fm); font-size: .8rem;
  background: var(--bg); color: var(--tx);
  border: 1px solid var(--line2); border-radius: 9px; padding: 10px 12px;
  width: min(100%, 220px);
}
.htl-name:focus { outline: 2px solid var(--g); outline-offset: 1px; border-color: transparent; }
.htl-saved { font-family: var(--fm); font-size: .66rem; color: var(--g); min-height: 1em; }

.htl-btn {
  font-family: var(--fm);
  font-weight: 700; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase;
  color: #04140a; background: var(--g);
  border: 0; border-radius: 9px; padding: 11px 18px;
  cursor: pointer; text-decoration: none; display: inline-block;
  transition: filter .15s ease, transform .08s ease;
}
.htl-btn:hover { filter: brightness(1.08); }
.htl-btn:active { transform: translateY(1px); }
.htl-btn:disabled { opacity: .45; cursor: default; filter: none; transform: none; }
.htl-btn--ghost { background: transparent; color: var(--tx); border: 1px solid var(--line2); }
.htl-btn--ghost:hover { background: var(--bg3); }
.htl-btn:focus-visible { outline: 2px solid var(--g); outline-offset: 3px; }

.htl-hint { font-family: var(--fm); font-size: .68rem; line-height: 1.6; color: var(--dim); text-align: center; margin: 0; }
.htl-hint b { color: var(--mut); font-weight: 700; }

.htl-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- scoreboard --------------------------------------------------------- */
.htl-board {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 12px 10px;
  font-family: var(--fm);
  font-variant-numeric: tabular-nums;
}
.htl-board-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 18px;
  margin: 0 0 10px; padding: 0 2px;
}
.htl-board-head h3 { margin: 0; font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); font-weight: 700; }
.htl-board-head p { margin: 0; font-size: .72rem; color: var(--mut); }
.htl-board-head p b { color: var(--tx); }
.htl-board-scroll { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
.htl-board table { width: 100%; border-collapse: collapse; font-size: .72rem; }
.htl-board th, .htl-board td { padding: 7px 9px; text-align: left; white-space: nowrap; }
.htl-board th { position: sticky; top: 0; background: var(--bg3); color: var(--dim); font-size: .58rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; }
.htl-board td { border-top: 1px solid var(--line); color: var(--tx); }
.htl-board td.n, .htl-board td.when { color: var(--dim); }
.htl-board td.who { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; }
.htl-board td.who i { color: var(--mut); font-style: normal; }
.htl-board .num, .htl-board th.num { text-align: right; }
.htl-board tr.top td { color: var(--htl-coin); }
.htl-board tr.me td { background: rgba(46, 224, 122, .1); color: var(--g); }
.htl-board tr.me td.n::after { content: ' you'; font-size: .52rem; letter-spacing: .1em; text-transform: uppercase; }
.htl-board .sim {
  display: inline-block; margin-left: 5px; padding: 1px 5px; border-radius: 4px;
  font-size: .52rem; letter-spacing: .1em; text-transform: uppercase;
  background: rgba(46, 224, 122, .12); color: var(--g); vertical-align: middle;
}
.htl-board-note { margin: 8px 2px 0; font-size: .62rem; color: var(--dim); }

/* --- wider: panel on the left --------------------------------------------- */
@media (min-width: 720px) {
  .htl-main { grid-template-columns: 172px minmax(0, 1fr); align-items: start; }
  .htl-panel { order: 1; grid-template-columns: 1fr; gap: 5px; }
  .htl-screen { order: 2; }
  .htl-panel-title { display: block; margin: 0 0 2px; font-size: .58rem; letter-spacing: .16em; text-transform: uppercase; color: var(--dim); }
  .htl-tool {
    grid-template-columns: 36px 1fr auto;
    grid-template-areas: "ico nm cost" "ico tip tip";
    justify-items: start; align-items: center; column-gap: 8px; row-gap: 1px;
    padding: 5px 8px 5px 5px; text-align: left;
  }
  .htl-tool canvas { grid-area: ico; }
  .htl-tool .nm { grid-area: nm; font-size: .64rem; }
  .htl-tool .cost { grid-area: cost; }
  .htl-tool .tip { grid-area: tip; display: block; }
  .htl-tool .key { grid-area: cost; display: none; }
  .htl-sel { grid-template-columns: 1fr 1fr; }
  .htl-sel .nm, .htl-sel .info { grid-column: 1 / -1; }
  .htl-sel .htl-btn { grid-row: auto; }
  .htl-wave { flex-direction: column; align-items: stretch; text-align: center; gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .htl-btn, .htl-tool { transition: none; }
  .htl-stat.flash { animation: none; }
}
