:root {
  color-scheme: dark;
  --bg-top: #090b16;
  --bg-bottom: #171028;
  --panel: rgba(12, 15, 25, 0.72);
  --panel-strong: rgba(12, 15, 25, 0.9);
  --border: rgba(255, 255, 255, 0.14);
  --text: #f4f7ff;
  --muted: rgba(244, 247, 255, 0.72);
  --accent: #73e0ff;
  --accent-2: #ffcf6f;
  --success: #84f5b5;
  --danger: #ff8686;
  --shadow: 0 20px 45px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 15%, rgba(115, 224, 255, 0.16), transparent 26%),
    radial-gradient(circle at 80% 20%, rgba(255, 207, 111, 0.15), transparent 22%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  gap: 10px;
}

.topbar,
.destination-row,
.hud-bottom,
.inventory-drawer,
.prompt,
.toast {
  pointer-events: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.status-chip,
.small-chip,
.pill,
.action-btn,
.wide-button,
.icon-button {
  border: 1px solid var(--border);
  color: var(--text);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.status-chip,
.small-chip {
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.destination-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.pill:hover,
.pill.active,
.action-btn:hover,
.wide-button:hover,
.icon-button:hover,
.button-like:hover {
  transform: translateY(-1px);
  border-color: rgba(115, 224, 255, 0.45);
}

.prompt {
  align-self: center;
  max-width: min(720px, 100%);
  padding: 12px 16px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 14px;
  text-align: center;
  color: var(--muted);
}

.inventory-drawer {
  position: absolute;
  top: 72px;
  right: 12px;
  width: min(92vw, 340px);
  max-height: calc(100vh - 170px);
  overflow: auto;
  border-radius: 22px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 16px;
  transform: translateX(calc(100% + 20px));
  opacity: 0;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.inventory-drawer.open {
  transform: translateX(0);
  opacity: 1;
}

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

.drawer-kicker {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
}

.drawer-header h2 {
  margin: 0;
  font-size: 20px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  cursor: pointer;
}

.resource-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.resource-card {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.resource-name {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.resource-value {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 700;
}

.craft-row {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.wide-button,
.button-like {
  width: 100%;
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 13px;
}

.held-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 12px;
}

.held-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
}

.held-value {
  font-weight: 700;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 112px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(7, 10, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.24s ease, transform 0.24s ease;
  max-width: min(92vw, 560px);
  text-align: center;
}

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

.hud-bottom {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.mobile-controls {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: end;
  pointer-events: auto;
  z-index: 25;
}

.joystick {
  position: fixed;
  left: 14px;
  bottom: 112px;
  width: 150px;
  height: 150px;
  justify-self: start;
  touch-action: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.08s ease;
  z-index: 25;
}

.joystick-base,
.joystick-knob {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
}

.joystick-base {
  width: 150px;
  height: 150px;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.04));
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow);
}

.joystick-knob {
  width: 58px;
  height: 58px;
  background: linear-gradient(180deg, rgba(115, 224, 255, 0.9), rgba(115, 224, 255, 0.45));
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  transform: translate(0, 0);
}

.joystick.active {
  opacity: 1;
}

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

.action-btn {
  min-height: 58px;
  padding: 12px 14px;
  border-radius: 18px;
  font-size: 13px;
  line-height: 1.15;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.button-like {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

@media (max-width: 760px) {
  .prompt {
    font-size: 13px;
  }

  .mobile-controls {
    grid-template-columns: 1fr;
  }

  .joystick {
    width: 132px;
    height: 132px;
    left: 12px;
    bottom: 108px;
  }

  .joystick-base {
    width: 132px;
    height: 132px;
  }

  .joystick-knob {
    width: 52px;
    height: 52px;
  }

  .inventory-drawer {
    top: auto;
    bottom: 168px;
    right: 12px;
    left: 12px;
    width: auto;
    max-height: 46vh;
    transform: translateY(calc(100% + 20px));
  }

  .inventory-drawer.open {
    transform: translateY(0);
  }

  .toast {
    bottom: 178px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #ui {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .topbar {
    gap: 8px;
  }

  .status-chip,
  .small-chip {
    padding: 7px 10px;
    font-size: 10px;
  }

  .destination-row {
    gap: 6px;
  }

  .pill {
    padding: 7px 10px;
    font-size: 11px;
  }

  .prompt {
    max-width: 52vw;
    font-size: 12px;
    padding: 9px 12px;
  }

  .inventory-drawer {
    width: min(30vw, 185px);
    max-height: calc(100vh - 86px);
    top: 52px;
    left: 10px;
    right: auto;
    padding: 10px;
    border-radius: 18px;
  }

  .hud-bottom {
    gap: 8px;
  }

  .mobile-controls {
    margin-top: 0;
  }

  .joystick {
    left: 12px;
    bottom: 12px;
    width: 118px;
    height: 118px;
  }

  .joystick-base {
    width: 118px;
    height: 118px;
  }

  .joystick-knob {
    width: 46px;
    height: 46px;
  }

  .action-stack {
    position: fixed;
    right: 12px;
    bottom: 12px;
    width: 138px;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    z-index: 25;
  }

  .action-btn {
    min-height: 40px;
    padding: 7px 8px;
    border-radius: 13px;
    font-size: 10px;
    line-height: 1.02;
  }

  .toast {
    bottom: 84px;
    max-width: 60vw;
    font-size: 12px;
  }
}

@media (orientation: landscape) and (max-height: 420px) {
  .destination-row {
    display: none;
  }

  .prompt {
    display: none;
  }

  .hud-bottom {
    display: none;
  }

  .inventory-drawer {
    top: 42px;
    width: min(26vw, 155px);
    max-height: calc(100vh - 64px);
    padding: 9px;
  }

  .drawer-header {
    margin-bottom: 8px;
  }

  .drawer-header h2 {
    font-size: 16px;
  }

  .drawer-kicker {
    font-size: 9px;
  }

  .resource-grid {
    gap: 5px;
    margin-bottom: 8px;
  }

  .resource-card {
    padding: 8px;
    border-radius: 12px;
  }

  .resource-name {
    font-size: 9px;
  }

  .resource-value {
    margin-top: 4px;
    font-size: 16px;
  }

  .held-row {
    padding-top: 8px;
  }

  .held-label {
    font-size: 9px;
  }

  .held-value {
    font-size: 12px;
  }

  .action-stack {
    width: 132px;
    gap: 5px;
  }

  .action-btn {
    min-height: 36px;
    padding: 6px 7px;
    font-size: 9px;
  }

  .wide-button,
  .icon-button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }
}
