* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  height: 100%;
  width: 100%;
  background: #0a0608;
  overflow: hidden;
  font-family: 'Courier New', 'Lucida Console', ui-monospace, monospace;
  color: #d4a04a;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

#game-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  align-items: stretch;
  justify-content: center;
  background: #050304;
}

.side-panel {
  flex: 1 1 0;
  max-width: 280px;
  min-width: 180px;
  background: linear-gradient(180deg, #1a1014 0%, #100a0c 100%);
  border-left: 2px solid #2a1a14;
  border-right: 2px solid #2a1a14;
  padding: 18px 16px;
  display: none;
  flex-direction: column;
  gap: 18px;
}

@media (min-width: 820px) {
  .side-panel { display: flex; }
}

#game-frame {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: #050304;
}

@media (min-width: 820px) {
  #game-frame {
    width: auto;
    aspect-ratio: 9 / 16;
    max-height: 100dvh;
    border-left: 2px solid #2a1a14;
    border-right: 2px solid #2a1a14;
  }
}

#hud-top, #hud-bottom {
  flex: 0 0 auto;
  background: #0d0708;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  border-bottom: 2px solid #2a1a14;
}

#hud-top { padding-top: max(10px, env(safe-area-inset-top)); }
#hud-bottom {
  border-bottom: none;
  border-top: 2px solid #2a1a14;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.hud-cell { white-space: nowrap; }
.hud-ore { color: #ffd770; }

#hud-bottom button {
  flex: 1;
  background: #2a1a14;
  border: 2px solid #3a2a1f;
  color: #d4a04a;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 1.5px;
  padding: 12px 8px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.1s;
}

#hud-bottom button:not(:disabled):active {
  background: #3a2a1f;
}

#hud-bottom button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #050304;
  overflow: hidden;
  position: relative;
}

#game-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 270 / 480;
  width: auto;
  height: auto;
  background: #0a0608;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  touch-action: none;
}

@supports (height: 100dvh) {
  #game-canvas { height: auto; }
}

.panel-title {
  font-size: 14px;
  letter-spacing: 4px;
  font-weight: bold;
  text-align: center;
  padding-bottom: 14px;
  border-bottom: 2px solid #2a1a14;
  color: #d4a04a;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel-label {
  font-size: 10px;
  letter-spacing: 2.5px;
  color: #6a4a2f;
  text-transform: uppercase;
}

.panel-stat {
  font-size: 24px;
  font-weight: bold;
  color: #ffd770;
}

.panel-stat-small {
  font-size: 12px;
  color: #a07a4f;
}

#ascend-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(60, 30, 80, 0.92) 0%, rgba(40, 20, 50, 0.92) 100%);
  border: 2px solid #b070ff;
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  text-align: center;
  animation: pulse 1.4s ease-in-out infinite;
  z-index: 5;
}

#ascend-banner.hidden { display: none; }

.banner-label {
  font-size: 10px;
  letter-spacing: 2px;
  color: #d8b0ff;
  font-weight: bold;
}

.banner-detail {
  font-size: 11px;
  color: #ffd0ff;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(176, 112, 255, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(176, 112, 255, 0); }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 3, 4, 0.88);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 100%;
  background: linear-gradient(180deg, #1a1014 0%, #0d0708 100%);
  border: 2px solid #3a2a1f;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 2px solid #2a1a14;
}

.modal-header h2 {
  font-size: 14px;
  letter-spacing: 4px;
  color: #d4a04a;
  font-weight: bold;
}

.modal-close {
  background: transparent;
  border: none;
  color: #d4a04a;
  font-size: 24px;
  cursor: pointer;
  padding: 0 8px;
  line-height: 1;
  font-family: inherit;
}

.modal-close:active { color: #ffd770; }

.modal-resources {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 2px solid #2a1a14;
  flex-wrap: wrap;
}

.resource-pill {
  flex: 1 1 100px;
  background: #0a0608;
  border: 1px solid #2a1a14;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.resource-label {
  font-size: 9px;
  letter-spacing: 1.5px;
  color: #6a4a2f;
  text-transform: uppercase;
}

.resource-value {
  font-size: 15px;
  font-weight: bold;
  color: #ffd770;
}

.tree-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.tree-branch {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.branch-header {
  font-size: 11px;
  letter-spacing: 2px;
  color: #6a4a2f;
  text-transform: uppercase;
  text-align: center;
  padding-bottom: 4px;
  border-bottom: 1px solid #2a1a14;
}

.tree-node {
  background: #0d0708;
  border: 2px solid #2a1a14;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}

.tree-node.locked {
  opacity: 0.4;
}

.tree-node.available {
  border-color: #3a2a1f;
}

.tree-node.affordable {
  border-color: #d4a04a;
  background: #1a1014;
}

.tree-node.owned {
  border-color: #6ad06a;
  background: #0d1a0d;
}

.node-name {
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1px;
  color: #d4a04a;
  text-transform: uppercase;
}

.tree-node.owned .node-name { color: #90e090; }

.node-desc {
  font-size: 10px;
  color: #a07a4f;
  line-height: 1.3;
}

.node-cost {
  font-size: 10px;
  color: #ffd770;
  margin-top: auto;
}

.tree-node.owned .node-cost { color: #90e090; }
.tree-node.locked .node-cost { color: #6a4a2f; }

.node-buy {
  margin-top: 6px;
  background: #2a1a14;
  border: 1px solid #3a2a1f;
  color: #d4a04a;
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 1.5px;
  padding: 6px;
  cursor: pointer;
  text-transform: uppercase;
}

.node-buy:not(:disabled):active {
  background: #3a2a1f;
}

.tree-node.affordable .node-buy {
  background: #3a2a1f;
  border-color: #d4a04a;
  color: #ffd770;
}

.node-buy:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 2px solid #2a1a14;
}

.btn-primary, .btn-secondary {
  flex: 1;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 2px;
  padding: 12px;
  cursor: pointer;
  text-transform: uppercase;
  border: 2px solid;
}

.btn-primary {
  background: #3a1f50;
  border-color: #b070ff;
  color: #d8b0ff;
}

.btn-primary:not(:disabled):active { background: #5a2f78; }

.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: #2a1a14;
  border-color: #3a2a1f;
  color: #6a4a2f;
}

.btn-secondary {
  background: transparent;
  border-color: #3a2a1f;
  color: #6a4a2f;
}

.btn-secondary:active { color: #d04030; border-color: #d04030; }

@media (max-width: 480px) {
  .tree-grid { grid-template-columns: 1fr 1fr; }
  .resource-pill { flex: 1 1 80px; }
  .resource-value { font-size: 13px; }
}
