:root {
  --bg: #1a1206;
  --panel: #2a1d0f;
  --grid: #4a3520;
  --accent: #f2b34d;        /* gold */
  --accent-dim: #c98f34;
  --dig: #d9863a;           /* dig button */
  --found: #6fc98a;         /* found button */
  --build: #7fa4ff;         /* build button */
  --text: #fbeedd;
  --muted: #b89b7a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}

.board {
  position: relative;
  width: min(94vw, calc(82vh * 3 / 4));
  aspect-ratio: 3 / 4;
  max-height: 82vh;
  border: 2px solid var(--grid);
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(180deg, #2a1d0f 0%, #1a1206 100%);
}

.wrap:fullscreen,
.wrap:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  padding: 0;
  gap: 0;
}
.wrap:fullscreen .board,
.wrap:-webkit-full-screen .board {
  width: min(100vw, calc(100vh * 3 / 4));
  max-height: 100vh;
  border-radius: 0;
  border: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* HUD bar overlaid at the top of the board */
.bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  pointer-events: none;
  z-index: 3;
}

.bar h1 { font-size: 14px; font-weight: 700; letter-spacing: 0.5px; text-shadow: 0 1px 3px rgba(0,0,0,.7); }

.scores { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.score { font-size: 11px; color: var(--muted); text-shadow: 0 1px 3px rgba(0,0,0,.7); }
.score strong { color: var(--text); margin-left: 3px; }

/* HUD buttons (mute / fullscreen / home / end) */
.mute {
  pointer-events: auto;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(26, 18, 6, 0.7);
  border: 1px solid var(--grid);
  color: var(--text);
  border-radius: 8px;
  font-size: 13px; line-height: 1;
  padding: 5px 7px;
  cursor: pointer;
  text-decoration: none;
}
.mute:hover { border-color: var(--accent); }

/* Overlays (start / summary) */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(26, 18, 6, 0.88);
  text-align: center;
  padding: 16px;
  cursor: pointer;
  transition: opacity 0.15s ease;
  z-index: 6;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
#overlay-title { font-size: 22px; font-weight: 700; }
#overlay-sub { font-size: 13px; color: var(--muted); max-width: 280px; }
.overlay-actions { display: flex; flex-direction: column; gap: 8px; cursor: default; }
.overlay-actions.hidden { display: none; }

/* Character picker */
.pick {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(26, 18, 6, 0.95);
  padding: 18px;
  z-index: 5;
  overflow-y: auto;
}
.pick.hidden { display: none; }
.pick-title { font-size: 18px; font-weight: 700; }
.pick-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 340px;
}
.char-card {
  background: var(--panel);
  border: 2px solid var(--grid);
  border-radius: 12px;
  padding: 6px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
  color: var(--text);
}
.char-card:hover { transform: translateY(-2px); }
.char-card.selected { border-color: var(--accent); background: #3a2a15; }
.char-card img { width: 40px; height: 40px; image-rendering: pixelated; }
.char-card .c-name { font-size: 10px; font-weight: 700; text-align: center; }

.play {
  background: var(--accent);
  color: #2a1d0f;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  padding: 10px 26px;
  cursor: pointer;
  transition: opacity .15s, transform .15s;
}
.play:disabled { opacity: .4; cursor: not-allowed; }
.play:not(:disabled):hover { transform: translateY(-1px); }
.play.alt { background: var(--build); color: #0d1730; }

/* Nickname input */
.nickname-input {
  background: var(--panel);
  border: 2px solid var(--grid);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 20px;
  font-weight: 700;
  padding: 10px 18px;
  text-align: center;
  width: 100%;
  max-width: 280px;
  outline: none;
  transition: border-color .15s;
}
.nickname-input:focus { border-color: var(--accent); }
.nickname-input::placeholder { color: var(--muted); font-weight: 400; }

/* Inventory strip */
.inventory {
  position: absolute;
  top: 40px; left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 4px 8px;
  z-index: 3;
  pointer-events: none;
  font-size: 12px;
}
.inventory.hidden { display: none; }
.inventory span {
  background: rgba(26,18,6,0.7);
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 2px 6px;
}
.inventory b { margin-left: 3px; color: var(--accent); }

/* Build menu */
.build-menu {
  position: absolute;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  background: rgba(26,18,6,0.92);
  border: 2px solid var(--grid);
  border-radius: 12px;
  padding: 8px;
  z-index: 5;
}
.build-menu.hidden { display: none; }
.build-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 8px;
  color: var(--text);
  font-size: 9px;
  padding: 6px 8px;
  cursor: pointer;
}
.build-item span { font-size: 18px; }
.build-item:hover { border-color: var(--accent); }
.build-close { color: #ff9f9f; }
.block-icon {
  width: 16px; height: 16px;
  background: var(--accent-dim);
  border: 1px solid var(--grid);
  border-radius: 3px;
  display: inline-block;
}

/* Action buttons */
.touch {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 14px;
  padding: 14px 16px;
  z-index: 3;
  pointer-events: none;
}
.tbtn {
  pointer-events: auto;
  border-radius: 50%;
  border: 2px solid var(--grid);
  color: #1a1206;
  font-weight: 700;
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
  width: 60px; height: 60px; font-size: 24px;
}
.tbtn:active { transform: translateY(2px); box-shadow: none; }
.tbtn.hidden { display: none; }
.tbtn.dig   { background: var(--dig); border-color: #a85f22; }
.tbtn.found { background: var(--found); border-color: #3f9a5a; }
.tbtn.build { background: var(--build); border-color: #4a6fd1; }
.tbtn.exit  { background: var(--accent); border-color: var(--accent-dim); }
.tbtn.in    { background: var(--found); border-color: #3f9a5a; }

.foot { font-size: 11px; color: var(--muted); }

/* D-pad */
.dpad {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 3;
  pointer-events: none;
}
.dpad.hidden { display: none; }
.dpad-row { display: flex; gap: 4px; align-items: center; pointer-events: none; }
.dpbtn {
  pointer-events: auto;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 2px solid var(--grid);
  background: rgba(26,18,6,0.85);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dpbtn:active { background: var(--accent); color: #1a1206; }
.dpad-center { width: 42px; height: 42px; }
