:root {
  --ink: #09010f;
  --panel: rgba(16, 6, 28, 0.9);
  --line: #ff2fb9;
  --gold: #2de2e6;
  --gold-dim: #ff2fb9;
  --text: #f4e8ff;
  --muted: #a888c8;
  --hp: #ff2fb9;
  --mp: #2de2e6;
  --xp: #c080ff;
  --rare: #2de2e6;
  --magic: #39ff88;
  --unique: #ff2fb9;
  --bound: #c080ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  height: 100dvh;
  background: var(--ink);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
canvas#view {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}
#ui { pointer-events: none; }
#ui * { pointer-events: auto; }

.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 0%, #ff2fb9 0%, transparent 42%),
    linear-gradient(180deg, #2a0838 0%, #09010f 55%, #050108 100%);
  z-index: 20;
}
.screen.hidden { display: none; }
.panel {
  width: min(440px, 94vw);
  max-height: 94dvh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid #ff2fb9;
  padding: 22px 22px 18px;
  box-shadow: 0 0 24px rgba(255,47,185,.25), 0 16px 40px rgba(0,0,0,.55);
}
.brand {
  text-align: center;
  letter-spacing: .28em;
  font-size: 22px;
  color: var(--gold);
  margin-bottom: 4px;
}
.ver {
  text-align: center;
  color: #ff2fb9;
  letter-spacing: .18em;
  font-size: 12px;
  margin-bottom: 4px;
}
.sub {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .12em;
  margin-bottom: 6px;
}
.sub.dim { margin-bottom: 14px; opacity: .8; letter-spacing: .08em; font-size: 11px; }
.about-box { margin-top: 12px; border: 1px solid #3a2048; padding: 8px 10px; }
.about-box summary { cursor: pointer; color: #2de2e6; letter-spacing: .08em; font-size: 12px; }
.about-body { font-size: 12px; color: #d8d0c0; line-height: 1.45; margin-top: 8px; white-space: pre-wrap; }
.about-body h4 { color: #2de2e6; letter-spacing: .08em; font-weight: normal; margin: 10px 0 4px; }
.about-body ul { margin: 4px 0 8px 16px; }
.site { text-align: center; margin-top: 12px; font-size: 11px; color: var(--muted); }
.site a { color: #2de2e6; text-decoration: none; }
.text-pane {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: min(420px, 92vw); max-height: 80dvh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); padding: 14px;
  z-index: 18; display: none;
}
.text-pane.open { display: block; }
.text-pane h3 { font-weight: normal; letter-spacing: .12em; font-size: 13px; color: var(--gold); margin-bottom: 8px; }
.text-pane .cta, .text-pane .ghost { margin-top: 12px; width: 100%; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; letter-spacing: .06em; }
input[type=text], input[type=password] {
  width: 100%; padding: 8px 10px;
  background: #0a0b10; color: var(--text);
  border: 1px solid #3a3348; font-family: inherit;
}
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.sprites {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 8px 0 10px;
}
.spr {
  background: #0a0b10;
  border: 1px solid #3a3348;
  height: 64px;
  cursor: pointer;
  position: relative;
}
.spr.sel { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.spr canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.colors { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.colors label { text-align: center; font-size: 10px; margin: 0; }
.colors input[type=color] {
  width: 100%; height: 28px; border: 1px solid #3a3348; background: #0a0b10; padding: 0; cursor: pointer;
}
button.cta, button.ghost {
  width: 100%; margin-top: 12px; padding: 10px;
  letter-spacing: .14em; cursor: pointer; font-family: inherit;
}
button.cta { background: #ff2fb9; color: #120814; border: 1px solid #ff7ad4; font-weight: 700; }
button.ghost { background: transparent; color: #2de2e6; border: 1px solid #2de2e6; }
.err { color: #e07a6a; font-size: 13px; min-height: 18px; margin-top: 8px; text-align: center; }
.hint { color: var(--muted); font-size: 11px; line-height: 1.45; margin-top: 10px; }

#hud {
  position: fixed; left: 10px; right: 10px; bottom: 10px;
  display: flex; gap: 8px; align-items: flex-end; z-index: 8;
}
.bars {
  flex: 1; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); padding: 8px 10px;
}
.who { font-size: 13px; color: var(--gold); letter-spacing: .08em; }
.bar { height: 10px; background: #1a1214; margin-top: 5px; border: 1px solid #000; position: relative; }
.bar > i { display: block; height: 100%; }
.bar.hp > i { background: linear-gradient(#ff6ad4,#ff2fb9); }
.bar.mp > i { background: linear-gradient(#7af0f2,#2de2e6); }
.bar.xp > i { background: linear-gradient(#d0a0ff,#8040c8); }
.bar span { position: absolute; inset: 0; font-size: 9px; text-align: center; line-height: 10px; color: #fff; font-family: sans-serif; }
#minimap {
  width: 112px; height: 112px;
  border: 1px solid var(--line); background: #0a0b10;
  image-rendering: pixelated;
}
#chat {
  position: fixed; left: 10px; bottom: 92px; width: min(340px, 72vw);
  z-index: 8;
  background: rgba(12, 4, 20, 0.72);
  border: 1px solid rgba(255,47,185,.35);
  padding: 8px;
  pointer-events: auto;
}
#log {
  height: 160px;
  overflow-y: auto;
  overflow-x: hidden;
  font-size: 12px; line-height: 1.4; color: #f0e6ff;
  text-shadow: 0 1px 2px #000;
  pointer-events: auto;
  -webkit-overflow-scrolling: touch;
}
#log div { margin-top: 2px; }
#log .sys { color: var(--gold); }
#log .drop { color: #6bcf7a; }
#log .rare { color: #6eb4e8; }
#chat form { display: flex; margin-top: 6px; pointer-events: auto; gap: 6px; }
#chat input {
  flex: 1; background: var(--panel); border: 1px solid var(--line);
  color: var(--text); padding: 8px; font-family: inherit; font-size: 16px;
  user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
#chat button {
  width: auto; padding: 8px 12px; margin: 0;
  background: #ff2fb9; color: #120814; border: 1px solid #ff7ad4;
  letter-spacing: .08em; cursor: pointer; font-family: inherit;
  touch-action: manipulation;
}
input, textarea, button, select {
  touch-action: manipulation;
  user-select: text;
  -webkit-user-select: text;
}
#inv {
  position: fixed; right: 10px; top: 10px; width: min(280px, 92vw);
  background: var(--panel); border: 1px solid var(--line); padding: 10px;
  z-index: 9; display: none;
}
#inv.open { display: block; }
#skills, #shopui, #smithui, #chestui {
  position: fixed; left: 10px; top: 48px; width: min(300px, 92vw);
  background: var(--panel); border: 1px solid var(--line); padding: 10px;
  z-index: 9; display: none; max-height: 60vh; overflow: auto;
}
#skills.open, #shopui.open, #smithui.open, #chestui.open { display: block; }
#skills h3, #shopui h3, #smithui h3, #chestui h3 { font-weight: normal; letter-spacing: .12em; font-size: 13px; color: var(--gold); margin-bottom: 8px; }
.chest-grid { grid-template-columns: repeat(8, 1fr); max-height: 42vh; overflow: auto; }
.craft-qty { display: flex; gap: 6px; margin-bottom: 8px; }
.craft-qty button { flex: 1; padding: 8px; background: #120814; color: #2de2e6; border: 1px solid #3a2048; }
.recipe.picked { border-color: #ff2fb9; background: #2a1020; }
.sk { font-size: 12px; margin: 4px 0; color: #f0e6ff; }
.sk b { color: #2de2e6; }
.recipe, .listing { font-size: 11px; border: 1px solid #3a3348; padding: 6px; margin: 4px 0; cursor: pointer; }
.recipe:hover, .listing:hover { border-color: #2de2e6; }
.shop-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.shop-tabs button {
  flex: 1 1 30%; width: auto; padding: 6px 4px; margin: 0;
  font-size: 10px; letter-spacing: .04em;
  background: #120814; color: #2de2e6; border: 1px solid #3a2048;
}
.shop-tabs button.on { background: #ff2fb9; color: #120814; border-color: #ff2fb9; }
.recipe.locked { opacity: .45; }
.recipe .need { display: block; color: #a888c8; font-size: 10px; margin-top: 3px; }
#inv h3 { font-weight: normal; letter-spacing: .12em; font-size: 13px; color: var(--gold); margin-bottom: 8px; }
.slots { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.slot {
  aspect-ratio: 1; background: #0a0b10; border: 1px solid #3a3348;
  font-size: 9px; color: var(--muted); padding: 2px; overflow: hidden;
  cursor: pointer; position: relative;
}
.slot:hover { border-color: var(--gold-dim); }
.slot.r-magic { border-color: #4aa3ff; color: #4aa3ff; }
.slot.r-rare { border-color: #e8d44d; color: #e8d44d; }
.slot.r-unique { border-color: #ff9a3a; color: #ff9a3a; }
.slot.mat-copper { background: #3a2210; }
.slot.mat-iron { background: #2a3038; }
.slot.mat-steel, .slot.mat-coal { background: #1a1a1a; }
.slot.mat-oak { background: #2a1a0c; }
.slot.mat-pine { background: #142818; }
.slot.mat-ironwood { background: #241428; }
#tip b { display: block; margin-bottom: 4px; }
.eq { display: flex; gap: 4px; margin-bottom: 8px; }
.eq .slot { flex: 1; aspect-ratio: auto; height: 42px; }
#tip {
  position: fixed; z-index: 30; display: none; max-width: 220px;
  background: #120f16; border: 1px solid var(--gold-dim); padding: 8px 10px;
  font-size: 12px; pointer-events: none; line-height: 1.4;
}
#tip b { color: var(--gold); display: block; margin-bottom: 4px; }
#menubar {
  position: fixed; top: calc(6px + env(safe-area-inset-top, 0px)); left: 8px;
  z-index: 12; display: none; gap: 4px; pointer-events: auto;
  align-items: flex-start;
}
body.playing #menubar { display: flex; }
.menu-group { position: relative; }
.menu-top, .menu-drop button {
  background: rgba(16,6,28,.88); color: #2de2e6; border: 1px solid #ff2fb9;
  font-family: inherit; font-size: 11px; letter-spacing: .1em;
  padding: 6px 10px; cursor: pointer;
}
#file-drop, .menu-drop {
  position: absolute; top: 100%; left: 0; min-width: 160px;
  background: rgba(16,6,28,.96); border: 1px solid #ff2fb9;
  flex-direction: column;
  display: none !important;
}
#file-drop.open, .menu-drop.open {
  display: flex !important;
}
.menu-drop[hidden] { display: none !important; }
.menu-drop button { border: 0; border-bottom: 1px solid #3a2048; text-align: left; width: 100%; }
#settings, #help-pane {
  position: fixed; left: 50%; top: 18%; transform: translateX(-50%);
  width: min(320px, 92vw); background: var(--panel); border: 1px solid var(--line);
  padding: 14px; z-index: 13; display: none;
}
#settings.open, #help-pane.open { display: block; }
#settings label { display: block; margin: 8px 0; font-size: 13px; color: #f0e6ff; }
#help-pane p { font-size: 13px; color: #d8d0c0; margin: 8px 0; line-height: 1.4; }
body.hide-help #help { display: none; }
body.hide-map #minimap { display: none; }
#online {
  position: fixed; top: calc(36px + env(safe-area-inset-top, 0px)); left: 10px; z-index: 8;
  font-size: 13px; color: #2de2e6; letter-spacing: .1em;
  text-shadow: 0 1px 2px #000;
}
#statline {
  position: fixed; top: calc(52px + env(safe-area-inset-top, 0px)); left: 10px; z-index: 8;
  font-size: 11px; color: #2de2e6; letter-spacing: .04em;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
#dead {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(10,6,8,.72); z-index: 15; flex-direction: column; gap: 12px;
}
#dead.open { display: flex; }
#help {
  position: fixed; left: 50%; transform: translateX(-50%); top: 8px;
  font-size: 11px; color: #7a7064; letter-spacing: .04em; z-index: 7;
  text-shadow: 0 1px 2px #000; pointer-events: none; text-align: center;
}
.place-mode canvas#view { cursor: cell; }

#target-plate {
  position: fixed; top: calc(28px + env(safe-area-inset-top, 0px)); left: 50%;
  transform: translateX(-50%);
  z-index: 8; min-width: 140px; text-align: center;
  background: var(--panel); border: 1px solid #ff2fb9;
  padding: 6px 12px; font-size: 12px; letter-spacing: .08em;
  color: #2de2e6; pointer-events: none;
}
#target-plate[hidden] { display: none; }

#actbar {
  position: fixed;
  right: calc(10px + env(safe-area-inset-right, 0px));
  bottom: calc(118px + env(safe-area-inset-bottom, 0px));
  z-index: 9; display: flex; flex-direction: column; gap: 8px;
}
#actbar .act {
  width: 58px; height: 58px; border-radius: 50%;
  background: rgba(16,6,28,.88); color: #2de2e6;
  border: 2px solid #2de2e6; font-family: inherit; font-size: 11px;
  letter-spacing: .08em; cursor: pointer;
}
#actbar .act:active, #actbar .act.on { background: #ff2fb9; color: #120814; border-color: #ff2fb9; }

#hud {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#online { top: calc(8px + env(safe-area-inset-top, 0px)); }
#help { top: calc(6px + env(safe-area-inset-top, 0px)); }

@media (pointer: coarse), (max-width: 700px) {
  #help { display: none; }
  #chat {
    left: 8px; bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    width: min(240px, 58vw);
  }
  #log { height: 120px; font-size: 11px; }
  #chat input { font-size: 16px; padding: 8px; }
  #hud { left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  #minimap { width: 84px; height: 84px; }
  .bars { padding: 8px; }
  .bar { height: 12px; }
  .bar span { line-height: 12px; }
  #inv, #chestui, #shopui, #smithui, #skills {
    left: 8px; right: 8px; top: auto;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 42vh;
  }
  #tip { max-width: min(220px, 70vw); font-size: 12px; }
  .slots { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .slot { font-size: 10px; min-height: 44px; }
  #actbar { bottom: calc(108px + env(safe-area-inset-bottom, 0px)); }
  #actbar .act { width: 64px; height: 64px; }
  .panel { max-height: 92dvh; overflow: auto; -webkit-overflow-scrolling: touch; }
  .sprites { grid-template-columns: repeat(5, 1fr); }
  .spr { height: 56px; }
  button.cta, button.ghost { min-height: 44px; }
  input[type=text], input[type=password] { font-size: 16px; }
}
