* { box-sizing: border-box; }

:root {
  --bg: #0b0d12;
  --panel: #11141b;
  --panel-2: #171b24;
  --border: #252b36;
  --text: #f4f6fa;
  --muted: #8b93a3;
  --accent: #6d7cff;
  --danger: #ff5f6d;
}

html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}
button, input, textarea { font: inherit; }
button { border: 1px solid var(--border); background: var(--panel-2); color: var(--text); border-radius: 8px; padding: 9px 13px; cursor: pointer; }
button:hover { border-color: #3b4352; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.topbar {
  min-height: 64px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg);
}
.brand-area, .top-actions, .editor-actions, .modal-actions, .file-head-actions { display: flex; align-items: center; gap: 9px; }
.brand-area { min-width: 0; }
.brand { color: var(--text); text-decoration: none; font-size: 19px; font-weight: 750; }
.brand-separator { color: var(--border); }
.brand-workspace { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.primary { background: var(--accent); border-color: var(--accent); color: white; }
.danger, .subtle-danger { color: var(--danger); }

.workspace { padding: 22px; min-width: 0; }
.workspace-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; }
.eyebrow { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
h1, h2, p { margin: 0; }
h1 { font-size: 21px; margin-top: 4px; }
.title-row { display: flex; align-items: center; gap: 8px; }
.icon-button { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; font-size: 14px; flex: 0 0 auto; }
.workspace-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; flex-wrap: wrap; justify-content: flex-end; }
.dot { width: 4px; height: 4px; border-radius: 50%; background: var(--muted); }

.editor-area {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) minmax(0, 1fr);
  min-height: 560px;
  height: calc(100vh - 154px);
  background: var(--panel);
}
.file-sidebar { min-width: 0; min-height: 0; background: #0e1016; border-right: 1px solid var(--border); overflow: hidden; }
.file-head { min-height: 45px; padding: 6px 10px 6px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.file-head > div:first-child { min-width: 0; }
.section-title { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.file-head > div:first-child > span:last-child { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.files { padding: 8px; display: flex; flex-direction: column; gap: 4px; overflow: auto; height: calc(100% - 45px); min-height: 0; }
.file { width: 100%; min-width: 0; text-align: left; padding: 9px 10px; background: transparent; border-color: transparent; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file:hover { background: var(--panel-2); color: var(--text); }
.file.active { background: var(--panel-2); border-color: #303846; color: var(--text); }
.file.folder { display: flex; align-items: center; justify-content: flex-start; gap: 8px; }
.file.folder.drop-target { background: var(--panel-2); border-color: var(--accent); color: var(--text); }
.folder-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.editor-panel { min-width: 0; min-height: 0; background: #0a0c10; display: flex; flex-direction: column; overflow: hidden; }
.tabs { min-width: 0; height: 45px; display: flex; align-items: stretch; overflow-x: auto; background: #0e1016; border-bottom: 1px solid var(--border); }
.tab { height: 45px; border: 0; border-right: 1px solid var(--border); border-radius: 0; background: transparent; color: var(--muted); padding: 0 14px; white-space: nowrap; flex: 0 0 auto; }
.tab:hover { background: var(--panel-2); }
.tab.active { color: var(--text); background: var(--panel); box-shadow: inset 0 -2px var(--accent); }
.editor-toolbar { min-height: 42px; padding: 0 12px; border-bottom: 1px solid var(--border); background: var(--panel); color: var(--muted); display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; overflow: hidden; }
#currentFile { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-actions { flex: 0 0 auto; }
#saveState { color: var(--muted); font-size: 11px; white-space: nowrap; }
.subtle-danger { border-color: transparent; background: transparent; padding: 5px 7px; font-size: 11px; white-space: nowrap; }

.editor-wrap { min-height: 0; flex: 1; display: grid; grid-template-columns: 45px minmax(0, 1fr); overflow: hidden; }
.line-numbers { padding: 18px 9px 18px 0; border-right: 1px solid #1c2028; background: #090b0f; color: #555d6b; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 13px; font-weight: 400; line-height: 21px; letter-spacing: normal; word-spacing: normal; text-align: right; user-select: none; white-space: normal; overflow: hidden; display: flex; flex-direction: column; }
.code-stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.line-number { display: block; flex: 0 0 21px; height: 21px; line-height: 21px; }
#codeHighlight, #codeEditor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 18px;
  border: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  font-weight: 400;
  line-height: 21px;
  letter-spacing: normal;
  word-spacing: normal;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}
#codeHighlight {
  display: block;
  color: #dce1ea;
  pointer-events: none;
}
#codeEditor {
  display: block;
  resize: none;
  outline: 0;
  background: transparent;
  color: transparent;
  caret-color: #f4f6fa;
  z-index: 1;
  -webkit-text-fill-color: transparent;
}
.token-comment { color: #6b7280; }
.token-string { color: #d8a657; }
.token-keyword { color: #c792ea; }
.token-number { color: #f78c6c; }
.token-tag { color: #7dd3fc; }
.token-attr { color: #a5b4fc; }
.token-selector { color: #7dd3fc; }
.token-property { color: #c4b5fd; }
.statusbar { min-height: 27px; padding: 0 11px; border-top: 1px solid var(--border); background: #0e1016; display: flex; align-items: center; justify-content: flex-end; gap: 14px; color: var(--muted); font-size: 10px; }
#languageLabel { margin-right: auto; }

.preview-panel { min-width: 0; min-height: 0; background: white; border-left: 1px solid var(--border); overflow: hidden; }
.preview-head { min-height: 42px; padding: 0 12px; background: var(--panel); color: var(--muted); display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; }
.preview-title { display: flex; align-items: center; gap: 7px; min-width: 0; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: #58c779; flex: 0 0 auto; }
.preview-head button { padding: 5px 9px; }
#preview { display: block; width: 100%; height: calc(100% - 42px); min-height: 0; border: 0; background: white; }

.bottom-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; color: var(--muted); font-size: 11px; }
.bottom-actions span { min-width: 0; }
.danger { border-color: transparent; background: transparent; padding: 5px 7px; }
.danger:hover { border-color: #3b4352; background: var(--panel-2); }

.context-menu {
  position: fixed;
  z-index: 50;
  width: 180px;
  padding: 5px;
  background: #151922;
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 14px 35px rgba(0, 0, 0, .4);
}

.context-menu button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 9px 10px;
  text-align: left;
  font-size: 13px;
}

.context-menu button:hover,
.context-menu button:focus-visible {
  background: var(--panel-2);
  border-color: transparent;
}

.context-menu .context-danger {
  color: var(--danger);
}

.modal { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .6); display: grid; place-items: center; padding: 20px; }
.modal-card { width: min(420px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 13px; padding: 22px; }
.modal-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.modal-card h2 { font-size: 19px; margin-top: 4px; }
.modal-card p { color: var(--muted); margin: 7px 0 18px; font-size: 14px; line-height: 1.5; }
.modal-card label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.modal-card input { width: 100%; min-width: 0; border: 1px solid var(--border); background: #0c0f14; color: var(--text); border-radius: 8px; padding: 11px; outline: none; }
.modal-card input:focus { border-color: var(--accent); }
.close-button { width: 32px; height: 32px; padding: 0; border-color: transparent; background: transparent; color: var(--muted); font-size: 20px; flex: 0 0 auto; }
.close-button:hover { color: var(--text); }
.modal-actions { justify-content: flex-end; margin-top: 18px; }
.hidden { display: none !important; }

@media (max-width: 1050px) {
  .editor-area { grid-template-columns: 210px minmax(0, 1fr); height: auto; }
  .preview-panel { grid-column: 1 / -1; min-height: 420px; border-left: 0; border-top: 1px solid var(--border); }
  #preview { min-height: 378px; }
  .editor-panel { min-height: 560px; }
}
@media (max-width: 700px) {
  .topbar, .workspace { padding: 14px; }
  .topbar { align-items: stretch; flex-direction: column; }
  .top-actions { width: 100%; }
  .top-actions button { flex: 1; min-width: 0; }
  .workspace-head { align-items: flex-start; flex-direction: column; }
  .workspace-meta { justify-content: flex-start; }
  .editor-area { grid-template-columns: 1fr; min-height: 0; }
  .file-sidebar { border-right: 0; border-bottom: 1px solid var(--border); max-height: 230px; }
  .files { height: 185px; }
  .editor-panel { height: 520px; min-height: 520px; }
  .preview-panel { grid-column: auto; min-height: 360px; }
  #preview { min-height: 318px; }
  .bottom-actions { align-items: flex-start; flex-direction: column-reverse; }
}
@media (max-width: 420px) {
  .workspace { padding: 10px; }
  .editor-toolbar { align-items: flex-start; flex-direction: column; padding: 8px 10px; }
  .editor-actions { width: 100%; justify-content: space-between; }
  .statusbar { gap: 8px; }
  .statusbar span { white-space: nowrap; }
}