*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #080810;
  --void:     #080810;
  --deep:     #0d0d1a;
  --surface:  #12121f;
  --raised:   #1a1a2e;
  --border:   #1e1e3a;
  --border2:  #2a2a4a;
  --accent:   #00d4ff;
  --cyan:     #00d4ff;
  --cyan-dim: rgba(0,212,255,0.12);
  --cyan-glow:rgba(0,212,255,0.35);
  --pink:     #ff4f9a;
  --amber:    #ffb740;
  --green:    #3dffa0;
  --red:      #ff4f6a;
  --text:     #c8d0e8;
  --muted:    #4a4a7a;
  --muted2:   #6a6a9a;
  --html-c:   #ff7b6b;
  --css-c:    #7bc0ff;
  --js-c:     #ffd26b;
  --font-ui:  'Syne', sans-serif;
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--void);
  color: var(--text);
  font-family: var(--font-ui);
  display: flex;
  flex-direction: column;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── HEADER ── */
header {
  height: 46px;
  background: var(--deep);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
  flex-shrink: 0;
  position: relative;
  z-index: 50;
}

.logo {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--cyan) 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  flex-shrink: 0;
}

.divider { width: 1px; height: 22px; background: var(--border2); flex-shrink: 0; }

#pen-title {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  width: 200px;
  transition: all .18s;
}
#pen-title:hover { border-color: var(--border2); background: var(--raised); }
#pen-title:focus { border-color: var(--cyan); background: var(--raised); outline: none; box-shadow: 0 0 0 2px var(--cyan-dim); }

.spacer { flex: 1; }

.save-status {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted2);
  transition: color .3s;
}
.save-status .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  transition: background .3s, box-shadow .3s;
}
.save-status.saving .dot { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.save-status.saving { color: var(--amber); }
.save-status.saved .dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.save-status.saved { color: var(--green); }

/* layout toggle */
.lay-grp { display: flex; gap: 2px; }
.lay-btn {
  width: 30px; height: 26px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.lay-btn:hover { color: var(--text); border-color: var(--border2); background: var(--raised); }
.lay-btn.active { color: var(--cyan); border-color: var(--cyan); background: var(--cyan-dim); }

/* icon button */
.icon-btn {
  width: 30px; height: 30px;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted2);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--cyan); background: var(--cyan-dim); }

/* text buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border2);
  background: var(--raised);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  flex-shrink: 0;
}
.btn:hover { border-color: var(--cyan); color: var(--cyan); background: var(--cyan-dim); }
.btn-cta { background: var(--cyan); color: var(--void); border-color: var(--cyan); }
.btn-cta:hover { filter: brightness(1.12); color: var(--void); }
.btn-danger { border-color: transparent; background: rgba(255,79,106,.1); color: var(--red); }
.btn-danger:hover { background: rgba(255,79,106,.2); border-color: var(--red); }
.btn-sm { padding: 3px 9px; font-size: 11px; }
.btn-ghost { background: transparent; border-color: var(--border2); color: var(--muted2); }
.btn-ghost:hover { color: var(--text); border-color: var(--cyan); background: var(--cyan-dim); }

/* user pill */
.user-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 10px 3px 4px;
  background: var(--raised);
  border: 1px solid var(--border2);
  border-radius: 99px;
  cursor: pointer;
  font-size: 12px; font-weight: 600;
  transition: all .15s;
  flex-shrink: 0;
}
.user-pill:hover { border-color: var(--cyan); background: var(--cyan-dim); }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; color: var(--void);
  flex-shrink: 0;
}
.avatar.unknown { background: var(--border2); }

/* ── WORKSPACE ── */
#workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  position: relative;
}
#workspace.layout-h { flex-direction: row; }

/* panels */
#editors-panel {
   display: flex;
   flex-direction: row;
   flex: 1 1 0;
   position: relative;
   overflow: hidden;
   min-height: 0;
}
#workspace.layout-h #editors-panel {
   flex-direction: column;
   flex: 0 0 auto;
   min-height: 0;
}

.ed-pane {
   display: flex;
   flex-direction: column;
   overflow: hidden;
   position: relative;
   flex: 1 1 0;
   min-width: 0;
   min-height: 0;
}
#workspace.layout-h .ed-pane {
   flex: 1 1 0;
   min-height: 0;
}

.ed-pane-head {
  height: 33px;
  background: var(--deep);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted2);
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
}
.ed-pane-head:hover { background: var(--surface); color: var(--text); }
.lang-pip { width: 7px; height: 7px; border-radius: 50%; }

.ed-body { flex: 1; overflow: hidden; position: relative; background: #1e1e1e; }

/* Expanded feature classes */
#editors-panel.has-expanded .ed-pane:not(.expanded) { display: none !important; }
#editors-panel.has-expanded .ed-pane.expanded { flex: 1 1 0 !important; min-width: 0 !important; min-height: 0 !important; }
#editors-panel.has-expanded .ui-resizable-handle { display: none !important; }

/* ── JQUERY UI HANDLES CUSTOMIZATION ── */
.ui-resizable-e {
   width: 6px !important; right: 0px !important;
   background: var(--border); transition: background .12s; z-index: 90 !important;
   top: 0; height: 100%;
}
.ui-resizable-s {
   height: 6px !important; bottom: 0px !important;
   background: var(--border); transition: background .12s; z-index: 90 !important;
   left: 0; width: 100%;
}
.ui-resizable-handle:hover, .ui-resizable-resizing { background: var(--cyan) !important; }

#preview-panel {
   flex: 1 1 0;
   display: flex;
   flex-direction: column;
   background: #fff;
   min-height: 0;
   min-width: 0;
}
.preview-head {
  height: 33px;
  background: var(--deep);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted2);
}
.preview-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 5px var(--green); animation: pulse 2.5s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

#preview { flex: 1; border: none; width: 100%; }

/* ── MODALS ── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--raised);
  border: 1px solid var(--border2);
  border-radius: 14px;
  padding: 28px;
  width: 92%;
  max-width: 460px;
  transform: translateY(10px) scale(.97);
  transition: transform .22s cubic-bezier(.16,1,.3,1);
  box-shadow: 0 40px 80px rgba(0,0,0,.6), 0 0 0 1px rgba(0,212,255,.06);
}
.overlay.open .modal { transform: translateY(0) scale(1); }
.modal-lg { max-width: 660px; }

.modal-title {
  font-size: 17px; font-weight: 800;
  margin-bottom: 22px;
  display: flex; align-items: center; gap: 10px;
}
.modal-title .accent { color: var(--cyan); }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--muted2); margin-bottom: 7px; }
.field input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  transition: all .18s;
}
.field input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px var(--cyan-dim); }
.field input.ok { border-color: var(--green); }
.field input.err { border-color: var(--red); }

.hint { font-size: 11px; margin-top: 5px; color: var(--muted2); }
.hint.ok { color: var(--green); }
.hint.err { color: var(--red); }

.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

.pen-list { max-height: 420px; overflow-y: auto; margin: -4px; padding: 4px; }

.pen-card {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all .18s;
}
.pen-card:hover { border-color: var(--cyan); background: rgba(0,212,255,.05); transform: translateX(2px); }
.pen-card.current { border-color: var(--cyan); background: var(--cyan-dim); }

.pen-card-icon {
  width: 36px; height: 36px; border-radius: 8px;
  background: linear-gradient(135deg, var(--html-c) 0%, var(--css-c) 50%, var(--js-c) 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0; opacity: .85;
}
.pen-card-info { flex: 1; min-width: 0; }
.pen-card-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pen-card-meta { font-size: 11px; color: var(--muted2); margin-top: 2px; }
.pen-card-actions { display: flex; gap: 6px; flex-shrink: 0; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--muted2); }
.empty-state .big { font-size: 42px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; line-height: 1.7; }

/* ── TOASTS ── */
#toasts {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 9999; display: flex; flex-direction: column-reverse; gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--raised); border: 1px solid var(--border2); border-radius: 9px;
  font-size: 13px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.5);
  animation: toast-in .3s cubic-bezier(.16,1,.3,1) both; pointer-events: auto;
}
.toast.ok { border-color: var(--green); color: var(--green); }
.toast.err { border-color: var(--red); color: var(--red); }
.toast.info { border-color: var(--cyan); color: var(--cyan); }
@keyframes toast-in { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toast-out { from { transform: translateX(0); opacity: 1; } to { transform: translateX(120%); opacity: 0; } }

.run-flash { animation: run-flash .25s ease; }
@keyframes run-flash { 50% { box-shadow: 0 0 20px var(--cyan); } }
#user-label {
  color: white!important;
}