:root {
  --ink: #e8e6df;
  --dim: #9aa3ab;
  --panel: rgba(18, 24, 32, 0.92);
  --edge: rgba(255, 255, 255, 0.14);
  --gold: #ffd479;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #0d1219;
  color: var(--ink);
  font: 15px/1.45 "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#app { position: relative; width: 100%; height: 100%; }

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ------------------------------------------------------------------ hud */

#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 26px;
  padding: 10px 18px;
  background: linear-gradient(rgba(8, 12, 18, 0.85), rgba(8, 12, 18, 0));
  pointer-events: none;
  flex-wrap: wrap;
}

.hud-group { display: flex; align-items: baseline; gap: 8px; }
.hud-group.score strong { color: var(--gold); font-size: 22px; }
.hud-group strong { font-size: 18px; letter-spacing: 0.02em; }

.hud-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--dim);
}

.hud-group.buttons { margin-left: auto; pointer-events: auto; gap: 8px; }

#hud-shots { display: inline-flex; gap: 6px; }

.shot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #cfd2c8, #7b7a6f 60%, #4b4a42);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

button {
  font: inherit;
  color: var(--ink);
  background: rgba(30, 38, 48, 0.9);
  border: 1px solid var(--edge);
  border-radius: 7px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

button:hover { background: rgba(52, 64, 78, 0.95); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: default; pointer-events: none; }

#btn-addblocks.on, #btn-boulder.on {
  border-color: var(--gold);
  background: rgba(80, 62, 26, 0.85);
  color: var(--ink);
}

button.primary {
  background: linear-gradient(#b98a3a, #8d6522);
  border-color: #d9ab5e;
  font-weight: bold;
}

button.primary:hover { background: linear-gradient(#cd9c46, #9d7228); }

#hint {
  position: absolute;
  left: 0; right: 0;
  bottom: 18px;
  margin: 0;
  text-align: center;
  color: rgba(232, 230, 223, 0.78);
  text-shadow: 0 2px 6px #000;
  pointer-events: none;
  font-size: 15px;
}

/* ----------------------------------------------------------- build mode */

/* Wrapper is display:contents on desktop so the palette and action bar keep
   their existing absolute positions. Phone layout (below) turns it into a
   single bottom dock so the two pieces stack without covering the stage. */
#build-dock { display: contents; }

/* The stone palette: a panel docked to the right, two columns of buttons.
   Slides in from off-screen - shown for the dedicated build screen and for
   the same tools opened over a round in progress (body.adding) alike. */
#stonepanel {
  position: absolute;
  top: 76px;
  right: 0;
  bottom: 118px;
  width: 208px;
  transform: translateX(110%);
  transition: transform 0.25s ease;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-right: none;
  border-radius: 12px 0 0 12px;
  padding: 14px 12px;
  overflow-y: auto;
  z-index: 5;
}

body.building #stonepanel, body.adding #stonepanel { transform: translateX(0); }

#stonepanel h3 {
  margin: 0 0 10px;
  font: bold 13px/1.2 Georgia, serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  color: var(--dim);
}

#palette { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.pal-btn {
  width: 100%; height: 74px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  font-size: 11px;
  color: var(--dim);
}

.pal-btn img { max-width: 68px; max-height: 34px; }
.pal-btn.on { border-color: var(--gold); color: var(--ink); background: rgba(80, 62, 26, 0.85); }

/* The action bar: a slim strip along the bottom, left of the stone panel so
   the two never overlap regardless of viewport width. */
#buildbar {
  position: absolute;
  left: 16px;
  right: 232px;
  bottom: 0;
  transform: translateY(110%);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  padding: 12px 16px 14px;
  transition: transform 0.25s ease;
}

body.building #buildbar, body.adding #buildbar { transform: translateY(0); }
body.building #hint, body.adding #hint { bottom: 190px; }

.build-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.build-actions .count { color: var(--dim); font-size: 13px; margin-left: 4px; }

.phone-build-only { display: none; }

/* --------------------------------------------------------------- panels */

.panel {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 14, 0.66);
  backdrop-filter: blur(3px);
}

.panel.show { display: flex; }

.panel-inner {
  width: min(620px, 92vw);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 26px 30px 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.panel h1 {
  margin: 0 0 6px;
  font: bold 40px/1.1 Georgia, "Times New Roman", serif;
  letter-spacing: 0.04em;
}

.panel h2 { margin: 0 0 4px; font: bold 30px/1.2 Georgia, serif; }
.lede { color: var(--dim); margin: 0 auto 18px; max-width: 46ch; }
.keys { color: var(--dim); font-size: 12.5px; margin: 14px 0 0; }
.panel-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

#levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }

.level-btn {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 0 10px;
  text-align: left;
  padding: 9px 12px;
}

.level-btn .n {
  grid-row: span 2;
  align-self: center;
  font: bold 22px Georgia, serif;
  color: var(--gold);
}

.level-btn .t { font-size: 14px; }
.level-btn .stars { font-size: 12px; color: var(--gold); letter-spacing: 2px; }
.stars-big { font-size: 40px; color: var(--gold); letter-spacing: 6px; margin: 4px 0 8px; }

/* -------------------------------------------------------------- loading */

#loading {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #0d1219;
  z-index: 10;
}

body.loading #loading { display: flex; }
body.loading #hud, body.loading #hint { display: none; }

.load-title { font: bold 38px Georgia, serif; letter-spacing: 0.08em; }
.load-track { width: 260px; height: 6px; background: #1e2733; border-radius: 3px; overflow: hidden; }
#loadbar { width: 0; height: 100%; background: var(--gold); transition: width 0.2s; }

@media (max-width: 720px), (max-height: 500px) {
  #hud { gap: 14px; padding: 8px 10px; font-size: 13px; }
  .hud-group.buttons { width: 100%; margin-left: 0; }
  #hint { font-size: 13px; }

  /* Phone (and short landscape) keeps the playfield clear. The world is a
     letterboxed 16:9 strip in the middle of a tall screen, so a 40vh bottom
     sheet used to sit on top of the floor and steal taps. Dock the tools as
     a compact strip at the very bottom instead, and let the palette collapse
     after a stone is picked. */
  #build-dock {
    display: flex;
    flex-direction: column;
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 0;
    z-index: 5;
    max-height: 42%;
    pointer-events: none;
    transform: translateY(110%);
    transition: transform 0.25s ease;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  body.building #build-dock,
  body.adding #build-dock {
    transform: translateY(0);
  }

  #stonepanel {
    position: relative;
    top: auto;
    right: auto;
    left: auto;
    bottom: auto;
    width: auto;
    max-height: none;
    transform: none;
    border-radius: 12px 12px 0 0;
    border: 1px solid var(--edge);
    border-bottom: none;
    padding: 8px 10px 6px;
    overflow: hidden;
    pointer-events: none;
  }
  body.building #stonepanel,
  body.adding #stonepanel {
    transform: none;
  }
  body.build-palette-collapsed #stonepanel {
    display: none;
  }

  #stonepanel h3 {
    margin: 0 0 6px;
    font-size: 11px;
  }

  #palette {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
    pointer-events: auto;
  }
  .pal-btn {
    flex: 0 0 62px;
    width: 62px;
    height: 56px;
    pointer-events: auto;
  }
  .pal-btn img { max-width: 52px; max-height: 26px; }

  /* Keep the boulder chip on screen while the rest of the row scrolls. */
  #palette .pal-btn-boulder {
    position: sticky;
    left: 0;
    z-index: 2;
    background: rgba(30, 38, 48, 0.98);
    box-shadow: 4px 0 8px rgba(0, 0, 0, 0.35);
  }

  #buildbar {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    transform: none;
    border-radius: 0;
    padding: 8px 10px 10px;
    pointer-events: none;
  }
  body.building #buildbar,
  body.adding #buildbar {
    transform: none;
  }
  body.build-palette-collapsed #buildbar {
    border-radius: 12px 12px 0 0;
  }

  .phone-build-only { display: inline-block; }
  .build-actions { gap: 5px; pointer-events: auto; }
  .build-actions button { padding: 6px 8px; font-size: 12px; }

  /* Hint stays just above the dock so it does not sit in the middle of the
     stage the way the old 40vh offset did. */
  body.building #hint,
  body.adding #hint { bottom: 96px; }
  body.building:not(.build-palette-collapsed) #hint,
  body.adding:not(.build-palette-collapsed) #hint { bottom: 168px; }
}
