/* =====================================================================
   Timberman — fixed "forest daytime" theme.
   Same page frame as Flappy Bird (full-height app shell, frosted top bar,
   chunky arcade buttons, hard-shadow stage, card overlays, colored rules
   modal) but with this game's own palette, taken straight from its canvas:
   leaf green, log brown, lumberjack red, harvest gold, deep-brown ink.
   Deliberately ignores the center's light/dark mode; no glass.css loaded.
   ===================================================================== */
:root {
  --tm-sky:    #7cc4de;   /* page gradient top */
  --tm-sky2:   #bde6f0;   /* canvas sky, matches the stage backdrop */
  --tm-meadow: #dcf0c0;   /* page gradient bottom */
  --tm-grass:  #57a83c;
  --tm-leaf:   #3fa14a;
  --tm-leafdk: #1d5f28;
  --tm-wood:   #996a3c;
  --tm-wooddk: #4e2f16;
  --tm-gold:   #f5b81f;
  --tm-red:    #c23a3a;   /* lumberjack shirt */
  --tm-reddk:  #6e1d1d;
  --tm-cream:  #f6e8c8;
  --tm-ink:    #2b2013;   /* outline ink — main text color */
  --tm-line:   rgba(43, 32, 19, .8);
}

html, body { height: 100%; }
body.tm-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, var(--tm-sky) 0%, var(--tm-sky2) 55%, var(--tm-meadow) 100%);
  color: var(--tm-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.tm-page *,
body.tm-page *::before,
body.tm-page *::after { box-sizing: border-box; }

/* ---------- App frame ---------- */
.c-app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.c-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(255, 255, 255, .38);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--tm-leaf);
  z-index: 20;
}
.c-bar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-bar__brand svg { filter: drop-shadow(0 2px 0 rgba(43, 32, 19, .18)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 26px);
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--tm-ink);
  text-shadow: 2px 2px 0 rgba(255, 255, 255, .55);
}
.c-bar__stats { display: flex; align-items: center; gap: 8px 18px; margin-left: auto; }
.c-bar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stat { font-size: 14px; font-weight: 700; letter-spacing: .03em; white-space: nowrap; color: rgba(43, 32, 19, .72); }
.stat b { color: var(--tm-wooddk); font-size: 16px; }

/* Lives: three hearts next to the stats, greyed out as branches whack */
.lives { display: flex; align-items: center; gap: 4px; }
.life { width: 16px; height: 16px; display: inline-block; }
.life::before {
  content: "\2665";
  font-size: 16px; line-height: 16px;
  color: #d5333c;
  transition: opacity .2s ease, filter .2s ease;
}
.life.lost::before { opacity: .22; filter: grayscale(1); }

/* ---------- Buttons (chunky arcade style, matches Flappy's frame) ------ */
.c-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 12px;
  border: 2px solid var(--tm-line);
  background: #fff;
  color: var(--tm-ink);
  box-shadow: 0 3px 0 rgba(43, 32, 19, .35);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
}
.c-btn:hover { background: #fdf3dd; border-color: var(--tm-leaf); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(43, 32, 19, .35); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(63, 161, 74, .5); }
/* Primary = lumberjack shirt red, this game's stand-in for pipe green. */
.c-btn--primary {
  background: linear-gradient(140deg, #d64c4c, var(--tm-red));
  border-color: var(--tm-line);
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .2);
}
.c-btn--primary:hover { background: linear-gradient(140deg, #e05a5a, var(--tm-red)); }

/* ---------- Table / stage column ---------- */
.c-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2.4vh, 22px);
}
.tm-board {
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* 2:3 portrait; capped by viewport height minus chrome (bar + energy +
     caption). Same sizing idea as Flappy, a bit more allowance below. */
  width: min(92vw, calc((100vh - 205px) * 0.6667), 420px);
  width: min(92vw, calc((100dvh - 205px) * 0.6667), 420px);
}
.tm-stage {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 14px;
  overflow: hidden;
  background: var(--tm-sky2);
  border: 3px solid var(--tm-line);
  box-shadow: 0 10px 0 rgba(43, 32, 19, .22), 0 22px 48px rgba(43, 32, 19, .35);
  touch-action: manipulation;
  cursor: pointer;
}
#board {
  display: block;
  width: 100%; height: 100%;
  touch-action: none;                  /* capture taps without page scroll */
  -webkit-user-select: none; user-select: none;
}

/* ---------- Energy bar ---------- */
/* Fill is anchored left and drains toward the right; JS swaps the colour
   tier (ok / warn / low) so a nearly-empty bar always reads red. */
.timerbar {
  flex: none;
  height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .55);
  border: 2px solid var(--tm-line);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(43, 32, 19, .18);
}
.timerbar__fill {
  height: 100%; width: 100%;
  border-radius: 999px;
  background: linear-gradient(180deg, #5ad17e, #35a95a);
  transition: width .12s linear, background-color .3s ease;
}
.timerbar__fill.warn { background: linear-gradient(180deg, #ffd35a, #e2a52e); }
.timerbar__fill.low  { background: linear-gradient(180deg, #ff6a6f, #d5333c); }

/* ---------- Caption under the stage ---------- */
.tm-caption {
  flex: none;
  margin: 0;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.9;
  color: rgba(43, 32, 19, .72);
}
.tm-card kbd, .c-modal kbd, .tm-caption kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin: 0 1px;
  font: 700 12px/1.5 ui-monospace, "Segoe UI", monospace;
  text-align: center;
  color: var(--tm-ink);
  background: #fff;
  border: 1px solid var(--tm-line);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(43, 32, 19, .3);
}

/* ---------- Ready / game-over overlays ---------- */
.tm-overlay {
  touch-action: manipulation;
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(43, 32, 19, .32);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.tm-overlay[hidden] { display: none; }
.tm-card {
  touch-action: manipulation;
  max-width: 300px;
  text-align: center;
  padding: 22px 24px 20px;
  border-radius: 16px;
  background: linear-gradient(160deg, #fdf3d9, var(--tm-cream));
  border: 2px solid var(--tm-line);
  box-shadow: 0 8px 0 rgba(43, 32, 19, .25), 0 22px 50px rgba(43, 32, 19, .4);
  color: var(--tm-ink);
  animation: tmPop .3s ease;
}
@keyframes tmPop { from { transform: scale(.88); opacity: 0; } }
.tm-card__big { font-size: 40px; line-height: 1.1; }
.tm-card h2 {
  margin: 6px 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--tm-ink);
  text-shadow: 2px 2px 0 rgba(255, 255, 255, .5);
}
.tm-card p { margin: 0 0 14px; color: #6b5a44; font-size: 13.5px; line-height: 1.55; }
.tm-card p b { color: var(--tm-leafdk); }
.tm-card .c-btn { font-size: 14px; }

/* ---------- Rules modal ---------- */
.c-modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(43, 32, 19, .5);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
/* Panel is "inside a log": deep heart-wood brown with cream text. */
.c-modal__panel {
  position: relative;
  width: min(92vw, 470px);
  max-height: 86vh;
  overflow: auto;
  background: linear-gradient(160deg, #7a5228, #4e3014);
  color: #f5e9d2;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, .55);
  box-shadow: 0 8px 0 rgba(43, 32, 19, .3), 0 24px 60px rgba(43, 32, 19, .55);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, .28);
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em;
  color: #fff; text-shadow: 2px 2px 0 rgba(0, 0, 0, .25);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: #f5e9d2; font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--tm-gold); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.55; }
.c-modal__body h3 {
  margin: 16px 0 6px; font-size: 13px;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--tm-gold);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--tm-gold); }
.c-modal__lead { margin: 12px 0; }
.c-modal__note {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .32);
  font-size: 13px;
  color: #efe0c2;
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }
.c-modal .c-btn { border-color: rgba(255, 255, 255, .8); box-shadow: 0 3px 0 rgba(0, 0, 0, .3); }
.c-modal .c-btn--primary { border-color: var(--tm-line); }

/* ---------- Responsive (same breakpoints as Flappy's frame) ---------- */
@media (max-width: 700px), (max-height: 560px) {
  .c-bar { gap: 5px 12px; padding: 7px clamp(10px, 3vw, 18px); padding-top: max(7px, env(safe-area-inset-top)); }
  .c-bar__brand { gap: 8px; }
  .c-bar__title { font-size: 16px; }
  .c-bar__stats { gap: 4px 12px; margin-left: auto; }
  .stat { font-size: 12px; }
  .stat b { font-size: 13px; }
  .life { width: 13px; height: 13px; }
  .life::before { font-size: 13px; line-height: 13px; }
  .c-btn { padding: 8px 10px; font-size: 12px; }
  .c-bar__controls { gap: 6px; }
  .c-bar__controls .c-btn { padding: 9px 10px; white-space: nowrap; }
  .tm-board { width: min(94vw, calc((100vh - 180px) * 0.6667), 420px); width: min(94vw, calc((100dvh - 180px) * 0.6667), 420px); }
}
/* Narrow screens only: the buttons drop to a row of their own and split it
   evenly into full-width thumb targets. */
@media (max-width: 700px) {
  .c-bar__controls { flex: 1 1 100%; flex-wrap: nowrap; }
  .c-bar__controls .c-btn { flex: 1 1 auto; min-width: 0; padding: 9px 6px; overflow: hidden; text-overflow: ellipsis; }
}
/* Smallest phones: labels scale down with the viewport instead of stacking. */
@media (max-width: 380px) {
  .c-bar { gap: 5px 8px; }
  .c-bar__title { font-size: 15px; }
  .stat { font-size: 11px; }
  .stat b { font-size: 12px; }
  .c-bar__controls { gap: 4px; }
  .c-bar__controls .c-btn { font-size: clamp(10px, 3.2vw, 12px); padding: 9px 4px; letter-spacing: .01em; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .tm-card, .timerbar__fill, .life::before { transition: none; animation: none; }
}
