:root {
  color-scheme: dark;
  --bg: #07120d;
  --panel: rgba(12, 22, 18, .9);
  --panel-strong: rgba(18, 32, 26, .96);
  --line: rgba(193, 230, 205, .2);
  --text: #f2fff6;
  --muted: #a6b9ad;
  --accent: #59d987;
  --blue: #55a7ff;
  --danger: #ff6b76;
}

* { box-sizing: border-box; }

html, body, #app {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button, input, select { font: inherit; }

#world {
  display: block;
  width: 100vw;
  height: 100vh;
}

.panel {
  position: fixed;
  z-index: 5;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .24);
  backdrop-filter: blur(14px);
}

.right-panel {
  right: 16px;
  top: 16px;
  display: grid;
  gap: 10px;
  width: 220px;
  padding: 12px;
}

.status-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 12px;
}

.status-card span,
label,
.edit-head span,
.inventory-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.status-card strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.edit-menu {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  background: rgba(2, 7, 5, .58);
  backdrop-filter: blur(6px);
}

.edit-menu.open {
  display: grid;
}

.edit-shell,
.inventory-shell {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .36);
  padding: 16px;
}

.edit-head,
.inventory-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
  padding-bottom: 14px;
}

.edit-head strong,
.inventory-head strong {
  display: block;
  font-size: 28px;
  line-height: 1.05;
}

.inventory-menu {
  position: fixed;
  inset: 0;
  z-index: 22;
  display: none;
  place-items: center;
  background: rgba(2, 7, 5, .6);
  backdrop-filter: blur(6px);
}

.inventory-menu.open {
  display: grid;
}

.inventory-shell {
  width: min(760px, calc(100vw - 32px));
}

.inventory-section {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.inventory-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.inventory-hotbar,
.inventory-grid {
  display: grid;
  gap: 8px;
}

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

.inventory-grid {
  grid-template-columns: repeat(6, minmax(82px, 1fr));
}

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

label {
  display: grid;
  gap: 6px;
}

input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(4, 10, 8, .8);
  color: var(--text);
  min-height: 40px;
  outline: none;
  padding: 8px 10px;
  text-transform: none;
}

input[type="search"] {
  min-width: min(320px, 100%);
}

select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(4, 10, 8, .8);
  color: var(--text);
  min-height: 40px;
  outline: none;
  padding: 8px 10px;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

input[type="color"] {
  padding: 4px;
}

input[type="file"] {
  padding: 8px;
}

input[type="range"] {
  accent-color: var(--accent);
}

.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
}

button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 8px;
  background: #1b3328;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  min-height: 40px;
  padding: 9px 11px;
}

button:hover {
  border-color: rgba(255, 255, 255, .28);
  transform: translateY(-1px);
}

button.secondary {
  background: #1a2630;
}

button.danger {
  background: #4b1f28;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
  transform: none;
}

.start-menu {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: #e8ebef;
  color: #15191f;
  padding: 24px;
}

.start-menu input,
.start-menu select {
  border-color: #c9d0d8;
  background: #ffffff;
  color: #15191f;
}

.start-menu label {
  color: #687382;
}

.start-menu.hidden {
  display: none;
}

.start-shell {
  display: grid;
  gap: 16px;
  width: min(1220px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.start-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #d3d8df;
  border-radius: 8px;
  background: #ffffff;
  padding: 12px 16px;
}

.start-top strong {
  font-size: 22px;
  letter-spacing: 0;
}

.start-top div {
  display: flex;
  gap: 6px;
}

.start-top button {
  min-height: 34px;
  border-color: transparent;
  background: transparent;
  color: #5f6875;
  font-weight: 900;
  padding: 7px 10px;
}

.start-top button:hover,
.start-top button.active {
  border-color: #d3d8df;
  background: #eef1f4;
  color: #15191f;
  transform: none;
}

.start-hero,
.world-browser,
.create-world {
  border: 1px solid #d3d8df;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 16px 40px rgba(36, 44, 54, .1);
}

.start-hero {
  position: relative;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  min-height: 230px;
  overflow: hidden;
  padding: 24px;
}

.start-hero::after {
  content: "";
  align-self: stretch;
  width: min(420px, 42%);
  border-radius: 8px;
  background:
    linear-gradient(#8fd0ff 0 44%, #69b458 44% 100%);
  box-shadow: inset 0 -48px 0 rgba(43, 92, 55, .22);
}

.start-hero::before {
  content: "";
  position: absolute;
  right: 72px;
  bottom: 58px;
  width: 190px;
  height: 92px;
  background:
    linear-gradient(90deg, #ffcf4a 0 36%, #ef7a3c 36% 70%, #2563eb 70% 100%);
  border: 4px solid rgba(21, 25, 31, .18);
  border-radius: 6px 6px 3px 3px;
  box-shadow:
    -96px 34px 0 -18px #3b82f6,
    92px 44px 0 -24px #e11d48,
    0 -42px 0 -26px #273142;
}

.start-hero span,
.start-section-head span {
  color: #5f6875;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.start-hero h1 {
  max-width: 560px;
  margin: 8px 0 10px;
  font-size: 44px;
  line-height: 1;
  letter-spacing: 0;
}

.start-hero p {
  max-width: 520px;
  margin: 0;
  color: #5f6875;
  font-size: 16px;
}

.start-hero button,
.create-world button {
  min-width: 180px;
  background: #178a42;
  color: #ffffff;
}

.start-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
}

.world-browser,
.create-world {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px;
}

.start-section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.start-section-head strong {
  display: block;
  margin-top: 2px;
  color: #15191f;
  font-size: 24px;
  line-height: 1.05;
}

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

.world-card {
  display: grid;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #ffffff;
  padding: 0;
  text-align: left;
  box-shadow: none;
}

.world-card.active {
  border-color: #178a42;
  box-shadow: 0 0 0 3px rgba(23, 138, 66, .14);
}

.world-card h2 {
  margin: 0 8px;
  color: #15191f;
  font-size: 16px;
  line-height: 1.15;
}

.world-card p {
  min-height: 36px;
  margin: 0 8px;
  color: #5f6875;
  font-size: 13px;
  line-height: 1.28;
}

.world-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 8px;
}

.world-meta span {
  border: 1px solid #d3d8df;
  border-radius: 999px;
  background: #f4f6f8;
  color: #5f6875;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 8px;
}

.world-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 8px;
  color: #687382;
  font-size: 12px;
  font-weight: 800;
}

.world-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 2px 8px 8px;
}

.world-actions button {
  min-height: 36px;
}

.world-actions button:first-child {
  background: #178a42;
  color: #ffffff;
}

.world-actions button.secondary {
  background: #eef1f4;
  color: #15191f;
}

.world-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / .72;
  min-height: 138px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: #8fd0ff;
  padding: 0;
  box-shadow: none;
}

.world-thumb:hover {
  transform: translateY(-2px);
}

.thumb-sky,
.thumb-ground,
.thumb-shop,
.thumb-sign,
.thumb-player,
.play-badge {
  position: absolute;
  display: block;
}

.thumb-sky {
  inset: 0 0 42%;
  background: #87ceeb;
}

.thumb-ground {
  inset: 48% 0 0;
  background: #5dae57;
}

.thumb-shop {
  bottom: 24%;
  border-radius: 4px 4px 2px 2px;
  box-shadow: inset 0 -18px 0 rgba(0, 0, 0, .12);
}

.thumb-shop-a {
  left: 10%;
  width: 38%;
  height: 34%;
  background: #f3b33d;
}

.thumb-shop-b {
  right: 10%;
  width: 32%;
  height: 42%;
  background: #2d7dd2;
}

.thumb-sign {
  left: 38%;
  bottom: 50%;
  width: 24%;
  height: 12%;
  border: 3px solid rgba(21, 25, 31, .24);
  border-radius: 4px;
  background: #fff7d6;
}

.thumb-player {
  left: 48%;
  bottom: 17%;
  width: 16px;
  height: 32px;
  border-radius: 6px 6px 3px 3px;
  background: #15191f;
}

.thumb-player::before {
  content: "";
  position: absolute;
  left: 2px;
  top: -12px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #f6c37a;
}

.play-badge {
  right: 10px;
  bottom: 10px;
  border-radius: 999px;
  background: rgba(21, 25, 31, .86);
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  padding: 6px 10px;
}

.thumb-night .thumb-sky { background: #273142; }
.thumb-night .thumb-ground { background: #2f6a50; }
.thumb-night .thumb-shop-a { background: #7c3aed; }
.thumb-night .thumb-shop-b { background: #ef4444; }
.thumb-night .thumb-sign { background: #f6d365; }

.thumb-collector .thumb-sky { background: #a7c7e7; }
.thumb-collector .thumb-ground { background: #7a9b76; }
.thumb-collector .thumb-shop-a { background: #16a34a; }
.thumb-collector .thumb-shop-b { background: #f97316; }

.thumb-food .thumb-shop-a { background: #ef4444; }
.thumb-food .thumb-shop-b { background: #f59e0b; }

.thumb-art .thumb-shop-a { background: #db2777; }
.thumb-art .thumb-shop-b { background: #06b6d4; }

.thumb-local .thumb-shop-a { background: #64748b; }
.thumb-local .thumb-shop-b { background: #22c55e; }

.empty-worlds {
  grid-column: 1 / -1;
  border: 1px dashed #b8c0ca;
  border-radius: 8px;
  color: #5f6875;
  padding: 20px;
  text-align: center;
}

.crosshair {
  position: fixed;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, .8);
  border-radius: 999px;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.prompt {
  position: fixed;
  z-index: 6;
  left: 50%;
  top: 16px;
  display: grid;
  gap: 4px;
  max-width: min(720px, calc(100vw - 280px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 12, 9, .82);
  padding: 12px 16px;
  text-align: center;
  transform: translateX(-50%);
}

.prompt span {
  color: var(--muted);
}

.open-link {
  position: fixed;
  z-index: 7;
  right: 16px;
  bottom: 104px;
  min-width: 190px;
  background: #21643a;
}

.hotbar {
  position: fixed;
  z-index: 8;
  left: 50%;
  bottom: 16px;
  display: grid;
  grid-template-columns: repeat(9, 72px);
  gap: 8px;
  transform: translateX(-50%);
}

.slot,
.inventory-slot {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  height: 72px;
  border: 2px solid rgba(255, 255, 255, .16);
  border-radius: 8px;
  background: rgba(8, 18, 14, .82);
  color: var(--text);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .24);
  cursor: pointer;
  user-select: none;
}

.slot.active,
.inventory-slot.selected {
  border-color: var(--blue);
  background: rgba(37, 91, 138, .72);
}

.slot.danger.active,
.inventory-slot.danger.selected {
  border-color: var(--danger);
  background: rgba(118, 34, 46, .78);
}

.slot-num {
  position: absolute;
  left: 7px;
  top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.slot-icon {
  font-size: 24px;
  line-height: 1;
}

.slot-label {
  max-width: 64px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-controls {
  display: none;
}

body.mobile-play {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

body.mobile-play #world {
  touch-action: none;
}

@media (max-width: 900px) {
  .right-panel {
    display: none;
  }

  .prompt {
    max-width: calc(100vw - 32px);
  }

  .hotbar {
    grid-template-columns: repeat(9, minmax(38px, 1fr));
    width: calc(100vw - 16px);
    gap: 4px;
  }

  .slot {
    height: 58px;
  }

  .hotbar .slot-label {
    display: none;
  }

  .edit-grid,
  .row,
  .inventory-hotbar,
  .inventory-grid,
  .start-layout,
  .world-list {
    grid-template-columns: 1fr;
  }

  .start-menu {
    align-items: start;
    padding: 12px;
  }

  .start-shell {
    max-height: calc(100vh - 24px);
  }

  .start-hero,
  .start-section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .start-hero {
    min-height: 0;
    padding: 18px;
  }

  .start-top,
  .start-top div {
    align-items: flex-start;
    flex-direction: column;
  }

  .start-top div {
    width: 100%;
    gap: 6px;
  }

  .start-top button {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
  }

  .start-hero::before,
  .start-hero::after {
    display: none;
  }

  .start-hero h1 {
    font-size: 38px;
  }

  .inventory-slot {
    min-height: 52px;
  }
}

@media (hover: none) and (pointer: coarse) {
  .prompt {
    top: 10px;
    padding: 9px 12px;
    font-size: 12px;
  }

  .prompt span {
    display: none;
  }

  .open-link {
    display: none;
  }

  .hotbar {
    bottom: calc(14px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(9, minmax(34px, 1fr));
    width: calc(100vw - 16px);
    gap: 4px;
  }

  .slot {
    height: 48px;
    padding: 6px 4px;
  }

  .slot-icon {
    font-size: 17px;
  }

  .slot-num {
    left: 5px;
    top: 4px;
    font-size: 9px;
  }

  .mobile-controls {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: none;
    pointer-events: none;
  }

  body.mobile-play .mobile-controls {
    display: block;
  }

  body.mobile-play.menu-open .mobile-controls {
    display: none;
  }

  .mobile-stick {
    position: absolute;
    left: 14px;
    bottom: calc(82px + env(safe-area-inset-bottom));
    width: 112px;
    height: 112px;
    border: 2px solid rgba(255, 255, 255, .2);
    border-radius: 999px;
    background: rgba(5, 12, 9, .62);
    box-shadow: 0 18px 42px rgba(0, 0, 0, .28);
    pointer-events: auto;
    touch-action: none;
  }

  .mobile-stick span {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 42px;
    height: 42px;
    border-radius: 999px;
    background: rgba(242, 255, 246, .88);
    box-shadow: 0 10px 22px rgba(0, 0, 0, .26);
    transform: translate(-50%, -50%);
  }

  .mobile-actions {
    position: absolute;
    right: 14px;
    bottom: calc(82px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(2, minmax(72px, 1fr));
    gap: 8px;
    width: min(260px, calc(100vw - 150px));
    pointer-events: auto;
  }

  .mobile-actions button {
    min-height: 50px;
    border-color: rgba(255, 255, 255, .18);
    background: rgba(8, 18, 14, .82);
    box-shadow: 0 14px 32px rgba(0, 0, 0, .24);
    color: var(--text);
    padding: 8px;
  }

  .mobile-actions button:first-child {
    background: #21643a;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  .hotbar {
    bottom: calc(14px + env(safe-area-inset-bottom));
    left: 50%;
    grid-template-columns: repeat(9, minmax(28px, 1fr));
    width: min(52vw, calc(100vw - 390px));
    min-width: 320px;
  }

  .slot {
    height: 46px;
  }

  .mobile-stick {
    left: 14px;
    bottom: calc(50px + env(safe-area-inset-bottom));
    width: 96px;
    height: 96px;
  }

  .mobile-actions {
    right: 14px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: min(228px, 28vw);
  }

  .mobile-actions button {
    min-height: 42px;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  .hotbar {
    bottom: calc(14px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(9, minmax(32px, 1fr));
    width: calc(100vw - 16px);
  }

  .mobile-stick {
    left: 14px;
    bottom: calc(98px + env(safe-area-inset-bottom));
  }

  .mobile-actions {
    right: 14px;
    bottom: calc(98px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(2, minmax(90px, 1fr));
    width: min(54vw, 300px);
  }
}
