:root {
  --ink: #fff;
  --ink-2: rgba(255, 255, 255, .78);
  --ink-3: rgba(255, 255, 255, .55);
  --glass: rgba(10, 18, 38, .55);
  --line: rgba(255, 255, 255, .16);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1a33; }
body {
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}
#sky {
  --sky-top: #4f93ee;
  --sky-bot: #b7dcff;
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bot) 70%);
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#water-tint { position: fixed; inset: 0; background: rgba(20, 60, 140, .38); opacity: 0; pointer-events: none; transition: opacity .2s; }
#water-tint.on { opacity: 1; }
[hidden] { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
.crosshair { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; mix-blend-mode: difference; }
.crosshair::before, .crosshair::after { content: ""; position: absolute; background: #fff; }
.crosshair::before { left: 10px; top: 0; width: 2px; height: 22px; }
.crosshair::after { left: 0; top: 10px; width: 22px; height: 2px; }
.info { position: absolute; left: 12px; top: calc(10px + env(safe-area-inset-top)); padding: 6px 10px; border-radius: 8px; background: rgba(0, 0, 0, .4); font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; }
.status { position: absolute; right: 12px; top: calc(10px + env(safe-area-inset-top)); display: flex; gap: 8px; }
.status span { padding: 5px 10px; border-radius: 999px; background: rgba(0, 0, 0, .35); font-size: 12px; }
.hotbar {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .38);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
  pointer-events: auto;
}
.hotbar button {
  position: relative;
  width: 50px;
  height: 50px;
  padding: 4px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  cursor: pointer;
}
.hotbar button.on { background: rgba(255, 255, 255, .22); box-shadow: inset 0 0 0 2.5px #fff; }
.hotbar img { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.hotbar span { position: absolute; left: 4px; top: 2px; font-size: 10px; color: var(--ink-3); }
.blockname {
  position: absolute;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  font-size: 15px;
  font-weight: 700;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .5);
  opacity: 0;
  transition: opacity .3s;
}
.blockname.show { opacity: 1; }
.chat { position: absolute; left: 12px; bottom: calc(86px + env(safe-area-inset-bottom)); width: min(420px, 70vw); }
.chat .log { display: flex; flex-direction: column; gap: 3px; max-height: 40vh; overflow: hidden; }
.chat p { margin: 0; padding: 4px 8px; border-radius: 6px; background: rgba(0, 0, 0, .4); font-size: 14px; line-height: 1.45; transition: opacity 1s; word-break: break-word; align-self: flex-start; }
.chat p b { color: #ffe27a; font-weight: 600; }
.chat p.sys { color: #9fe0ff; }
.chat p.old { opacity: 0; }
.chat.open p.old { opacity: 1; }
.chat form { margin-top: 6px; pointer-events: auto; }
.chat input {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font: 15px var(--font);
  outline: 2px solid rgba(255, 255, 255, .3);
  -webkit-user-select: text;
  user-select: text;
}
.hint {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .45);
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .6s;
}
.hint.show { opacity: 1; }

/* ---------- touch controls ---------- */
.touch { position: fixed; inset: 0; z-index: 1; }
.touch-zone { position: absolute; inset: 0; }
.joy {
  position: absolute;
  left: 0;
  top: 0;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .3);
  transform: translate(40px, calc(100vh - 230px));
  opacity: .5;
  pointer-events: none;
  transition: opacity .2s;
}
.joy.on { opacity: 1; }
.joy i { position: absolute; left: 45px; top: 45px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 255, 255, .55); }
.tb { position: absolute; display: flex; gap: 10px; }
.tb-top { right: 12px; top: calc(44px + env(safe-area-inset-top)); }
.tb-right { right: 16px; bottom: calc(92px + env(safe-area-inset-bottom)); flex-direction: column; align-items: center; }
.tb button {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 14px;
  background: rgba(0, 0, 0, .35);
  color: #fff;
  font: 700 18px var(--font);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .3);
}
.tb button.big { width: 68px; height: 68px; border-radius: 50%; font-size: 24px; }
.tb button:active { background: rgba(255, 255, 255, .3); }

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
  touch-action: pan-y;
  z-index: 5;
}
#title { background: radial-gradient(80% 70% at 50% 40%, rgba(5, 12, 30, .1), rgba(5, 12, 30, .45)); }
#pause, #picker { background: rgba(5, 10, 24, .5); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.title-wrap { width: min(440px, 100%); text-align: center; }
.logo {
  margin: 0;
  font-size: clamp(54px, 13vw, 88px);
  font-weight: 900;
  letter-spacing: .04em;
  line-height: 1;
  text-shadow:
    0 1px 0 #e8eef6, 0 2px 0 #d2dae6, 0 3px 0 #bcc6d4, 0 4px 0 #a6b1c2, 0 5px 0 #919cb0,
    0 6px 0 #7c879d, 0 12px 26px rgba(0, 20, 60, .5);
}
.tagline { margin: 14px 0 22px; color: var(--ink); font-size: 15px; text-shadow: 0 1px 10px rgba(0, 20, 60, .5); }
.card {
  display: grid;
  gap: 12px;
  padding: 22px;
  border-radius: 22px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  box-shadow: inset 0 0 0 1px var(--line), 0 30px 70px rgba(0, 10, 30, .35);
  text-align: left;
}
.field { display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); }
.field input {
  height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  font: 16px var(--font);
  box-shadow: inset 0 0 0 1px var(--line);
  -webkit-user-select: text;
  user-select: text;
}
.field input:focus { outline: 2px solid #6fd25a; }
.btn {
  --b: rgba(255, 255, 255, .12);
  --bd: rgba(0, 0, 0, .28);
  display: grid;
  gap: 3px;
  justify-items: center;
  width: 100%;
  min-height: 52px;
  padding: 10px 16px;
  border: 0;
  border-radius: 14px;
  background: var(--b);
  color: #fff;
  font: 600 15px var(--font);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--bd);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.btn b { font-size: 17px; }
.btn small { font-size: 12px; font-weight: 400; opacity: .85; }
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 5px 0 var(--bd); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--bd); }
.btn-green { --b: #4caf3c; --bd: #2c7422; }
.btn-blue { --b: #2f8cf0; --bd: #1c5da8; }
.btn-glass { --b: rgba(255, 255, 255, .1); box-shadow: inset 0 0 0 1px var(--line), 0 3px 0 rgba(0, 0, 0, .2); }
.btn-sm { min-height: 40px; font-size: 13px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.panel { display: grid; gap: 12px; padding: 14px; border-radius: 14px; background: rgba(0, 0, 0, .22); }
.range { display: grid; grid-template-columns: 64px 1fr 58px; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }
.range input { width: 100%; accent-color: #6fd25a; }
.range output { text-align: right; font-variant-numeric: tabular-nums; }
.help p { margin: 0; font-size: 13px; line-height: 1.7; color: var(--ink-2); }
.err { margin: 0; color: #ffb4a8; font-size: 13px; }
.foot { margin: 18px 0 0; font-size: 12px; line-height: 1.8; color: var(--ink-2); text-shadow: 0 1px 6px rgba(0, 0, 0, .5); }
.loading-box { text-align: center; }
.loading-box p { margin: 0 0 14px; letter-spacing: .25em; color: var(--ink-2); }
.bar { width: 220px; height: 14px; padding: 2px; border: 2px solid rgba(255, 255, 255, .75); }
.bar i { display: block; width: 0; height: 100%; background: repeating-linear-gradient(90deg, #6fd25a 0 10px, transparent 10px 12px); transition: width .2s; }
#loading { background: #0b1a33; }
.pause-card { width: min(360px, 100%); }
.pause-card h2, .picker-card h2 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.picker-card { width: min(560px, 100%); }
.picker-head { display: flex; align-items: center; justify-content: center; position: relative; }
.picker-head .x { position: absolute; right: -6px; top: -6px; width: 36px; height: 36px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .1); color: #fff; font-size: 16px; cursor: pointer; }
.sub { margin: 0; text-align: center; font-size: 13px; color: var(--ink-3); }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.picker-grid button {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 10px 4px 8px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, .07);
  color: var(--ink-2);
  font: 12px var(--font);
  cursor: pointer;
}
.picker-grid button:hover { background: rgba(255, 255, 255, .16); color: #fff; }
.picker-grid img { width: 44px; height: 44px; image-rendering: pixelated; }
.toast {
  position: fixed;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top));
  transform: translate(-50%, -8px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(10, 18, 36, .85);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 14px;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 600px) {
  .hotbar { gap: 2px; padding: 3px; }
  .hotbar button { width: 36px; height: 36px; padding: 2px; border-radius: 6px; }
  .hotbar span { display: none; }
  .hint { display: none; }
  .chat { bottom: calc(60px + env(safe-area-inset-bottom)); width: 60vw; }
  .chat p { font-size: 12px; }
  .tb-right { bottom: calc(70px + env(safe-area-inset-bottom)); }
}

/* ---------- survival HUD ---------- */
#hurt { position: fixed; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(200, 0, 0, .55)); z-index: 1; }
.bars { position: absolute; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: 476px; display: grid; gap: 3px; }
.bars .row { display: flex; justify-content: space-between; }
.icons { display: flex; gap: 1px; }
.icons i { position: relative; width: 18px; height: 18px; background-size: 100% 100%; image-rendering: pixelated; }
.icons i.half::after { content: ""; position: absolute; inset: 0; background-size: 100% 100%; image-rendering: pixelated; }
.hearts i { background-image: var(--heart-empty); }
.hearts i.full { background-image: var(--heart); }
.hearts i.half::after { background-image: var(--heart); clip-path: inset(0 50% 0 0); }
.food { flex-direction: row-reverse; }
.food i { background-image: var(--food-empty); }
.food i.full { background-image: var(--food); }
.food i.half::after { background-image: var(--food); clip-path: inset(0 0 0 50%); }
.air { flex-direction: row-reverse; justify-content: flex-start; }
.air i { background-image: var(--bubble); opacity: 0; }
.air i.full { opacity: 1; }
.hotbar b { position: absolute; right: 4px; bottom: 2px; font-size: 13px; font-weight: 800; text-shadow: 1px 1px 0 #000; }
.dur { position: absolute; left: 5px; right: 5px; bottom: 4px; height: 3px; background: #000; }
.dur em { display: block; height: 100%; }

/* ---------- inventory screens ---------- */
#inv { background: rgba(5, 10, 24, .55); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); touch-action: none; }
.inv-card { width: min(520px, 100%); gap: 14px; }
.inv-head { display: flex; align-items: center; gap: 10px; }
.inv-head h2 { margin: 0; font-size: 20px; flex: 1; }
.inv-head .x { width: 36px; height: 36px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .1); color: #fff; font-size: 16px; cursor: pointer; }
.chip { height: 32px; padding: 0 12px; border: 0; border-radius: 999px; background: rgba(255, 255, 255, .1); color: var(--ink-2); font: 13px var(--font); cursor: pointer; }
.chip.on { background: #4caf3c; color: #fff; }
.inv-top { display: flex; justify-content: center; padding: 6px 0 4px; }
.slots { display: grid; grid-template-columns: repeat(var(--w), 1fr); gap: 4px; }
.slots.hot { margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.slot {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 3px;
  border: 0;
  border-radius: 7px;
  background: rgba(0, 0, 0, .35);
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, .35), inset 0 -1px 0 rgba(255, 255, 255, .08);
  cursor: pointer;
  touch-action: none;
}
.slot:hover { background: rgba(255, 255, 255, .14); }
.slot img { width: 100%; height: 100%; image-rendering: pixelated; display: block; pointer-events: none; }
.slot img:not([src]) { visibility: hidden; }
.slot b { position: absolute; right: 3px; bottom: 1px; font-size: 13px; font-weight: 800; text-shadow: 1px 1px 0 #000; pointer-events: none; }
.slot .dur { left: 4px; right: 4px; bottom: 3px; }
.slot.big { width: 60px; }
.craft, .furnace { display: flex; align-items: center; gap: 16px; }
.craft .slots { width: calc(var(--w) * 52px); }
.arrow { font-size: 26px; color: var(--ink-3); position: relative; }
.arrow.progress em { position: absolute; left: 0; top: 50%; height: 4px; margin-top: -2px; background: #fff; width: 0; border-radius: 2px; }
.fcol { display: grid; justify-items: center; gap: 6px; width: 52px; }
.fcol .slot { width: 52px; }
.flame { position: relative; width: 16px; height: 18px; background: rgba(255, 255, 255, .12); clip-path: polygon(50% 0, 100% 60%, 80% 100%, 20% 100%, 0 60%); }
.flame em { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(0deg, #ff7a1a, #ffd34d); }
#cursor-stack { position: fixed; left: 0; top: 0; width: 48px; height: 48px; pointer-events: none; z-index: 60; }
#cursor-stack img { width: 100%; height: 100%; image-rendering: pixelated; }
#cursor-stack b { position: absolute; right: 2px; bottom: 0; font-size: 14px; font-weight: 800; text-shadow: 1px 1px 0 #000; }
.seg { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.seg span { flex: 1; }
.seg button { height: 32px; padding: 0 16px; border: 0; border-radius: 9px; background: rgba(255, 255, 255, .1); color: var(--ink-2); font: 600 14px var(--font); cursor: pointer; }
.seg button.on { background: #4caf3c; color: #fff; }
#death { background: rgba(120, 0, 0, .45); }
.death { width: min(360px, 100%); display: grid; gap: 12px; text-align: center; }
.death h2 { margin: 0; font-size: 40px; text-shadow: 0 3px 0 rgba(0, 0, 0, .4); }
.death p { margin: 0; color: var(--ink-2); }
.death .note { font-size: 12px; color: var(--ink-3); }

@media (max-width: 600px) {
  .bars { width: 340px; bottom: calc(46px + env(safe-area-inset-bottom)); }
  .icons i { width: 13px; height: 13px; }
  .inv-card { padding: 14px; }
  .slots { gap: 3px; }
  .craft .slots { width: calc(var(--w) * 44px); }
}
