:root {
  --bg-dark: #07090d;
  --accent-teal: #4fd6c8;
  --accent-amber: #ffb347;
  --border-color: #1a1d22;
  --text-dim: #6b7280;
  --text-bright: #e0e8f0;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  color: var(--text-bright);
  font-family: var(--font-mono);
  font-size: 12px;
  overflow: hidden;
}

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

#view {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.panel {
  position: fixed;
  background: rgba(7, 9, 13, 0.85);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(8px);
  padding: 12px 16px;
  font-size: 11px;
  line-height: 1.6;
  z-index: 10;
}

#hud {
  top: 16px;
  left: 16px;
  width: 280px;
}

#hud h1 {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: normal;
  letter-spacing: 2px;
  color: var(--accent-teal);
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 6px 0;
  gap: 12px;
}

.row .k {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.row .v {
  color: var(--text-bright);
  font-variant-numeric: tabular-nums;
  text-align: right;
  flex-grow: 1;
}

#bar {
  height: 4px;
  background: rgba(79, 214, 200, 0.1);
  border: 1px solid rgba(79, 214, 200, 0.25);
  margin-top: 8px;
  overflow: hidden;
}

#bar-fill {
  height: 100%;
  background: var(--accent-teal);
  width: 0%;
  transition: width 0.3s ease-out;
  box-shadow: 0 0 6px rgba(79, 214, 200, 0.3);
}

#mini {
  top: 16px;
  right: 16px;
  width: 260px;
  height: 260px;
  padding: 8px;
}

#minimap {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#help {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 400px;
  text-align: center;
  color: var(--text-dim);
  font-size: 10px;
  letter-spacing: 0.5px;
  line-height: 1.4;
}

#toast {
  position: fixed;
  bottom: 60px;
  left: 16px;
  background: rgba(7, 9, 13, 0.95);
  border: 1px solid var(--accent-amber);
  color: var(--accent-amber);
  padding: 8px 12px;
  font-size: 11px;
  letter-spacing: 0.5px;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.25s ease-out, transform 0.25s ease-out;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
  animation: toast-display 2.5s ease-in-out forwards;
}

@keyframes toast-display {
  0% {
    opacity: 1;
    transform: translateY(0);
  }
  85% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(8px);
  }
}

#loader {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  color: var(--accent-teal);
  font-size: 13px;
  letter-spacing: 1px;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.4s ease-out;
  pointer-events: auto;
}

#loader.done {
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 700px) {
  .panel {
    padding: 10px 12px;
    font-size: 10px;
  }

  #hud {
    width: 240px;
    top: 12px;
    left: 12px;
  }

  #hud h1 {
    font-size: 12px;
    margin-bottom: 6px;
  }

  .row {
    margin: 5px 0;
  }

  .row .k {
    font-size: 9px;
  }

  .row .v {
    font-size: 9px;
  }

  #mini {
    display: none;
  }

  #help {
    bottom: 12px;
    right: 12px;
    left: auto;
    transform: none;
    max-width: 90%;
    text-align: right;
    font-size: 9px;
  }

  #toast {
    bottom: 50px;
    font-size: 10px;
  }

  #loader {
    font-size: 12px;
  }
}

/* ---- manual overlay ---- */
#manual {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 5, 8, 0.72);
  backdrop-filter: blur(3px);
  padding: 24px;
  overflow-y: auto;
}
#manual-box {
  position: relative;
  max-width: 640px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  background: rgba(7, 9, 13, 0.97);
  border: 1px solid var(--accent-teal);
  padding: 26px 30px 22px;
  font-size: 12px;
  line-height: 1.65;
  color: var(--text-bright);
}
#manual-box h2 {
  margin: 0 0 14px;
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent-teal);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
}
#manual-box h3 {
  margin: 20px 0 6px;
  font-size: 10px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--accent-amber);
}
#manual-box p { margin: 0 0 8px; color: #b9c4cf; }
#manual-box p.lede { color: var(--text-bright); }
#manual-box p.foot { margin-top: 18px; color: var(--text-dim); font-size: 10px; }
#manual-box b { color: var(--text-bright); font-weight: 600; }
#manual-box code { color: var(--accent-teal); }
#manual-box .hl { color: var(--accent-teal); }
#manual-box table { width: 100%; border-collapse: collapse; }
#manual-box td { padding: 3px 0; vertical-align: top; color: #b9c4cf; }
#manual-box td:first-child {
  width: 38%;
  padding-right: 14px;
  color: var(--text-bright);
  white-space: nowrap;
}
#manual-box kbd {
  display: inline-block;
  border: 1px solid var(--border-color);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0 4px;
  margin-right: 2px;
  background: #11151c;
  font: inherit;
  font-size: 10px;
  color: var(--accent-teal);
}
#manual-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}
#manual-close:hover { color: var(--accent-amber); }
@media (max-width: 700px) {
  #manual-box { padding: 18px 16px; font-size: 11px; }
  #manual-box td:first-child { width: 46%; white-space: normal; }
}
#manual[hidden] { display: none; }

/* ---- on-screen control pad (touch / small screens) ---- */
#pad {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 30;
  display: none;
}
#dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 6px;
}
#dpad button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  background: rgba(7, 9, 13, 0.88);
  border: 1px solid var(--border-color);
  color: var(--accent-teal);
  font: inherit;
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  backdrop-filter: blur(6px);
}
#dpad button:active { background: rgba(79, 214, 200, 0.22); border-color: var(--accent-teal); }
#pad-help, #pad-in, #pad-out { color: var(--accent-amber); font-size: 15px; }
@media (pointer: coarse), (max-width: 900px) {
  #pad { display: block; }
  #help {
    left: 12px;
    right: auto;
    bottom: 10px;
    transform: none;
    text-align: left;
    max-width: calc(100vw - 200px);
    font-size: 9px;
  }
}
@media (max-width: 700px) {
  #dpad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); }
  #hud { font-size: 10px; }
}
