/* Fucking Beans map builder. Full-screen canvas with floating bars; the
   bottom bar wraps to two rows on a portrait phone and is one row otherwise. */
:root {
  --bg: #17121f;
  --panel: rgba(28, 22, 38, 0.88);
  --panel-solid: #221a2e;
  --line: rgba(255, 255, 255, 0.10);
  --text: #f6f0ff;
  --dim: #b4a8c8;
  --accent: #ffc83d;
  --accent-ink: #2a1a00;
  --hot: #ff5a6e;
  --ok: #6be38a;
  --tap: 46px;
  --radius: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
body { height: 100dvh; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#view.pan { cursor: grab; }
#view.panning { cursor: grabbing; }

/* ---- bars ---------------------------------------------------------- */
.bar {
  position: fixed; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding-left: calc(8px + var(--safe-l)); padding-right: calc(8px + var(--safe-r));
}
#top { top: 0; padding-top: calc(6px + var(--safe-t)); padding-bottom: 6px; border-bottom: 1px solid var(--line); }
#tools {
  bottom: 0; padding-top: 6px; padding-bottom: calc(6px + var(--safe-b));
  border-top: 1px solid var(--line); flex-wrap: wrap; justify-content: center; row-gap: 4px; column-gap: 14px;
}
.group { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
#optGroup { flex: 1 1 auto; max-width: 420px; min-width: 0; }

.brand { display: flex; flex-direction: column; line-height: 1.05; color: var(--text); text-decoration: none; padding: 0 6px 0 2px; white-space: nowrap; }
.brand b { font-size: 15px; letter-spacing: 0.2px; color: var(--accent); }
.brand span { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 1.2px; }
@media (max-width: 560px) { .brand { display: none; } }

#name {
  flex: 1 1 auto; min-width: 0; height: 40px; padding: 0 12px;
  background: rgba(255, 255, 255, 0.07); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; font: inherit; font-weight: 600;
  user-select: text; -webkit-user-select: text;
}
#name::placeholder { color: #8d81a3; font-weight: 500; }
#name:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---- buttons ------------------------------------------------------- */
.btn {
  min-width: var(--tap); height: var(--tap); padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08); color: var(--text);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { background: rgba(255, 255, 255, 0.14); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.35; cursor: default; transform: none; }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.accent:hover { background: #ffd666; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 0; width: var(--tap); }
.btn:focus-visible, .tool:focus-visible, .start:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#btnSave { padding: 0 18px; }
#btnSave.busy { opacity: 0.6; pointer-events: none; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

.tool {
  width: 52px; height: 52px; padding: 4px 0 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--dim); font: inherit; cursor: pointer; touch-action: manipulation;
}
.tool span { font-size: 10.5px; font-weight: 700; letter-spacing: 0.2px; }
.tool:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.tool.on { color: var(--accent-ink); background: var(--accent); }

.size { flex: 1 1 0; display: flex; align-items: center; gap: 6px; min-width: 96px; height: var(--tap); padding: 0 4px; }
.size output { width: 30px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--dim); font-size: 13px; }
input[type=range] { flex: 1 1 0; width: 100%; min-width: 0; height: var(--tap); margin: 0; background: transparent; -webkit-appearance: none; appearance: none; touch-action: pan-x; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.18); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.18); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -10px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel-solid); box-shadow: 0 1px 4px rgba(0,0,0,.5); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel-solid); }

.swatch i { display: block; width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,.75); box-shadow: inset 0 -9px 0 var(--sw-ground, #7a4b25); background: var(--sw-sky, #8ec5ff); }

/* Narrow phones: tighten so six tools fit in 360 px. */
@media (max-width: 380px) {
  .tool { width: 50px; }
  #toolGroup { gap: 2px; }
  #optGroup { gap: 2px; }
}

/* ---- status pill ---------------------------------------------------- */
.pill {
  position: fixed; z-index: 4; left: calc(10px + var(--safe-l)); top: calc(62px + var(--safe-t));
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  pointer-events: none; max-width: calc(100vw - 20px);
}
.pill .ok { color: var(--ok); }
.pill .bad { color: var(--hot); }
.pill.warn { border-color: rgba(255, 90, 110, 0.6); }

/* ---- theme popover --------------------------------------------------- */
.pop {
  position: fixed; z-index: 8; padding: 10px; border-radius: 14px;
  background: var(--panel-solid); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.popTitle { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: 1.2px; margin: 0 2px 8px; }
.themes { display: grid; grid-template-columns: repeat(5, 56px); gap: 6px; }
.themes button {
  height: 70px; padding: 0 0 4px; border-radius: 10px; border: 2px solid transparent; cursor: pointer;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  color: #fff; font: 700 11px system-ui, sans-serif; text-shadow: 0 1px 2px rgba(0,0,0,.8);
  background: var(--sw);
}
.themes button.on { border-color: var(--accent); }

/* ---- sheets ---------------------------------------------------------- */
.sheet {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: calc(12px + var(--safe-t)) 12px calc(12px + var(--safe-b));
  background: rgba(10, 6, 16, 0.62); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.sheet[hidden], .pop[hidden], .toast[hidden] { display: none; }
.card {
  position: relative; width: 100%; max-width: 560px; max-height: 100%; overflow: auto;
  padding: 20px 18px 16px; border-radius: 18px;
  background: var(--panel-solid); border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0,0,0,.55);
  touch-action: pan-y;
}
.card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.2px; }
.card .sub { margin: 0 0 14px; color: var(--dim); }
.card .small { font-size: 13px; margin: 12px 0 0; word-break: break-all; }
.card .small a { color: var(--accent); }
.card .close { position: absolute; top: 6px; right: 6px; height: 44px; min-width: 0; padding: 0 12px; font-size: 13px; color: var(--dim); }
.card h1 { padding-right: 70px; }
.starts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.start {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 8px 10px;
  border-radius: 14px; border: 1px solid var(--line); background: rgba(255,255,255,.05);
  color: var(--text); font: inherit; text-align: left; cursor: pointer; touch-action: manipulation;
}
.start:hover { background: rgba(255,255,255,.1); border-color: rgba(255,200,61,.5); }
.start[hidden] { display: none; }
.start canvas { width: 100%; height: auto; aspect-ratio: 2 / 1; border-radius: 9px; margin-bottom: 6px; background: #0d0a14; }
.start b { font-size: 15px; }
.start span { font-size: 12px; color: var(--dim); }
.tips { margin: 14px 0 0; font-size: 12.5px; color: var(--dim); }
.tips kbd { font: 700 11px ui-monospace, Consolas, monospace; padding: 1px 5px; border-radius: 4px; background: rgba(255,255,255,.1); color: var(--text); }

.link { display: flex; gap: 6px; margin-bottom: 10px; }
.link input {
  flex: 1 1 auto; min-width: 0; height: var(--tap); padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: rgba(0,0,0,.3); color: var(--accent);
  font: 600 15px ui-monospace, Consolas, monospace; user-select: all; -webkit-user-select: all;
}
.row { display: flex; gap: 8px; }
.row .btn { flex: 1 1 0; }

/* ---- toast ----------------------------------------------------------- */
.toast {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  top: calc(64px + var(--safe-t)); max-width: min(92vw, 520px);
  padding: 10px 16px; border-radius: 12px; font-weight: 700; pointer-events: none;
  background: #2b2236; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.toast.err { background: #4a1621; border-color: rgba(255, 90, 110, .7); color: #ffd9de; }
.toast.ok { background: #183823; border-color: rgba(107, 227, 138, .6); color: #d8ffe3; }

/* Short landscape phones: slimmer bars, keep 44 px targets. */
@media (max-height: 460px) and (orientation: landscape) {
  #top { padding-top: calc(3px + var(--safe-t)); padding-bottom: 3px; }
  #tools { padding-top: 3px; padding-bottom: calc(3px + var(--safe-b)); }
  .tool { height: 46px; }
  .pill { top: calc(54px + var(--safe-t)); }
  .card { padding: 14px; }
  .starts { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .start span { display: none; }
}
