/* Buddy Blocks — light, professional theme.
 * Solid surfaces, one accent, restrained shadows. No gradient "glow". */

:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f1f2f6;
  --surface-3: #e9ebf1;
  --text: #1b2030;
  --text-2: #4b5266;
  --muted: #888fa3;
  --border: #e3e5ec;
  --border-strong: #d2d6e0;
  --brand: #4f46e5;
  --brand-hover: #443bd1;
  --brand-soft: #eef0fe;
  --success: #0e9f6e;
  --success-soft: #e6f6ef;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(20, 23, 40, .06), 0 1px 3px rgba(20, 23, 40, .05);
  --shadow-md: 0 6px 24px rgba(20, 23, 40, .10);
  --ring: 0 0 0 3px rgba(79, 70, 229, .22);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--brand); }

/* ---------- Buttons ---------- */
button {
  font: inherit; cursor: pointer; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 15px; background: var(--brand); color: #fff; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; gap: 7px; line-height: 1;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .04s ease;
}
button:hover { background: var(--brand-hover); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: var(--ring); }

button.ghost {
  background: var(--surface); color: var(--text-2); border-color: var(--border-strong);
}
button.ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--muted); }

button.success { background: var(--success); }
button.success:hover { background: #0c8a5f; }

button.danger { background: var(--danger); }
button.danger:hover { background: #d23a3f; }

button.icon { padding: 7px 9px; }

/* ---------- Inputs ---------- */
input {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input::placeholder { color: var(--muted); }
input:focus { border-color: var(--brand); box-shadow: var(--ring); }
label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin: 14px 0 6px; }

/* ---------- Brand mark ---------- */
.logo { display: flex; align-items: center; gap: 11px; }
.logo .dot {
  position: relative; width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: var(--brand); box-shadow: var(--shadow-sm);
}
.logo .dot::before, .logo .dot::after {
  content: ""; position: absolute; top: 12px; width: 6px; height: 6px; border-radius: 50%; background: #fff;
}
.logo .dot::before { left: 9px; }
.logo .dot::after { right: 9px; }
.logo h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; font-weight: 700; }

/* ---------- Auth landing ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 30px; border: 1px solid var(--border);
}
.auth-card .logo { margin-bottom: 14px; }
.subtitle { color: var(--text-2); font-size: 14px; line-height: 1.5; margin: 0 0 20px; }
.tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 10px; margin: 0 0 18px; }
.tabs button {
  flex: 1; background: transparent; color: var(--text-2); border: none; font-weight: 600; padding: 8px;
}
.tabs button:hover { background: transparent; color: var(--text); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---------- Editor layout ---------- */
.app { display: grid; grid-template-rows: 58px 1fr; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm); z-index: 2;
}
.topbar .logo h1 { font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--text-2); font-size: 13px; font-weight: 500; margin-left: 4px; }
.topbar .sep { width: 1px; height: 26px; background: var(--border); margin: 0 4px; }
.pill {
  background: var(--surface-2); padding: 6px 12px; border-radius: 999px; font-size: 12.5px;
  color: var(--text-2); font-weight: 500; border: 1px solid var(--border);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.main { display: grid; grid-template-columns: 248px 1fr; min-height: 0; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px; overflow: auto; }
.sidebar h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  font-weight: 700; margin: 20px 4px 10px;
}
.prog-item {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  padding: 9px 11px; border-radius: var(--radius-sm); background: var(--surface);
  border: 1px solid var(--border); margin-bottom: 7px; font-size: 14px; transition: border-color .12s, background .12s;
}
.prog-item:hover { border-color: var(--border-strong); background: var(--surface-2); }
.prog-item.active { border-color: var(--brand); background: var(--brand-soft); }
.prog-item span { cursor: pointer; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.prog-item .del {
  background: transparent; border: none; color: var(--muted); padding: 4px 6px; font-size: 13px; border-radius: 6px;
}
.prog-item .del:hover { background: var(--danger-soft); color: var(--danger); }
.empty-hint { color: var(--muted); font-size: 13px; padding: 2px 4px; }

#blocklyArea { position: relative; min-width: 0; background: var(--surface); }
#blocklyDiv { position: absolute; inset: 0; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 23, 40, .42); display: none; place-items: center;
  /* Above Blockly's toolbox (z 70) / zoom controls so nothing punches through. */
  z-index: 1000; padding: 20px; backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: grid; }
.modal {
  width: 100%; max-width: 440px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 24px; border: 1px solid var(--border);
}
.modal h2 { margin: 0 0 4px; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.modal p.hint { color: var(--text-2); font-size: 13px; line-height: 1.5; margin: 4px 0 14px; }
.modal .row { display: flex; gap: 10px; margin-top: 18px; }
.modal .row button { flex: 1; justify-content: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: #1b2030; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-md); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 1100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--success); }
.toast.warn { background: #b45309; }
