:root {
  --bg: #0b0f17;
  --bg-2: #0f1521;
  --panel: #111826;
  --panel-2: #141c2c;
  --line: #1e293b;
  --line-soft: #172235;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --brand: #3b82f6;
  --brand-2: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(0, 0, 0, .45);
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow-x: hidden;
}

* {
  scrollbar-width: thin;
  scrollbar-color: #1f2c42 transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: #1f2c42;
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: #2a3a56; background-clip: padding-box; }

body {
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(59, 130, 246, .16), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(37, 99, 235, .12), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 23, .82);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(160deg, var(--brand), #1e40af);
  color: #fff;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 14px; letter-spacing: .2px; }
.brand-text span { font-size: 11.5px; color: var(--muted); }

.topbar-status { display: flex; align-items: center; gap: 10px; }

.net-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.net-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: #475569; }
.net-pill.is-live .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.net-pill.is-live { color: var(--text); }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, background .18s ease, border-color .18s ease, opacity .18s;
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--line);
}
.btn:hover { background: #1a2438; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, var(--brand), var(--brand-2));
  border-color: #1d4ed8;
  color: #fff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, .32);
}
.btn-primary:hover { background: linear-gradient(180deg, #4b8dfa, #2b6ef0); }
.btn-block { width: 100%; justify-content: center; }
.btn-ghost { background: transparent; }

.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---------- shell ---------- */
.shell {
  flex: 1;
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  height: fit-content;
}
.rail-item {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 6px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  cursor: pointer;
}
.rail-item svg { width: 18px; height: 18px; }
.rail-item:hover { background: var(--panel-2); color: var(--text); }
.rail-item.is-active {
  background: rgba(59, 130, 246, .14);
  border-color: rgba(59, 130, 246, .42);
  color: #dbeafe;
}
.rail-check {
  position: absolute; top: 6px; right: 8px;
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(180deg, #3ddc84, #16a34a);
  border: 1.5px solid rgba(255, 255, 255, .92);
}
.rail-check::after {
  content: ""; position: absolute; left: 3.4px; top: 1.6px;
  width: 3px; height: 6px;
  border-right: 1.8px solid #fff; border-bottom: 1.8px solid #fff;
  transform: rotate(45deg);
}

.workspace {
  display: grid;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  grid-template-columns: minmax(0, 1.55fr) minmax(340px, .85fr);
  grid-template-rows: auto minmax(0, 1fr) 150px;
  gap: 14px;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-editor { grid-row: 1 / 4; grid-column: 1; }
.panel-compile { grid-column: 2; grid-row: 1; }
.panel-deploy  { grid-column: 2; grid-row: 2; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  min-height: 44px;
}
.panel-head h2 {
  margin: 0; padding: 0 6px;
  font-size: 12px; font-weight: 600;
  letter-spacing: .4px; text-transform: uppercase;
  color: var(--muted);
}

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 6px 11px;
  border-radius: 8px;
  font: 12.5px var(--mono);
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { background: #16203380; color: var(--text); }
.tab.is-active {
  background: #162033;
  border-color: var(--line);
  color: var(--text);
}
.tab-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); }

/* ---------- editor ---------- */
.editor {
  position: relative;
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  min-height: 0;
  background: var(--bg-2);
}

.gutter {
  margin: 0;
  padding: 14px 8px 14px 0;
  text-align: right;
  color: #3d4d66;
  font: 12.5px/1.65 var(--mono);
  user-select: none;
  overflow: hidden;
  border-right: 1px solid var(--line-soft);
}

#code {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: #d5e2f5;
  font: 12.5px/1.65 var(--mono);
  padding: 14px 16px;
  min-height: 0;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}
#code::selection { background: rgba(59, 130, 246, .35); }

.editor-foot {
  display: flex; justify-content: space-between;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
}

/* ---------- side panels ---------- */
.side-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 11.5px; color: var(--muted); letter-spacing: .2px; }

.input, .select {
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font-size: 12.5px;
  outline: none;
}
.input:focus, .select:focus { border-color: rgba(59, 130, 246, .6); box-shadow: 0 0 0 3px rgba(59, 130, 246, .16); }
.mono { font-family: var(--mono); }

.check { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--muted); }
.check input { accent-color: var(--brand); width: 15px; height: 15px; }

.result {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  padding: 12px;
  font: 11.5px/1.7 var(--mono);
  color: var(--muted);
  max-height: 120px;
  overflow: auto;
}
.result-empty { margin: 0; text-align: center; color: #4a5a74; }
.result .ok { color: var(--ok); }
.result .meta { color: #6f819b; }

/* ---------- contract card ---------- */
.contract-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: linear-gradient(180deg, #131c2c, #101724);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.contract-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.contract-row .lbl { font-size: 11.5px; color: var(--muted); }
.val-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.val-row code, .contract-row code {
  font-size: 11.5px;
  color: #cfe0f8;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.btn-fn {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 8px 6px;
  background: #16233a;
  border-color: #22304a;
}
.btn-fn:hover { background: #1c2b45; }
.link { color: #7fb0ff; font-size: 12px; text-decoration: none; }
.link:hover { text-decoration: underline; }


/* ---------- mobile ---------- */
.mobile-tabs { display: none; }

@media (max-width: 900px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    padding: 10px 10px 76px;
    gap: 10px;
  }
  .rail { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .panel { display: none; }
  .panel.is-shown { display: flex; grid-column: 1; grid-row: 1; }
  .panel-editor { min-height: calc(100dvh - 210px); }

  .mobile-tabs {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: rgba(11, 15, 23, .94);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
    z-index: 30;
  }
  .mtab {
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 600;
    padding: 9px 4px;
    border-radius: 10px;
    cursor: pointer;
  }
  .mtab.is-active { background: rgba(59, 130, 246, .16); border-color: rgba(59, 130, 246, .4); color: #dbeafe; }

  .topbar { padding: 10px 12px; gap: 8px; }
  .brand-text span { display: none; }
  .brand-text strong { white-space: nowrap; font-size: 13px; }
  .btn { padding: 10px 14px; }
  #wallet-btn { padding: 8px 11px; font-size: 12px; white-space: nowrap; }
  .net-pill { padding: 5px 9px; font-size: 11px; }
  .editor { grid-template-columns: 34px minmax(0, 1fr); }
  .gutter { padding-right: 6px; }
  .fns { grid-template-columns: 1fr; }
  #code, .gutter { font-size: 12px; }
}

.send-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px dashed var(--line);
}
.send-row .input { padding: 8px 10px; }


/* ---------- file tree ---------- */
.head-actions { display: flex; align-items: center; gap: 2px; }

.editor-wrap {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  min-height: 0;
  flex: 1;
}

.tree {
  border-right: 1px solid var(--line);
  background: #0c121c;
  padding: 8px 6px;
  overflow-y: auto;
  min-width: 0;
}
.tree-group { margin-bottom: 10px; }
.tree-title {
  font-size: 10.5px;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: #4c5e79;
  padding: 4px 10px;
}
.tree-item {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 6px 9px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: #a9bcd6;
  font: 12px var(--mono);
  cursor: pointer;
  text-align: left;
}
.tree-item:hover { background: #141d2b; color: var(--text); }
.tree-item.is-active {
  background: rgba(59, 130, 246, .14);
  border-color: rgba(59, 130, 246, .38);
  color: #dbeafe;
}
.tree-item .ti { width: 14px; height: 14px; flex: 0 0 14px; display: inline-flex; align-items: center; justify-content: center; }
.tree-item .tn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-empty { color: #46566f; font-size: 11.5px; padding: 8px 10px; }

.head-actions #tree-toggle { display: none; }

@media (max-width: 900px) {
  .editor-wrap { grid-template-columns: minmax(0, 1fr); }
  .tree {
    position: absolute;
    z-index: 15;
    left: 10px;
    right: 10px;
    top: 54px;
    max-height: 60vh;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,.55);
    display: none;
  }
  .tree.is-open { display: block; }
  .head-actions #tree-toggle { display: grid; }
  .panel-editor { position: relative; }
}


/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 12, .72);
  backdrop-filter: blur(6px);
  animation: fade .16s ease;
}
.modal-card {
  position: relative;
  width: min(440px, 100%);
  background: linear-gradient(180deg, #131c2c, #0f1622);
  border: 1px solid #22304a;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .65);
  animation: pop .18s cubic-bezier(.2, .8, .3, 1);
}
.modal-card h3 {
  margin: 0 0 6px;
  font-size: 15px;
  letter-spacing: .2px;
}
.modal-hint {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--muted);
}
.modal-hint code {
  font-family: var(--mono);
  font-size: 11.5px;
  color: #9fc0f0;
  background: #0d1522;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid #1d2a3f;
}
.modal-card .input {
  width: 100%;
  font-size: 13px;
  padding: 11px 12px;
}
.modal-error {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: #f47c7c;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98) } to { opacity: 1; transform: none } }


/* ---------- steps (compile → deploy) ---------- */
.step {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #121a29, #0f1622);
}
.step + .step { margin-top: 10px; }
.step-num {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(59, 130, 246, .16);
  border: 1px solid rgba(59, 130, 246, .45);
  color: #bfdbfe;
  font-size: 11.5px;
  font-weight: 700;
}
.step-body { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.step-title {
  margin: 0;
  font-size: 11.5px;
  letter-spacing: .35px;
  text-transform: uppercase;
  color: var(--muted);
}
.step-note {
  margin: 0;
  font-size: 11.5px;
  color: #6f819b;
}
.step-note code {
  font-family: var(--mono);
  font-size: 11px;
  color: #9fc0f0;
}
.step .result { max-height: 108px; }
.gateway-empty {
  margin: 0;
  padding: 14px 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: #52627c;
  font-size: 12px;
  text-align: center;
}


/* ---------- read-only reference file ---------- */
.tree-item.is-locked {
  opacity: .55;
  cursor: default;
}
.tree-item.is-locked:hover {
  background: transparent;
  color: #a9bcd6;
}
.tree-item .ti-lock {
  flex: 0 0 11px;
  color: #5b6c85;
}


/* ---------- deployed contracts list ---------- */
.deployed-list { display: flex; flex-direction: column; gap: 10px; }
.contract-card .tag {
  font-size: 10.5px;
  letter-spacing: .2px;
  color: #9fc0f0;
  background: #16233a;
  border: 1px solid #22304a;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.contract-card .addr { max-width: 150px; }


/* ---------- terminal ---------- */
.panel-terminal { grid-column: 2; grid-row: 3; }
.terminal {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  font: 11.5px/1.8 var(--mono);
  background: #080c13;
}
.log { display: flex; gap: 8px; align-items: baseline; }
.log time { color: #3f5170; flex: 0 0 auto; }
.log .msg { color: #a9bcd6; }
.log.ok .msg { color: #63d489; }
.log.err .msg { color: #f47c7c; }
.log a { color: #7fb0ff; text-decoration: none; }
.log a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .panel-terminal { grid-column: 1; grid-row: 1; }
}


/* ---------- tree column + new file button ---------- */
.tree-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #0b111b;
}
.btn-new-file {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 10px 10px 4px;
  padding: 9px 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: #dbe9ff;
  background: #16233a;
  border: 1px solid #24334d;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-new-file:hover { background: #1b2b46; border-color: #31507d; }
.btn-new-file svg { width: 14px; height: 14px; }
.tree { border-right: 0; }


/* keep the right column inside the viewport (deploy list scrolls, terminal visible) */
.panel { min-height: 0; }
.panel-side .side-body { min-height: 0; overflow-y: auto; }
.deployed-list { max-height: 46vh; overflow-y: auto; padding-right: 2px; }


/* ---------- danger button + confirm modal ---------- */
.btn-danger {
  background: #7f1d1d;
  border-color: #991b1b;
  color: #fecaca;
}
.btn-danger:hover { background: #991b1b; border-color: #b91c1c; }
.modal-card h3 { margin: 0 0 6px; font-size: 15px; }


.brand-mark { background: none !important; border: 0 !important; padding: 0 !important; box-shadow: none !important; }
.brand-mark svg { display: block; border-radius: 7px; }
