:root {
  color-scheme: dark;
  --bg: #120f0b;
  --panel: rgba(22, 18, 14, 0.84);
  --panel-strong: rgba(14, 12, 9, 0.94);
  --panel-soft: rgba(41, 31, 20, 0.78);
  --line: rgba(255, 232, 176, 0.18);
  --text: #f6edd6;
  --muted: #ccb890;
  --accent: #f3b04c;
  --accent-2: #78d1c1;
  --danger: #ef7058;
  --shadow: 0 24px 90px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --pixel: "Trebuchet MS", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(243, 176, 76, 0.14), transparent 32%),
    linear-gradient(180deg, #1f2735 0%, #1b2f3e 30%, #20150f 100%);
  color: var(--text);
  font-family: var(--pixel);
}

body {
  min-height: 100vh;
}

button,
canvas {
  font: inherit;
}

.shell {
  width: min(1380px, calc(100% - 24px));
  margin: 0 auto;
  padding: 12px 0 28px;
}

.viewport-panel {
  position: relative;
  min-height: min(92vh, 880px);
  overflow: clip;
  border: 1px solid var(--line);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(79, 116, 153, 0.08), rgba(12, 9, 6, 0.44)),
    linear-gradient(160deg, rgba(255, 255, 255, 0.02), transparent 24%);
  box-shadow: var(--shadow);
}

#game {
  display: block;
  width: 100%;
  height: min(92vh, 880px);
  background: linear-gradient(180deg, #6fa9d9 0%, #2d4f70 46%, #18130d 100%);
  touch-action: none;
}

.sky-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 227, 150, 0.28), transparent 14%),
    linear-gradient(180deg, transparent 0%, transparent 60%, rgba(0, 0, 0, 0.2) 100%);
}

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 244, 217, 0.92);
  box-shadow: 0 0 12px rgba(255, 194, 92, 0.35);
}

.crosshair::before {
  left: 9px;
  top: 0;
  width: 2px;
  height: 20px;
}

.crosshair::after {
  left: 0;
  top: 9px;
  width: 20px;
  height: 2px;
}

.brand-bar,
.top-actions,
.hud-card,
.inventory-dock,
.message-stack,
.overlay,
.fallback-card {
  position: absolute;
  z-index: 2;
}

.brand-bar {
  left: 18px;
  top: 18px;
  max-width: min(540px, calc(100% - 36px));
  padding: 16px 18px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(17, 14, 10, 0.92), rgba(35, 27, 18, 0.78));
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(34px, 6vw, 60px);
  line-height: 0.95;
}

h2 {
  margin-bottom: 10px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
}

h3 {
  margin-bottom: 8px;
  font-size: 18px;
}

.brief {
  margin: 0;
  max-width: 42ch;
  color: var(--muted);
  line-height: 1.45;
}

.top-actions {
  top: 18px;
  right: 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  max-width: min(540px, calc(100% - 36px));
}

.pixel-button {
  appearance: none;
  border: 1px solid rgba(255, 229, 178, 0.22);
  border-bottom-width: 4px;
  border-radius: 14px;
  padding: 12px 16px;
  background: linear-gradient(180deg, rgba(53, 39, 27, 0.94), rgba(27, 21, 15, 0.94));
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.pixel-button:hover,
.pixel-button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(255, 229, 178, 0.44);
}

.pixel-button:active {
  transform: translateY(1px);
}

.pixel-button.primary {
  background: linear-gradient(180deg, #f3b04c, #cd7e2c);
  color: #20150f;
}

.status-card {
  left: 18px;
  bottom: 148px;
  width: min(390px, calc(100% - 36px));
}

.help-card {
  right: 18px;
  bottom: 148px;
  width: min(356px, calc(100% - 36px));
}

.hud-card {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(12px);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.status-grid div {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
}

dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

dd {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.help-card ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.help-card li {
  line-height: 1.4;
}

.help-card b {
  color: var(--text);
}

.inventory-dock {
  left: 18px;
  right: 18px;
  bottom: 18px;
  padding: 14px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(16, 13, 10, 0.96), rgba(38, 28, 19, 0.85));
  backdrop-filter: blur(10px);
}

.inventory-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.inventory-note,
.touch-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.touch-note {
  max-width: 34ch;
  text-align: right;
}

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

.slot {
  appearance: none;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(255, 236, 196, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.slot.is-selected {
  border-color: rgba(243, 176, 76, 0.82);
  background: rgba(243, 176, 76, 0.14);
  box-shadow: inset 0 0 0 1px rgba(243, 176, 76, 0.4);
}

.slot-visual,
.swatch {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
}

.slot-copy {
  min-width: 0;
}

.slot-copy strong,
.slot-copy span,
.slot-index {
  display: block;
}

.slot-copy strong {
  font-size: 15px;
}

.slot-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.slot-index {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.message-stack {
  left: 50%;
  top: 120px;
  transform: translateX(-50%);
  width: min(640px, calc(100% - 36px));
}

.message-banner {
  padding: 12px 16px;
  border: 1px solid rgba(120, 209, 193, 0.28);
  border-radius: 999px;
  background: rgba(15, 13, 11, 0.82);
  color: var(--accent-2);
  text-align: center;
  backdrop-filter: blur(12px);
}

.overlay {
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(7, 8, 10, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

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

.overlay-card,
.fallback-card {
  max-width: 540px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.overlay-points {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 20px;
}

.overlay-points span {
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 13px;
}

.fallback-card {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 32px));
  z-index: 4;
}

.is-hidden {
  display: none;
}

.materials-panel {
  margin-top: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(19, 15, 11, 0.92), rgba(35, 24, 16, 0.86));
  box-shadow: var(--shadow);
}

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

.materials-grid article {
  padding: 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
}

.materials-grid p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.swatch {
  display: block;
  margin-bottom: 12px;
}

.grass {
  background: linear-gradient(180deg, #8fd363 0 46%, #8a5d38 46% 100%);
}

.dirt {
  background: linear-gradient(135deg, #9c6e43, #7f5530);
}

.stone {
  background: linear-gradient(135deg, #9fa7b0, #65707b);
}

.wood {
  background: linear-gradient(135deg, #9f6e3b, #6e471f);
}

.crystal {
  background: linear-gradient(135deg, #66f2ef, #2d71e9);
}

@media (max-width: 1120px) {
  .top-actions {
    top: auto;
    left: 18px;
    right: 18px;
    bottom: 298px;
    justify-content: flex-start;
  }

  .status-card {
    bottom: 210px;
  }

  .help-card {
    bottom: 210px;
  }

  .materials-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .shell {
    width: min(100%, calc(100% - 16px));
    padding-top: 8px;
  }

  .viewport-panel {
    min-height: auto;
  }

  #game {
    height: 92svh;
  }

  .brand-bar,
  .status-card,
  .help-card,
  .top-actions,
  .inventory-dock,
  .message-stack {
    position: absolute;
  }

  .brand-bar {
    top: 12px;
    left: 12px;
    right: 12px;
    max-width: none;
  }

  .top-actions {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 292px;
    max-width: none;
  }

  .status-card,
  .help-card {
    width: calc(100% - 24px);
  }

  .status-card {
    left: 12px;
    bottom: 180px;
  }

  .help-card {
    left: 12px;
    right: auto;
    bottom: 12px;
    display: none;
  }

  .inventory-dock {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .inventory-header {
    display: block;
  }

  .touch-note {
    margin-top: 10px;
    max-width: none;
    text-align: left;
  }

  .inventory-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .materials-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .shell {
    width: calc(100% - 10px);
  }

  #game {
    height: 88svh;
  }

  .brand-bar,
  .top-actions,
  .status-card,
  .inventory-dock,
  .message-stack {
    left: 10px;
    right: 10px;
    width: auto;
  }

  .brand-bar {
    padding: 14px;
  }

  .top-actions {
    bottom: 286px;
    gap: 8px;
  }

  .pixel-button {
    flex: 1 1 calc(50% - 8px);
    min-width: 126px;
    padding: 11px 12px;
    text-align: center;
  }

  .message-stack {
    top: 148px;
    transform: translateX(0);
  }

  .status-card {
    bottom: 180px;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .inventory-grid,
  .materials-grid {
    grid-template-columns: 1fr;
  }

  .slot {
    grid-template-columns: 38px minmax(0, 1fr) auto;
  }

  .slot-visual,
  .swatch {
    width: 38px;
    height: 38px;
  }

  .overlay-card,
  .fallback-card {
    padding: 22px;
  }

  .materials-panel {
    padding: 18px;
  }
}
