/* ---------------------------------------------------------------------------
   WebSim Clone — browser chrome styling
   Pure CSS, no imports, system fonts only.
--------------------------------------------------------------------------- */

:root {
  --chrome-bg: #e8e8ea;
  --chrome-bg-2: #dcdcdf;
  --chrome-border: #b6b6bb;
  --chrome-line: #c9c9cd;
  --text: #2b2b30;
  --text-muted: #74747c;
  --accent: #3466d6;
  --accent-hover: #2a56b8;
  --danger: #c23a3a;
  --ok: #2e8b57;
  --radius: 10px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: #26262b;
  background-image: radial-gradient(ellipse at 50% 0%, #33333a 0%, #222227 70%);
  font-family: var(--font-ui);
  color: var(--text);
  overflow: hidden;
}

/* Global utility */
.hidden { display: none !important; }
.flex { flex: 1; }

/* ---------------------------------------------------------------- window */

#chrome {
  position: fixed;
  inset: 12px;
  display: flex;
  flex-direction: column;
  background: var(--chrome-bg);
  border: 1px solid var(--chrome-border);
  border-radius: var(--radius);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.45),
    0 2px 8px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  overflow: hidden;
}

/* -------------------------------------------------------------- titlebar */

#titlebar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  min-height: 30px;
  background: linear-gradient(#f2f2f4, var(--chrome-bg-2));
  border-bottom: 1px solid var(--chrome-line);
  user-select: none;
}

.traffic {
  display: flex;
  gap: 7px;
  flex: 0 0 auto;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.4);
}
.dot.red    { background: #ff5f57; }
.dot.yellow { background: #febc2e; }
.dot.green  { background: #28c840; }

/* truly centered window title, independent of traffic-light / badge widths */
#title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: 46%;
  font-size: 13px;
  font-weight: 600;
  color: #4a4a52;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: #555560;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#titlebar .badge {
  margin-left: auto;
  max-width: 26%;
}

#modelBadge:not(:empty) {
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 999px;
  padding: 2px 9px;
}

/* --------------------------------------------------------------- toolbar */

#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-line);
}

#toolbar button {
  flex: 0 0 auto;
  min-width: 32px;
  height: 30px;
  padding: 0 8px;
  font-size: 14px;
  line-height: 1;
  color: #3c3c44;
  background: linear-gradient(#fdfdfe, #ececef);
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
  cursor: pointer;
}
#toolbar button:hover:not(:disabled) {
  background: linear-gradient(#ffffff, #f4f4f6);
  border-color: #a3a3aa;
}
#toolbar button:active:not(:disabled) {
  background: #e2e2e6;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}
#toolbar button:disabled {
  opacity: 0.42;
  cursor: default;
}
#toolbar button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#addressBar {
  flex: 1 1 160px;
  min-width: 160px;
  height: 30px;
  padding: 0 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--chrome-border);
  border-radius: 15px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.08);
  outline: none;
}
#addressBar::placeholder { color: #a2a2ab; }
#addressBar:focus {
  border-color: var(--accent);
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.06),
    0 0 0 3px rgba(52, 102, 214, 0.22);
}

/* ------------------------------------------------------------- frame area */

#frameWrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #ffffff;
}

.tabFrame { position: absolute; inset: 0; }
.tabFrame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}
.tabFrame .frame-preview { pointer-events: none; }

/* ------------------------------------------------------------- tab strip */

#tabStrip {
  display: flex;
  align-items: stretch;
  gap: 3px;
  padding: 4px 8px 0;
  background: var(--chrome-bg-2);
  border-bottom: 1px solid var(--chrome-line);
  overflow-x: auto;
  min-height: 30px;
}
#tabStrip:empty { display: none; }
.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 200px;
  min-width: 84px;
  padding: 4px 8px 5px;
  font-size: 12px;
  color: #55555e;
  background: linear-gradient(#efeff2, #e4e4e8);
  border: 1px solid var(--chrome-border);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { background: linear-gradient(#f4f4f6, #e9e9ed); }
.tab.active {
  color: var(--text);
  background: #ffffff;
  box-shadow: 0 -1px 0 var(--accent) inset;
}
.tab .tab-label { overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; }
.tab .tab-close {
  flex: 0 0 auto;
  width: 15px; height: 15px;
  line-height: 13px; text-align: center;
  border-radius: 4px;
  color: #8a8a92;
}
.tab .tab-close:hover { background: rgba(0,0,0,0.12); color: #333; }
.tab .tab-spin {
  flex: 0 0 auto;
  width: 10px; height: 10px;
  border: 2px solid rgba(52,102,214,0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
#btnNewTab {
  flex: 0 0 auto;
  align-self: center;
  width: 26px; height: 24px;
  margin-left: 2px;
  font-size: 16px; line-height: 1;
  color: #55555e;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
#btnNewTab:hover:not(:disabled) { background: rgba(0,0,0,0.08); }
#btnNewTab:disabled { opacity: 0.35; cursor: default; }

/* ------------------------------------------------------------- tree overlay */

#treeOverlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(248, 248, 250, 0.97);
}
.tree-scroll { position: absolute; inset: 0; overflow: auto; }
#treeSvg { display: block; }
#treeSvg text { user-select: none; }

/* favicon slot in the toolbar */
#favSlot { flex: 0 0 auto; border-radius: 3px; }
#favSlot.hidden { display: none; }

/* links chip + popover (statusbar) */
#linksChip { cursor: pointer; background: transparent; border: 1px solid transparent; }
#linksChip:hover { border-color: var(--chrome-border); }
#statusbar { position: relative; }
#linksPopover {
  position: absolute;
  bottom: 100%;
  left: 8px;
  margin-bottom: 6px;
  max-height: 50vh;
  overflow: auto;
  min-width: 240px;
  max-width: 380px;
  background: #fafafb;
  border: 1px solid var(--chrome-border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  z-index: 55;
}
#linksPopover.hidden { display: none; }
#linksPopover .lp-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--chrome-line);
  padding: 8px 12px;
  cursor: pointer;
}
#linksPopover .lp-row:last-child { border-bottom: 0; }
#linksPopover .lp-row:hover { background: #eef2f8; }
#linksPopover .lp-title { font-size: 13px; color: var(--text); }
#linksPopover .lp-url { font-size: 11px; }

/* --------------------------------------------------------------- statusbar */

#statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--chrome-bg-2);
  border-top: 1px solid var(--chrome-line);
  user-select: none;
}

#byteCount {
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.spinner {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  border: 2px solid rgba(52, 102, 214, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.chip {
  padding: 1px 8px;
  font-size: 10.5px;
  font-weight: 600;
  color: #9e2323;
  background: rgba(194, 58, 58, 0.12);
  border: 1px solid rgba(194, 58, 58, 0.35);
  border-radius: 999px;
  cursor: default;
}

/* ------------------------------------------------------------------ dialog */

#settingsDialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 20px 22px;
  color: var(--text);
  background: #fafafb;
  border: 1px solid var(--chrome-border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

#settingsDialog::backdrop {
  background: rgba(20, 20, 25, 0.5);
  backdrop-filter: blur(2px);
}

#settingsDialog h2 {
  margin: 0 0 14px;
  font-size: 17px;
}
#settingsDialog h3 {
  margin: 18px 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

#settingsDialog label {
  display: block;
  margin: 14px 0 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: #46464e;
}

#settingsDialog input[type="text"],
#settingsDialog input[type="password"],
#settingsDialog select {
  display: block;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
  outline: none;
}
#settingsDialog input:focus,
#settingsDialog select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 102, 214, 0.2);
}

#settingsDialog input[type="range"] {
  display: block;
  width: 100%;
  margin: 6px 0;
  accent-color: var(--accent);
}

#tempVal {
  font-family: var(--font-mono);
  font-weight: 400;
  color: var(--text-muted);
}

.hint {
  margin: 6px 0 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-muted);
}
.hint a { color: var(--accent); }

.hint-inline {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.row.end { justify-content: flex-end; margin-top: 18px; }

#settingsDialog button {
  height: 30px;
  padding: 0 14px;
  font-size: 13px;
  color: #3c3c44;
  background: linear-gradient(#fdfdfe, #ececef);
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
  cursor: pointer;
}
#settingsDialog button:hover {
  background: linear-gradient(#ffffff, #f4f4f6);
}
#settingsDialog button:active {
  background: #e2e2e6;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}

button.primary {
  color: #ffffff !important;
  background: var(--accent) !important;
  border-color: var(--accent-hover) !important;
}
button.primary:hover {
  background: var(--accent-hover) !important;
}

#keyTestResult {
  font-size: 12px;
  color: var(--text-muted);
}

/* saved pages list */
#savedList {
  margin: 0;
  padding: 4px;
  max-height: 180px;
  overflow-y: auto;
  list-style: none;
  background: #ffffff;
  border: 1px solid var(--chrome-line);
  border-radius: 6px;
}
#savedList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  font-size: 12.5px;
  border-radius: 4px;
}
#savedList li:hover { background: #f2f4fa; }
#savedList li .title,
#savedList li .url {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#savedList li .url {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}
#savedList li button {
  flex: 0 0 auto;
  height: 22px !important;
  min-width: 22px;
  padding: 0 6px !important;
  font-size: 11px !important;
  line-height: 1;
}
#savedList li.hint {
  color: var(--text-muted);
  background: none;
}

/* ------------------------------------------------------------------ toasts */

#toasts {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: 340px;
  padding: 9px 14px;
  font-size: 12.5px;
  line-height: 1.4;
  color: #f0f0f2;
  background: #2f2f36;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.22s ease-out;
  pointer-events: auto;
}

.toast.error {
  color: #ffd9d9;
  background: #4a2626;
  border-color: rgba(255, 120, 120, 0.35);
}

.toast.ok {
  color: #d9f5e2;
  background: #234432;
  border-color: rgba(110, 220, 160, 0.35);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --------------------------------------------------------------- tip link */

#tipLink {
  margin-left: 10px;
  color: inherit;
  text-decoration: none;
  opacity: 0.75;
  white-space: nowrap;
}
#tipLink:hover { opacity: 1; text-decoration: underline; }

/* --------------------------------------------------------- welcome overlay */

#welcome {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 12, 16, 0.62);
  backdrop-filter: blur(2px);
}
#welcome.hidden { display: none; }

.welcome-card {
  position: relative;
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 30px 22px;
  background: var(--chrome-bg, #f2f2f4);
  color: var(--text, #23232a);
  border: 1px solid var(--chrome-border, #b9b9c0);
  border-radius: 12px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}
.welcome-card h1 {
  margin: 0;
  font-size: 2em;
  letter-spacing: 0.5px;
}
.welcome-card h1 em {
  font-style: normal;
  color: var(--accent, #3466d6);
}
.welcome-card .wtag {
  margin: 2px 0 14px;
  font-style: italic;
  opacity: 0.65;
}
.welcome-card p { line-height: 1.45; }
.welcome-card ol {
  margin: 12px 0;
  padding-left: 22px;
  line-height: 1.6;
}
.welcome-card button.primary {
  margin-top: 6px;
  padding: 9px 18px;
  font-size: 1em;
}
#btnWelcomeClose {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.6;
}
#btnWelcomeClose:hover { opacity: 1; background: rgba(0, 0, 0, 0.07); }

/* ---------------------------------------------------------- world switcher */
/* Replaces the old centered #title — same absolute centering, but clickable. */

#brand {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 600;
  color: #4a4a52;
  white-space: nowrap;
  pointer-events: none;
  letter-spacing: 0.3px;
}

#worldSwitcher {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: 46%;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #4a4a52;
  white-space: nowrap;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  pointer-events: auto;
}
#worldSwitcher:hover { background: rgba(0, 0, 0, 0.07); }
#worldSwitcher:active { background: rgba(0, 0, 0, 0.11); }
#worldSwitcher:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#wsBrand { font-weight: 400; }

#wsName {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
#wsName:not(:empty)::before {
  content: " \00B7  ";
  font-weight: 400;
  color: var(--text-muted);
}

#worldSwitcher .caret {
  font-size: 9px;
  color: var(--text-muted);
}

/* ----------------------------------------------------------- world popover */

#worldPopover {
  position: absolute;
  top: 110%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  min-width: 300px;
  max-width: 380px;
  padding: 6px;
  background: #ffffff;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.28), 0 2px 8px rgba(0, 0, 0, 0.12);
}

.wp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  border-left: 3px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
.wp-row:hover { background: #f2f4fa; }
.wp-row.active { border-left-color: var(--accent); }
.wp-row.active .wp-name { font-weight: 700; }

.wp-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.wp-meta {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.wp-actions {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
}

.wp-actions button,
.wp-foot button {
  flex: 0 0 auto;
  height: 22px;
  min-width: 22px;
  padding: 0 7px;
  font-size: 11px;
  line-height: 1;
  color: #3c3c44;
  background: linear-gradient(#fdfdfe, #ececef);
  border: 1px solid var(--chrome-border);
  border-radius: 4px;
  cursor: pointer;
}
.wp-actions button:hover,
.wp-foot button:hover {
  background: linear-gradient(#ffffff, #f4f4f6);
  border-color: #a3a3aa;
}

.wp-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 8px 10px 4px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--chrome-line);
}
.wp-foot .flex { flex: 1; }

/* --------------------------------------------------------- view-only banner */

#viewBanner {
  padding: 5px 12px;
  font-size: 12px;
  text-align: center;
  color: #6d5a1b;
  background: #fff7e0;
  border-bottom: 1px solid #e8d9a0;
}
#viewBanner b { color: #4a3d10; }
#viewBanner button {
  height: 22px;
  margin-left: 8px;
  padding: 0 9px;
  font-size: 11.5px;
  line-height: 1;
  color: #5c4c14;
  background: #fffdf4;
  border: 1px solid #d8c890;
  border-radius: 4px;
  cursor: pointer;
}
#viewBanner button:hover { background: #ffffff; border-color: #c6b478; }

/* ---------------------------------------------------- archive chip + stepper */

.archChip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  font-size: 10.5px;
  font-weight: 600;
  color: #2a56b8;
  background: rgba(52, 102, 214, 0.1);
  border: 1px solid rgba(52, 102, 214, 0.35);
  border-radius: 999px;
}

#verPrev,
#verNext {
  padding: 0 3px;
  font-size: 11px;
  line-height: 1;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 3px;
  cursor: pointer;
}
#verPrev:hover:not(:disabled),
#verNext:hover:not(:disabled) { background: rgba(52, 102, 214, 0.15); }
#verPrev:disabled,
#verNext:disabled { opacity: 0.35; cursor: default; }

#verLabel {
  font-family: var(--font-mono);
  font-size: 10.5px;
}

/* starred page indicator */
#btnSave.active { color: #b8860b; }

/* ----------------------------------------------------------- confirm dialog */
/* Mirrors #settingsDialog's look, narrower. */

#confirmDialog {
  width: min(360px, calc(100vw - 32px));
  padding: 20px 22px;
  color: var(--text);
  background: #fafafb;
  border: 1px solid var(--chrome-border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
#confirmDialog::backdrop {
  background: rgba(20, 20, 25, 0.5);
  backdrop-filter: blur(2px);
}

#confirmMsg {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

#confirmDialog input[type="text"] {
  display: block;
  width: 100%;
  height: 32px;
  margin-top: 12px;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
  outline: none;
}
#confirmDialog input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 102, 214, 0.2);
}

#confirmDialog button {
  height: 30px;
  padding: 0 14px;
  font-size: 13px;
  color: #3c3c44;
  background: linear-gradient(#fdfdfe, #ececef);
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
  cursor: pointer;
}
#confirmDialog button:hover {
  background: linear-gradient(#ffffff, #f4f4f6);
}
#confirmDialog button:active {
  background: #e2e2e6;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* ------------------------------------------------------------- compare split */

#frameWrap.comparing .tabFrame:not(.hidden) { top: 26px; right: 50%; }
.cmp-head {
  position: absolute;
  height: 26px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  font-size: 11.5px;
  color: #55555e;
  background: var(--chrome-bg-2);
  border-bottom: 1px solid var(--chrome-line);
  z-index: 5;
}
.cmp-head.cmp-left { top: 0; left: 0; right: 50%; }
.cmp-pane-right {
  position: absolute;
  top: 0; bottom: 0; left: 50%; right: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--chrome-border);
  background: #fff;
  z-index: 4;
}
.cmp-head.cmp-right { position: relative; left: auto; right: auto; top: auto; }
.cmp-head .cmp-model {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
}
.cmp-head .cmp-cost { flex: 0 0 auto; font-family: var(--font-mono); color: var(--text-muted); }
.cmp-head .cmp-keep {
  flex: 0 0 auto;
  padding: 2px 10px;
  font-size: 11px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}
.cmp-head .cmp-keep:disabled { opacity: 0.4; cursor: default; }
.cmp-head .cmp-x {
  flex: 0 0 auto;
  width: 18px; height: 18px;
  font-size: 14px; line-height: 1;
  background: transparent;
  border: 0;
  cursor: pointer;
  color: #77777f;
}
.cmp-body { position: relative; flex: 1 1 auto; }
#btnCompare.active { background: #e2e2e6; box-shadow: inset 0 1px 3px rgba(0,0,0,0.15); }

#comparePopover {
  position: absolute;
  top: 100%;
  right: 12px;
  margin-top: 4px;
  z-index: 55;
  min-width: 260px;
  padding: 12px 14px;
  background: #fafafb;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.28);
}
#comparePopover.hidden { display: none; }
#comparePopover select,
#comparePopover input[type="text"] {
  width: 100%;
  height: 30px;
  margin: 6px 0;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
}

/* ============================================================ BUILD MODE */

#modeToggle { display: flex; gap: 0; margin-left: 4px; flex: 0 0 auto; z-index: 2; }
#modeToggle button {
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #55555e;
  background: linear-gradient(#fdfdfe, #ececef);
  border: 1px solid var(--chrome-border);
  cursor: pointer;
}
#modeToggle button:first-child { border-radius: 6px 0 0 6px; }
#modeToggle button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
#modeToggle button.active { color: #fff; background: var(--accent); border-color: var(--accent); }

/* When in Build mode, hide the browse chrome and show the build view. */
#chrome[data-mode="build"] #tabStrip,
#chrome[data-mode="build"] #comparePopover,
#chrome[data-mode="build"] #toolbar,
#chrome[data-mode="build"] #viewBanner,
#chrome[data-mode="build"] #frameWrap,
#chrome[data-mode="build"] #statusbar,
#chrome[data-mode="build"] #worldSwitcher { display: none !important; }

#buildView { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; background: var(--chrome-bg); }
#buildView.hidden { display: none; }

#buildBar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-line);
  position: relative;
}
#projTitle {
  flex: 0 1 240px;
  min-width: 120px;
  height: 28px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
}
#buildBar button {
  flex: 0 0 auto;
  height: 28px;
  padding: 0 10px;
  font-size: 12.5px;
  color: #3c3c44;
  background: linear-gradient(#fdfdfe, #ececef);
  border: 1px solid var(--chrome-border);
  border-radius: 6px;
  cursor: pointer;
}
#buildBar button:hover { background: linear-gradient(#ffffff, #f4f4f6); }
#buildTabs { display: flex; gap: 0; }
#buildTabs button { border-radius: 0; border-left: 0; }
#buildTabs button:first-child { border-radius: 6px 0 0 6px; border-left: 1px solid var(--chrome-border); }
#buildTabs button:last-child { border-radius: 0 6px 6px 0; }
#buildTabs button.active { color: #fff; background: var(--accent); border-color: var(--accent); }

#buildBody { flex: 1 1 auto; min-height: 0; display: flex; }
#buildPanel { flex: 0 0 320px; min-width: 260px; display: flex; flex-direction: column; border-right: 1px solid var(--chrome-line); background: #f6f6f8; }
.build-pane { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.build-pane.hidden { display: none; }

#chatLog { flex: 1 1 auto; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { padding: 8px 11px; border-radius: 10px; font-size: 13px; line-height: 1.4; max-width: 92%; }
.chat-user { align-self: flex-end; background: var(--accent); color: #fff; }
.chat-chip { align-self: flex-start; font-size: 11.5px; color: var(--text-muted); background: #e7e7ec; border-radius: 8px; padding: 3px 9px; }
.chat-pending { align-self: flex-start; display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-muted); }
#chatInputRow { flex: 0 0 auto; padding: 10px; border-top: 1px solid var(--chrome-line); background: #f6f6f8; }
#chatInput { width: 100%; resize: vertical; padding: 8px 10px; font-family: var(--font-ui); font-size: 13px; border: 1px solid var(--chrome-border); border-radius: 8px; box-sizing: border-box; }
.chat-actions { display: flex; gap: 6px; margin-top: 6px; }
.chat-actions button { flex: 1 1 auto; height: 30px; border: 1px solid var(--chrome-border); border-radius: 6px; background: linear-gradient(#fdfdfe, #ececef); cursor: pointer; }
.chat-actions button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.chat-actions button:disabled { opacity: 0.45; cursor: default; }

#codePane { padding: 10px; gap: 8px; }
#codeArea { flex: 1 1 auto; width: 100%; resize: none; font-family: var(--font-mono); font-size: 11.5px; padding: 8px; border: 1px solid var(--chrome-border); border-radius: 6px; box-sizing: border-box; white-space: pre; }
#btnCodeApply { flex: 0 0 auto; height: 30px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }

#timelinePane { overflow-y: auto; }
#timelineList { list-style: none; margin: 0; padding: 8px; }
.tl-row { display: flex; align-items: center; gap: 6px; padding: 7px 6px; border-bottom: 1px solid var(--chrome-line); font-size: 12px; }
.tl-label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-row button { flex: 0 0 auto; font-size: 11px; padding: 2px 7px; border: 1px solid var(--chrome-border); border-radius: 5px; background: #fff; cursor: pointer; }

#buildFrameHost { flex: 1 1 auto; position: relative; background: #fff; min-width: 0; }
#buildFrameHost iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
#buildFrameHost .frame-preview { pointer-events: none; }

#newProjectScreen { position: absolute; inset: 0; z-index: 3; overflow-y: auto; padding: 40px 32px; background: #fdf6e3; }
#newProjectScreen.hidden { display: none; }
#newProjectScreen h2 { font-family: Georgia, serif; font-size: 1.8em; margin: 0 0 18px; color: #333; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.template-card { text-align: left; padding: 14px; background: #fff; border: 1px solid #e0dcc8; border-radius: 10px; cursor: pointer; }
.template-card:hover { border-color: var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,0.08); }
.tc-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; color: #222; }
.tc-desc { font-size: 12px; color: #777; line-height: 1.4; }

#revBanner { position: absolute; top: 0; left: 0; right: 0; z-index: 4; padding: 6px 12px; text-align: center; font-size: 12px; background: #fff7e0; border-bottom: 1px solid #e8d9a0; }
#revBanner.hidden { display: none; }

#projPopover { position: absolute; top: 100%; left: 10px; margin-top: 4px; z-index: 55; min-width: 240px; max-height: 50vh; overflow: auto; background: #fafafb; border: 1px solid var(--chrome-border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.22); }
#projPopover.hidden { display: none; }
.pp-row { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 8px 12px; border: 0; border-bottom: 1px solid var(--chrome-line); background: none; cursor: pointer; }
.pp-row:hover { background: #eef2f8; }
.pp-name { flex: 1 1 auto; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.pp-del { flex: 0 0 auto; width: 18px; height: 18px; border: 0; background: transparent; color: #999; cursor: pointer; font-size: 14px; }
.pp-del:hover { color: var(--danger); }

/* shared full-bleed app view */
#appView { position: fixed; inset: 0; z-index: 80; background: #fff; }
#appView.hidden { display: none; }
#appFrameHost { position: absolute; inset: 0 0 34px 0; }
#appFrameHost iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
#appBanner { position: absolute; left: 0; right: 0; bottom: 0; height: 34px; display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 12px; background: #1c1c22; color: #ddd; }
#appBanner button { font-size: 12px; padding: 3px 12px; border: 0; border-radius: 5px; cursor: pointer; }
#btnAppRemix { background: var(--accent); color: #fff; }
#btnAppClose { background: transparent; color: #999; font-size: 16px; }
