:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #ecf6f4;
  background: #0a1014;
  --plate: #111b20;
  --line: #2b4148;
  --ink-dim: #a5bec3;
  --mint: #8bffd9;
  --mono: "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 8% 0%, #14303a 0%, transparent 50%),
    linear-gradient(135deg, #0d171d, #090e13 72%);
}

main { width: min(1510px, 100%); padding: clamp(15px, 3.6vw, 55px); margin-inline: auto; }
button, input { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: default; }
button, input { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }
h1, h2, p { margin: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: clamp(17px, 3vw, 35px);
  padding-bottom: 17px;
  border-bottom: 1px solid var(--line);
}

.brand, .settings { display: flex; align-items: center; gap: 12px; }
.mark {
  width: 37px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  transform: rotate(-14deg);
  border: 1px solid #73cfb48a;
  border-radius: 29%;
  box-shadow: inset 0 0 15px #4becbd22;
}
.mark i { width: 15px; aspect-ratio: 1; border: 2px solid #a5ffe7; transform: rotate(45deg); box-shadow: 0 0 14px #54f2c49c; }
h1 { font-size: clamp(1.8rem, 4.1vw, 3.4rem); line-height: 1; font-weight: 750; letter-spacing: -.07em; }
h1 em { color: var(--mint); font-style: normal; }

.subtle {
  min-height: 40px;
  border: 1px solid #38515a;
  border-radius: 4px;
  padding: 6px 11px;
  background: #10191dcf;
  color: #c0d1d3;
  font-size: .875rem;
}
.subtle:hover:not(:disabled) { background: #203139; border-color: #a4d7d3; }
.subtle:disabled { opacity: .47; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(282px, 1fr); align-items: start; gap: clamp(12px, 2vw, 24px); }
.workbench, .inventory { border: 1px solid #3a555c; background: #111a1f; border-radius: 8px; box-shadow: 0 16px 42px #0005; }
.workbench { overflow: hidden; }
.surface-header, .inventory-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(150deg, #1c2b32, #121d21 72%);
  min-height: 65px;
}
h2 { font-weight: 650; font-size: clamp(1rem, 1.8vw, 1.23rem); }
.chamber {
  isolation: isolate;
  position: relative;
  height: clamp(330px, 51svh, 615px);
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 50% 50%, #0a1522a0, #090f18b8 55%, #080e14ed),
    url("banco.png") center / cover,
    linear-gradient(140deg, #152a3a, #101821);
}
.chamber::before {
  content: "";
  position: absolute;
  inset: 16px;
  border: 1px solid #71bdc147;
  clip-path: polygon(0 0, 9% 0, 9% 2px, 91% 2px, 91% 0, 100% 0, 100% 100%, 0 100%);
  pointer-events: none;
}
.mix {
  display: grid;
  grid-template-columns: 1fr clamp(26px, 9vw, 135px) 1fr;
  align-items: center;
  width: min(76%, 550px);
  transform: translateY(-23px);
}
.socket {
  display: grid;
  justify-items: center;
  align-content: center;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 8px;
}
.well {
  --item: #91aeb3;
  display: grid;
  place-items: center;
  position: relative;
  width: 100%;
  max-width: 184px;
  aspect-ratio: 1;
  border-radius: 17px;
  border: 1px dashed #738d99;
  background: radial-gradient(ellipse, #30414c70, #0c151de8 75%);
  color: #aac3ca;
}
.well::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 12px;
  border: 1px solid #6e8c962e;
  pointer-events: none;
}
.socket[aria-pressed="true"] .well, .socket.drop-target .well { border-color: var(--mint); box-shadow: 0 0 24px #3cf5c62e, inset 0 0 22px #52bcad18; }
.socket:hover .well { background-color: #6bdac936; }
.placeholder { font: 300 clamp(1.4rem, 4.8vw, 3rem)/1 var(--mono); }
.well.filled { border-style: solid; color: var(--item); background: radial-gradient(ellipse, color-mix(in srgb, var(--item) 17%, #0b141c), #0c151df5 73%); }
.well .glyph { font-size: clamp(1.8rem, 5.4vw, 4.6rem); filter: drop-shadow(0 0 17px color-mix(in srgb, var(--item) 60%, transparent)); }
.socket-label { margin-top: 12px; min-height: 3em; line-height: 1.3; text-align: center; color: #b8c9d2; font: clamp(.875rem, 1.25vw, 1.05rem) var(--mono); overflow-wrap: anywhere; }
.conduit { height: 1px; align-self: center; display: grid; place-items: center; margin-top: -45px; background: #496774a3; }
.conduit i { width: 10px; aspect-ratio: 1; transform: rotate(45deg); background: #253443; border: 1px solid #749ba1; }
.ready .conduit { background: #77e9c7; box-shadow: 0 0 12px #35dcba; }
.ready .conduit i { background: #9fffdc; border-color: #b5fff0; box-shadow: 0 0 13px #4fffd5; }
.result {
  position: absolute;
  bottom: 27px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 91%;
  padding: 7px 15px;
  border: 1px solid color-mix(in srgb, var(--item) 64%, #283e47);
  border-radius: 5px;
  background: #0b1b20f2;
  color: #edf9f3;
  font-size: .95rem;
  animation: appear .24s ease-out;
}
.result .glyph { color: var(--item); font-size: 1.55rem; }
.reaction-bar {
  min-height: 77px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 11px;
  border-top: 1px solid var(--line);
}
.reaction-bar p { color: var(--ink-dim); font-size: .95rem; }
.reaction-bar p.good { color: #99ffd9; }
.reaction-bar p.bad { color: #ffb5a6; }
.pulse-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px 13px;
  border-top: 1px solid var(--line);
}
.pulse-button[data-ready="true"] { color: #b7eaff; border-color: #6399a9; }
.pulse-charge { color: var(--ink-dim); font: .8rem var(--mono); }
.fuse {
  min-width: 126px;
  min-height: 48px;
  padding: 9px 16px;
  border: 1px solid #9effe0;
  background: #9effe0;
  color: #0c2a29;
  border-radius: 4px;
  font-weight: 750;
}
.fuse:hover:not(:disabled) { background: #c4ffed; box-shadow: 0 0 24px #3be5be54; }
.fuse:disabled { background: #263b40; border-color: #476369; color: #b0c0c4; }

.inventory { overflow: hidden; min-height: calc(clamp(330px, 51svh, 615px) + 144px); }
.inventory-header output { font: 600 .92rem var(--mono); color: var(--mint); }
.search {
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid #304852;
  background: #0b171d;
  border-radius: 4px;
  margin: 13px 13px 0;
  padding: 0 10px;
}
.search:focus-within { outline: 2px solid var(--mint); outline-offset: 1px; }
.search-mark { width: 12px; height: 12px; border: 1.5px solid #abc7cc; border-radius: 50%; flex: none; position: relative; margin-right: 2px; }
.search-mark::after { content: ""; width: 6px; height: 1.5px; position: absolute; right: -5px; bottom: -3px; transform: rotate(45deg); background: #abc7cc; }
.search input { width: 100%; border: 0; outline: 0; min-height: 41px; background: transparent; color: #e1f2f2; font-size: .875rem; }
.search input::placeholder { color: var(--ink-dim); }
.items {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: 8px;
  padding: 13px;
  max-height: calc(clamp(330px, 51svh, 615px) + 20px);
  overflow: auto;
  scrollbar-color: #516b70 #10181c;
}
.item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 83px;
  border: 1px solid color-mix(in srgb, var(--item) 28%, #203239);
  border-radius: 5px;
  padding: 7px 4px;
  background: radial-gradient(ellipse at 50% 20%, color-mix(in srgb, var(--item) 13%, #15222a), #132027 65%);
  text-align: center;
  color: #ebf6f5;
}
.item:hover, .item.in-use { border-color: var(--item); }
.item:hover { filter: brightness(1.24); }
.item.in-use { background-color: #2c4b49; box-shadow: inset 0 0 17px #73f7d62b; }
.item .glyph { color: var(--item); font-size: 1.65rem; line-height: 1.05; text-shadow: 0 0 12px color-mix(in srgb, var(--item) 45%, transparent); }
.item-name { font-size: .875rem; line-height: 1.15; overflow-wrap: anywhere; }
.no-matches, .storage-note { color: var(--ink-dim); font-size: .9rem; padding: 10px 14px; }

[data-color="water"] { --item: #6be3e7; }
[data-color="sky"] { --item: #a0cdff; }
[data-color="earth"] { --item: #e4b990; }
[data-color="ember"] { --item: #ff967d; }
[data-color="stone"] { --item: #bfd3d5; }
[data-color="green"] { --item: #8bffd1; }
[data-color="gold"] { --item: #ffe095; }
[data-color="violet"] { --item: #cfb8ff; }
.chamber.flash-good .mix { animation: spark .35s ease-in-out; }
.chamber.flash-bad .mix { animation: recoil .23s ease-in-out; }
@keyframes spark { 40% { filter: brightness(1.9) drop-shadow(0 0 13px #79ffde); } }
@keyframes recoil {
  33% { transform: translate(-4px, -23px); }
  66% { transform: translate(4px, -23px); }
}
@keyframes appear {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

dialog { width: min(410px, calc(100vw - 32px)); background: #17242c; border: 1px solid #577580; border-radius: 8px; color: inherit; padding: 24px; }
dialog::backdrop { background: #05090dd9; }
dialog p { color: var(--ink-dim); margin: 12px 0 22px; }
.dialog-buttons { display: flex; gap: 10px; justify-content: end; }
.danger { min-height: 40px; border: 1px solid #ffbcad; border-radius: 4px; background: #ffbcad; color: #3a1816; font-weight: 700; padding-inline: 12px; }

@media (max-width: 760px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .chamber { height: clamp(222px, 37svh, 400px); }
  .inventory { min-height: auto; }
  .items { max-height: min(50svh, 480px); grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .surface-header, .inventory-header, .reaction-bar { min-height: 59px; padding-inline: 12px; }
  .mix { width: min(72%, 360px); }
  .chamber::before { inset: 10px; }
  .result { bottom: 17px; }
}
@media (max-width: 425px) {
  main { padding: 11px; }
  .mark { width: 24px; border-radius: 5px; }
  .mark i { width: 11px; }
  .topbar { gap: 9px; }
  .settings, .brand { gap: 6px; }
  .settings .subtle { font-size: .8rem; min-height: 36px; padding: 5px 6px; }
  .items { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .item { min-height: 74px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}

.stations, .shelf-tabs, .surface-actions { display: flex; align-items: center; gap: 6px; }
.stations { flex-wrap: wrap; margin: -5px 0 15px; }
.stations button, .shelf-tabs button {
  flex-shrink: 0;
  border: 1px solid #34515a;
  border-radius: 5px;
  background: #142126;
  color: #d1e3e2;
  padding: 8px 11px;
  min-height: 39px;
  font-size: .875rem;
}
.stations button[aria-pressed="true"], .shelf-tabs button[aria-pressed="true"] {
  color: #afffe5;
  border-color: #6ecdb0;
  background: #183632;
}
.shelf-tabs { padding: 11px; border-bottom: 1px solid var(--line); }
.shelf-tabs button { flex: 1; padding-inline: 6px; }
.surface-actions { flex-wrap: wrap; justify-content: end; }
.surface-actions label { font-size: .875rem; color: var(--ink-dim); }
.surface-header h2 { min-width: 0; }
select, textarea, #plan-name {
  max-width: 100%;
  color: #e5f5f3;
  font: inherit;
  border: 1px solid #3e5a63;
  border-radius: 5px;
  min-height: 37px;
  padding: 7px 9px;
  background: #102027;
}
select {
  appearance: none;
  padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, #8dc5c5 50%), linear-gradient(135deg, #8dc5c5 50%, transparent 50%);
  background-position: calc(100% - 12px) 52%, calc(100% - 8px) 52%;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}
.filters { display: flex; align-items: center; justify-content: space-between; gap: 9px; padding: 12px 13px 0; font-size: .875rem; }
.filters output, #intelligence { color: var(--mint); font: .875rem var(--mono); }
.mix {
  grid-template-columns: repeat(var(--columns, 2), minmax(0, 1fr));
  gap: clamp(9px, 3.5vw, 48px);
  width: min(86%, 720px);
  position: relative;
  z-index: 1;
}
.mix.grid-mode { width: min(75%, 331px); gap: 7px; transform: translateY(-14px); }
.chamber[data-station="cartuchos"] { box-shadow: inset 0 0 80px #91c0ff36; }
.chamber[data-station="dimensional"] { box-shadow: inset 0 0 100px #af6dff65; }
.chamber[data-station="herramientas"] { box-shadow: inset 0 0 90px #ffc1773b; }
.chamber[data-station="materiales"] { box-shadow: inset 0 0 90px #ff9d6533; }
.chamber[data-station="ensamblaje"] { box-shadow: inset 0 0 90px #65ffd851; }
.chamber[data-station="electronica"] { box-shadow: inset 0 0 90px #5ac5fa3e; }
.grid-mode .socket { position: relative; }
.grid-mode .well { border-radius: 8px; }
.grid-mode .well::before { border-radius: 5px; inset: 4px; }
.grid-mode .socket-label { position: absolute; z-index: 1; bottom: 2px; right: 5px; min-height: 0; margin: 0; font-size: .72rem; color: #d6f3f3; font-weight: 700; }
.grid-mode .placeholder { opacity: .66; font-size: 1.26rem; }
.well .emblem { width: 80%; max-width: 117px; aspect-ratio: 1; }
.grid-mode .emblem { width: 78%; }
.item .emblem { width: 48px; aspect-ratio: 1; }
.result { z-index: 3; }
.result .emblem { width: 34px; aspect-ratio: 1; }
#effects { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; pointer-events: none; }
.ready .well.filled { border-color: #65ad99; }
.chamber.flash-bad { animation: bench-rattle .34s ease-out; }
@keyframes bench-rattle {
  20% { transform: translateX(-3px); } 42% { transform: translateX(4px); }
  64% { transform: translateX(-2px); } 86% { transform: translateX(1px); }
}

.ledger { padding: 12px; }
.ledger h2 { margin-bottom: 7px; }
.ledger button { margin-top: 7px; }
.ledger article { border-block-end: 1px solid var(--line); padding: 13px 0; }
.ledger article h3 { font-size: 1rem; margin: 0 0 4px; }
.ledger article p, .ledger ol, .ledger > div > p { color: var(--ink-dim); font-size: .875rem; line-height: 1.4; overflow-wrap: anywhere; white-space: pre-wrap; }
.ledger .layout-preview { margin-top: 8px; }
.ledger ol { overflow: auto; max-height: 440px; padding-left: 1.35rem; margin-block: 8px; }
.ledger li { padding: 8px 2px; border-bottom: 1px solid var(--line); }
.ledger li strong { display: block; color: #e5f2f0; }
.ledger .controls { display: flex; flex-wrap: wrap; gap: 6px; }
.layout-preview { display: grid; grid-template-columns: repeat(var(--preview-columns, 3), minmax(0, 1fr)); gap: 4px; }
.layout-preview .part {
  display: grid; place-items: center; align-content: center; gap: 3px; min-height: 47px;
  text-align: center; border: 1px solid var(--line); border-radius: 3px; background: #112026;
  padding: 4px; font-size: .74rem; overflow-wrap: anywhere;
}
.layout-preview .emblem { width: 29px; aspect-ratio: 1; }
#plan-form > label, .research-block label { display: grid; margin: 11px 0; gap: 4px; color: #cfdfdb; }
#plan-form textarea { resize: vertical; }
#plan-form fieldset { border: 1px solid #40585e; border-radius: 3px; margin: 12px 0; }
#plan-form fieldset p { margin: 4px 0 9px; }
.research-body { min-height: 365px; padding: clamp(14px, 4vw, 35px); background: radial-gradient(ellipse at 20% 0%, #183638, #121d21 56%); }
.research-block { padding: 10px 0 18px; }
.research-block + .research-block { border-top: 1px solid var(--line); }
.research-block h3 { margin: 0; }
.research-block label { max-width: 480px; }
#research-feedback, #research-locked { color: #bbddda; line-height: 1.55; }

@media (min-width: 761px) {
  .chamber { height: clamp(385px, 56svh, 680px); }
  .inventory { min-height: calc(clamp(385px, 56svh, 680px) + 144px); }
}
@media (max-width: 760px) {
  .chamber { height: clamp(285px, 43svh, 405px); }
  .mix.grid-mode { width: min(74%, 245px); }
  .grid-mode + #effects + .result { bottom: 6px; }
  .stations button { min-height: 35px; padding: 6px 8px; }
}
@media (max-width: 410px) {
  .surface-actions .subtle { padding-inline: 6px; }
  .mix { gap: 7px; }
  .socket-label { font-size: .78rem; }
}
