:root {
  --ink: #2a2118;
  --panel: rgba(44, 30, 18, 0.68);
  --brown: #7a4f2a;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe3f0; color: #fff; }
button { font: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
kbd {
  font: 700 0.85em/1 ui-monospace, monospace;
  padding: 0.15em 0.4em;
  border-radius: 0.3em;
  background: #f1e8dc;
  border: 1px solid #d3c2ab;
  color: var(--ink);
}

/* Stacked fractions: 3 over 4 */
.fr {
  display: inline-flex; flex-direction: column;
  vertical-align: middle;
  font-size: 0.62em; line-height: 0.95;
  text-align: center;
  margin: 0 0.04em;
}
.fr > span:first-child { border-bottom: 0.1em solid currentColor; padding: 0 0.1em; }

/* ---------- Scene ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; }
#scene3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.plank-num, .tape-num {
  position: absolute; left: 0; top: 0;
  font-weight: 800; line-height: 1;
  white-space: nowrap;
}
.plank-num {
  transform: translate(-50%, -50%);
  font-size: 4.2vh;
  color: var(--ink);
  text-shadow: 0 0 0.2em rgba(255, 255, 255, 0.8);
  transition: opacity 0.2s;
}
.tape-num {
  transform: translate(-50%, 0);
  font-size: 3vh;
  color: #1d2a33;
  text-shadow: 0 0 0.25em #fff, 0 0 0.25em #fff;
}
.tape-num.end { color: #b3261e; font-size: 3.6vh; }

/* ---------- Top: toolbar, task and sum, ways found ---------- */
#hud-top {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; align-items: flex-start; gap: 2vw;
  padding: 2vh 2vw;
  z-index: 10;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }
#toolbar { display: flex; gap: 0.5vw; flex: 0 0 auto; width: 26vh; }
#toolbar button {
  width: 5.4vh; height: 5.4vh;
  border-radius: 1.4vh;
  border: none;
  background: var(--panel);
  font-size: 2.8vh;
  cursor: pointer;
  color: #fff;
  display: grid; place-items: center;
}
#toolbar button:hover { background: rgba(44, 30, 18, 0.88); }

#board { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1vh; }
#task, #sum {
  text-align: center;
  font-weight: 800;
  line-height: 1.2;
  border-radius: 3vh;
}
#task {
  font-size: clamp(20px, 4vh, 58px);
  padding: 0.6vh 2.4vw;
  max-width: 60vw;
  background: var(--panel);
  text-shadow: 0 0.25vh 0 rgba(0, 0, 0, 0.3);
}
#sum {
  font-size: clamp(22px, 5vh, 72px);
  padding: 0.2vh 2vw;
  background: rgba(255, 255, 255, 0.93);
  color: var(--ink);
}
#sum small { font-size: 0.55em; margin-left: 0.4em; color: #8a6d4c; }
#sum.exact small { color: #2e8b3e; }
#sum.long small { color: #b3261e; }
#task:empty, #sum:empty { visibility: hidden; }
#task.pop { animation: pop 0.45s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes pop { from { transform: scale(0.85); opacity: 0.3; } to { transform: scale(1); opacity: 1; } }

#tally-box {
  flex: 0 0 auto; width: 26vh;
  background: var(--panel);
  border-radius: 2vh;
  padding: 1vh 1.4vh 1.2vh;
}
#tally-box h3 { margin: 0 0 0.6vh; font-size: 2.3vh; line-height: 1.1; opacity: 0.85; }
#tally { display: flex; flex-direction: column; gap: 0.6vh; }
.way {
  background: #fff;
  color: var(--ink);
  border-radius: 1.2vh;
  padding: 0.3vh 1vh;
  font-size: 2.9vh; font-weight: 800; line-height: 1.25;
}
.way.empty { background: rgba(255, 255, 255, 0.15); color: rgba(255, 255, 255, 0.55); }

/* ---------- Bottom: the pile and the buttons ---------- */
#controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; align-items: flex-end; gap: 1.6vw;
  padding: 0 2vw 2vh;
  z-index: 10;
}
#pile-box, #buttons {
  background: var(--panel);
  border-radius: 2.4vh;
  padding: 1.2vh 1.4vh;
}
#pile-box { flex: 1; min-width: 0; }
#pile { display: flex; flex-wrap: wrap; gap: 1.2vh 1.6vh; align-items: center; }
/* Each plank is drawn to the same scale as the bridge (--unit is set by main.js) */
.plank {
  position: relative;
  width: calc(var(--unit, 80px) * var(--len));
  height: 7.4vh;
  border: none;
  border-radius: 0.8vh;
  background:
    linear-gradient(transparent 32%, rgba(0, 0, 0, 0.14) 32% 35%, transparent 35% 65%, rgba(0, 0, 0, 0.14) 65% 68%, transparent 68%),
    var(--c);
  box-shadow: 0 0.6vh 0 rgba(0, 0, 0, 0.3);
  color: var(--ink);
  font-size: 4.4vh; font-weight: 800; line-height: 1;
  cursor: pointer;
}
.plank:active { transform: translateY(0.5vh); box-shadow: none; }
.plank:disabled { opacity: 0.35; cursor: default; transform: none; }
.plank i {
  position: absolute; right: -0.8vh; top: -1.2vh;
  font-style: normal; font-size: 2.4vh;
  background: #fff; color: var(--ink);
  border-radius: 999px; padding: 0 0.8vh;
  box-shadow: 0 0.2vh 0.6vh rgba(0, 0, 0, 0.3);
}
#hint { margin: 0.8vh 0 0; min-height: 3vh; font-size: 2.5vh; font-weight: 700; color: #ffe08a; line-height: 1.25; }

#buttons { display: flex; flex-direction: column; gap: 1vh; }
.pair { display: flex; gap: 1vh; }
#buttons button {
  border: none;
  border-radius: 1.6vh;
  font-weight: 800; line-height: 1;
  cursor: pointer;
}
#undo, #clear { flex: 1; height: 6vh; padding: 0 2vh; background: rgba(255, 255, 255, 0.2); color: #fff; font-size: 2.8vh; }
#go {
  height: 8vh; min-width: 26vh; padding: 0 3vh;
  background: #5fd068; color: #0e3a1a;
  font-size: 4.4vh;
  box-shadow: 0 0.5vh 0 #2f8f3a;
}
#go.next { background: #ffd23f; color: #4a3300; box-shadow: 0 0.5vh 0 #c99a12; }
#buttons button:active { transform: translateY(0.4vh); box-shadow: none; }
#buttons button:disabled { opacity: 0.45; cursor: default; transform: none; }

/* ---------- Setup menu ---------- */
#setup {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 20;
  background: radial-gradient(ellipse at center, rgba(36, 24, 12, 0.5), rgba(18, 12, 6, 0.85));
  overflow: auto;
  padding: 3vh 2vw;
}
.panel {
  width: min(900px, 94vw);
  background: rgba(255, 252, 246, 0.97);
  color: var(--ink);
  border-radius: 28px;
  padding: 26px 34px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.logo { margin: 0; font-size: 50px; line-height: 1; font-weight: 800; color: var(--brown); letter-spacing: -0.5px; }
.tagline { margin: 8px 0 18px; font-size: 19px; line-height: 1.35; color: #5a4a38; }
.panel h2 { margin: 0 0 8px; font-size: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-bottom: 18px; }
.cards.modes { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.cards button {
  border: 3px solid #e6d8c4;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.cards button:hover { transform: translateY(-2px); }
.cards button[aria-pressed='true'] { border-color: var(--brown); background: #f8efe3; }
.cards b { display: block; font-size: 22px; line-height: 1.1; }
.cards span { display: block; font-size: 15px; color: #6e5d4a; line-height: 1.3; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.check input { width: 20px; height: 20px; accent-color: var(--brown); }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
.buttons button {
  border: 2px solid var(--brown);
  background: #fff;
  color: var(--brown);
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 19px; font-weight: 800;
  cursor: pointer;
}
.buttons button.primary { background: var(--brown); color: #fff; font-size: 22px; padding: 12px 34px; box-shadow: 0 6px 0 #4e3119; }
.buttons button.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #4e3119; }
#offline-status { margin: 10px 0 0; font-size: 15px; font-weight: 700; color: #2e7d4a; }
.help { margin-top: 16px; font-size: 15px; color: #5a4a38; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { padding-left: 20px; line-height: 1.5; }
