:root {
  --bg: #0d121b; --panel: #151c28; --panel2: #1b2433; --line: #283347; --text: #e8eef8; --muted: #8b98ad;
  --accent: #3dd6a0; --accent2: #4dd7ff; --warn: #ffb020; --bad: #ff5a5a; --buy: #ff9f43;
  --r: 12px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); } .small { font-size: 13px; } .pad { padding: 8px 12px; }
.hi { color: #ff6b6b; font-weight: 700; } .lo { color: #7fb2ff; font-weight: 700; } .mid { color: #ffd166; font-weight: 700; }
.ok { color: var(--accent); } .warn { color: var(--warn); }

#top { height: 58px; display: flex; align-items: center; gap: 14px; padding: 0 14px; background: linear-gradient(180deg, #172133, #121a28); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 210px; }
.brand b { display: block; font-size: 16px; } .brand small { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.logo { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: linear-gradient(135deg, #3dd6a0, #2f7bff); font-size: 20px; }
.proj-title { background: none; border: 1px dashed transparent; border-radius: 8px; padding: 4px 8px; font-weight: 600; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-title:hover { border-color: var(--line); color: var(--text); }
.tb { display: flex; align-items: center; gap: 8px; } .tb.right { margin-left: auto; }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; transition: .15s; white-space: nowrap; }
.btn:hover { border-color: #3a4a66; background: #222d40; }
.btn.icon { padding: 7px 10px; }
.btn.primary { background: #1f6f5a; border-color: #2a8f75; } .btn.primary:hover { background: #26876d; }
.btn.run { background: linear-gradient(180deg, #2fc98f, #1fa476); border: none; color: #04150e; font-weight: 800; padding: 9px 18px; font-size: 16px; box-shadow: 0 4px 16px #2fc98f44; }
.btn.run.stop { background: linear-gradient(180deg, #ff7070, #e04646); color: #fff; box-shadow: 0 4px 16px #ff505044; }
.btn.danger { border-color: #6b2a2a; color: #ffb3b3; } .btn.danger:hover { background: #3a1c1f; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.hold { user-select: none; } .btn.hold.on { background: #2a8f75; }
.status { white-space: nowrap; font-size: 13px; padding: 5px 10px; border-radius: 20px; background: var(--panel2); color: var(--muted); }
.status.running { color: #3dd6a0; background: #12352b; } .status.error { color: #ff8a8a; background: #3a1c1f; } .status.compiling { color: #ffd166; background: #3a3218; }

main { display: grid; grid-template-columns: 290px 1fr 430px; height: calc(100% - 58px); }
aside { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
#left { border-right: 1px solid var(--line); } #right { border-left: 1px solid var(--line); }
.tabs { display: flex; gap: 1px; padding: 8px 6px 0; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { background: none; border: none; padding: 7px 7px; border-radius: 10px 10px 0 0; color: var(--muted); font-weight: 600; font-size: 13px; position: relative; white-space: nowrap; }
.tab.on { background: var(--panel2); color: var(--text); }
.tb-badge { font-style: normal; background: var(--bad); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; margin-left: 2px; }
.tb-badge:empty { display: none; }
.pane { display: none; flex: 1; min-height: 0; overflow: auto; flex-direction: column; }
.pane.on { display: flex; }
.search { margin: 10px 10px 0; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }

.pal-cat { padding: 4px 10px 8px; }
.pal-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 8px 2px 6px; }
.pal-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--panel2); border: 1px solid transparent; border-radius: 10px; padding: 8px 10px; margin-bottom: 5px; }
.pal-item:hover { border-color: #3a4a66; transform: translateX(2px); }
.pal-emoji { font-size: 20px; width: 26px; text-align: center; } .pal-name { flex: 1; font-size: 14px; }
.badge { font-size: 11px; border-radius: 6px; padding: 1px 6px; font-weight: 700; white-space: nowrap; }
.badge.kit { background: #12352b; color: #3dd6a0; } .badge.buy { background: #3a2a14; color: var(--buy); }

.ex-card { margin: 10px; padding: 12px; background: var(--panel2); border-radius: var(--r); border: 1px solid var(--line); }
.ex-h { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; } .ex-emoji { font-size: 22px; } .lvl { margin-left: auto; color: #ffd166; font-size: 12px; }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.buyline { color: var(--buy); margin-top: 4px; }
.kit-row { padding: 4px 12px; font-size: 14px; }

#stage { position: relative; min-width: 0; }
#stage3d { position: absolute; inset: 0; }
#stage3d canvas { display: block; touch-action: none; }
.labels-layer { position: absolute; inset: 0; pointer-events: none; }
.part-label { font-size: 12px; font-weight: 700; background: #0d121bcc; border: 1px solid #ffffff22; padding: 2px 8px; border-radius: 20px; white-space: nowrap; color: #dfe8f5; }
.hint-bar { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); font-size: 12px; color: var(--muted); background: #0d121bcc; padding: 5px 12px; border-radius: 20px; pointer-events: none; white-space: nowrap; max-width: 96%; overflow: hidden; text-overflow: ellipsis; }

.card { background: #151c28f2; backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px #0008; }
#inspector { position: absolute; right: 12px; top: 12px; width: 340px; max-height: calc(100% - 64px); overflow: auto; padding: 14px; }
.ins-head { display: flex; gap: 10px; align-items: flex-start; } .ins-emoji { font-size: 28px; line-height: 1; }
.ins-head .x, .help-card .x { margin-left: auto; background: none; border: none; color: var(--muted); font-size: 18px; }
.ins-desc { margin: 10px 0 6px; } .ins-how { margin: 0 0 8px; color: #c9d4e6; font-size: 14px; }
.ins-sub { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 10px 0 6px; }
.ctl { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; font-size: 14px; }
.ctl.tog { flex-direction: row; align-items: center; gap: 8px; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); }
.ctl select { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 5px; }
.ins-ctls .btn { margin: 0 6px 6px 0; }
.pinrow { display: flex; gap: 6px; align-items: center; font-size: 13px; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.pinrow:hover { background: var(--panel2); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; border: 1px solid #fff4; }
.ins-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff3; margin: 0 2px; }
.swatch.on { border-color: #fff; }
.ins-row { margin: 10px 0; display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }

#tip { position: fixed; z-index: 50; max-width: 320px; background: #0b1019f5; border: 1px solid #3a4a66; border-radius: 10px; padding: 8px 10px; font-size: 13px; pointer-events: none; box-shadow: 0 8px 24px #0009; }
.tip-h { font-weight: 800; color: var(--accent2); margin-bottom: 2px; }

#chat { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.hello { background: linear-gradient(135deg, #16313a, #1b2433); border: 1px solid #245a66; border-radius: var(--r); padding: 12px; }
.msg { padding: 10px 12px; border-radius: 14px; max-width: 94%; font-size: 14.5px; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: #1f4f7a; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--panel2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg pre.code { background: #0b0f17; border-radius: 8px; padding: 8px; overflow: auto; font-size: 12.5px; max-height: 280px; }
.msg code { background: #0b0f17; padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.thinking span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent2); margin-right: 3px; animation: bounce 1s infinite; }
.thinking span:nth-child(2) { animation-delay: .15s; } .thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 100% { transform: translateY(0); opacity: .4; } 50% { transform: translateY(-5px); opacity: 1; } }
.proj-card { margin-top: 10px; padding: 10px; border-radius: 10px; background: #12352b; border: 1px solid #2a8f75; }
.proj-t { font-weight: 800; margin-bottom: 4px; }
.chips { display: flex; gap: 6px; padding: 0 10px 6px; flex-wrap: wrap; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px; font-size: 13px; }
.chip:hover { border-color: var(--accent); }
.ask { display: flex; gap: 6px; padding: 8px 10px 12px; }
.ask textarea, .ask input { flex: 1; resize: none; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; font: inherit; }
.ask textarea:focus, .ask input:focus, .search:focus { outline: none; border-color: var(--accent); }

.code-bar { display: flex; gap: 6px; align-items: center; padding: 8px 10px; flex-wrap: wrap; }
#editor { flex: 1; min-height: 0; overflow: hidden; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
#editor .cm-editor { height: 100%; }
.compile-out { margin: 0; padding: 10px 12px; font-size: 13px; white-space: pre-wrap; max-height: 34%; overflow: auto; color: var(--muted); font-family: var(--font); }
.compile-out.err { color: #ffb3b3; background: #2a1417; font-family: Menlo, monospace; font-size: 12px; }
.compile-out.ok { color: var(--accent); }
.compile-out .btn { margin-top: 8px; font-family: var(--font); }
#serialOut { flex: 1; margin: 0; padding: 10px 12px; background: #080b11; color: #b8f5d0; font: 13px/1.4 Menlo, monospace; overflow: auto; white-space: pre-wrap; }
#serialOut .sys { color: var(--muted); }

.empty { padding: 20px; color: var(--muted); text-align: center; }
.issue { margin: 8px 10px 0; padding: 10px 12px; border-radius: 10px; font-size: 14px; cursor: pointer; border-left: 4px solid; background: var(--panel2); }
.issue.bad { border-color: var(--bad); background: #2a1417; } .issue.warn { border-color: var(--warn); } .issue.info { border-color: #4a6a9a; color: #c1cde0; }
.issue .go { float: right; color: var(--muted); font-size: 12px; margin-left: 8px; }
.steps-head { padding: 12px; } .steps-head p { margin: 4px 0 8px; }
.progress { height: 8px; border-radius: 8px; background: var(--bg); overflow: hidden; margin: 6px 0 4px; }
.progress div { height: 100%; background: linear-gradient(90deg, #3dd6a0, #4dd7ff); transition: width .4s; }
.step { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; margin: 0 8px 4px; border-radius: 10px; cursor: pointer; font-size: 14.5px; }
.step:hover { background: var(--panel2); }
.step .num { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--panel2); border: 1px solid var(--line); font-size: 13px; font-weight: 700; }
.step.done { color: var(--muted); } .step.done .num { background: #1f6f5a; border-color: #2a8f75; color: #fff; }
.step.cur { background: #1d2d22; outline: 2px solid #3dd6a0; } .step.cur .num { background: #ffd21f; color: #000; }
.celebrate { margin: 12px; padding: 14px; text-align: center; font-size: 18px; font-weight: 800; background: linear-gradient(135deg, #1f6f5a, #2f5a9f); border-radius: 12px; }

#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 60; pointer-events: none; }
.toast { background: #0b1019f0; border: 1px solid #3a4a66; padding: 9px 16px; border-radius: 24px; font-size: 14px; box-shadow: 0 8px 24px #0008; animation: tin .25s; transition: .4s; max-width: 70vw; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
#confetti i { position: absolute; top: -10px; width: 9px; height: 14px; border-radius: 2px; animation: fall 2.4s ease-in forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

#help { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 80; }
#help[hidden] { display: none; }
.help-card { position: relative; width: min(680px, 94vw); max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px 26px; }
.help-card .x { position: absolute; right: 14px; top: 12px; }
.help-card li { margin-bottom: 8px; }

@media (max-width: 1200px) { main { grid-template-columns: 250px 1fr 360px; } .brand small, .proj-title { display: none; } }
@media (max-width: 900px) {
  html, body { overflow: auto; }
  #top { height: auto; flex-wrap: wrap; padding: 8px 12px; }
  .tb.right { margin-left: 0; flex-wrap: wrap; }
  main { display: flex; flex-direction: column; height: auto; }
  #stage { height: 62vh; order: 1; }
  #right { order: 2; height: 70vh; } #left { order: 3; max-height: 60vh; }
  #inspector { width: auto; right: 12px; left: 12px; bottom: 12px; max-height: 50%; }
  .hint-bar { display: none; }
}

.part-label.buy { border-color: #ff9f43; color: #ffc98a; }
.ex-card.mine { border-color: #3a5a8a; }
.board-tabs { display: flex; gap: 4px; flex-basis: 100%; }
.board-tabs:empty { display: none; }

.hw-chip.on { background: #12352b; border-color: #2a8f75; color: #3dd6a0; }
.hw-card { margin: 10px; padding: 14px; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--r); display: flex; flex-direction: column; gap: 10px; }
.hw-status { font-size: 15px; } .hw-status.on { color: var(--accent); }
.hw-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hw-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.hw-grid select, #hwBaud { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.btn.wide { width: 100%; } .btn[disabled] { opacity: .45; cursor: not-allowed; }
.hw-progress { height: 8px; border-radius: 8px; background: var(--bg); overflow: hidden; }
.hw-progress div { height: 100%; width: 0; background: linear-gradient(90deg, #3dd6a0, #4dd7ff); transition: width .2s; }
.hw-log { font-size: 13px; max-height: 180px; overflow: auto; } .hw-log .ok { color: var(--accent); } .hw-log .err { color: #ff8a8a; } .hw-log .muted { color: var(--muted); }
.hw-sub { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: 4px; }

.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 90; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { position: relative; width: min(440px, 94vw); max-height: 90vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px 22px; display: flex; flex-direction: column; gap: 10px; }
.modal-card.wide-card { width: min(720px, 96vw); }
.modal-card .x { position: absolute; right: 12px; top: 10px; background: none; border: none; color: var(--muted); font-size: 18px; }
.modal-card h3 { margin: 0 24px 4px 0; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: #c9d4e6; }
.modal-card input:not([type=checkbox]):not([type=color]), .modal-card textarea, .modal-card select, .grow { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font: inherit; }
.modal-card label.small { flex-direction: row; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 6px; } .grow { flex: 1; min-width: 0; }
.auth-tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 12px; }
.auth-tabs button { flex: 1; background: none; border: none; padding: 8px; border-radius: 9px; color: var(--muted); font-weight: 700; }
.auth-tabs button.on { background: var(--panel2); color: var(--text); }
.auth-err { color: #ff8a8a; min-height: 18px; font-size: 14px; }
.pal-item.lib { padding: 0; display: flex; align-items: center; gap: 2px; }
.pal-main { flex: 1; display: flex; align-items: center; gap: 10px; background: none; border: none; padding: 8px 10px; text-align: left; min-width: 0; }
.pal-thumb { width: 26px; height: 26px; object-fit: cover; border-radius: 6px; }
.icon-mini { background: none; border: none; padding: 4px; opacity: .7; } .icon-mini:hover { opacity: 1; }
.kit-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.pt-photo { display: flex; align-items: center; gap: 12px; } .pt-photo img { max-width: 160px; max-height: 120px; border-radius: 10px; border: 1px solid var(--line); }
.pt-reply { font-size: 14px; } .pt-builtin { background: #12352b; border: 1px solid #2a8f75; border-radius: 10px; padding: 10px; margin: 6px 0; }
.pt-results { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow: auto; }
.pt-item { display: flex; gap: 10px; align-items: center; justify-content: space-between; background: var(--panel2); border-radius: 10px; padding: 8px 10px; }
.pt-editor { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.pt-grid { display: grid; grid-template-columns: 1fr 120px; gap: 8px; }
.pt-sub { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.pt-pins { display: flex; flex-direction: column; gap: 4px; }
.pt-pin { display: grid; grid-template-columns: 1fr 1fr 110px 36px; gap: 4px; }
.pt-pin input, .pt-pin select { padding: 6px 8px !important; }
.row { align-items: center; }
a.btn { color: inherit; text-decoration: none; display: inline-block; }
a.brand { color: inherit; text-decoration: none; }
.moved-bar { background: #3a3218; color: #ffe8a3; padding: 8px 14px; font-size: 14px; text-align: center; border-bottom: 1px solid #6b5a22; }
.moved-bar a { color: #fff; } .moved-bar .btn { margin-left: 8px; color: #04150e; }
