:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #64748b;
  --line: #d9e1ec;
  --surface: #ffffff;
  --brand: #5b5ce2;
  --brand-dark: #4647bd;
  --shell: #eef2ff;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--shell); color: var(--ink); }
body.is-loading { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--brand); color: white; font-weight: 800; cursor: pointer; transition: transform .16s ease, background .16s ease, opacity .16s ease; }
button:hover { background: var(--brand-dark); transform: translateY(-1px); }
button:disabled { opacity: .55; cursor: wait; transform: none; }
input, textarea, select { width: 100%; border-radius: 12px; border: 1px solid #cbd5e1; padding: 12px 14px; background: white; color: var(--ink); outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px #5b5ce21d; }
textarea { min-height: 108px; resize: vertical; }
label { display: grid; gap: 8px; font-weight: 650; }
a { color: #4338ca; font-weight: 800; }

.eyebrow { color: #5b5ce2; font-size: 12px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
.status { min-height: 24px; margin: 0; font-weight: 700; white-space: pre-wrap; }
.status.error { color: #b42318; }
.status.success { color: #087443; }
.badge { display: inline-flex; align-items: center; min-height: 30px; padding: 6px 10px; border-radius: 999px; background: #eef2ff; color: #4338ca; font-size: 12px; font-weight: 900; }
.secondary { background: #334155; }
.ghost { background: #e8edf5; color: #334155; }
.ghost:hover { background: #dce4ef; }

.app-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: radial-gradient(circle at 10% 0%, #d9e1ff, transparent 35%), var(--shell); }
.panel { width: min(760px, 100%); background: var(--surface); padding: 36px; border-radius: 26px; box-shadow: 0 24px 80px #25316d24; }
.panel h1 { margin: 8px 0 12px; font-size: clamp(34px, 6vw, 52px); line-height: 1.02; }
.lead { margin: 0 0 26px; color: var(--muted); font-size: 18px; line-height: 1.55; }

.home-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 28px; padding: 6px; border-radius: 16px; background: #eef2f7; }
.home-tab { min-height: 48px; border-radius: 11px; padding: 10px 14px; background: transparent; color: #475569; box-shadow: none; }
.home-tab:hover { background: #e2e8f0; color: #1e293b; transform: none; }
.home-tab.active { background: white; color: #3730a3; box-shadow: 0 5px 18px #33415518; }
.home-tab:focus-visible { outline: 3px solid #818cf8; outline-offset: 2px; }
.home-section[hidden] { display: none; }
.section-heading { margin-bottom: 22px; }
.section-heading h2 { margin: 0 0 8px; font-size: 26px; line-height: 1.15; }
.section-heading p { margin: 0; color: var(--muted); line-height: 1.55; }
.open-project-section { padding: 4px 0 6px; }
.open-project-card { display: grid; gap: 20px; padding: 28px; border: 1px solid #dbe3ef; border-radius: 20px; background: linear-gradient(145deg, #f8faff, #ffffff); }
.open-project-icon { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 17px; background: #e0e7ff; color: #4338ca; font-size: 28px; font-weight: 900; }
.open-project-form { gap: 12px; }
.access-code-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: stretch; }
.access-code-input { min-height: 54px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 23px; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }
.access-code-row button { min-width: 180px; }
.open-project-help { margin: 0; color: #64748b; font-size: 13px; line-height: 1.45; }
form { display: grid; gap: 18px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.preloader[hidden] { display: none; }
.preloader { position: fixed; z-index: 1000; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(9, 14, 28, .72); backdrop-filter: blur(10px); }
.preloader-card { width: min(440px, 100%); padding: 34px; border-radius: 24px; background: white; text-align: center; box-shadow: 0 30px 100px rgba(0, 0, 0, .36); }
.preloader-card h2 { margin: 20px 0 8px; }
.preloader-card p { color: #475569; line-height: 1.5; }
.preloader-note { margin-top: 14px; color: #64748b; font-size: 13px; }
.spinner { width: 56px; height: 56px; margin: auto; border: 6px solid #e5e7eb; border-top-color: var(--brand); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.editor-shell { display: grid; grid-template-columns: 310px minmax(440px, .9fr) minmax(520px, 1.1fr); height: 100vh; overflow: hidden; background: #dbe4f0; }
.controls { background: white; padding: 22px; overflow: auto; display: grid; align-content: start; gap: 14px; border-right: 1px solid var(--line); }
.editor-title { margin: 4px 0 0; font-size: 28px; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick button { min-height: 48px; padding: 9px; font-size: 12px; }
.public-link { display: inline-flex; justify-content: center; padding: 11px 12px; border: 1px solid #c7d2fe; border-radius: 12px; text-decoration: none; }
.back-link { display: inline-flex; justify-content: center; padding: 9px 12px; color: #475569; text-decoration: none; }
.back-link:hover { color: #3730a3; }

.workspace { display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; background: #f7f9fc; border-right: 1px solid #cbd5e1; }
.workspace-header, .preview-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 74px; padding: 14px 18px; background: white; border-bottom: 1px solid var(--line); }
.workspace-header h2, .preview-header h2 { margin: 3px 0 0; font-size: 20px; }
.file-workspace { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 0; }
.file-tree-panel { overflow: auto; padding: 12px 8px; background: #f1f5f9; border-right: 1px solid var(--line); }
.file-tree { display: grid; gap: 2px; font-size: 13px; }
.tree-folder, .tree-file { width: 100%; min-height: 34px; display: flex; align-items: center; gap: 7px; padding: 7px 8px; border-radius: 7px; text-align: left; background: transparent; color: #334155; font-weight: 650; }
.tree-folder { cursor: pointer; }
.tree-folder:hover, .tree-file:hover { background: #e2e8f0; transform: none; }
.tree-file.active { background: #dfe4ff; color: #3730a3; }
.tree-children { margin-left: 14px; padding-left: 5px; border-left: 1px solid #cbd5e1; }
.tree-chevron { width: 12px; color: #64748b; }
.file-icon { display: inline-grid; place-items: center; min-width: 24px; height: 22px; border-radius: 5px; background: #334155; color: white; font-size: 9px; font-weight: 900; }
.tree-file-css .file-icon { background: #2563eb; }
.tree-file-js .file-icon { background: #d8b400; color: #111827; }
.tree-file-html .file-icon { background: #e85d24; }

.code-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; background: #111827; }
.code-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 46px; padding: 8px 12px; background: #1f2937; color: #f8fafc; font-size: 13px; }
.file-mode { margin-left: 8px; color: #94a3b8; font-size: 11px; }
.file-mode.editable { color: #86efac; }
.save-status { font-size: 11px; color: #94a3b8; text-align: right; }
.save-status.success { color: #86efac; }
.save-status.error { color: #fca5a5; }
.save-status.saving, .save-status.pending { color: #fde68a; }
.code-editor { min-height: 0; height: 100%; resize: none; border: 0; border-radius: 0; padding: 16px; background: #0f172a; color: #cbd5e1; box-shadow: none; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 13px; line-height: 1.55; tab-size: 2; }
.code-editor:focus { border: 0; box-shadow: inset 0 0 0 2px #5b5ce2; }
.code-editor.editable { color: #f8fafc; background: #111827; }
.code-hint { margin: 0; padding: 9px 12px; background: #1f2937; color: #94a3b8; font-size: 11px; line-height: 1.4; }

.preview { display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; min-height: 0; padding: 0 16px 16px; background: #dbe4f0; }
.preview-header { margin: 0 -16px 16px; }
.preview iframe { width: 100%; height: 100%; border: 0; border-radius: 18px; background: white; box-shadow: 0 16px 45px #33415530; }

@media (max-width: 1250px) {
  .editor-shell { grid-template-columns: 290px 1fr; height: auto; min-height: 100vh; overflow: visible; }
  .workspace { min-height: 700px; }
  .preview { grid-column: 1 / -1; height: 78vh; }
}

@media (max-width: 800px) {
  .app-shell { padding: 14px; }
  .panel { padding: 24px; }
  .row { grid-template-columns: 1fr; }
  .home-tabs { grid-template-columns: 1fr; }
  .access-code-row { grid-template-columns: 1fr; }
  .access-code-row button { width: 100%; }
  .open-project-card { padding: 22px; }
  .editor-shell { display: block; }
  .controls { border-right: 0; }
  .workspace { min-height: 820px; }
  .file-workspace { grid-template-columns: 150px minmax(0, 1fr); }
  .preview { height: 75vh; }
}
