/* ============================================================
   SANDHOLD — desert strategy UI
   Palette: sand #e6c88a · deep #2a1d10 · gold #e8b463
            wall stone #d9b478 · enemy crimson #a63a2f
   ============================================================ */

:root {
  --sand: #e6c88a;
  --deep: #2a1d10;
  --gold: #e8b463;
  --gold-dim: #b8873f;
  --wallstone: #d9b478;
  --crimson: #a63a2f;
  --glass: rgba(38, 25, 14, .78);
  --glass-solid: rgba(30, 20, 11, .94);
  --trim: rgba(232, 196, 120, .35);
  --trim-strong: rgba(232, 196, 120, .62);
  --wood: #a9743f;
  --stonec: #9aa2a8;
  --food: #cf8f3d;
  --serif: 'Palatino Linotype', 'Book Antiqua', Palatino, 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --hud-h: 56px;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #120c06;
}

body {
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  color: #f4e6c8;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.3;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img { -webkit-user-drag: none; user-select: none; }

button {
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ------------------------------------------------------------
   App shell / board / hotspot grid
   ------------------------------------------------------------ */

#app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(140% 100% at 50% 0%, #5b452a 0%, #2c1f11 42%, #150e07 100%);
  isolation: isolate;
}

canvas#board {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
  touch-action: none;
  z-index: 1;
}

/* soft warm vignette + haze to seat the iso desert in the frame */
#app::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 42%, rgba(0, 0, 0, 0) 42%, rgba(24, 14, 6, .30) 78%, rgba(12, 7, 3, .62) 100%),
    linear-gradient(180deg, rgba(255, 214, 148, .10) 0%, rgba(255, 214, 148, 0) 22%);
  mix-blend-mode: multiply;
}

#grid {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
}

#grid .cell,
.cell {
  position: absolute;
  pointer-events: auto;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  outline: none;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  -webkit-clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  transition: background-color .14s ease;
  touch-action: manipulation;
}

.cell.ok:hover,
.cell:hover {
  outline: none;
  background-color: rgba(232, 196, 120, .10);
}

.cell:active {
  background-color: rgba(232, 196, 120, .18);
}

.cell.has-building {
  cursor: default;
}

.cell.has-building:hover {
  background-color: rgba(232, 196, 120, .05);
}

/* ------------------------------------------------------------
   HUD — top bar of sand-glass panels
   ------------------------------------------------------------ */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: calc(7px + env(safe-area-inset-top, 0px)) 10px 7px;
  border-radius: 0 0 16px 16px;
  background:
    linear-gradient(180deg, rgba(48, 32, 17, .96) 0%, var(--glass) 62%, rgba(30, 20, 11, .86) 100%);
  border: 1px solid var(--trim);
  border-top: 0;
  box-shadow:
    0 10px 28px rgba(0, 0, 0, .52),
    0 1px 0 rgba(255, 226, 170, .10) inset,
    0 -1px 0 rgba(0, 0, 0, .5) inset;
  -webkit-backdrop-filter: blur(10px) saturate(1.15);
  backdrop-filter: blur(10px) saturate(1.15);
  -webkit-mask-image: none;
}

/* resource pills ------------------------------------------------ */

#stat-wood,
#stat-stone,
#stat-food {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 74px;
  padding: 5px 11px 5px 9px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(0, 0, 0, .34), rgba(0, 0, 0, .20));
  border: 1px solid rgba(232, 196, 120, .20);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 2px 6px rgba(0, 0, 0, .35);
  color: #ffffff;
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  letter-spacing: .01em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
  white-space: nowrap;
}

#stat-wood::before,
#stat-stone::before,
#stat-food::before {
  content: '';
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  transform: rotate(45deg) scale(.82);
  transform-origin: 50% 50%;
  background: var(--wood);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, .45),
    0 0 8px rgba(0, 0, 0, .35),
    inset 0 2px 2px rgba(255, 255, 255, .38),
    inset 0 -2px 3px rgba(0, 0, 0, .42);
}

#stat-wood::before  { background-color: var(--wood); }
#stat-stone::before { background-color: var(--stonec); }
#stat-food::before  { background-color: var(--food); }

#stat-wood  { box-shadow: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 2px 6px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(169, 116, 63, .28); }
#stat-stone { box-shadow: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 2px 6px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(154, 162, 168, .26); }
#stat-food  { box-shadow: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 2px 6px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(207, 143, 61, .28); }

/* keep level badge ---------------------------------------------- */

#keep-level {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(88, 60, 26, .55), rgba(40, 26, 12, .55));
  border: 1px solid var(--trim-strong);
  color: var(--gold);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8), 0 0 12px rgba(232, 180, 99, .35);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .10) inset, 0 2px 8px rgba(0, 0, 0, .4);
  white-space: nowrap;
}

#keep-level::before {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 1px;
  transform: rotate(45deg);
  background: linear-gradient(135deg, #ffe6ad, var(--gold) 55%, #8a5c22);
  box-shadow: 0 0 8px rgba(232, 180, 99, .7);
}

/* threat ------------------------------------------------------- */

#threat-fill {
  display: block;
  height: 4px;
  min-width: 2px;
  border-radius: 3px;
  background-image: linear-gradient(90deg, #5fbf6a 0%, #cdbb57 42%, #e8b463 62%, #c15a30 82%, #a63a2f 100%);
  background-color: rgba(12, 8, 4, .55);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  box-shadow:
    0 0 8px rgba(232, 180, 99, .40),
    0 0 0 1px rgba(0, 0, 0, .55) inset;
  transition: width .3s ease, filter .3s ease;
  will-change: width;
}

/* probable wrapper around the threat bar */
#threat,
.threat,
.threat-track,
#threat-track,
#hud > div:has(> #threat-fill) {
  border-radius: 4px;
  background: rgba(8, 5, 3, .55);
  box-shadow: 0 0 0 1px rgba(232, 196, 120, .18) inset;
}

#threat-label {
  display: inline-block;
  color: rgba(244, 230, 200, .78);
  font-family: var(--sans);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .9);
  white-space: nowrap;
}

/* ------------------------------------------------------------
   Build bar
   ------------------------------------------------------------ */

#buildbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  padding: 10px max(10px, calc((100vw - 680px) / 2)) calc(9px + env(safe-area-inset-bottom, 0px));
  background:
    linear-gradient(180deg, rgba(26, 17, 9, 0) 0%, rgba(26, 17, 9, .72) 34%, rgba(26, 17, 9, .95) 100%);
  border-top: 1px solid var(--trim);
  box-shadow: 0 -14px 34px rgba(0, 0, 0, .48), 0 1px 0 rgba(255, 226, 170, .07) inset;
  -webkit-backdrop-filter: blur(7px) saturate(1.1);
  backdrop-filter: blur(7px) saturate(1.1);
}

#buildbar > button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 62px;
  min-width: 0;
  padding: 5px 3px 4px;
  border-radius: 11px;
  border: 1px solid var(--trim);
  background: linear-gradient(180deg, #4a3520 0%, #3a2917 46%, #2e2013 100%);
  color: #f2e3c2;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-shadow:
    0 1px 0 rgba(255, 231, 184, .14) inset,
    0 -2px 0 rgba(0, 0, 0, .38) inset,
    0 3px 9px rgba(0, 0, 0, .42);
  transition: transform .12s ease, border-color .16s ease, box-shadow .16s ease, filter .16s ease, background .16s ease;
  overflow: hidden;
}

#buildbar > button::after {
  /* faint sandstone sheen across the button face */
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 236, 196, .10), rgba(255, 236, 196, 0) 46%);
  opacity: .9;
}

#buildbar > button:active {
  transform: scale(.95) translateY(1px);
}

#buildbar > button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

#buildbar > button.sel,
#buildbar > button.selected,
#buildbar > button.armed {
  border-color: var(--gold);
  background: linear-gradient(180deg, #6a4d2b 0%, #4b3419 46%, #382513 100%);
  box-shadow:
    0 0 0 1px rgba(232, 180, 99, .62),
    0 0 18px rgba(232, 180, 99, .48),
    0 1px 0 rgba(255, 243, 205, .28) inset,
    0 4px 12px rgba(0, 0, 0, .45);
}

#buildbar > button:disabled,
#buildbar > button[disabled],
#buildbar > button.off,
#buildbar > button.poor,
#buildbar > button.cant,
#buildbar > button.disabled {
  filter: grayscale(.55) brightness(.72) saturate(.55);
  opacity: .62;
  cursor: not-allowed;
}

#buildbar > button:disabled:active,
#buildbar > button.poor:active,
#buildbar > button.cant:active,
#buildbar > button.disabled:active {
  transform: none;
}

/* per-button accent strip -------------------------------------- */

#btn-wall   { --acc: #cbb086; }
#btn-tower  { --acc: #a9b3bb; }
#btn-farm   { --acc: #cf8f3d; }
#btn-wood   { --acc: #a9743f; }
#btn-stone  { --acc: #9aa2a8; }
#btn-upgrade{ --acc: #e8b463; }

#buildbar > button::before {
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  top: 0;
  height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--acc, var(--gold));
  opacity: .55;
  transition: opacity .18s ease, box-shadow .18s ease;
}

#buildbar > button.sel::before {
  opacity: 1;
  box-shadow: 0 0 10px var(--acc, var(--gold));
}

/* button text -------------------------------------------------- */

.b-name {
  display: block;
  max-width: 100%;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  line-height: 1.05;
  color: #f7ebd2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .85);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.b-cost {
  display: block;
  max-width: 100%;
  font-family: var(--sans);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.1;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .9);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: .95;
}

.b-key {
  position: absolute;
  top: 3px;
  right: 5px;
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: .04em;
  color: rgba(232, 196, 120, .58);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .9);
  pointer-events: none;
}

/* upgrade gets a warmer face ----------------------------------- */

#btn-upgrade {
  background: linear-gradient(180deg, #6a4a22 0%, #4d3416 48%, #34220f 100%);
  border-color: rgba(232, 196, 120, .5);
}

#btn-upgrade .b-name { color: #ffe9bd; }
#btn-upgrade .b-cost { color: #ffd68a; }

#btn-upgrade:not(:disabled):not(.poor):not(.off):not(.cant) {
  animation: sandhold-upgrade-pulse 2.6s ease-in-out infinite;
}

@keyframes sandhold-upgrade-pulse {
  0%, 100% { box-shadow: 0 1px 0 rgba(255, 231, 184, .16) inset, 0 -2px 0 rgba(0, 0, 0, .38) inset, 0 3px 9px rgba(0, 0, 0, .42), 0 0 0 rgba(232, 180, 99, 0); }
  50%      { box-shadow: 0 1px 0 rgba(255, 231, 184, .22) inset, 0 -2px 0 rgba(0, 0, 0, .38) inset, 0 3px 9px rgba(0, 0, 0, .42), 0 0 16px rgba(232, 180, 99, .45); }
}

/* cancel ------------------------------------------------------- */

#btn-cancel {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid rgba(166, 58, 47, .55);
  background: linear-gradient(180deg, rgba(96, 36, 28, .55), rgba(48, 18, 13, .60));
  color: #ffdcc4;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: 0 1px 0 rgba(255, 214, 180, .12) inset, 0 2px 7px rgba(0, 0, 0, .4);
  transition: transform .12s ease, filter .16s ease, border-color .16s ease;
}

#btn-cancel:active {
  transform: scale(.98) translateY(1px);
}

#btn-cancel:hover {
  border-color: rgba(232, 120, 96, .8);
  filter: brightness(1.08);
}

#btn-cancel:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ------------------------------------------------------------
   Iso-cube icon (.ico) — two skewed faces + diamond top
   ------------------------------------------------------------ */

.ico {
  position: relative;
  display: block;
  width: 20px;
  height: 17px;
  margin: 0 auto 1px;
  flex: 0 0 auto;
  --c: var(--acc, var(--gold));
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .55));
}

.ico > div,
.ico > i,
.ico > span {
  position: absolute;
  top: 5px;
  width: 9px;
  height: 10px;
  background: var(--c);
  display: block;
}

.ico > div:nth-child(1),
.ico > i:nth-child(1),
.ico > span:nth-child(1) {
  left: 1px;
  transform: skewY(24deg);
  filter: brightness(.72);
  border-radius: 0 0 0 1px;
}

.ico > div:nth-child(2),
.ico > i:nth-child(2),
.ico > span:nth-child(2) {
  right: 1px;
  transform: skewY(-24deg);
  filter: brightness(1.02);
  border-radius: 0 0 1px 0;
}

.ico::before {
  content: '';
  position: absolute;
  left: 1px;
  top: 1px;
  width: 18px;
  height: 9px;
  background: var(--c);
  filter: brightness(1.32);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  -webkit-clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

/* ------------------------------------------------------------
   Toast + hint
   ------------------------------------------------------------ */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(154px + env(safe-area-inset-bottom, 0px));
  z-index: 9;
  max-width: min(88vw, 420px);
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid rgba(232, 180, 99, .55);
  background: linear-gradient(180deg, rgba(126, 44, 30, .96), rgba(62, 21, 14, .96));
  color: #ffe9c4;
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .02em;
  line-height: 1.25;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
  box-shadow:
    0 10px 28px rgba(0, 0, 0, .55),
    0 1px 0 rgba(255, 226, 180, .18) inset,
    0 0 22px rgba(166, 58, 47, .30);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  transform: translate(-50%, 12px) scale(.97);
  pointer-events: none;
  transition: opacity .28s ease, transform .28s cubic-bezier(.2, .85, .3, 1.25);
  will-change: opacity, transform;
}

#toast.show,
#toast.on,
#toast.visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

#toast.warn {
  border-color: rgba(255, 190, 120, .75);
  background: linear-gradient(180deg, rgba(148, 92, 26, .96), rgba(74, 43, 12, .96));
}

#hint {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(128px + env(safe-area-inset-bottom, 0px));
  z-index: 7;
  max-width: 90vw;
  padding: 0 10px;
  color: rgba(244, 230, 200, .48);
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .10em;
  text-transform: uppercase;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------
   Overlays — menu & end screen
   ------------------------------------------------------------ */

#menu,
#over {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: max(22px, env(safe-area-inset-top, 0px)) 22px max(22px, env(safe-area-inset-bottom, 0px));
  text-align: center;
  overflow: hidden;
  background:
    radial-gradient(125% 92% at 50% 16%, #4a3620 0%, #2a1d10 44%, #120c06 82%, #0a0603 100%);
  box-shadow: 0 0 0 1px rgba(232, 196, 120, .12) inset;
  animation: sandhold-fade-in .5s ease both;
}

@keyframes sandhold-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#menu::before,
#over::before {
  content: '';
  position: absolute;
  inset: -10%;
  pointer-events: none;
  background:
    radial-gradient(45% 38% at 50% 8%, rgba(232, 180, 99, .16), rgba(232, 180, 99, 0) 70%),
    radial-gradient(60% 50% at 50% 108%, rgba(0, 0, 0, .70), rgba(0, 0, 0, 0) 70%);
  mix-blend-mode: screen;
  opacity: .85;
}

#menu::after,
#over::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: 0 0 120px 40px rgba(0, 0, 0, .62) inset;
}

#menu > *,
#over > * {
  position: relative;
  z-index: 1;
}

#menu img,
#over img {
  display: block;
  width: 240px;
  max-width: min(72vw, 240px);
  height: auto;
  border-radius: 14px;
  box-shadow:
    0 22px 54px rgba(0, 0, 0, .74),
    0 0 0 1px rgba(232, 196, 120, .28),
    0 0 42px rgba(232, 180, 99, .14);
  -webkit-user-select: none;
  user-select: none;
  pointer-events: none;
}

#menu .title,
.title {
  margin: 0;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow:
    0 1px 0 #7a5122,
    0 3px 0 #4a2f12,
    0 8px 22px rgba(0, 0, 0, .85),
    0 0 36px rgba(232, 180, 99, .30);
}

#menu .sub,
.sub {
  margin: 0;
  max-width: 320px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.55;
  letter-spacing: .02em;
  color: rgba(246, 233, 208, .76);
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
}

#menu .sub {
  font-style: italic;
  font-family: var(--serif);
  font-size: 14px;
}

/* gold action buttons ------------------------------------------ */

#btn-start,
#btn-restart {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 300px;
  height: 52px;
  margin-top: 4px;
  padding: 0 18px;
  border-radius: 13px;
  border: 1px solid #f5dca8;
  background: linear-gradient(180deg, #f6d796 0%, #e3b163 46%, #c68b3e 72%, #a9743f 100%);
  color: #2a1d10;
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  text-shadow: 0 1px 0 rgba(255, 240, 210, .55);
  box-shadow:
    0 12px 28px rgba(0, 0, 0, .55),
    0 1px 0 rgba(255, 255, 255, .75) inset,
    0 -3px 0 rgba(112, 72, 26, .55) inset,
    0 0 26px rgba(232, 180, 99, .22);
  transition: transform .12s ease, filter .18s ease, box-shadow .18s ease;
}

#btn-start:hover,
#btn-restart:hover {
  filter: brightness(1.07) saturate(1.05);
  box-shadow:
    0 14px 32px rgba(0, 0, 0, .58),
    0 1px 0 rgba(255, 255, 255, .8) inset,
    0 -3px 0 rgba(112, 72, 26, .55) inset,
    0 0 34px rgba(232, 180, 99, .40);
}

#btn-start:active,
#btn-restart:active {
  transform: translateY(1px) scale(.985);
  filter: brightness(.98);
}

#btn-start:focus-visible,
#btn-restart:focus-visible,
#btn-share:focus-visible {
  outline: 2px solid #ffe6ad;
  outline-offset: 3px;
}

#btn-share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 300px;
  height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--trim-strong);
  background: linear-gradient(180deg, rgba(74, 53, 32, .55), rgba(36, 24, 13, .70));
  color: var(--gold);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: 0 1px 0 rgba(255, 226, 170, .12) inset, 0 6px 16px rgba(0, 0, 0, .42);
  transition: transform .12s ease, filter .18s ease, border-color .18s ease;
}

#btn-share:hover {
  filter: brightness(1.12);
  border-color: var(--gold);
}

#btn-share:active {
  transform: translateY(1px) scale(.99);
}

/* end screen --------------------------------------------------- */

#over-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  line-height: 1.1;
  color: var(--gold);
  text-shadow:
    0 1px 0 #7a5122,
    0 3px 0 #462d11,
    0 8px 22px rgba(0, 0, 0, .85),
    0 0 34px rgba(232, 180, 99, .28);
}

#over-title.win  { color: #f2d489; }
#over-title.lose { color: #e08170; text-shadow: 0 1px 0 #5c1f16, 0 3px 0 #3a130d, 0 8px 22px rgba(0, 0, 0, .85), 0 0 34px rgba(166, 58, 47, .45); }

#over-score {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 20px;
  border-radius: 11px;
  border: 1px solid rgba(232, 196, 120, .28);
  background: rgba(0, 0, 0, .34);
  color: #fff3dc;
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
  box-shadow: 0 1px 0 rgba(255, 226, 170, .08) inset, 0 6px 18px rgba(0, 0, 0, .4);
}

#over .sub { margin-top: -2px; }

/* hidden states for overlays ---------------------------------- */

#menu[hidden],
#over[hidden],
#menu.hidden,
#over.hidden,
#menu.hide,
#over.hide,
#menu.off,
#over.off {
  display: none !important;
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------
   Small screens
   ------------------------------------------------------------ */

@media (max-width: 520px) {
  #hud {
    gap: 5px 7px;
    padding: calc(6px + env(safe-area-inset-top, 0px)) 8px 6px;
    border-radius: 0 0 13px 13px;
  }

  #stat-wood,
  #stat-stone,
  #stat-food {
    min-width: 62px;
    padding: 4px 8px 4px 7px;
    font-size: 13px;
    gap: 5px;
    border-radius: 8px;
  }

  #stat-wood::before,
  #stat-stone::before,
  #stat-food::before {
    width: 11px;
    height: 11px;
  }

  #keep-level {
    padding: 4px 9px;
    font-size: 10.5px;
    letter-spacing: .12em;
  }

  #threat-label { font-size: 8.5px; letter-spacing: .12em; }

  #buildbar {
    gap: 4px;
    padding: 8px 6px calc(7px + env(safe-area-inset-bottom, 0px));
  }

  #buildbar > button {
    height: 56px;
    border-radius: 9px;
    padding: 4px 2px 3px;
  }

  .b-name { font-size: 9.5px; letter-spacing: .03em; }
  .b-cost { font-size: 8.5px; }
  .b-key  { font-size: 8px; top: 2px; right: 3px; }

  #btn-cancel { height: 32px; font-size: 10px; letter-spacing: .10em; }

  #toast {
    bottom: calc(138px + env(safe-area-inset-bottom, 0px));
    font-size: 11.5px;
    padding: 8px 14px;
  }

  #hint { display: none; }

  .title { font-size: 27px; letter-spacing: 1.4px; }
  #over-title { font-size: 24px; letter-spacing: 1.4px; }
  #menu img, #over img { width: 200px; max-width: 66vw; }
  #menu .sub { font-size: 12.5px; max-width: 280px; }
  #btn-start, #btn-restart { height: 50px; font-size: 13.5px; letter-spacing: .14em; }
  #over-score { font-size: 15px; padding: 7px 16px; }
}

@media (max-width: 360px) {
  .b-name { font-size: 8.5px; }
  .b-cost { font-size: 8px; }
  #buildbar > button { height: 52px; }
}

@media (min-width: 900px) {
  #hud {
    gap: 8px 16px;
    padding: calc(9px + env(safe-area-inset-top, 0px)) 18px 9px;
  }

  #stat-wood, #stat-stone, #stat-food { min-width: 92px; }
  .b-name { font-size: 11.5px; }
  .b-cost { font-size: 10px; }
  #buildbar > button { height: 66px; }
}

/* ------------------------------------------------------------
   Reduce motion — non-essential pulses only
   ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  #btn-upgrade:not(:disabled) { animation: none !important; }
  #menu, #over { animation: none !important; }
  #toast { transition: opacity .12s linear !important; transform: translate(-50%, 0) !important; }
  #threat-fill { transition: width .12s linear !important; }
  #buildbar > button,
  #btn-start,
  #btn-restart,
  #btn-share,
  #btn-cancel { transition: none !important; }
  #buildbar > button:active { transform: none !important; }
}
