:root {
  --night: #090b10; --night2: #11141b; --night3: #191d26;
  --white: #f7f6f1; --muted: #9a9da6; --border: rgba(247, 246, 241, .12);
  --ember: #ff4b0a; --magenta: #ff0a8a; --violet: #aa35ff; --electric: #3867ff; --cyan: #28d9f7;
  --warm: #ffad8a;
  --glass: rgba(13, 15, 21, .72);
  --spectrum: linear-gradient(90deg, var(--ember), var(--magenta), var(--violet), var(--electric), var(--cyan));
  font-family: Inter, "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--white); }
#app, #view { position: fixed; inset: 0; width: 100%; height: 100%; }
#view { display: block; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
:is(button, input, select):focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
kbd { font-family: ui-monospace, "JetBrains Mono", monospace; font-size: 12px; padding: 1px 6px; border-radius: 4px;
      border: 1px solid var(--border); background: rgba(255,255,255,.08); }

.brand { font-weight: 750; font-size: 26px; letter-spacing: -.01em; }
.brand span { font-weight: 450; color: var(--muted); }

#loader, #start { position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% 40%, #151925 0%, var(--night) 70%); z-index: 20; }
#start { background: rgba(9, 11, 16, .55); backdrop-filter: blur(6px); }
.loader-card, .start-card { width: min(560px, 92vw); padding: 28px 30px; border-radius: 14px; background: var(--glass);
  border: 1px solid var(--border); box-shadow: 0 30px 80px rgba(0,0,0,.45); position: relative; }
.loader-card::before, .start-card::before { content: ""; position: absolute; left: 24px; right: 24px; top: -1px; height: 2px;
  background: var(--spectrum); border-radius: 2px; }
.bar { height: 4px; background: rgba(255,255,255,.08); border-radius: 4px; margin: 22px 0 10px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--spectrum); transition: width .25s; }
#load-text { font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); }
.start-card p { color: #c9cad0; line-height: 1.5; margin: 14px 0 18px; }
.start-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; font-size: 13px; color: #cfd0d6; margin-bottom: 22px; }
.start-grid b { color: var(--white); font-weight: 650; }
.start-sub { margin-top: 12px; font-size: 12px; color: var(--muted); }
button.primary { background: var(--white); color: var(--night); border: 0; border-radius: 9px; padding: 10px 22px; font-weight: 650; }
button.primary:hover { background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.12); }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
#hud-top { position: absolute; top: 16px; left: 18px; pointer-events: none; text-shadow: 0 1px 8px rgba(0,0,0,.6); }
#room-name { font-weight: 700; font-size: 20px; letter-spacing: -.01em; }
#clock { font-family: ui-monospace, monospace; font-size: 12px; color: #d6d7dc; margin-top: 2px; }
.furnishing-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--night2); color: var(--white); font-size: 13px; white-space: nowrap; }
.furnishing-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.furnishing-toggle[aria-pressed="true"] svg { color: var(--warm); }
.furnishing-toggle:hover:not(:disabled) { background: var(--night3); border-color: var(--warm); }
.furnishing-toggle:disabled { cursor: progress; color: #c9cad0; }
#furnishing-toggle { position: absolute; top: 78px; left: 18px; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%;
  background: rgba(255,255,255,.85); box-shadow: 0 0 0 1.5px rgba(0,0,0,.35); pointer-events: none; transition: transform .12s; }
#crosshair.hot { transform: scale(1.9); background: var(--warm); }
#prompt { position: absolute; left: 50%; top: calc(50% + 26px); transform: translateX(-50%); padding: 7px 12px; border-radius: 8px;
  background: var(--glass); border: 1px solid var(--border); font-size: 13px; display: flex; gap: 8px; align-items: center; pointer-events: none; }
#toast { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); padding: 9px 16px; border-radius: 9px;
  background: var(--glass); border: 1px solid var(--border); font-size: 13px; pointer-events: none; z-index: 16; }

#toolbar { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; gap: 4px; padding: 6px;
  border-radius: 13px; background: var(--glass); border: 1px solid var(--border); backdrop-filter: blur(10px); }
#toolbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 64px; padding: 7px 8px 6px;
  border: 0; background: transparent; border-radius: 9px; color: #d9dae0; font-size: 11px; }
#toolbar button:hover { background: rgba(255,255,255,.07); color: var(--white); }
#toolbar button.on { background: rgba(255,255,255,.12); color: var(--white); box-shadow: inset 0 -2px 0 var(--warm); }
#toolbar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.panel { position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%); width: min(430px, 92vw); padding: 16px 18px;
  max-height: calc(100dvh - 115px); overflow-y: auto; overscroll-behavior: contain;
  border-radius: 13px; background: var(--glass); border: 1px solid var(--border); backdrop-filter: blur(12px); font-size: 13px; }
.panel-head { font-weight: 700; font-size: 14px; margin-bottom: 12px; display: flex; justify-content: space-between; }
.panel-head span { font-family: ui-monospace, monospace; font-weight: 500; color: var(--warm); }
.panel input[type=range] { width: 100%; accent-color: var(--warm); }
.panel ul { margin: 0; padding-left: 18px; line-height: 1.6; color: #d4d5da; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chips button { border: 1px solid var(--border); background: rgba(255,255,255,.04); border-radius: 999px; padding: 5px 11px; font-size: 12px; }
.chips button:hover, .chips button.on { background: rgba(255,255,255,.12); border-color: rgba(255,173,138,.5); }
.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; color: #d4d5da; }
.row input[type=range] { flex: 1; }
.row select { background: var(--night3); color: var(--white); border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; margin-left: auto; }
.note { color: var(--muted); font-size: 12px; margin-top: 6px; font-family: ui-monospace, monospace; }
#lights-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#lights-list button { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--border);
  background: rgba(255,255,255,.03); border-radius: 8px; padding: 7px 10px; font-size: 12px; text-align: left; }
#lights-list button i { width: 9px; height: 9px; border-radius: 50%; background: #3b3e47; }
#lights-list button.on i { background: #ffd39a; }
#lights-list button.here { border-color: rgba(255,173,138,.55); }

#minimap { position: absolute; right: 16px; bottom: 16px; width: 300px; border-radius: 12px; overflow: hidden;
  background: var(--glass); border: 1px solid var(--border); cursor: crosshair; transition: width .18s ease; }
#minimap:hover { width: 480px; }
#minimap canvas { display: block; width: 100%; }
.mm-hint { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; text-align: center; padding: 3px; color: var(--muted);
  background: linear-gradient(transparent, rgba(0,0,0,.5)); pointer-events: none; }

#joystick { position: absolute; left: 26px; bottom: 96px; width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,.06); border: 1px solid var(--border); touch-action: none; }
#joy-knob { position: absolute; left: 40px; top: 40px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.35); }

#gallery { position: fixed; inset: 0; z-index: 15; display: grid; grid-template-columns: 250px 1fr; background: #090b10; }
.gal-side { border-right: 1px solid var(--border); overflow-y: auto; padding: 16px 12px; }
.gal-head { font-weight: 750; margin: 0 6px 12px; }
#gal-list button { display: grid; grid-template-columns: 74px 1fr; gap: 10px; align-items: center; width: 100%; border: 0;
  background: transparent; padding: 6px; border-radius: 8px; text-align: left; font-size: 12px; color: #d4d5da; }
#gal-list button img { width: 74px; height: 49px; object-fit: cover; border-radius: 5px; background: #222; }
#gal-list button.on, #gal-list button:hover { background: rgba(255,255,255,.08); color: var(--white); }
.gal-main { display: grid; grid-template-rows: 1fr auto; min-width: 0; }
#gal-stage { position: relative; margin: 18px; overflow: hidden; border-radius: 10px; background: #000; }
#gal-live, #gal-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#gal-img { clip-path: inset(0 0 0 50%); }
#gal-split { position: absolute; top: 0; bottom: 0; left: 50%; width: 30px; margin-left: -15px; cursor: ew-resize; }
#gal-split i { position: absolute; left: 14px; top: 0; bottom: 0; width: 2px; background: var(--white); box-shadow: 0 0 10px rgba(0,0,0,.6); }
.gal-tag { position: absolute; top: 10px; font-size: 11px; padding: 3px 8px; border-radius: 6px; background: var(--glass); font-family: ui-monospace, monospace; }
.gal-tag.left { left: 10px; } .gal-tag.right { right: 10px; }
#gal-real { position: absolute; right: 12px; bottom: 12px; margin: 0; z-index: 2; display: flex; flex-direction: column; overflow: hidden;
  border-radius: 8px; border: 1px solid var(--border); background: #000; box-shadow: 0 8px 28px rgba(0,0,0,.6); cursor: zoom-in; }
#gal-real img { display: block; object-fit: contain; }
#gal-real figcaption { font-size: 11px; line-height: 1.3; padding: 5px 8px; background: var(--glass); font-family: ui-monospace, monospace; }
#gal-real.big { right: auto; bottom: auto; cursor: zoom-out; }
.gal-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; padding: 0 18px 16px; gap: 12px; font-size: 13px; }
#gal-sub { color: var(--muted); }
.gal-actions { display: flex; gap: 10px; align-items: center; }
.gal-actions button:not(.primary) { border: 1px solid var(--border); background: transparent; border-radius: 9px; padding: 9px 16px; }
.gal-actions { flex-wrap: wrap; justify-content: flex-end; }
.gal-actions button.furnishing-toggle { min-height: 44px; }
/* pantallas estrechas o bajas: el minimapa sube a la esquina superior para no tapar la barra */
@media (max-width: 1220px), (max-height: 520px) {
  #minimap { top: 16px; bottom: auto; width: 240px; } #minimap:hover { width: 360px; }
}
@media (max-width: 760px) {
  #hud-top { max-width: calc(100vw - 185px); }
  #room-name { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #toolbar button span { display: none; } #toolbar button { min-width: 40px; }
  #minimap, #minimap:hover { width: 150px; } #gallery { grid-template-columns: 1fr; grid-template-rows: 150px 1fr; }
}
@media (max-width: 600px) {
  .start-grid { grid-template-columns: 1fr; }
  .start-card { max-height: 94dvh; overflow-y: auto; padding: 22px; }
  #gallery { grid-template-rows: 112px minmax(0, 1fr); }
  .gal-side { padding: 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .gal-head { font-size: 13px; margin-bottom: 4px; }
  #gal-list { display: flex; overflow-x: auto; }
  #gal-list button { min-width: 145px; grid-template-columns: 62px 1fr; font-size: 11px; }
  #gal-list button img { width: 62px; height: 42px; }
  .gal-main { min-height: 0; }
  #gal-stage { margin: 8px; }
  .gal-bar { flex-wrap: wrap; padding: 0 10px 12px; gap: 8px; }
  .gal-actions { flex-wrap: wrap; gap: 8px; }
  .gal-actions button { min-height: 42px; }
  #toast { max-width: 90vw; width: max-content; text-align: center; }
}
@media (max-width: 370px) {
  #toolbar { gap: 0; padding: 4px; }
  #toolbar button { min-width: 37px; padding-inline: 7px; }
  #minimap, #minimap:hover { width: 125px; right: 10px; }
}
@media (max-height: 520px) and (min-width: 601px) {
  #gallery { grid-template-columns: 180px minmax(0, 1fr); }
  .gal-side { padding: 10px 6px; }
  #gal-list button { grid-template-columns: 52px 1fr; gap: 6px; }
  #gal-list button img { width: 52px; height: 36px; }
  .gal-bar { flex-wrap: wrap; padding: 0 12px 10px; gap: 8px; }
  .gal-actions button, .gal-actions label { white-space: nowrap; flex-shrink: 0; }
}

/* Three-source comparison: photographs stay in their own unregistered panel. */
#gal-note { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
#gal-note:empty { display: none; }
#gal-pair { max-width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--night2); color: var(--white); font: inherit; }
#gal-pair option:disabled { color: var(--muted); }
#gal-real { border: 0; border-radius: 0; box-shadow: none; cursor: default; z-index: 0; }
#gal-real img { flex: 1; object-fit: contain; }
#gal-split { touch-action: none; z-index: 2; }
#gal-split:focus-visible { outline-offset: -3px; }
#gal-split i::after { content: ''; position: absolute; width: 24px; height: 44px; left: -11px; top: calc(50% - 22px); border: 2px solid var(--white); border-radius: 12px; background: var(--glass); }
.gal-tag { z-index: 3; pointer-events: none; font-family: inherit; }
.gal-main { min-height: 0; }
#gal-stage { min-height: 40px; }
@media (max-width: 600px) {
  .gal-actions { justify-content: flex-start; }
  .gal-actions label[for="gal-pair"] { display: none; }
  #gal-pair { width: 100%; }
  .gal-tag { font-size: 11px; padding: 3px 5px; }
  .gal-tag.left { left: 4px; } .gal-tag.right { right: 4px; }
  .gal-bar { max-height: 46dvh; overflow-y: auto; }
}
@media (max-height: 520px) {
  .gal-bar { max-height: 44dvh; overflow-y: auto; }
  #gal-note { font-size: 11px; }
}
