* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #12151c; color: #dfe6f0;
  display: flex; flex-direction: column;
  font-size: 13px;
}
button { font-family: inherit; }

#topbar {
  height: 50px; flex: 0 0 50px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  background: #1a1f2a; border-bottom: 1px solid #2a3140;
}
.logo { font-weight: 700; font-size: 16px; white-space: nowrap; }
.logo span { color: #4fa3ff; }
.proj-name {
  background: #12151c; border: 1px solid #2a3140; color: #fff;
  border-radius: 6px; padding: 6px 10px; font-size: 13px; width: 160px;
}
.tools { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; overflow-x: auto; }
.sep { width: 1px; height: 22px; background: #2a3140; margin: 0 4px; flex: 0 0 1px; }
.btn {
  background: #242b3a; color: #dfe6f0; border: 1px solid #333c50;
  border-radius: 7px; padding: 7px 12px; font-size: 12.5px; cursor: pointer;
  white-space: nowrap; transition: background .15s;
}
.btn:hover { background: #2f3850; }
.btn.play { background: #1f7a44; border-color: #2a9a58; font-weight: 600; }
.btn.play:hover { background: #269151; }
.btn.stop { background: #a33a3a; border-color: #c04848; font-weight: 600; }
.btn.stop:hover { background: #b84545; }
.btn.exe { background: #2f6fb0; border-color: #3f88d4; font-weight: 600; }
.btn.exe:hover { background: #3880c8; }
.btn.danger { background: #5a2a2a; border-color: #7a3838; }
.btn.danger:hover { background: #6f3434; }
.btn:disabled { opacity: .5; cursor: wait; }

#main { flex: 1; display: flex; min-height: 0; }
#left, #right {
  width: 230px; flex: 0 0 230px; background: #171b24;
  border-right: 1px solid #2a3140; overflow-y: auto; padding: 10px;
}
#right { width: 300px; flex: 0 0 300px; border-right: none; border-left: 1px solid #2a3140; display: flex; flex-direction: column; padding: 0; }
.panel-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: #8b96ab; margin: 12px 0 6px; font-weight: 600;
}
.panel-title:first-child { margin-top: 2px; }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.palette button {
  background: #202634; border: 1px solid #2e3749; color: #dfe6f0;
  border-radius: 7px; padding: 8px 4px; font-size: 12px; cursor: pointer;
}
.palette button:hover { background: #2a3346; border-color: #4fa3ff; }
#objList { display: flex; flex-direction: column; gap: 3px; max-height: 40vh; overflow-y: auto; }
.obj-item {
  display: flex; align-items: center; justify-content: space-between;
  background: #1d222e; border: 1px solid transparent; border-radius: 6px;
  padding: 5px 8px; cursor: pointer; font-size: 12px;
}
.obj-item:hover { background: #242b3a; }
.obj-item.sel { border-color: #4fa3ff; background: #23304a; }
.obj-item .del { color: #8b96ab; cursor: pointer; padding: 0 3px; }
.obj-item .del:hover { color: #ff7a7a; }
.world-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.world-row label { width: 48px; color: #8b96ab; }
.world-row select, .world-row input[type=range] { flex: 1; }
select {
  background: #202634; color: #dfe6f0; border: 1px solid #2e3749;
  border-radius: 6px; padding: 5px;
}

#viewport { flex: 1; position: relative; min-width: 0; background: #0a0d13; }
#viewport canvas { display: block; }
#editHint {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: rgba(255,255,255,.55); background: rgba(10,13,20,.55);
  padding: 4px 12px; border-radius: 12px; pointer-events: none; white-space: nowrap; z-index: 4;
}
.overlay-stop { position: absolute; top: 12px; right: 14px; z-index: 10; }

.tabs { display: flex; border-bottom: 1px solid #2a3140; flex: 0 0 auto; }
.tab {
  flex: 1; background: none; border: none; color: #8b96ab;
  padding: 10px; cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent;
}
.tab.active { color: #fff; border-bottom-color: #4fa3ff; }
.pane { padding: 12px; overflow-y: auto; flex: 1; }
.muted { color: #8b96ab; }
.prop-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.prop-row label { width: 76px; color: #8b96ab; flex: 0 0 76px; }
.prop-row input[type=text], .prop-row input[type=number] {
  flex: 1; background: #202634; border: 1px solid #2e3749; color: #fff;
  border-radius: 6px; padding: 6px 8px; font-size: 12.5px; min-width: 0;
}
.prop-row input[type=color] { width: 46px; height: 30px; border: none; background: none; cursor: pointer; }
.prop-xyz { display: flex; gap: 6px; margin: 8px 0; }
.prop-xyz > div { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.prop-xyz label { color: #8b96ab; font-size: 11px; }
.prop-xyz input {
  background: #202634; border: 1px solid #2e3749; color: #fff;
  border-radius: 6px; padding: 6px; font-size: 12.5px; width: 100%;
}
.prop-btns { display: flex; gap: 8px; margin-top: 14px; }
.prop-btns .btn { flex: 1; }

.script-help { font-size: 12px; color: #aab4c8; margin-bottom: 8px; line-height: 1.45; }
.script-help a { color: #4fa3ff; }
#scriptBox {
  width: 100%; height: 46vh; min-height: 220px; resize: vertical;
  background: #0e1118; color: #cfe3ff; border: 1px solid #2e3749; border-radius: 8px;
  font-family: Consolas, 'Courier New', monospace; font-size: 12.5px; line-height: 1.5;
  padding: 10px; white-space: pre; overflow: auto;
}
.script-btns { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
#scriptErrors { font-size: 12px; }
.err-line { color: #ff8f8f; padding: 3px 0; border-bottom: 1px solid #232836; }
.ok-line { color: #6fdc9a; padding: 3px 0; }

#statusbar {
  flex: 0 0 84px; background: #141821; border-top: 1px solid #2a3140;
  overflow-y: auto; padding: 6px 12px;
}
#console { font-family: Consolas, monospace; font-size: 11.5px; line-height: 1.5; }
#console .log { color: #9aa5bb; }
#console .ok { color: #6fdc9a; }
#console .error { color: #ff8f8f; }

body.playing #left, body.playing #right, body.playing #statusbar, body.playing #editHint { display: none; }
body.playing #topbar .tools .btn:not(#btnStop) { display: none; }
body.playing #topbar .sep { display: none; }
body.playing .proj-name { display: none; }

.modal {
  position: fixed; inset: 0; background: rgba(5,8,15,.7);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  background: #1a1f2a; border: 1px solid #333c50; border-radius: 12px;
  width: min(680px, 92vw); max-height: 86vh; display: flex; flex-direction: column;
}
.modal-box.small { width: min(440px, 92vw); }
.modal-head {
  padding: 14px 18px; font-weight: 600; font-size: 15px;
  border-bottom: 1px solid #2a3140; display: flex; justify-content: space-between; align-items: center;
}
.modal-body { padding: 16px 18px; overflow-y: auto; line-height: 1.5; }
.modal-body pre {
  background: #0e1118; border: 1px solid #2e3749; border-radius: 8px;
  padding: 10px 12px; font-size: 12px; overflow-x: auto; color: #cfe3ff;
  font-family: Consolas, monospace; line-height: 1.55;
}
.modal-body code { background: #0e1118; padding: 1px 5px; border-radius: 4px; color: #cfe3ff; }
.modal-body h4 { margin: 14px 0 6px; color: #4fa3ff; }
.build-bar { height: 8px; background: #0e1118; border-radius: 4px; overflow: hidden; margin: 14px 0 10px; }
#buildFill { height: 100%; width: 5%; background: linear-gradient(90deg,#2f6fb0,#4fa3ff); transition: width .4s; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #2e3749; border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }
