:root {
  --bg: #0b1020; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.13);
  --text: #e8ecff; --mute: #98a3c9;
  --cy: #22d3ee; --vi: #8b5cf6; --pk: #f472b6; --ok: #34d399; --bad: #fb7185;
  --grad: linear-gradient(90deg, #22d3ee, #8b5cf6, #f472b6);
  --spd: 1; --r: 14px;
  --mono: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--text);
  background: radial-gradient(1100px 560px at 8% -10%, rgba(34,211,238,.16), transparent 60%),
              radial-gradient(900px 520px at 100% 0%, rgba(244,114,182,.14), transparent 60%), var(--bg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:focus-visible { outline: 2px solid var(--cy); outline-offset: 2px; border-radius: 6px; }
button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
code, pre, textarea { font-family: var(--mono); }

/* header + tabs */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 6px; max-width: 1100px; margin: 0 auto; }
.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.logo { font-size: 26px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 0 10px rgba(139,92,246,.7)); }
.name { font-weight: 800; font-size: 22px; letter-spacing: .3px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tag { color: var(--mute); font-size: 13px; }
.topr { display: flex; align-items: center; gap: 8px; }
.tabs { display: flex; gap: 6px; padding: 8px 16px; max-width: 1100px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
.tab { flex: 1 0 auto; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); white-space: nowrap; transition: .2s; }
.tab:hover { border-color: var(--cy); }
.tab[aria-selected="true"] { background: var(--grad); color: #0b1020; font-weight: 700; border-color: transparent; box-shadow: 0 0 22px -4px var(--vi); }
main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 24px; }
footer { max-width: 1100px; margin: 0 auto; padding: 8px 16px 28px; color: var(--mute); font-size: 12.5px; text-align: center; }

/* shared bits */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin: 0 0 12px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 10px 30px -18px #000; }
.note { color: var(--mute); font-size: 13px; }
.btn { padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.08); transition: .2s; }
.btn:hover { border-color: var(--cy); background: rgba(34,211,238,.12); }
.btn.primary { background: var(--grad); color: #0b1020; font-weight: 700; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.12); }
.btn.glow { border-color: var(--pk); box-shadow: 0 0 16px -2px var(--pk); }
.btn.danger:hover { border-color: var(--bad); background: rgba(251,113,133,.15); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.06); font-size: 13px; transition: .2s; }
.chip:hover { border-color: var(--vi); }
.chip[aria-pressed="true"] { background: var(--vi); border-color: transparent; font-weight: 700; box-shadow: 0 0 14px -2px var(--vi); }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.fld { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--mute); min-width: 0; }
select, input[type=text], input[type=number], input:not([type]), textarea {
  background: rgba(8,12,28,.75); border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; color: var(--text); min-width: 0; width: 100%;
}
select { color-scheme: dark; }
.kw { color: var(--cy); font-weight: 600; }
.msg { margin: 10px 0; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.msg:empty { display: none; }
.msg.err { background: rgba(251,113,133,.13); border: 1px solid var(--bad); }
.msg.ok { background: rgba(52,211,153,.12); border: 1px solid var(--ok); }
.msg code { display: block; margin-top: 6px; color: var(--mute); font-size: 12px; white-space: pre-wrap; word-break: break-word; }
#toast { position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; background: #1b2347; border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; font-size: 13px; transition: .3s; z-index: 50; max-width: 90vw; }
#toast.on { transform: translate(-50%, 0); opacity: 1; }

/* result grids */
.gridbox { margin: 10px 0; }
.cnt { color: var(--mute); font-size: 12.5px; margin-bottom: 4px; }
.gridwrap { overflow: auto; max-height: 380px; border: 1px solid var(--line); border-radius: 10px; }
.grid { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.grid th, .grid td { padding: 6px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid rgba(255,255,255,.07); }
.grid th { position: sticky; top: 0; background: #161d3b; color: var(--cy); font-weight: 600; }
.grid td.nul, .nul { color: var(--mute); font-style: italic; }

/* ---------- Join Theater ---------- */
.ctl { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.ctl .row2, .ctl .tools { grid-column: 1 / -1; }
.row2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.venn { width: 96px; height: 56px; flex: none; }
.venn circle { fill: rgba(255,255,255,.04); stroke-width: 1.5; transition: fill .4s; }
.venn .a { stroke: var(--cy); } .venn .b { stroke: var(--pk); }
.venn .a.on { fill: rgba(34,211,238,.5); } .venn .b.on { fill: rgba(244,114,182,.5); }
.venn .i { fill: rgba(139,92,246,.95); stroke: none; }
.sqlbar { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.sql { margin: 0; font-size: 13px; white-space: pre-wrap; word-break: break-word; flex: 1 1 260px; }

.stage { position: relative; perspective: 1100px; display: flex; justify-content: center; align-items: flex-start; gap: 64px; padding: 22px 6px 18px; min-height: 230px; overflow: hidden; border-radius: var(--r); background: radial-gradient(600px 220px at 50% 50%, rgba(139,92,246,.14), transparent 70%); border: 1px solid var(--line); margin-bottom: 8px; }
.tbl { --c: var(--cy); position: relative; z-index: 2; min-width: 0; max-width: 48%; flex: 0 1 auto; padding: 8px; border-radius: 12px; border: 1px solid var(--c); background: rgba(10,15,36,.82); transform-style: preserve-3d; box-shadow: 0 0 26px -6px var(--c), inset 0 0 22px -14px var(--c); transition: transform calc(1.1s / var(--spd)) cubic-bezier(.2,.8,.2,1), opacity calc(.8s / var(--spd)), filter .6s; }
.tbl.r { --c: var(--pk); }
.tname { font-weight: 700; color: var(--c); margin-bottom: 4px; text-shadow: 0 0 10px var(--c); }
.stage[data-phase="enter"] .tbl.l { transform: translateX(-130%) rotateY(42deg); opacity: 0; }
.stage[data-phase="enter"] .tbl.r { transform: translateX(130%) rotateY(-42deg); opacity: 0; }
.stage[data-phase="stand"] .tbl.l { transform: translateX(-22px) rotateY(24deg); }
.stage[data-phase="stand"] .tbl.r { transform: translateX(22px) rotateY(-24deg); }
.stage[data-phase="near"] .tbl.l { transform: translateX(26px) rotateY(9deg); }
.stage[data-phase="near"] .tbl.r { transform: translateX(-26px) rotateY(-9deg); }
.stage[data-phase="back"] .tbl.l { transform: translateX(18px) translateZ(-70px) scale(.94); opacity: .75; }
.stage[data-phase="back"] .tbl.r { transform: translateX(-18px) translateZ(-70px) scale(.94); opacity: .75; }

.trow { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(52px, 1fr)); font-size: 12.5px; border-radius: 6px; transition: transform calc(.4s / var(--spd)), background .3s, box-shadow .3s, opacity .5s; }
.thead { color: var(--mute); font-weight: 700; font-size: 11.5px; border-bottom: 1px solid var(--line); margin-bottom: 2px; }
.tbody { position: relative; }
.c { padding: 3px 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c.key { background: rgba(255,255,255,.07); box-shadow: inset 0 0 0 1px var(--c, var(--cy)); color: #fff; text-shadow: 0 0 8px var(--c, var(--cy)); animation: keyglow 2.2s ease-in-out infinite; }
.cross .c.key { background: none; box-shadow: none; text-shadow: none; animation: none; }
.cross .plug, .cross .wire { display: none; }
@keyframes keyglow { 50% { box-shadow: inset 0 0 0 1px var(--c, var(--cy)), 0 0 12px -2px var(--c, var(--cy)); } }
.plug { margin-right: 4px; }
.c.nul { color: var(--mute); font-style: italic; background: repeating-linear-gradient(135deg, rgba(255,255,255,.1) 0 4px, transparent 4px 8px); }
.empty { color: var(--mute); font-style: italic; padding: 8px; font-size: 13px; }
.trow.done { opacity: .5; }
.trow.cur { transform: translateZ(34px) scale(1.04); background: rgba(34,211,238,.2); box-shadow: 0 0 18px -2px var(--cy); opacity: 1; z-index: 3; position: relative; }
.tbl.r .trow.cur, .tbl.r .trow.scan { background: rgba(244,114,182,.22); box-shadow: 0 0 18px -2px var(--pk); }
.trow.scan { background: rgba(244,114,182,.16); }
.trow.flash { animation: flash calc(.9s / var(--spd)) ease-out; }
.trow.shake { animation: shake calc(.6s / var(--spd)); }
.trow.drop { opacity: .35; text-decoration: line-through; }
@keyframes flash { 0%, 100% { filter: none; } 35% { filter: brightness(2.4) saturate(1.4); } }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(4px); } }
.beam { position: absolute; left: -4px; right: -4px; top: 0; border-radius: 6px; pointer-events: none; opacity: 0; background: linear-gradient(90deg, transparent, rgba(244,114,182,.5), transparent); box-shadow: 0 0 14px var(--pk); transition: transform calc(.35s / var(--spd)), opacity .3s; }
.beam.on { opacity: 1; }

.wire { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; opacity: 0; transition: opacity .6s; }
.stage[data-phase="near"] .wire { opacity: 1; }
.wire line { stroke: var(--vi); stroke-width: 2; stroke-dasharray: 6 6; stroke-linecap: round; filter: drop-shadow(0 0 5px var(--vi)); animation: dash .8s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -12; } }
.spark { position: absolute; z-index: 6; width: 0; height: 0; pointer-events: none; }
.spark i { position: absolute; left: -3px; top: -3px; width: 6px; height: 6px; border-radius: 50%; background: #fff; box-shadow: 0 0 10px 2px var(--pk), 0 0 18px 4px var(--cy); animation: burst .8s ease-out forwards; }
@keyframes burst { from { transform: rotate(var(--a)) translateX(0); opacity: 1; } to { transform: rotate(var(--a)) translateX(42px); opacity: 0; } }

.narr { min-height: 44px; padding: 10px 12px; margin-bottom: 8px; border-radius: 10px; font-family: var(--mono); font-size: 13.5px; background: rgba(8,12,28,.7); border: 1px solid var(--line); word-break: break-word; }
.narr.ok { border-color: var(--ok); } .narr.bad { border-color: rgba(251,113,133,.6); }
.result { position: relative; z-index: 5; transition: box-shadow .6s, border-color .6s; }
.result .thead .c.lc, .mrow .c.lc { color: var(--cy); }
.result .thead .c.rc, .mrow .c.rc { color: var(--pk); }
.mrow .c.lc { background: rgba(34,211,238,.1); } .mrow .c.rc { background: rgba(244,114,182,.1); }
.mrow { margin-bottom: 2px; }
.mrow.fly { animation: fly calc(.85s / var(--spd)) cubic-bezier(.2,.8,.2,1); }
@keyframes fly { 0% { transform: translateY(-160px) scale(1.08); opacity: 0; filter: brightness(2); } 55% { opacity: 1; } 100% { transform: none; filter: none; } }
.result.glow { border-color: var(--vi); box-shadow: 0 0 44px -6px var(--vi); }
.rhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.badge { padding: 3px 12px; border-radius: 999px; background: var(--grad); color: #0b1020; font-weight: 800; animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }
.verify { margin-top: 8px; font-size: 13px; color: var(--mute); }
.verify.ok { color: var(--ok); } .verify.bad { color: var(--bad); }

/* ---------- Lab ---------- */
.lab { display: grid; grid-template-columns: 1fr; gap: 12px; }
.schema summary { cursor: pointer; font-weight: 700; color: var(--cy); }
.stbl { margin-top: 8px; }
.tn, .col { display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 8px; background: none; border: 0; text-align: left; padding: 3px 6px; border-radius: 6px; }
.tn { font-weight: 700; color: var(--pk); }
.col { font-size: 13px; font-family: var(--mono); }
.tn:hover, .col:hover { background: rgba(255,255,255,.09); }
.ct { color: var(--mute); font-size: 11px; }
.editor { min-height: 140px; resize: vertical; line-height: 1.5; margin: 8px 0; tab-size: 2; }
@media (min-width: 760px) { .lab { grid-template-columns: 230px 1fr; align-items: start; } }

/* ---------- Builder ---------- */
.bld { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 900px) { .bld { grid-template-columns: 1fr 1fr; align-items: start; } .bld .wide { grid-column: 1 / -1; } }
.bld h3, .mis h3 { margin: 0 0 8px; font-size: 16px; }
.colrow { display: grid; grid-template-columns: 1.3fr .9fr auto auto auto 1.6fr auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.colrow label { font-size: 12px; color: var(--mute); display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.colrow input[type=checkbox] { width: auto; }
@media (max-width: 700px) { .colrow { grid-template-columns: 1fr 1fr; padding: 8px; border: 1px solid var(--line); border-radius: 10px; } }
.preview { margin: 8px 0; padding: 10px; background: rgba(8,12,28,.75); border: 1px solid var(--line); border-radius: 10px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }
.tcard h4 { margin: 0 0 6px; color: var(--cy); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tcard .cols { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.pill { padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; font-family: var(--mono); }
.pill.pk { border-color: var(--cy); } .pill.fk { border-color: var(--pk); }
.addrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 6px; margin: 8px 0; }
.er { width: 100%; overflow: auto; }
.er svg { min-width: 520px; width: 100%; }
.er text { fill: var(--text); font-size: 12px; font-family: var(--mono); }

/* ---------- Missions ---------- */
.mis { display: grid; gap: 12px; }
.bar { height: 10px; border-radius: 999px; background: rgba(255,255,255,.1); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--grad); transition: width .5s; }
.mlist { display: grid; gap: 8px; }
.mbtn { display: flex; justify-content: space-between; gap: 8px; text-align: left; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); width: 100%; }
.mbtn[aria-current="true"] { border-color: var(--vi); box-shadow: 0 0 18px -4px var(--vi); }
.lvl { font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); text-transform: uppercase; }
.lvl.easy { color: var(--ok); } .lvl.medium { color: #fbbf24; } .lvl.hard { color: var(--bad); }
.done-mark { color: var(--ok); font-weight: 700; }
.hint { color: #fbbf24; font-size: 13.5px; }

/* ---------- account ---------- */
dialog { background: #121936; color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: min(92vw, 380px); box-shadow: 0 20px 60px -10px #000; }
dialog::backdrop { background: rgba(5,8,20,.7); backdrop-filter: blur(3px); }
dialog form { display: grid; gap: 10px; }
.saved { font-size: 12px; color: var(--mute); }
.saved.bad { color: var(--bad); }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  .tag { display: none; }
  .stage { flex-direction: column; align-items: stretch; gap: 22px; padding: 16px 6px; }
  .tbl { max-width: 100%; }
  .stage[data-phase="enter"] .tbl.l { transform: translateX(-130%) rotateY(30deg); }
  .stage[data-phase="enter"] .tbl.r { transform: translateX(130%) rotateY(-30deg); }
  .stage[data-phase="stand"] .tbl.l, .stage[data-phase="near"] .tbl.l { transform: translateY(6px) rotateX(6deg); }
  .stage[data-phase="stand"] .tbl.r, .stage[data-phase="near"] .tbl.r { transform: translateY(-6px) rotateX(-6deg); }
  .stage[data-phase="back"] .tbl.l, .stage[data-phase="back"] .tbl.r { transform: scale(.95); opacity: .75; }
  .trow { font-size: 12px; }
  .ctl { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
