/* =========================================================================
 * app.css — LÖVE Web IDE
 * Dark developer-tool aesthetic: near-black surfaces, 1px subtle borders,
 * compact controls, monospace editor, minimal radii.
 * ========================================================================= */
:root {
  --bg: #1e1e1e;
  --titlebar: #3c3c3c;
  --activity: #333333;
  --sidebar: #252526;
  --sidebar-head: #252526;
  --editor-bg: #1e1e1e;
  --tabs-bg: #252526;
  --tab-active: #1e1e1e;
  --panel-bg: #1e1e1e;
  --status: #007acc;
  --border: #333333;
  --border-soft: #2d2d2d;
  --fg: #cccccc;
  --fg-dim: #9d9d9d;
  --fg-faint: #6e6e6e;
  --accent: #007acc;
  --accent-hover: #1f8ad2;
  --run: #2e8b3d;
  --run-hover: #37a24a;
  --stop: #b03434;
  --warn: #d9a33c;
  --err: #e05555;
  --ok: #4fbf6a;
  --mono: "Menlo", "Consolas", "DejaVu Sans Mono", "Courier New", monospace;
  --ui: -apple-system, "Segoe UI", "Ubuntu", "Roboto", sans-serif;
  --radius: 3px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--ui);
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
#app { display: flex; flex-direction: column; height: 100vh; }

.hidden { display: none !important; }
.flex-spacer { flex: 1; }
button { font-family: inherit; }

/* ============ Top application bar ============ */
#titlebar {
  height: 38px; flex: none;
  background: var(--titlebar);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px; user-select: none; z-index: 20;
}
.tb-group { display: flex; align-items: center; gap: 4px; }
.tb-sep { width: 1px; height: 18px; background: #4a4a4a; margin: 0 6px; }
#logo {
  display: flex; align-items: center; gap: 7px;
  color: var(--fg); font-weight: 600; font-size: 12.5px;
  letter-spacing: 0.2px; padding: 0 8px 0 4px;
}
#logo svg { color: var(--accent); }
.tb-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid transparent;
  color: var(--fg-dim); font-size: 12.5px; padding: 4px 9px;
  border-radius: var(--radius); cursor: pointer; height: 26px;
}
.tb-btn:hover { background: #4a4a4a; color: #fff; }
.tb-btn:active { background: #555; }
.tb-run {
  background: var(--run); color: #eaf5ec; font-weight: 600;
  border-color: #2a7a36; padding: 4px 12px;
}
.tb-run:hover { background: var(--run-hover); color: #fff; }
.tb-run:disabled { background: #3a3a40; border-color: #3a3a40; color: var(--fg-faint); cursor: default; }
.tb-stop { color: #d99; }
.tb-stop:hover { background: #3a2a2a; color: #ffaaaa; }

.mode-select {
  display: inline-flex; align-items: center; gap: 6px;
  background: #333; border: 1px solid #454545;
  padding: 4px 10px; border-radius: var(--radius);
  cursor: pointer; height: 26px; font-size: 12.5px; color: var(--fg);
}
.mode-select:hover { background: #3c3c3c; }
.mode-select svg { color: var(--accent); }
#project-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#sw-banner {
  background: #4a3a14; color: #e8d9a8; padding: 5px 12px;
  font-size: 12px; border-bottom: 1px solid #5a4a1a;
}

/* ============ Main region ============ */
#main { flex: 1; display: flex; min-height: 0; }

/* ---- Activity bar ---- */
#activitybar {
  width: 46px; flex: none; background: var(--activity);
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; padding: 4px 0;
}
.act-btn {
  width: 46px; height: 44px; background: none; border: none;
  color: var(--fg-faint); cursor: pointer; display: flex;
  align-items: center; justify-content: center; border-left: 2px solid transparent;
}
.act-btn svg { width: 21px; height: 21px; }
.act-btn:hover { color: #fff; }
.act-btn.active { color: #fff; border-left-color: #fff; }
.act-spacer { flex: 1; }

/* ---- Sidebar ---- */
#sidebar {
  width: 240px; min-width: 170px; max-width: 520px; flex: none;
  background: var(--sidebar); border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-header {
  height: 30px; flex: none; display: flex; align-items: center;
  justify-content: space-between; padding: 0 8px 0 12px;
  background: var(--sidebar-head); border-bottom: 1px solid var(--border-soft);
  font-size: 11px; font-weight: 700; letter-spacing: 0.8px; color: var(--fg-dim);
}
#sidebar-body { flex: 1; overflow: auto; min-height: 0; }
.sidebar-view { height: 100%; overflow: auto; }

/* Explorer tree */
#tree { padding: 4px 0 40px; user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 5px; height: 24px;
  padding-right: 8px; cursor: pointer; color: var(--fg-dim);
  font-size: 12.5px; white-space: nowrap; overflow: hidden;
}
.tree-row:hover { background: #2a2d2e; color: #e7e7e7; }
.tree-row.selected { background: #37373d; color: #fff; }
.tree-row.drop-target { background: #062f4a; outline: 1px dashed var(--accent); }
.tree-row.dragging { opacity: 0.45; }
.tree-row .tw {
  width: 14px; flex: none; display: inline-flex; justify-content: center;
  color: var(--fg-faint); font-size: 10px;
}
.tree-row .ficon { width: 15px; flex: none; display: inline-flex; justify-content: center; font-size: 12px; }
.tree-row .tname { overflow: hidden; text-overflow: ellipsis; }
.tree-row .tname.dirty { font-style: italic; }
.tree-row .dirty-dot { color: var(--warn); margin-left: auto; font-size: 9px; }
.tree-indent { display: inline-block; }

.tree-input {
  background: #101014; border: 1px solid var(--accent); color: var(--fg);
  font: 12.5px var(--mono); padding: 2px 5px; width: 60%; border-radius: 2px; outline: none;
}

#explorer-empty { padding: 18px 14px; color: var(--fg-faint); font-size: 12px; line-height: 1.6; }

/* Search view */
.search-box { padding: 10px; display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--border-soft); }
.search-box input {
  background: #101014; border: 1px solid var(--border); color: var(--fg);
  font: 12.5px var(--ui); padding: 5px 8px; border-radius: 2px; outline: none;
}
.search-box input:focus { border-color: var(--accent); }
#search-count { font-size: 11px; color: var(--fg-faint); }
.search-file { padding: 6px 10px 2px; color: var(--accent); font-size: 12px; font-family: var(--mono); cursor: pointer; }
.search-hit {
  padding: 2px 10px 2px 22px; color: var(--fg-dim); font: 11.5px var(--mono);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.search-hit:hover { background: #2a2a30; color: var(--fg); }
.search-hit .hl { color: #fff; background: #5a4a1a; }

/* Projects view */
#project-list { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.proj-card {
  border: 1px solid var(--border-soft); background: #232328; border-radius: var(--radius);
  padding: 8px 10px; cursor: pointer; position: relative;
}
.proj-card:hover { border-color: #3c3c3c; background: #2d2d2d; }
.proj-card.current { border-color: var(--accent); background: #094771; }
.proj-card .p-name { font-weight: 600; font-size: 13px; color: var(--fg); }
.proj-card .p-meta { font-size: 11px; color: var(--fg-faint); margin-top: 3px; }
.proj-card .p-actions { position: absolute; right: 6px; top: 6px; display: none; gap: 2px; }
.proj-card:hover .p-actions { display: inline-flex; }
.proj-card .p-actions button {
  background: none; border: none; color: var(--fg-faint); cursor: pointer;
  font-size: 12px; padding: 2px 4px; border-radius: 2px;
}
.proj-card .p-actions button:hover { color: var(--fg); background: #33333a; }
.proj-new {
  border: 1px dashed var(--border); border-radius: var(--radius); text-align: center;
  padding: 7px; color: var(--fg-dim); cursor: pointer; font-size: 12.5px; margin-top: 2px;
}
.proj-new:hover { color: var(--fg); border-color: var(--fg-faint); }

/* Settings view */
#settings-body { padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.set-group { display: flex; flex-direction: column; gap: 8px; }
.set-group h3 { margin: 0; font-size: 11px; letter-spacing: 0.8px; color: var(--fg-dim); text-transform: uppercase; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.5px; }
.set-row input[type="number"], .set-row input[type="text"], .set-row select {
  background: #101014; border: 1px solid var(--border); color: var(--fg);
  padding: 4px 6px; border-radius: 2px; width: 90px; font: 12.5px var(--ui); outline: none;
}
.set-row input[type="checkbox"] { transform: scale(1.15); accent-color: var(--accent); }
.set-hint { font-size: 11px; color: var(--fg-faint); line-height: 1.5; }

/* ---- Gutter / resize ---- */
#gutter-v { width: 4px; flex: none; background: var(--bg); border-right: 1px solid var(--border-soft); cursor: col-resize; }
#gutter-v:hover, #gutter-h:hover { background: var(--accent); }
#gutter-h { height: 4px; flex: none; background: var(--bg); border-top: 1px solid var(--border-soft); cursor: row-resize; }

/* ============ Center / editor ============ */
#center { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

#tabsbar {
  height: 33px; flex: none; background: var(--tabs-bg);
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: stretch;
}
#tabs { display: flex; overflow-x: auto; scrollbar-width: thin; }
#tabs::-webkit-scrollbar { height: 3px; }
#tabs::-webkit-scrollbar-thumb { background: #3a3a42; }
.tab {
  display: flex; align-items: center; gap: 7px; padding: 0 8px 0 11px;
  background: #2d2d2d; color: #969696; font-size: 12.5px;
  border-right: 1px solid #252526; cursor: pointer;
  white-space: nowrap; user-select: none; position: relative;
}
.tab:hover { color: #ccc; background: #2d2d2d; }
.tab.active { background: var(--tab-active); color: #fff; border-top: 1px solid var(--accent); }
.tab .tab-icon { font-size: 11px; width: 14px; text-align: center; color: var(--accent); }
.tab .tab-close {
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 3px; color: var(--fg-faint); font-size: 13px;
}
.tab .tab-close:hover { background: #4b4b4b; color: #fff; }
.tab.dirty::before {
  content: "●"; color: var(--warn); font-size: 9px; margin-right: -3px;
}
#tabs-actions { margin-left: auto; display: flex; align-items: center; padding: 0 6px; gap: 2px; }
#tabs-actions button {
  background: none; border: none; color: var(--fg-faint); cursor: pointer;
  font-size: 14px; padding: 3px 7px; border-radius: 3px;
}
#tabs-actions button:hover { color: #fff; background: #4a4a4a; }

#editors { flex: 1; display: flex; min-height: 0; position: relative; }
#monaco { position: absolute; inset: 0; }
#editor-host { flex: 1; position: relative; min-width: 0; }

#preview-host { flex: 1; overflow: auto; background: var(--editor-bg); padding: 20px; }
.preview-box { max-width: 680px; margin: 0 auto; }
.preview-head { font: 12.5px var(--mono); color: var(--fg-dim); border-bottom: 1px solid var(--border-soft); padding-bottom: 8px; margin-bottom: 14px; display: flex; justify-content: space-between; }
.preview-img { max-width: 100%; image-rendering: auto; background: repeating-conic-gradient(#26262b 0 25%, #1b1b1f 0 50%) 0 0 / 20px 20px; border: 1px solid var(--border); }
.preview-audio { width: 100%; }
.preview-text { font: 12px var(--mono); color: var(--fg-dim); white-space: pre-wrap; }
.preview-actions { display: flex; gap: 8px; margin-top: 14px; }

/* ---- Test tab ---- */
#test-host { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#test-toolbar {
  height: 30px; flex: none; background: #232327; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 8px; padding: 0 8px; font-size: 12px;
}
#test-title { font-weight: 600; color: var(--fg); }
.status-pill { font-size: 10.5px; padding: 1px 8px; border-radius: 8px; background: #33333a; color: var(--fg-dim); }
.status-pill.running { background: #1d3a24; color: var(--ok); }
.status-pill.crashed { background: #422; color: #ff8888; }
.status-pill.stopped { background: #333; color: var(--fg-faint); }
#test-res { color: var(--fg-faint); font-family: var(--mono); font-size: 11px; }
#test-frame-wrap { flex: 1; min-height: 0; background: #101012; position: relative; }
#test-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: none; background: #141416; }

/* ---- Empty state ---- */
#empty-state {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--editor-bg); z-index: 5;
}
.empty-inner { text-align: center; color: var(--fg-faint); font-size: 13px; }
.empty-logo { font: 42px var(--mono); color: #2e2e34; margin-bottom: 14px; }
.dim { font-size: 11.5px; color: #4a4a52; }

/* ============ Bottom panel / console ============ */
#panel {
  height: 170px; min-height: 32px; flex: none; background: var(--panel-bg);
  display: flex; flex-direction: column; border-top: 1px solid var(--border-soft);
}
#panel-tabs {
  height: 28px; flex: none; display: flex; align-items: center;
  padding: 0 8px 0 12px; gap: 12px; background: #202024; border-bottom: 1px solid var(--border-soft);
  user-select: none;
}
.panel-tab { font-size: 11px; letter-spacing: 0.6px; color: var(--fg-faint); cursor: pointer; padding: 2px 0; border-bottom: 1px solid transparent; }
.panel-tab.active { color: #fff; border-bottom-color: var(--accent); }
.panel-btn {
  background: none; border: none; color: var(--fg-faint); font-size: 11px;
  cursor: pointer; padding: 3px 7px; border-radius: 3px;
}
.panel-btn:hover { color: #fff; background: #3c3c3c; }

#console {
  flex: 1; overflow-y: auto; font: 12px var(--mono); padding: 4px 0 12px;
  scrollbar-width: thin; user-select: text;
}
#console::-webkit-scrollbar { width: 9px; }
#console::-webkit-scrollbar-thumb { background: #33333a; border-radius: 4px; }
.con-line { display: flex; gap: 8px; padding: 0 12px; line-height: 1.55; }
.con-line:hover { background: #262626; }
.con-ts { color: #4a4a52; flex: none; }
.con-tag { flex: none; width: 46px; text-align: right; }
.con-line.info .con-tag { color: #6a9fd8; }
.con-line.warn .con-tag { color: var(--warn); }
.con-line.error .con-tag { color: var(--err); }
.con-line.sys .con-tag { color: #7a7a84; }
.con-text { white-space: pre-wrap; word-break: break-word; }
.con-line.error .con-text { color: #ff9a9a; }
.con-line.warn .con-text { color: #e8cf9a; }
.con-line.sys .con-text { color: var(--fg-faint); font-style: italic; }
.con-err-link { color: #7ab8ff; text-decoration: underline; cursor: pointer; }
.con-err-link:hover { color: #a5d2ff; }

/* ============ Status bar ============ */
#statusbar {
  height: 22px; flex: none; background: var(--status);
  border-top: 1px solid var(--border-soft);
  display: flex; align-items: center; font-size: 11px; color: #ffffff;
  padding: 0 4px 0 0; user-select: none; overflow: hidden;
}
#statusbar .st-item { opacity: 0.95; }
#statusbar a.st-item {
  color: #fff; text-decoration: none; opacity: 0.9; margin-left: 4px;
  border-left: 1px solid rgba(255,255,255,0.25); cursor: pointer;
}
#statusbar a.st-item:hover { opacity: 1; text-decoration: underline; }
.st-accent { background: #0e639c; color: #fff; font-weight: 600; }

/* ============ Overlays ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 10vh;
}
.qo-box {
  width: 540px; max-width: 90vw; background: #232327; border: 1px solid var(--border);
  border-radius: 5px; box-shadow: 0 12px 40px rgba(0,0,0,0.6); overflow: hidden;
}
#qo-input {
  width: 100%; background: #101014; border: none; border-bottom: 1px solid var(--border);
  color: var(--fg); font: 13.5px var(--mono); padding: 10px 14px; outline: none;
}
#qo-list { max-height: 320px; overflow: auto; }
.qo-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 14px; cursor: pointer;
  font: 12.5px var(--mono); color: var(--fg-dim);
}
.qo-item.active { background: #04395e; color: #fff; }
.qo-item .qo-dir { color: var(--fg-faint); font-size: 11px; margin-left: auto; }
.qo-empty { padding: 14px; color: var(--fg-faint); font-size: 12.5px; }

/* Context menu */
#ctxmenu {
  position: fixed; z-index: 200; background: #26262c; border: 1px solid var(--border);
  border-radius: 4px; box-shadow: 0 8px 26px rgba(0,0,0,0.55); padding: 4px;
  min-width: 180px;
}
.ctx-item {
  display: flex; align-items: center; gap: 8px; padding: 5px 12px; font-size: 12.5px;
  color: var(--fg); cursor: pointer; border-radius: 3px; white-space: nowrap;
}
.ctx-item:hover { background: #04395e; color: #fff; }
.ctx-item.danger:hover { background: var(--stop); }
.ctx-sep { height: 1px; background: var(--border-soft); margin: 4px 6px; }
.ctx-label { padding: 5px 12px 2px; font-size: 10.5px; color: var(--fg-faint); }
.ctx-item .ctx-key { margin-left: auto; color: var(--fg-faint); font-size: 11px; }
.ctx-item:hover .ctx-key { color: #dbe9fb; }

/* Modal */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 300;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh;
}
#modal {
  width: 460px; max-width: 92vw; background: #232327; border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 14px 48px rgba(0,0,0,0.6);
}
.modal-head { padding: 13px 16px; font-size: 13.5px; font-weight: 600; border-bottom: 1px solid var(--border-soft); }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-body label { font-size: 12px; color: var(--fg-dim); display: block; margin-bottom: 5px; }
.modal-body input[type="text"], .modal-body select {
  width: 100%; background: #101014; border: 1px solid var(--border); color: var(--fg);
  font: 13px var(--ui); padding: 7px 9px; border-radius: 3px; outline: none;
}
.modal-body input[type="text"]:focus { border-color: var(--accent); }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--border-soft); display: flex; justify-content: flex-end; gap: 8px; }
.btn {
  background: #2d2d33; border: 1px solid var(--border); color: var(--fg);
  font-size: 12.5px; padding: 6px 14px; border-radius: 3px; cursor: pointer;
}
.btn:hover { background: #35353c; }
.btn.primary { background: var(--accent); border-color: #2668ac; color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: #6e2c2c; border-color: #7c3535; color: #f5d5d5; }
.btn.danger:hover { background: #853232; }
.radio-row { display: flex; gap: 16px; }
.radio-row label { display: inline-flex; gap: 5px; align-items: center; margin: 0; color: var(--fg); font-size: 12.5px; cursor: pointer; }

/* Toasts */
#toasts { position: fixed; right: 14px; bottom: 34px; z-index: 400; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #26262c; border: 1px solid var(--border); border-left: 3px solid var(--accent);
  color: var(--fg); font-size: 12.5px; padding: 9px 14px; border-radius: 4px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45); max-width: 340px;
  animation: toast-in 0.18s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Monaco tweaks */
#monaco .monaco-editor, #monaco .monaco-editor-background, #monaco .monaco-editor .margin { background-color: var(--editor-bg) !important; }
.monaco-editor .squiggly-error { background: none !important; border-bottom: 2px solid var(--err); }

/* Scrollbars (sidebar etc.) */
* { scrollbar-width: thin; scrollbar-color: #4f4f4f transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #4f4f4f; border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background-color: #7a7a7a; background-clip: content-box; }
*::-webkit-scrollbar-corner { background: transparent; }
