:root {
  --ink: #f7f4e8;
  --muted: #c6c0a9;
  --panel: rgba(20, 24, 20, 0.84);
  --panel-strong: rgba(18, 20, 17, 0.94);
  --border: rgba(247, 244, 232, 0.18);
  --line: rgba(247, 244, 232, 0.12);
  --green: #7fc36a;
  --leaf: #3f8f54;
  --water: #5eb6d9;
  --amber: #f2c45d;
  --clay: #c87758;
  --stone: #9da19d;
  --danger: #ef776d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background: #6ba7cf;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.experiment {
  position: fixed;
  inset: 0;
  min-width: 320px;
  isolation: isolate;
}

#world,
#world canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

#world canvas {
  cursor: crosshair;
  touch-action: none;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.hud {
  position: fixed;
  z-index: 4;
  top: 16px;
  left: 16px;
  width: min(330px, calc(100vw - 32px));
  padding: 14px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  color: #bdeaff;
  font-size: 12px;
  font-weight: 780;
  text-decoration: none;
  text-transform: uppercase;
}

.back-link:hover {
  color: var(--amber);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  margin-top: 4px;
  font-size: 28px;
  line-height: 1.05;
  font-weight: 800;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
  font-weight: 780;
}

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

.status-grid div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
}

.status-grid strong {
  display: block;
  min-width: 0;
  margin-top: 2px;
  overflow: hidden;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bars {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.meter {
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 18px;
}

.meter span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.meter div {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.26);
}

.meter i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--danger), var(--amber), var(--green));
  transition: width 140ms ease;
}

.crafting {
  position: fixed;
  z-index: 4;
  top: 16px;
  right: 16px;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 138px);
  padding: 14px;
  overflow: hidden;
}

.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  cursor: pointer;
}

.icon-button span,
.icon-button::before,
.icon-button::after {
  content: "";
  position: absolute;
  display: block;
}

.icon-button span {
  width: 16px;
  height: 16px;
  border: 2px solid var(--amber);
  border-right-color: transparent;
  border-radius: 50%;
}

.icon-button::before {
  right: 7px;
  top: 8px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid var(--amber);
  transform: rotate(-22deg);
}

.icon-button:hover,
.recipe:hover,
.slot:hover {
  border-color: rgba(247, 244, 232, 0.34);
  background: rgba(255, 255, 255, 0.11);
}

.recipe-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 200px);
  margin-top: 12px;
  overflow: auto;
  padding-right: 2px;
}

.recipe {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 9px;
  min-height: 50px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.recipe:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.recipe .swatch,
.slot .swatch {
  display: block;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.14);
}

.recipe .swatch {
  width: 34px;
  height: 34px;
}

.recipe strong,
.recipe small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recipe strong {
  font-size: 13px;
}

.recipe small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.recipe code {
  min-width: 30px;
  color: var(--amber);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 760;
  text-align: right;
}

.crosshair {
  position: fixed;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.42);
}

.crosshair::before {
  left: 10px;
  top: 0;
  width: 2px;
  height: 22px;
}

.crosshair::after {
  left: 0;
  top: 10px;
  width: 22px;
  height: 2px;
}

.hotbar {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: 16px;
  display: grid;
  grid-template-columns: repeat(9, 58px);
  gap: 7px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 9px;
  overflow-x: auto;
  transform: translateX(-50%);
}

.slot {
  position: relative;
  display: grid;
  grid-template-rows: 30px 1fr;
  place-items: center;
  gap: 4px;
  width: 58px;
  height: 60px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  cursor: pointer;
}

.slot.active {
  border-color: var(--amber);
  box-shadow: inset 0 0 0 1px rgba(242, 196, 93, 0.7), 0 0 18px rgba(242, 196, 93, 0.18);
}

.slot .swatch {
  width: 28px;
  height: 28px;
}

.slot strong {
  position: absolute;
  left: 5px;
  top: 4px;
  color: rgba(255, 255, 255, 0.72);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 800;
}

.slot span:last-child {
  max-width: 48px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.play-button,
.loading {
  position: fixed;
  z-index: 5;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.play-button {
  min-width: 150px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid rgba(247, 244, 232, 0.26);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
}

.play-button.hidden {
  display: none;
}

.loading {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--muted);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 720;
}

.loading.hidden {
  display: none;
}

.toast {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: 94px;
  max-width: min(340px, calc(100vw - 32px));
  min-height: 32px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 12px;
  font-weight: 720;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(189, 234, 255, 0.42);
  outline-offset: 2px;
}

@media (max-width: 840px) {
  .hud {
    top: 10px;
    left: 10px;
    width: min(300px, calc(100vw - 20px));
    padding: 11px;
  }

  .crafting {
    top: auto;
    right: 10px;
    bottom: 92px;
    width: min(300px, calc(100vw - 20px));
    max-height: 36vh;
    padding: 11px;
  }

  h1 {
    font-size: 23px;
  }

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

  .status-grid strong {
    font-size: 13px;
  }

  .recipe-list {
    max-height: calc(36vh - 54px);
  }

  .hotbar {
    bottom: 10px;
    grid-template-columns: repeat(9, 50px);
    gap: 5px;
    padding: 7px;
  }

  .slot {
    width: 50px;
    height: 54px;
  }
}

@media (max-width: 560px) {
  .crafting {
    display: none;
  }

  .hud {
    width: calc(100vw - 20px);
  }

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

  .status-grid div {
    padding: 7px 6px;
  }

  .status-grid span {
    font-size: 9px;
  }

  .status-grid strong {
    font-size: 11px;
  }

  .bars {
    display: none;
  }

  .hotbar {
    width: calc(100vw - 20px);
    transform: translateX(-50%);
  }
}
