:root{
  --bg:#f6f7fb;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#64748b;
  --line:#e2e8f0;
  --accent:#2563eb;
  --danger:#ef4444;
  --shadow: 0 10px 26px rgba(2,6,23,.08);
  --radius:14px;
  --topH:56px;
  --toolH:56px;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans";
  background: var(--bg);
  color: var(--text);
}
a{color:inherit;text-decoration:none}

.srOnly{
  position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden;
  clip: rect(0,0,0,0); border:0;
}

/* TOP BAR */
.top{
  height: var(--topH);
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 16px;
  background: var(--card);
  border-bottom:1px solid var(--line);
}
.brand{display:flex; align-items:center; gap:10px; font-weight:900}
.logoDot{
  width:12px; height:12px; border-radius:6px;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(37,99,235,.10);
}
.nav{display:flex; align-items:center; gap:12px}
.langWrap{display:flex; align-items:center; gap:10px}
.langLabel{font-size:12px; color:var(--muted)}
.langSelect{
  border:1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding:8px 12px;
  outline:none;
}

/* PAGE LAYOUT */
.page{
  min-height: calc(100vh - var(--topH));
  display:flex;
  flex-direction:column;
}

/* TOOLBAR */
.toolbar{
  height: var(--toolH);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:10px 16px;
  background: var(--bg);
  border-bottom:1px solid var(--line);
}
.toolLeft, .toolRight{display:flex; align-items:center; gap:10px; flex-wrap:wrap}
.ctrl{display:flex; align-items:center; gap:8px}
.ctrlLabel{font-size:12px; color: var(--muted)}
.ctrlSelect{
  border:1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding:9px 10px;
  outline:none;
  min-width: 150px;
}

.btn{
  border:1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding:9px 12px;
  border-radius: 12px;
  cursor:pointer;
  font-weight:900;
  transition: background .15s ease, border-color .15s ease, transform .06s ease;
}
.btn:hover{background:#f1f5ff; border-color:#cbd5e1}
.btn:active{transform: scale(.99)}
.btn.primary{
  background: var(--accent);
  border-color: rgba(37,99,235,.35);
  color:#fff;
}
.btn.primary:hover{filter:brightness(1.03)}
.btn.mini{padding:8px 10px}
.btn.danger{border-color: rgba(239,68,68,.35); color:#b91c1c; background:#fff5f5}
.btn.danger:hover{background:#ffecec}
.btn.icon{display:inline-flex; align-items:center; justify-content:center; width:42px; padding:9px}
.btnGroup{display:flex; gap:8px}

/* Segmented control */
.seg{
  display:flex;
  border:1px solid var(--line);
  border-radius: 999px;
  overflow:hidden;
  background: var(--card);
}
.segBtn{
  border:0;
  background:transparent;
  padding:9px 12px;
  cursor:pointer;
  font-weight:900;
  color: var(--muted);
}
.segBtn.active{
  background:#eaf0ff;
  color: var(--text);
}

/* WORKSPACE */
.workspace{
  flex:1;
  display:flex;
  gap:0;
  margin:12px 16px 0;
  border:1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow:hidden;
  min-height: 420px;
}

.panel{display:flex; flex-direction:column; min-width:0}
.editorPanel{flex: 0 0 56%}
.outputPanel{flex: 1 1 auto}

.panelHead{
  padding:12px 14px;
  font-weight:900;
  border-bottom:1px solid var(--line);
  background:#fbfcff;
}
.panelBody{
  padding:12px;
  display:flex;
  flex-direction:column;
  gap:10px;
  height:100%;
  min-height:0;
}

.divider{
  width:10px;
  background:#f1f5f9;
  cursor: col-resize;
  border-left:1px solid var(--line);
  border-right:1px solid var(--line);
}
.divider:after{
  content:"";
  display:block;
  margin: auto;
  width:2px; height:44px;
  border-radius:2px;
  background: rgba(15,23,42,.22);
}

.tabs{display:flex; gap:8px; flex-wrap:wrap}
.tab{
  border:1px solid var(--line);
  background:#fff;
  color: var(--muted);
  padding:7px 11px;
  border-radius:999px;
  cursor:pointer;
  font-weight:900;
}
.tab.active{
  background:#eaf0ff;
  border-color:#c7d2fe;
  color: var(--text);
}

.editors{flex:1; min-height: 320px}
.hidden{display:none !important}

/* CodeMirror (if loaded) */
.CodeMirror{
  flex:1;
  height: 100% !important;
  min-height: 320px;
  border-radius: 12px;
  border:1px solid var(--line);
}

/* Fallback textareas (if CodeMirror missing) */
textarea{
  width:100%;
  min-height: 320px;
  border:1px solid var(--line);
  border-radius: 12px;
  padding:12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
}

/* Output / Preview */
.output{
  flex:1;
  min-height: 320px;
  border:1px solid var(--line);
  border-radius: 12px;
  padding:12px;
  background:#fff;
  overflow:auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size:13px;
  line-height:1.5;
  white-space: pre-wrap;
}
.previewWrap{flex:1; min-height: 320px}
.preview{
  width:100%;
  height:100%;
  min-height: 320px;
  border:1px solid var(--line);
  border-radius: 12px;
  background:#fff;
}

.headRow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.headLeft{
  display:flex;
  align-items:center;
  gap:12px;
  flex-wrap:wrap;
}
.filterWrap{
  display:flex;
  align-items:center;
  gap:8px;
  padding:6px 10px;
  border:1px solid var(--line);
  border-radius:999px;
  background:#f8fafc;
}
.miniLabel{font-size:12px; color:var(--muted)}
.miniSelect{
  border:1px solid var(--line);
  background:#fff;
  border-radius:999px;
  padding:6px 10px;
  outline:none;
  font-size:12px;
}

/* Drawer */
.drawer{
  margin:10px 16px 0;
  border:1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow:hidden;
}
.drawerTop{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 12px;
  border-bottom:1px solid var(--line);
  background:#fbfcff;
}
.drawerTitle{font-weight:900}
.drawerTabs{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  padding:10px 12px;
  border-bottom:1px solid var(--line);
}
.drawerTab{
  border:1px solid var(--line);
  background:#fff;
  padding:7px 11px;
  border-radius:999px;
  cursor:pointer;
  font-weight:900;
  color: var(--muted);
}
.drawerTab.active{
  background:#eaf0ff;
  border-color:#c7d2fe;
  color: var(--text);
}
.drawerBody{padding:12px}
.formGrid{display:flex; gap:12px; flex-wrap:wrap}
.formGrid.two > *{flex:1 1 320px}
.field{display:flex; flex-direction:column; gap:6px; min-width: 220px}
.field.inline{flex-direction:row; align-items:center; min-width:auto; gap:10px}
.field label{font-size:12px; color:var(--muted)}
select, input[type="text"]{
  border:1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding:9px 10px;
  outline:none;
}
.input{width:100%}
.select{width:100%}
.actions{display:flex; gap:8px; flex-wrap:wrap; margin-top:10px}
.hint{font-size:12px; color: var(--muted); margin-top:10px}
.cardMini{
  border:1px solid var(--line);
  border-radius: 12px;
  padding:12px;
  background:#fbfcff;
}
.searchRow{display:flex; gap:8px; align-items:center; flex-wrap:wrap}
.historyBox{
  border:1px solid var(--line);
  border-radius: 12px;
  padding:10px 12px;
  background:#fbfcff;
}
.historyList{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size:12px;
  white-space: pre-wrap;
  max-height: 220px;
  overflow:auto;
  color: rgba(15,23,42,.85);
}
.cmMissing{
  font-size:12px;
  color: var(--muted);
}

.footer{
  padding:16px;
  color: rgba(15,23,42,.65);
}
.footerInner{
  margin:0 16px 16px;
  border-top:1px solid var(--line);
  padding-top:14px;
  display:flex;
  justify-content:space-between;
  gap:10px;
  flex-wrap:wrap;
}
.muted{color:var(--muted)}

@media (max-width: 980px){
  .editorPanel{flex-basis: 52%}
  .ctrlSelect{min-width: 120px}
}
@media (max-width: 820px){
  .workspace{flex-direction:column; margin:12px 12px 0}
  .divider{height:10px; width:100%; cursor: row-resize}
  .divider:after{width:44px; height:2px}
  .toolbar{height:auto}
}
