@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

body {
  background-color: #111;
  color: #ccc;
  font-family: 'Courier New', Courier, monospace;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  margin: 0;
  overflow: hidden;
}
#game-container {
  position: relative;
  border: none;
  box-shadow: 0 0 20px rgba(0,0,0,0.8);
  background-color: #000;
}
canvas {
  display: block;
}
.hidden {
  display: none !important;
}
.intro-screen {
  display: grid;
  place-items: center;
  width: 100%;
}
#introCanvas {
  width: min(100vw, 640px);
  height: auto;
  aspect-ratio: 8 / 5;
  background-color: #000;
  image-rendering: pixelated;
}
#fps-display {
  text-align: center;
  font-size: 12px;
  color: #0f0;
  font-family: monospace;
  padding: 4px 0 2px;
}
#ui {
  margin-top: 6px;
  padding-bottom: 16px;
  text-align: center;
  font-size: 14px;
  color: #0f0;
}
.key {
  background: #333;
  padding: 2px 6px;
  border-radius: 4px;
  color: #fff;
  font-weight: bold;
}
.group {
  padding: 2px 6px;
  border-radius: 4px;
  color: #ff0;
  font-weight: bold;
}

:root {
  --bg-grey: #757575;
  --hud-blue: #008;
  --text-green: #00FF00;
  --text-white: #FFFFFF;
  --life-green: #00FF00;
  --border-dark: #000000;
  --border-blue: #00e;
}

/* Ensure width calculations include padding and borders */
* {
  box-sizing: border-box;
}

.zeliard-hud {
  background-image: url('assets/images/mole/stone.png');
  padding: 7px 12px;
  display: flex;
  justify-content: space-between; /* This pushes the inventory panel to the far right */
  width: 100%; 
  font-family: 'Press Start 2P', cursive;
  font-size: 16px;
  border: none;
  border-top: none; /* Merges visually with game-container border */
  image-rendering: pixelated;
}

.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 7px 12px;
  flex: 0 0 420px;
  margin-right: 10px;
}

/* Ensure rows inside stats-panel stretch to fill the width */
.hud-row {
  width: 100%;
  background-color: var(--hud-blue);
  display: flex;
  align-items: center;
  border: 2px solid var(--border-dark);
  border-bottom: 2px solid var(--border-blue);
  height: 32px;
}

/* Specific Row Layouts */
.label {
  color: var(--text-green);
  padding: 0 8px;
  white-space: nowrap;
  flex: 0 0 auto;
  text-shadow: 2px 2px #e00;
}

.value {
  color: var(--text-white);
  flex: 1;
  min-width: 0;
  text-align: center;
}

.place-row .value {
  flex: 1;
  min-width: 0;
}

.place-row.indoor-place .label {
  display: none;
}

.place-row.indoor-place .value {
  padding-left: 8px;
}

.split-row {
  background: transparent;
  border: none;
  gap: 8px;
}

.currency-box {
  background-color: var(--hud-blue);
  border: 2px solid var(--border-dark);
  border-bottom: 2px solid var(--border-blue);
  display: flex;
  flex: 1;
  align-items: center;
  height: 32px;
}

.life-bar-container {
  background-color: #000;
  flex-grow: 1;
  height: 100%;
  position: relative;
  border-left: 2px solid var(--border-dark);
  display: flex;
  flex-direction: column;
}

.life-fill {
  position: absolute;
  top: 0;
  left: 0;
  margin-top: 0;
}

.life-fill-max {
  background-color: #e00;
  height: calc(80% - 1px);
  margin-bottom: 2px;
}

.life-fill-current {
  background-color: var(--life-green);
  height: calc(80% - 4px);
  margin-bottom: 4px;
}

.ticks {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 8px; /* Total height of the ruler area */
  border-bottom: 2px solid #fff; /* The horizontal baseline */
  
  /* Layered Gradients: 
     1. A tick pinned to the far right (100%)
     2. Long ticks every 25% (Every 5 divisions)
     3. Short ticks every 5% (Total 20 divisions) */
  background-image: 
    linear-gradient(to left, #fff 2px, transparent 2px),
    repeating-linear-gradient(to right, #fff 0, #fff 2px, transparent 2px, transparent 25%),
    repeating-linear-gradient(to right, #fff 0, #fff 2px, transparent 2px, transparent 5%);
  
  /* background-size controls the height of each layer:
     Right-pin: 50% height
     Long ticks: 50% height (4px)
     Short ticks: 25% height (2px) */
  background-size: 100% 50%, 100% 50%, 100% 25%;
  background-repeat: no-repeat;
  background-position: left bottom;
}

.slot-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.slot-counter {
  background-color: var(--hud-blue);
  border: 2px solid var(--border-dark);
  border-bottom: 2px solid var(--border-blue);
  color: var(--text-white);
  width: 100%;
  text-align: center;
  height: 32px; 
  line-height: 32px;
}

.inventory-panel {
  display: flex;
  /* Keeps items at the top of the inventory area */
  align-items: flex-start; 
  gap: 12px;
  /* Prevents the inventory from shrinking */
  flex-shrink: 0; 
}

.inventory-panel .slot-wrapper {
  align-self: center; 
}

.slot {
  margin-top: 3px;
  width: 64px;
  height: 64px;
  background-color: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  border-style: solid;
  border-width: 1px;
  border-color: #d6d6d6 #858585 #5a5a5a #dedede; 
  padding: 2px; 
}

/* Shared styles for the two inner border layers */
.slot::before,
.slot::after {
  content: "";
  position: absolute;
  pointer-events: none;
  box-sizing: border-box;
  border-style: solid;
  border-width: 1px;
}

/* Middle layer (2nd from outside) */
.slot::before {
  top: 0; 
  right: 0; 
  bottom: 0; 
  left: 0;
  border-color: #a5a5a5 #d7d7d7 #8c8c8c #a5a5a5;
}

/* Innermost layer (3rd from outside) */
.slot::after {
  top: 1px; 
  right: 1px; 
  bottom: 1px; 
  left: 1px;
  border-color: #6f6f6f #a4a4a4 #dedede #6f6f6f;
}

/* ─── Touch controls ─────────────────────────────────────────────────────── */
.touch-controls {
  flex-shrink: 0;
  width: 200px;
  align-self: center;
  visibility: hidden; /* occupy the 200px column on desktop, like the old spacers */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

body.touch-mode .touch-controls {
  visibility: visible;
}

body.touch-mode {
  touch-action: none;
}

body.touch-mode #touch-joystick {
  margin-right: 32px;
}

#touch-joystick {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  grid-template-rows: repeat(3, 76px);
  gap: 0;
  justify-content: center;
}

.touch-dpad-cell {
  width: 76px;
  height: 76px;
}

.touch-dpad-btn {
  width: 60px;
  height: 60px;
  margin: 8px 16px 8px 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.10);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-dpad-btn.pressed,
.touch-dpad-btn:active {
  background: rgba(255, 255, 255, 0.45);
  border-color: #fff;
  transform: scale(0.94);
}

/* CSS triangles for the D-pad (avoids relying on rare Unicode arrow glyphs) */
.touch-dpad-arrow {
  width: 0;
  height: 0;
  border-left: 13px solid transparent;
  border-right: 13px solid transparent;
  border-bottom: 21px solid #fff;
}

.touch-dpad-arrow--up   { transform: rotate(0deg); }
.touch-dpad-arrow--down { transform: rotate(180deg); }
.touch-dpad-arrow--left { transform: rotate(-90deg); }
.touch-dpad-arrow--right{ transform: rotate(90deg); }
.touch-dpad-arrow--nw   { transform: rotate(-45deg); }
.touch-dpad-arrow--ne   { transform: rotate(45deg); }

#touch-actions {
  display: flex;
  flex-direction: column;
  gap: 18px;
  justify-content: center;
  align-items: center;
}

.touch-action-btn {
  width: 104px;
  height: 72px;
  border-radius: 14px;
  border: 2px solid rgba(140, 210, 255, 0.65);
  background: rgba(30, 60, 110, 0.45);
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 48px;
  line-height: 1.5;
  padding: 0 4px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-action-btn.pressed,
.touch-action-btn:active {
  background: rgba(80, 160, 255, 0.6);
  transform: scale(0.96);
}

/* Intro action-bar overlay: the game layout (and its action buttons) stays
   hidden while the opening demo runs, so show a fixed copy of the action
   buttons during the intro so the demo can be skipped on smartphones. */
#intro-actions {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 18px;
  justify-content: center;
  align-items: center;
  width: auto;
  align-self: auto;
  visibility: hidden;
}

body.touch-mode #intro-screen:not(.hidden) ~ #intro-actions {
  visibility: visible;
}

/* Keep it hidden in touch mode once the demo ends (the in-layout action
   buttons take over then); also hidden on desktop. */
body.touch-mode #intro-actions,
#intro-actions {
  visibility: hidden;
}

/* ─── Settings menu (top-right corner, touch mode only) ───────────────────── */
#settings-menu {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 1001;
  display: none;
  flex-direction: column;
  align-items: flex-end;
  font-family: 'Press Start 2P', monospace;
}

body.touch-mode #settings-menu {
  display: flex;
}

/* Cancel / Back (Esc) button, top-left corner, touch devices only */
#escape-toggle {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1001;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid #888;
  background: rgba(25, 25, 25, 0.85);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: none;
  -webkit-tap-highlight-color: transparent;
}

body.touch-mode #escape-toggle {
  display: block;
}

#escape-toggle:active {
  background: rgba(80, 80, 80, 0.9);
}

#settings-toggle {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid #888;
  background: rgba(25, 25, 25, 0.85);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#settings-toggle:active {
  background: rgba(80, 80, 80, 0.9);
}

#fullscreen-toggle {
  width: 46px;
  height: 46px;
  margin-top: 8px;
  border-radius: 50%;
  border: 2px solid #888;
  background: rgba(25, 25, 25, 0.85);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#fullscreen-toggle:active {
  background: rgba(80, 80, 80, 0.9);
}

#settings-panel {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(20, 20, 20, 0.95);
  border: 2px solid #555;
  border-radius: 8px;
  padding: 6px;
  min-width: 150px;
}

#settings-panel button {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #eee;
  background: transparent;
  border: none;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}

#settings-panel button:active,
#settings-panel button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ff8;
}

/* ─── Speed-change digit pad (mobile) ────────────────────────────────────── */
#speed-pad {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  display: grid;
  grid-template-columns: repeat(5, 54px);
  gap: 8px;
  background: rgba(0, 0, 0, 0.88);
  border: 2px solid #666;
  border-radius: 12px;
  padding: 12px;
  font-family: 'Press Start 2P', monospace;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#speed-pad .speed-digit {
  height: 54px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
}

#speed-pad .speed-digit:active {
  background: rgba(255, 255, 255, 0.35);
}

#speed-pad:not(.phase-1) .speed-digit {
  opacity: 0.35;
}

#speed-pad .speed-pad-wide {
  height: 44px;
  border-radius: 10px;
  border: 2px solid rgba(255, 200, 80, 0.6);
  background: rgba(255, 200, 80, 0.15);
  color: #ffd;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  grid-column: span 2;
}

#speed-pad .speed-pad-wide:active {
  background: rgba(255, 200, 80, 0.35);
}

.mole-side {
  width: 64px;
  height: 600px;
}

body.touch-mode .mole-side {
  width: 1px;
}

/* Hide the desktop-only FPS counter and keyboard hints bar on touch devices */
body.touch-mode #fps-display,
body.touch-mode #ui {
  display: none;
}

/* ─── On-screen name keyboard for the save dialog (mobile) ─────────────────── */
#name-pad {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1002;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(94vw, 460px);
  background: rgba(0, 0, 0, 0.88);
  border: 2px solid #666;
  border-radius: 12px;
  padding: 10px;
  font-family: 'Press Start 2P', monospace;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#name-pad .name-pad-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

#name-pad .name-key {
  flex: 1 1 0;
  min-width: 26px;
  max-width: 46px;
  height: 42px;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

#name-pad .name-key:active {
  background: rgba(255, 255, 255, 0.35);
}

#name-pad .name-key--wide {
  flex: 1.2 1 0;
  font-size: 10px;
}

#name-pad .name-key--ok {
  flex: 1.8 1 0;
  font-size: 10px;
  border-color: rgba(120, 230, 120, 0.7);
  background: rgba(80, 200, 80, 0.18);
  color: #cfc;
}

#name-pad .name-key--ok:active {
  background: rgba(80, 200, 80, 0.4);
}

#name-pad .name-key--cancel {
  flex: 1.8 1 0;
  font-size: 10px;
  border-color: rgba(255, 120, 120, 0.7);
  background: rgba(200, 80, 80, 0.18);
  color: #fcc;
}

#name-pad .name-key--cancel:active {
  background: rgba(200, 80, 80, 0.4);
}

/* ─── Language selector ─────────────────────────────────────────────────────── */
#language-selector {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #111;
  z-index: 100;
  font-family: 'Courier New', Courier, monospace;
}

.lang-title {
  font-size: 18px;
  color: #ccc;
  margin-bottom: 24px;
  letter-spacing: 2px;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 260px;
  padding: 12px 16px;
  background: transparent;
  border: 1px solid #333;
  border-radius: 4px;
  color: #ccc;
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.lang-option:hover,
.lang-option:focus {
  background: rgba(255, 255, 255, 0.06);
  border-color: #666;
  outline: none;
}

.lang-option:active {
  background: rgba(255, 255, 255, 0.12);
}

.lang-flag {
  width: 48px;
  height: 32px;
  border-radius: 2px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
