/* UI layer for print("Hello, Miner") — dark translucent panels over the 3D scene. */

:root {
  --panel: rgba(28, 30, 36, .86);
  --panel-solid: #1c1e24;
  --panel-2: rgba(38, 41, 49, .92);
  --line: rgba(255, 255, 255, .08);
  --line-2: rgba(255, 255, 255, .14);
  --fg: #e8eaef;
  --fg-dim: rgba(232, 234, 239, .55);
  --fg-faint: rgba(232, 234, 239, .3);
  --err: #f26b5b;
  --ok: #5ccc8a;
  --gold: #f2c94c;
  --blur: blur(10px);
  --r: 10px;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease: cubic-bezier(.2, .8, .3, 1);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --display: 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --lh: 20px;
  --fs: 13px;
}

.hm-ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  font-family: var(--display);
  color: var(--fg);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.hm-ui * { box-sizing: border-box; }
.hm-ui button, .hm-ui input, .hm-ui textarea { font-family: inherit; color: inherit; }
.hm-ui :focus-visible { outline: 2px solid #8fd9e6; outline-offset: 2px; border-radius: 4px; }

.panel {
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .32);
}

.btn {
  pointer-events: auto;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .18s var(--ease), transform .2s var(--spring);
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .12); }
.btn:active:not(:disabled) { transform: scale(.96); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: #1c1e24; border-color: transparent; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #ffd75e; }

.icon-btn {
  pointer-events: auto;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  transition: background .18s var(--ease), transform .2s var(--spring);
}
.icon-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .13); }
.icon-btn:active:not(:disabled) { transform: scale(.92); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }

/* ---------- HUD ---------- */

.hud-ores {
  position: absolute; top: 14px; left: 14px; z-index: 9000;
  display: flex; gap: 6px; padding: 8px 10px;
  pointer-events: auto;
}
.ore {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 8px 2px 2px;
  border-radius: 7px;
  transition: background .2s var(--ease);
}
.ore.dim { opacity: .32; }
.ore-gem { display: block; filter: drop-shadow(0 0 1px rgba(255, 255, 255, .35)); }
.ore-n { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; min-width: 14px; }
.ore.pop .ore-n { animation: pop .3s var(--spring); }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.45); color: var(--gold); } 100% { transform: scale(1); } }

.hud-right {
  position: absolute; top: 14px; right: 14px; z-index: 9000;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.hud-bar { display: flex; align-items: center; gap: 8px; padding: 7px 9px; }
.room-code {
  font-family: var(--mono); font-size: 13px; letter-spacing: .16em;
  padding: 0 6px; color: var(--gold);
}
.host-tag { font-size: 11px; color: var(--fg-dim); padding-right: 4px; }
.chips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 320px; padding: 7px 9px; }
.chip {
  pointer-events: auto;
  display: flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 6px; border-radius: 999px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  font-size: 12px; cursor: pointer;
  transition: opacity .18s var(--ease), background .18s var(--ease);
}
.chip:hover { background: rgba(255, 255, 255, .12); }
.chip.off { opacity: .4; }
.chip-dot { width: 9px; height: 9px; border-radius: 50%; }

/* ---------- Toasts ---------- */

.toasts {
  position: absolute; z-index: 10500; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 7px;
}
.toast {
  pointer-events: auto;
  padding: 9px 15px; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
  animation: toast-in .26s var(--spring);
}
.toast.out { animation: toast-out .2s var(--ease) forwards; }
.toast-bar { width: 3px; height: 15px; border-radius: 2px; background: var(--gold); }
.toast.error .toast-bar { background: var(--err); }
.toast.error { color: var(--err); }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ---------- Lobby ---------- */

.lobby { position: absolute; inset: 0; z-index: 11000; pointer-events: auto; }
.lobby[hidden] { display: none; }

.lobby-scrim {
  position: absolute; inset: 0;
  background:
    linear-gradient(100deg, rgba(10, 11, 14, .94) 0%, rgba(10, 11, 14, .82) 26%, rgba(10, 11, 14, .3) 58%, rgba(10, 11, 14, .12) 100%),
    linear-gradient(to top, rgba(10, 11, 14, .55), transparent 34%);
}

.lobby-col {
  position: absolute; left: clamp(28px, 7vw, 104px); top: 50%;
  transform: translateY(-50%);
  width: min(520px, calc(100vw - 56px));
  animation: lobby-in .5s var(--ease) both;
}
@keyframes lobby-in { from { opacity: 0; transform: translateY(calc(-50% + 14px)); } to { opacity: 1; transform: translateY(-50%); } }

.lobby-eyebrow {
  font-size: 10px; letter-spacing: .34em; text-transform: uppercase;
  color: var(--fg-faint); margin-bottom: 14px;
}

.lobby-title {
  margin: 0; font-family: var(--mono); font-weight: 300;
  font-size: clamp(24px, 2.9vw, 36px); letter-spacing: -.01em;
  white-space: nowrap; color: var(--fg);
}
.lobby-title .t-fn { color: var(--fg); font-weight: 400; }
.lobby-title .t-p { color: var(--fg-faint); }
.lobby-title .t-s { color: var(--gold); }

.lobby-rule { height: 1px; background: var(--line-2); margin: 18px 0 14px; }

.lobby-sub {
  margin: 0 0 40px; font-size: 13px; line-height: 1.5;
  color: var(--fg-dim); max-width: 34ch;
}

.lobby-menu { display: flex; flex-direction: column; align-items: flex-start; }
.lobby-item {
  position: relative; pointer-events: auto;
  background: none; border: 0; padding: 13px 0 13px 18px; margin: 0;
  font-family: var(--display); font-size: 13px; font-weight: 500;
  letter-spacing: .2em; text-transform: uppercase;
  color: var(--fg-dim); cursor: pointer; text-align: left;
  transition: color .2s var(--ease), padding-left .24s var(--ease);
}
.lobby-item::before {
  content: ''; position: absolute; left: 0; top: 50%;
  width: 2px; height: 0; transform: translateY(-50%);
  background: var(--gold); border-radius: 2px;
  transition: height .24s var(--ease);
}
.lobby-item:hover, .lobby-item:focus-visible { color: var(--fg); padding-left: 24px; }
.lobby-item:hover::before, .lobby-item:focus-visible::before { height: 15px; }
.lobby-item.is-open { color: var(--fg); padding-left: 24px; }
.lobby-item.is-open::before { height: 22px; }
.lobby-item:focus-visible { outline: none; }
.lobby-item:focus-visible::after {
  content: ''; position: absolute; inset: 4px -8px; border-radius: 6px;
  border: 1px solid var(--line-2);
}

.lobby-panel {
  position: absolute; left: calc(100% + clamp(20px, 4vw, 56px)); bottom: 0;
  width: min(300px, 34vw); padding: 20px 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: 0 22px 50px rgba(0, 0, 0, .34);
  animation: panel-in .26s var(--ease) both;
}
.lobby-panel[hidden] { display: none; }
@keyframes panel-in {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: none; }
}
.lobby-panel-title {
  font-size: 10px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--fg-dim); margin-bottom: 16px;
}

.lobby-field { display: block; margin-bottom: 14px; }
.lobby-field > span {
  display: block; font-size: 10px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--fg-dim); margin-bottom: 7px;
}
.lobby-field input {
  width: 100%; padding: 10px 12px; font-size: 14px; color: var(--fg);
  background: rgba(0, 0, 0, .3); border: 1px solid var(--line); border-radius: 8px;
}
.lobby-field input::placeholder { color: var(--fg-faint); }
.lobby-field input.code-input {
  font-family: var(--mono); letter-spacing: .34em; text-transform: uppercase;
}
.lobby-go { width: 100%; padding: 11px; margin-top: 2px; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.sw {
  pointer-events: auto; width: 30px; height: 30px; border-radius: 9px;
  border: 2px solid transparent; cursor: pointer; padding: 0;
  transition: transform .22s var(--spring), border-color .18s var(--ease);
}
.sw:hover:not(:disabled) { transform: translateY(-3px); }
.sw[aria-pressed="true"] { border-color: var(--fg); transform: translateY(-3px); }
.sw:disabled { opacity: .22; cursor: not-allowed; }

.lobby-help { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 9px 16px; }
.lobby-help dt { font-family: var(--mono); font-size: 12px; color: var(--gold); white-space: nowrap; }
.lobby-help dd { margin: 0; font-size: 12px; color: var(--fg-dim); line-height: 1.45; }

.lobby-err { color: var(--err); font-size: 12px; min-height: 16px; margin-top: 10px; }

.lobby-hint {
  position: absolute; left: clamp(28px, 7vw, 104px); bottom: 26px;
  right: 28px;
  font-size: 9px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--fg-faint);
}

@media (max-height: 720px) {
  .lobby-col { top: 34px; transform: none; animation: none; }
  .lobby-sub { margin-bottom: 24px; }
  .lobby-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .lobby-col, .lobby-panel { animation: none; }
  .lobby-item, .lobby-item::before { transition: none; }
}

/* ---------- Code windows ---------- */

.win {
  position: absolute; pointer-events: auto;
  display: flex; flex-direction: column;
  min-width: 280px; min-height: 150px;
  overflow: hidden;
  animation: win-in .24s var(--spring);
}
@keyframes win-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.win[hidden] { display: none; }
.win-head {
  height: 30px; flex: 0 0 30px;
  display: flex; align-items: center; gap: 6px; padding: 0 6px;
  background: var(--pc); color: #14161a;
  cursor: grab; touch-action: none; user-select: none;
  border-radius: 9px 9px 0 0;
}
.win-head:active { cursor: grabbing; }
.win.running .win-head { animation: breathe 2.2s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 var(--pc-a); }
  50% { box-shadow: 0 0 16px 3px var(--pc-a); }
}
.win-title { flex: 1; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.win-head .icon-btn {
  width: 22px; height: 22px; border-radius: 6px;
  background: rgba(0, 0, 0, .18); border-color: rgba(0, 0, 0, .16); color: #14161a;
}
.win-head .icon-btn:hover:not(:disabled) { background: rgba(0, 0, 0, .34); }
.win-head .icon-btn:disabled { opacity: .35; }
.win-body { flex: 1; min-height: 0; background: rgba(20, 22, 27, .92); }
.win-foot {
  flex: 0 0 22px; display: flex; align-items: center; padding: 0 9px;
  font-family: var(--mono); font-size: 11px; color: var(--fg-faint);
  border-top: 1px solid var(--line); gap: 8px;
}
.win-foot.bad { color: var(--err); }
.win-grip {
  position: absolute; right: 0; bottom: 0; width: 16px; height: 16px;
  cursor: nwse-resize; touch-action: none;
  background:
    linear-gradient(135deg, transparent 48%, var(--line-2) 48%, var(--line-2) 58%, transparent 58%,
    transparent 70%, var(--line-2) 70%, var(--line-2) 80%, transparent 80%);
}
.win-dock {
  position: absolute; left: 14px; bottom: 14px;
  display: flex; gap: 7px; flex-wrap: wrap; max-width: 60vw;
}
.dock-chip {
  pointer-events: auto; display: flex; align-items: center; gap: 7px;
  padding: 6px 11px; border-radius: 8px; cursor: pointer;
  background: var(--panel); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--line); font-size: 12px;
  animation: toast-in .24s var(--spring);
}
.dock-chip:hover { border-color: var(--line-2); }
.dock-bar { width: 3px; height: 13px; border-radius: 2px; background: var(--pc); }

/* ---------- Editor ---------- */

.ed { position: relative; height: 100%; display: flex; overflow: hidden; font-family: var(--mono); font-size: var(--fs); line-height: var(--lh); }
.ed-gut {
  flex: 0 0 auto; position: relative; overflow: hidden;
  padding: 8px 6px 8px 8px; text-align: right;
  color: var(--fg-faint); background: rgba(0, 0, 0, .16);
  border-right: 1px solid var(--line); user-select: none;
}
.ed-gut-in { will-change: transform; }
.ed-gut i { display: block; font-style: normal; }
.ed-gut i.bad { color: var(--err); }
.ed-main { position: relative; flex: 1; min-width: 0; }
.ed-hl, .ed-ta, .ed-cursors {
  position: absolute; inset: 0; margin: 0;
  padding: 8px 10px;
  font-family: var(--mono); font-size: var(--fs); line-height: var(--lh);
  white-space: pre; tab-size: 4;
  border: 0;
}
.ed-hl { overflow: hidden; pointer-events: none; color: var(--fg); }
.ed-hl-in { will-change: transform; }
.ed-cursors { overflow: hidden; pointer-events: none; padding: 0; }
.ed-ta {
  overflow: auto; resize: none; background: transparent; color: transparent;
  caret-color: var(--fg); outline: none;
}
.ed-ta::selection { background: rgba(143, 217, 230, .28); }
.ed-ta:focus-visible { outline: none; }
.ed-hl .t-kw { color: #ffb454; }
.ed-hl .t-bi { color: #7fd4e8; }
.ed-hl .t-str { color: #b8d94a; }
.ed-hl .t-num { color: #f2c94c; }
.ed-hl .t-com { color: rgba(232, 234, 239, .32); font-style: italic; }
.ed-hl .t-op { color: rgba(232, 234, 239, .62); }
.ed-hl .t-id { color: var(--fg); }
.ed-hl .bad-line { text-decoration: underline wavy var(--err); text-decoration-skip-ink: none; text-underline-offset: 3px; }
.ed-exec { position: absolute; left: 0; right: 0; }
.ed-rc { position: absolute; width: 2px; }
.ed-rc-tag {
  position: absolute; top: -15px; left: -1px; white-space: nowrap;
  font-family: var(--display); font-size: 10px; font-weight: 600;
  padding: 1px 5px; border-radius: 4px 4px 4px 0; color: #14161a;
}
.ed-rs { position: absolute; border-radius: 2px; }
.ed-tip {
  position: absolute; z-index: 5; max-width: 300px;
  padding: 6px 9px; border-radius: 7px;
  background: #23262d; border: 1px solid var(--line-2);
  color: var(--err); font-family: var(--display); font-size: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .4); pointer-events: none;
}
.ed-pop {
  position: absolute; z-index: 6; min-width: 170px; max-height: 168px; overflow: auto;
  background: #23262d; border: 1px solid var(--line-2); border-radius: 8px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .45); padding: 4px;
}
.ed-pop div {
  padding: 4px 8px; border-radius: 5px; cursor: pointer;
  font-family: var(--mono); font-size: 12px; color: var(--fg-dim);
  display: flex; justify-content: space-between; gap: 10px;
}
.ed-pop div.sel { background: rgba(255, 255, 255, .1); color: var(--fg); }
.ed-pop em { font-style: normal; font-family: var(--display); font-size: 10px; color: var(--fg-faint); }

/* ---------- Overlays: tree + docs ---------- */

.scrim {
  position: absolute; inset: 0; z-index: 10000; pointer-events: auto;
  background: rgba(12, 14, 18, .5);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  animation: fade .2s var(--ease);
}
.scrim[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.tree-wrap {
  position: absolute; inset: 40px; display: flex; flex-direction: column; overflow: hidden;
  animation: lift .26s var(--spring);
}
.pane-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.pane-head h2 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }
.pane-inv { display: flex; gap: 10px; }
.tree-scroll { flex: 1; overflow: auto; position: relative; padding: 24px; }
.tree-canvas { position: relative; margin: 0 auto; }
.tree-canvas svg { position: absolute; inset: 0; overflow: visible; }
.tree-canvas svg path { fill: none; stroke: rgba(242, 201, 76, .3); stroke-width: 1.5; }
.node {
  position: absolute; width: 150px; height: 96px;
  display: flex; flex-direction: column;
  background: #22242b; border: 1px solid rgba(242, 201, 76, .45);
  border-radius: 8px; overflow: hidden; pointer-events: auto;
  transition: transform .2s var(--spring), border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.node:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0, 0, 0, .4); border-color: var(--gold); }
.node.locked { opacity: .42; border-color: var(--line); }
.node.maxed { border-color: var(--ok); }
.node-top { display: flex; align-items: center; gap: 7px; padding: 7px 9px 5px; }
.node-ic { width: 20px; height: 20px; border-radius: 5px; flex: 0 0 20px; display: grid; place-items: center; font-size: 11px; font-family: var(--mono); color: #14161a; font-weight: 700; }
.node-name { font-size: 12.5px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-lv { font-family: var(--mono); font-size: 10.5px; color: var(--fg-dim); }
.node-desc {
  padding: 0 9px; font-size: 10.5px; color: var(--fg-dim); line-height: 1.3; flex: 1;
  overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
}
.node-bot { margin-top: auto; display: flex; align-items: center; gap: 4px; padding: 5px 6px 5px 9px; border-top: 1px solid var(--line); }
.node-costs { display: flex; align-items: center; gap: 7px; overflow: hidden; }
.cost { display: flex; align-items: center; gap: 3px; font-family: var(--mono); font-size: 10.5px; }
.cost.no { color: var(--err); }
.cost b { width: 8px; height: 8px; border-radius: 2px; display: block; box-shadow: 0 0 0 1px rgba(255, 255, 255, .22); }
.node-buy { margin-left: auto; padding: 3px 9px; font-size: 11px; border-radius: 6px; }

.docs {
  position: absolute; top: 0; right: 0; bottom: 0; width: 380px; max-width: 92vw;
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--r) 0 0 var(--r); pointer-events: auto;
  animation: slide-in .26s var(--ease);
}
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.docs-list { flex: 1; overflow: auto; padding: 8px 14px 18px; }
.doc { padding: 11px 0; border-bottom: 1px solid var(--line); }
.doc:last-child { border-bottom: 0; }
.doc.locked { opacity: .4; }
.doc-h { display: flex; align-items: baseline; gap: 8px; }
.doc-sig { font-family: var(--mono); font-size: 13px; color: #7fd4e8; }
.doc.locked .doc-sig { color: var(--fg-dim); }
.doc-lock { font-size: 10px; color: var(--gold); margin-left: auto; }
.doc-d { font-size: 12px; color: var(--fg-dim); margin: 4px 0 6px; line-height: 1.4; }
.doc pre {
  margin: 0; padding: 7px 9px; border-radius: 6px;
  background: rgba(0, 0, 0, .3); border: 1px solid var(--line);
  font-family: var(--mono); font-size: 11.5px; line-height: 1.5;
  color: var(--fg); overflow-x: auto; white-space: pre;
}

@media (max-width: 1100px) {
  .tree-wrap { inset: 16px; }
  .chips { max-width: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  .hm-ui *, .hm-ui *::before, .hm-ui *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* HUD stays out of the menu */
.hm-ui.lobby-open .hud-ores,
.hm-ui.lobby-open .hud-right,
.hm-ui.lobby-open .win,
.hm-ui.lobby-open .dock,
.hm-ui.lobby-open .toasts { display: none !important; }

@media (max-width: 900px) {
  .lobby-panel {
    position: static; transform: none; width: auto; margin-top: 18px;
    animation: panel-in-flow .24s var(--ease) both;
  }
  @keyframes panel-in-flow { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
}
