:root {
  --bg: #07130d;
  --panel: rgba(10, 31, 16, 0.82);
  --panel-strong: rgba(14, 42, 22, 0.9);
  --line: rgba(255, 236, 142, 0.36);
  --text: #fff8cc;
  --muted: #c8e7bd;
  --accent: #4ade80;
  --gold: #f2cf66;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  background: #07130d;
  color: var(--text);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  user-select: none;
  touch-action: none;
}

button {
  font: inherit;
}

#gameRoot {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 45%, #173b20 0%, #07130d 72%);
}

#stageWrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#game {
  display: block;
  width: min(100vw, calc(100vh * 16 / 9));
  height: auto;
  max-width: 100vw;
  max-height: 100vh;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  cursor: pointer;
  outline: none;
  touch-action: none;
}

#game:focus-visible {
  box-shadow: 0 0 0 3px rgba(255, 236, 142, 0.62);
}

#topbar {
  position: absolute;
  z-index: 4;
  top: 10px;
  left: 10px;
  right: 10px;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(14, 42, 22, 0.88), rgba(7, 24, 13, 0.78));
  border: 1px solid rgba(255, 236, 142, 0.28);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(3px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff8c9;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(62, 38, 12, 0.75);
}

.brand-mark {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
  background:
    linear-gradient(90deg, transparent 0 25%, #4ade80 25% 75%, transparent 75%),
    linear-gradient(0deg, #d49b45 0 28%, #f4d56a 28% 42%, #2f8d38 42% 100%);
  border: 2px solid #ffe184;
  box-shadow: 0 0 14px rgba(242, 207, 102, 0.44);
}

.readouts {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.readouts div {
  min-width: 0;
  padding: 4px 8px;
  background: rgba(4, 18, 9, 0.62);
  border: 1px solid rgba(183, 226, 148, 0.18);
  border-radius: 6px;
}

.readouts dt {
  margin-bottom: 1px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.readouts dd {
  min-height: 18px;
  color: #fff7c9;
  font-size: clamp(14px, 2.4vw, 20px);
  font-weight: 900;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(73, 45, 10, 0.72);
}

.readout-sub {
  display: block;
  margin-top: 2px;
  color: #9edcb1;
  font-size: 10px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#toolbar {
  position: absolute;
  z-index: 4;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: grid;
  grid-template-columns: repeat(6, minmax(72px, 1fr));
  gap: 7px;
}

.primary-action,
.secondary-action,
.tool-btn {
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid rgba(183, 226, 148, 0.28);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.2px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 10px;
  background: linear-gradient(180deg, rgba(18, 44, 23, 0.92), rgba(6, 24, 12, 0.9));
  color: #d7f8c9;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(3px);
}

.tool-btn span {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: rgba(7, 20, 11, 0.74);
  color: var(--gold);
  line-height: 1;
}

.tool-btn.active {
  background: linear-gradient(180deg, rgba(38, 103, 55, 0.94), rgba(19, 69, 34, 0.92));
  border-color: #fff2a8;
  color: #fff7c9;
  box-shadow: 0 0 0 1px rgba(255, 242, 168, 0.18) inset, 0 0 18px rgba(74, 222, 128, 0.28);
}

.tool-btn.accent {
  background: linear-gradient(180deg, rgba(96, 62, 16, 0.94), rgba(49, 35, 12, 0.92));
  border-color: rgba(242, 207, 102, 0.58);
  color: #fff2a6;
}

.tool-btn:hover,
.primary-action:hover,
.secondary-action:hover {
  transform: translateY(-1px);
}

.tool-btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

#toast {
  position: absolute;
  left: 50%;
  top: 80px;
  z-index: 5;
  max-width: calc(100% - 24px);
  padding: 8px 13px;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(16, 42, 24, 0.96);
  border: 1px solid rgba(242, 207, 102, 0.58);
  border-radius: 8px;
  color: #fff7cb;
  font-size: 12px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transition: opacity 140ms ease, transform 140ms ease;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 14, 8, 0.28);
  backdrop-filter: blur(1px);
}

#overlay[hidden] {
  display: none;
}

.overlay-panel {
  width: min(92vw, 520px);
  padding: 22px;
  background: linear-gradient(180deg, rgba(31, 61, 34, 0.95), rgba(14, 34, 20, 0.95));
  border: 1px solid rgba(242, 207, 102, 0.48);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  text-align: center;
}

.overlay-panel h1 {
  margin-bottom: 8px;
  color: #fff2a8;
  font-size: clamp(34px, 8vw, 58px);
  line-height: 0.95;
  letter-spacing: 1px;
  text-shadow: 0 4px 0 #6e431b, 0 0 22px rgba(242, 207, 102, 0.32);
}

.overlay-panel p {
  color: #dbeed2;
  font-size: 14px;
  line-height: 1.55;
}

.overlay-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 18px;
}

.overlay-stats span {
  min-width: 0;
  padding: 8px;
  background: rgba(7, 22, 12, 0.64);
  border: 1px solid rgba(183, 226, 148, 0.2);
  border-radius: 6px;
  color: #fff7c9;
  font-size: 12px;
  font-weight: 900;
}

.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-action {
  padding: 10px 26px;
  background: linear-gradient(180deg, #72e38e, #37a956);
  color: #08210f;
  border-color: #a8f5a6;
}

.secondary-action {
  padding: 10px 20px;
  background: rgba(8, 24, 13, 0.74);
  color: #d8f8ce;
}

@media (max-width: 780px) {
  #topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
    min-height: 0;
    padding: 7px;
  }

  .brand {
    font-size: 12px;
  }

  .readouts {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .readouts div {
    padding: 4px 5px;
  }

  .readouts dt {
    font-size: 8px;
  }

  .readouts dd {
    font-size: 14px;
  }

  .readout-sub {
    font-size: 8px;
  }

  #toolbar {
    left: 8px;
    right: 8px;
    bottom: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .tool-btn {
    min-height: 38px;
    padding: 5px 6px;
    font-size: 11px;
  }

  .tool-btn span {
    width: 18px;
    height: 18px;
  }

  #toast {
    top: 112px;
  }

  .overlay-panel {
    padding: 18px;
  }

  .overlay-stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  #toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
