:root {
  --bg-deep: #0b0b10;
  --panel-bg: rgba(16, 15, 20, 0.72);
  --panel-border: rgba(130, 114, 96, 0.35);
  --text-main: #f4eadc;
  --text-dim: #a89988;
  --gold: #eab04d;
  --gold-bright: #ffd982;
  --danger: #e05246;
  --font-mono: "Consolas", "SFMono-Regular", ui-monospace, monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: system-ui, sans-serif;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

.viewport-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  touch-action: none;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
}

/* ==================== Whisper-Quiet Corner Icons ==================== */
.hud-top-right {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 10;
}

.corner-btns {
  display: flex;
  gap: 6px;
  opacity: 0.45;
  transition: opacity 0.25s ease;
}

.corner-btns:hover {
  opacity: 1;
}

.hud-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-bg);
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: border-color 0.15s, background 0.15s, transform 0.06s;
}

.hud-btn:hover {
  border-color: var(--gold-bright);
  background: rgba(40, 34, 28, 0.9);
}

.hud-btn:active {
  transform: translateY(1px);
}

.hud-btn.active {
  border-color: var(--gold-bright);
  background: rgba(65, 48, 25, 0.88);
}

.hud-btn.danger:hover {
  border-color: var(--danger);
}

.hud-btn.ngplus-btn {
  border-color: var(--gold-bright);
  background: rgba(74, 52, 18, 0.88);
  color: #fff2b2;
  box-shadow: 0 0 12px rgba(255, 214, 102, 0.45);
}

.hud-btn.ngplus-btn[hidden] {
  display: none;
}

.minimap-box {
  background: rgba(11, 11, 15, 0.8);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 5px;
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.minimap-box[hidden] {
  display: none;
}

#minimapCanvas {
  width: 144px;
  height: 210px;
  border-radius: 6px;
  background: #0a0a0e;
  display: block;
}

/* ==================== Wordless Ending Curtain (☀ FIN) ==================== */
.fin-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 42%, rgba(255, 224, 140, 0.14), rgba(14, 11, 8, 0.45));
  z-index: 16;
  opacity: 0;
  transition: opacity 2.2s ease;
  pointer-events: none;
}

.fin-overlay[hidden] {
  display: none;
}

.fin-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.fin-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 48px;
  border-radius: 16px;
  background: rgba(20, 16, 12, 0.76);
  border: 1px solid rgba(255, 217, 130, 0.48);
  backdrop-filter: blur(8px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 42px rgba(255, 206, 102, 0.22);
}

.fin-sun {
  font-size: 46px;
  line-height: 1;
  color: #ffe388;
  text-shadow: 0 0 22px rgba(255, 214, 102, 0.85);
  animation: sunPulse 3.6s ease-in-out infinite;
}

@keyframes sunPulse {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.08); filter: brightness(1.22); }
}

.fin-mark {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.42em;
  padding-left: 0.42em;
  color: #fff4d4;
  text-shadow: 0 2px 12px rgba(255, 198, 86, 0.45);
}

.fin-dots {
  display: flex;
  gap: 7px;
  margin-top: 2px;
}

.fin-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffd982;
  box-shadow: 0 0 8px rgba(255, 217, 130, 0.8);
}

.fin-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.fin-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 220, 132, 0.14);
  border: 1px solid rgba(255, 217, 130, 0.5);
  color: #fff3d1;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.fin-btn:hover {
  background: rgba(255, 220, 132, 0.28);
  box-shadow: 0 0 16px rgba(255, 214, 110, 0.45);
  transform: scale(1.06);
}

.fin-btn.fin-ngplus {
  background: linear-gradient(135deg, rgba(255, 214, 102, 0.42), rgba(235, 142, 48, 0.35));
  border-color: #ffe896;
  box-shadow: 0 0 20px rgba(255, 214, 102, 0.5);
  font-size: 18px;
}

/* ==================== Iconic Keycap Onboarding (Zero Text!) ==================== */
.iconic-keys {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 16px;
  pointer-events: none;
  z-index: 8;
  opacity: 0.72;
  transition: opacity 1.4s ease;
}

.iconic-keys.hidden-fade {
  opacity: 0;
}

.key-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.k-row {
  display: flex;
  gap: 4px;
}

.kcap {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: #efe3cf;
  background: rgba(20, 18, 22, 0.78);
  border: 1px solid rgba(234, 195, 130, 0.4);
  border-bottom: 3px solid rgba(0, 0, 0, 0.75);
  border-radius: 5px;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.kcap.k-space {
  width: 78px;
  letter-spacing: 0.08em;
  font-size: 10px;
}

/* ==================== Collapsible Sprite Stack Lab Drawer ==================== */
.lab-drawer {
  position: absolute;
  top: 56px;
  right: 14px;
  width: 310px;
  max-height: calc(100vh - 90px);
  background: rgba(18, 15, 14, 0.94);
  border: 1px solid rgba(234, 176, 77, 0.42);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 20;
  backdrop-filter: blur(10px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.65);
}

.lab-drawer[hidden] {
  display: none;
}

.lab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid var(--panel-border);
  color: var(--gold-bright);
  font-size: 12.5px;
}

.lab-close {
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 15px;
  cursor: pointer;
  padding: 2px 6px;
}

.lab-body {
  padding: 10px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.lab-control {
  background: rgba(12, 10, 9, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lab-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
}

.lab-val {
  font-family: var(--font-mono);
  color: var(--gold-bright);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
  cursor: pointer;
}

.lab-toggles {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(12, 10, 9, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 99px;
  padding: 3px 9px;
  font-size: 11px;
  cursor: pointer;
}

.toggle-chip input {
  accent-color: var(--gold);
}

.snap-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.snap-btn {
  background: #221d19;
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  padding: 4px;
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
}

.snap-btn.active {
  background: #47361e;
  border-color: var(--gold-bright);
  color: var(--gold-bright);
}

.lab-inspector {
  background: rgba(12, 10, 9, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.model-select {
  background: #171310;
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 11px;
  max-width: 170px;
}

.inspector-top {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
  align-items: center;
}

#previewCanvas {
  width: 84px;
  height: 84px;
  background: radial-gradient(circle, #251e18 0%, #100d0b 85%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.inspector-meta {
  font-size: 10.5px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.inspector-meta strong {
  color: var(--gold-bright);
  font-size: 11.5px;
}

.slice-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 145px;
  overflow-y: auto;
}

.slice-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #1d1814;
  border: 1px solid #352c24;
  border-radius: 4px;
  padding: 2px;
}

.slice-cell canvas {
  width: 30px;
  height: 30px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.slice-cell span {
  font-family: var(--font-mono);
  font-size: 8.5px;
  color: var(--text-dim);
}
