:root {
  --bg: #05080c;
  --ink: #e8f3f7;
  --aqua: #8fe9ff;
  --btn: #46e0c8;       /* button tag colour */
  --txt: #ffc24d;       /* text-input tag colour */
  --portal: #c98bff;    /* portal tag colour */
  --panel: rgba(10, 16, 22, 0.78);
  --hairline: rgba(143, 233, 255, 0.18);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 700px at 50% -10%, #0c1622 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font: 400 14px/1.4 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

.stage {
  position: relative; flex: 1; min-height: 0;
  background: #000;
  overflow: hidden;
}
.backdrop { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------- TAG screen ---------- */
#tagHit .hit { fill: #fff; fill-opacity: 0.001; cursor: pointer; }
#tagHit .outline {
  fill: transparent; stroke: rgba(143,233,255,0.0); stroke-width: 2.5;
  pointer-events: none; transition: stroke 0.18s ease, fill-opacity 0.18s ease;
}
#tagHit .tag-button .outline { stroke: var(--btn); fill: var(--btn); fill-opacity: 0.16; }
#tagHit .tag-text .outline { stroke: var(--txt); fill: var(--txt); fill-opacity: 0.14; stroke-dasharray: 9 7; }
#tagHit .tag-portal .outline { stroke: var(--portal); fill: var(--portal); fill-opacity: 0.18; stroke-dasharray: 3 6; }
#tagHit .g:hover .outline { stroke: rgba(143,233,255,0.7); }

.bloom { fill: url(#bloomGrad); pointer-events: none; }
#tagFx circle { pointer-events: none; }

/* floating confirmation labels */
.label-fx { position: absolute; inset: 0; pointer-events: none; }
.label-pop {
  position: absolute; transform: translate(-50%, -50%);
  padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: 14px; letter-spacing: 0.04em;
  white-space: nowrap; color: #04181f;
  animation: labelPop 1.15s ease forwards;
}
.label-pop.is-button { background: linear-gradient(180deg,#9ffbe9,var(--btn)); box-shadow: 0 6px 26px -6px rgba(70,224,200,0.8); }
.label-pop.is-text { background: linear-gradient(180deg,#ffdf9e,var(--txt)); box-shadow: 0 6px 26px -6px rgba(255,194,77,0.8); }
.label-pop.is-portal { background: linear-gradient(180deg,#e3c4ff,var(--portal)); color: #1b0830; box-shadow: 0 6px 26px -6px rgba(201,139,255,0.85); }
.label-pop.is-none { background: linear-gradient(180deg,#c4d2da,#8aa0ad); color: #0a0f14; box-shadow: 0 6px 26px -6px rgba(138,160,173,0.7); }
@keyframes labelPop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -55%) scale(1.06); }
  35% { transform: translate(-50%, -60%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -130%) scale(0.96); }
}

/* press-and-hold radial menu */
.radial { position: fixed; z-index: 40; display: flex; flex-direction: column; gap: 8px; transform: translate(-50%, -50%); }
.radial.hidden { display: none; }
.radial-opt {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--hairline); border-radius: 12px;
  padding: 11px 18px; font-weight: 600; font-size: 15px; color: var(--ink);
  backdrop-filter: blur(10px); box-shadow: 0 10px 30px -10px #000;
  transition: transform 0.1s ease, border-color 0.1s ease, background 0.1s ease;
}
.radial-opt.hot { transform: scale(1.08); border-color: var(--aqua); background: rgba(143,233,255,0.16); }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot-btn { background: var(--btn); } .dot-txt { background: var(--txt); } .dot-portal { background: var(--portal); } .dot-none { background: #8aa0ad; }

/* secondary scene-picker menu (Portal to…) */
.scene-menu {
  position: fixed; z-index: 45; transform: translate(-50%, -50%);
  min-width: 220px; max-width: 80vw;
  background: var(--panel); border: 1px solid rgba(201,139,255,0.35); border-radius: 14px;
  padding: 12px; backdrop-filter: blur(12px); box-shadow: 0 16px 44px -12px #000;
}
.scene-menu.hidden { display: none; }
.scene-menu-title { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: 0.85; margin-bottom: 10px; letter-spacing: 0.02em; }
.scene-list { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow: auto; }
.scene-item {
  appearance: none; cursor: pointer; text-align: left;
  background: rgba(201,139,255,0.08); color: var(--ink);
  border: 1px solid rgba(201,139,255,0.25); border-radius: 10px; padding: 11px 14px; font-size: 15px; font-weight: 600;
}
.scene-item:hover, .scene-item:active { background: rgba(201,139,255,0.22); border-color: var(--portal); }
.scene-empty { font-size: 13px; opacity: 0.6; padding: 8px 4px; }
.scene-cancel {
  display: block; width: 100%; margin-top: 10px; appearance: none; cursor: pointer;
  background: transparent; color: rgba(232,243,247,0.55); border: none; font-size: 12px; text-decoration: underline; text-underline-offset: 3px;
}
.scene-cancel:hover { color: var(--aqua); }

/* marquee drag-select */
.marquee {
  position: absolute; z-index: 6; pointer-events: none;
  border: 1.5px dashed var(--aqua); background: rgba(143,233,255,0.10);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
}
.marquee.hidden { display: none; }
.marquee .mq-tip {
  position: absolute; top: -26px; left: 0; font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  background: var(--aqua); color: #04181f; padding: 2px 8px; border-radius: 6px; white-space: nowrap;
}

/* blacked-out regions composited over the backdrop */
.blackout-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.alteration { position: absolute; pointer-events: none; }
.alteration img { width: 100%; height: 100%; display: block; }
.alteration-undo {
  position: absolute; right: 4px; bottom: 4px; pointer-events: auto; cursor: pointer;
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--hairline);
  background: rgba(10,16,22,0.85); color: var(--aqua); font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); box-shadow: 0 3px 12px -3px #000;
}
.alteration-undo:hover { background: rgba(143,233,255,0.2); border-color: var(--aqua); transform: scale(1.08); }

/* release menu: Re-tag / Re-tag+ / Blackout */
.retag-menu {
  position: fixed; z-index: 46; transform: translate(-50%, 0);
  display: flex; flex-direction: column; gap: 6px; min-width: 210px;
  background: var(--panel); border: 1px solid var(--hairline); border-radius: 14px; padding: 10px;
  backdrop-filter: blur(12px); box-shadow: 0 16px 44px -12px #000;
}
.retag-menu.hidden { display: none; }
.retag-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  appearance: none; cursor: pointer; text-align: left;
  background: rgba(143,233,255,0.07); color: var(--ink);
  border: 1px solid var(--hairline); border-radius: 10px; padding: 9px 13px;
}
.retag-opt b { font-size: 15px; }
.retag-opt small { font-size: 11px; opacity: 0.6; }
.retag-opt:hover { background: rgba(143,233,255,0.18); border-color: var(--aqua); }
.retag-row { display: flex; gap: 6px; align-items: stretch; }
.retag-row .grow { flex: 1; }
.retag-expand {
  appearance: none; cursor: pointer; width: 34px; flex: 0 0 34px;
  background: rgba(143,233,255,0.07); color: var(--aqua);
  border: 1px solid var(--hairline); border-radius: 10px; font-size: 20px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s ease, background 0.12s ease;
}
.retag-expand:hover { background: rgba(143,233,255,0.18); border-color: var(--aqua); }
.retag-expand.open { transform: rotate(90deg); }
.prompt-editor { display: flex; flex-direction: column; gap: 6px; padding: 2px 2px 4px; }
.prompt-editor.hidden { display: none; }
.prompt-editor label { font-size: 11px; opacity: 0.6; letter-spacing: 0.04em; }
.prompt-editor textarea {
  width: 100%; resize: vertical; min-height: 56px;
  background: rgba(0,0,0,0.35); color: var(--ink); border: 1px solid var(--hairline);
  border-radius: 9px; padding: 8px 10px; font: 400 13px/1.4 inherit; outline: none;
}
.prompt-editor textarea:focus { border-color: var(--aqua); }
.pe-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pe-hint { font-size: 11px; color: var(--btn); opacity: 0; transition: opacity 0.2s ease; }
.pe-hint.show { opacity: 1; }
.pe-save {
  appearance: none; cursor: pointer; background: rgba(143,233,255,0.12); color: var(--aqua);
  border: 1px solid var(--hairline); border-radius: 8px; padding: 6px 12px; font-size: 12px; font-weight: 600;
}
.pe-save:hover { background: rgba(143,233,255,0.22); border-color: var(--aqua); }
.retag-opt.sub { padding: 8px 13px; }
.retag-opt.sub b { font-weight: 600; font-size: 14px; }
.op-prompt { display: flex; flex-direction: column; gap: 6px; padding: 0 2px 6px; }
.op-prompt.hidden { display: none; }
.op-prompt textarea {
  width: 100%; resize: vertical; min-height: 46px;
  background: rgba(0,0,0,0.35); color: var(--ink); border: 1px solid var(--hairline);
  border-radius: 9px; padding: 8px 10px; font: 400 13px/1.4 inherit; outline: none;
}
.op-prompt textarea:focus { border-color: var(--aqua); }
.op-go {
  appearance: none; cursor: pointer; align-self: flex-end;
  background: linear-gradient(180deg, #aef0ff, #4fc6ff); color: #042033; font-weight: 700;
  border: none; border-radius: 8px; padding: 7px 15px; font-size: 13px;
}
.op-go:active { transform: scale(0.98); }
.retag-cancel {
  appearance: none; cursor: pointer; background: transparent; color: rgba(232,243,247,0.5);
  border: none; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; padding: 6px;
}

/* busy / spinner */
.busy {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; gap: 14px;
  flex-direction: column; background: rgba(4,7,11,0.74); backdrop-filter: blur(4px); color: var(--ink);
}
.busy.hidden { display: none; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 3px solid rgba(143,233,255,0.25); border-top-color: var(--aqua); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#busyMsg { font-size: 13px; letter-spacing: 0.03em; opacity: 0.9; }

/* portal transition overlay (experience) */
.portal-flash {
  position: absolute; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center;
  pointer-events: none; opacity: 0;
  background: radial-gradient(60% 60% at 50% 50%, rgba(201,139,255,0.5), rgba(10,4,20,0.92));
}
.portal-flash.show { animation: portalGo 1.5s ease forwards; }
.portal-flash .pf-text { font-size: 24px; font-weight: 800; letter-spacing: 0.06em; color: #fff; text-shadow: 0 0 24px rgba(201,139,255,0.9); }
@keyframes portalGo { 0% { opacity: 0; } 20% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--hairline);
}
.hint { font-size: 12.5px; opacity: 0.85; }
.tools { display: flex; align-items: center; gap: 10px; }
.count { font-size: 12px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.primary {
  appearance: none; cursor: pointer; border: none; border-radius: 10px; padding: 10px 18px;
  background: linear-gradient(180deg, #aef0ff, #4fc6ff); color: #042033; font-weight: 700;
  box-shadow: 0 6px 22px -8px rgba(79,198,255,0.8);
}
.primary:active { transform: scale(0.98); }
.ghost {
  appearance: none; cursor: pointer; background: transparent; color: var(--ink);
  border: 1px solid var(--hairline); border-radius: 9px; padding: 8px 12px; font-size: 12px;
}
.ghost:hover { border-color: var(--aqua); color: var(--aqua); }

/* ---------- EXPERIENCE screen ---------- */
#expHit .btn { transform-box: fill-box; transform-origin: center; will-change: transform; }
#expHit .hit { fill: #fff; fill-opacity: 0; pointer-events: all; cursor: pointer; }
.glow {
  fill: #bfefff; opacity: 0; transform-box: fill-box; transform-origin: center;
  will-change: opacity, transform;
  filter: drop-shadow(0 0 6px rgba(160,240,255,0.85)) drop-shadow(0 0 18px rgba(95,205,255,0.65)) drop-shadow(0 0 42px rgba(63,150,255,0.45));
}
.glow-portal {
  fill: #e3c4ff !important;
  filter: drop-shadow(0 0 6px rgba(201,139,255,0.9)) drop-shadow(0 0 18px rgba(170,90,255,0.7)) drop-shadow(0 0 42px rgba(140,60,255,0.5)) !important;
}
.exp-inputs { position: absolute; inset: 0; pointer-events: none; }
.exp-inputs .portal-vid { position: absolute; object-fit: cover; pointer-events: none; border-radius: 6px; box-shadow: 0 0 0 1px rgba(143,233,255,0.35), 0 0 26px -6px rgba(63,185,255,0.7); background: #000; }
.exp-inputs textarea {
  position: absolute; pointer-events: all; resize: none; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.22); border-radius: 8px;
  padding: 6px 9px; color: #fff; font: 500 16px/1.25 inherit;
  outline: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
}
.exp-inputs textarea::placeholder { color: rgba(255,255,255,0.55); }
.exp-inputs textarea:focus { border-color: var(--aqua); box-shadow: 0 0 0 2px rgba(143,233,255,0.35); }

.back {
  position: absolute; top: 12px; left: 12px; z-index: 8;
  appearance: none; cursor: pointer; background: var(--panel); color: var(--aqua);
  border: 1px solid var(--hairline); border-radius: 9px; padding: 8px 13px; font-size: 12px;
  backdrop-filter: blur(8px);
}
.back:hover { background: rgba(143,233,255,0.12); }
