:root {
  --header-height: 44px;
  --header: #575b61;
  --header-strong: #393d42;
  --text: #f2f3f4;
  --muted: #d0d3d6;
  --border: #747980;
  --hover: rgba(255, 255, 255, .14);
  --active: #fff;
  --active-text: #25282c;
  --menu-text: #171717;
  --dropdown-bg: var(--header-strong);
  --dropdown-text: var(--text);
  --accent: #f2f3f4;
  --alive: var(--muted);
  --radius: 8px;
}

:root[data-theme="ocean"] { --header: #dceeff; --header-strong: #bddcff; --text: #17324d; --muted: #426783; --border: #9fc5e8; --hover: rgba(255, 255, 255, .48); --active-text: #17324d; --menu-text: #171717; --accent: #1769aa; --alive: rgba(70, 82, 92, .58); }
:root[data-theme="forest"] { --header: #dcefdc; --header-strong: #b9dbbd; --text: #173d27; --muted: #497057; --border: #99c4a2; --accent: #257342; }
:root[data-theme="sunset"] { --header: #ffe7c7; --header-strong: #ffc989; --text: #603517; --muted: #8a6040; --border: #e5ad70; --accent: #b6501c; }
:root[data-theme="lavender"] { --header: #ebe2ff; --header-strong: #d1bcfb; --text: #3d2864; --muted: #6d578f; --border: #bba5e1; --accent: #7047b3; }
:root[data-theme="rose"] { --header: #ffe1ea; --header-strong: #f7b9cb; --text: #5e2638; --muted: #8a5364; --border: #df9fb2; --accent: #ae3d61; }
:root[data-theme="red"] { --header: #ffd9d7; --header-strong: #f29b96; --text: #5f1717; --muted: #8d3b38; --border: #d97c77; --accent: #b3261e; }
:root[data-theme="white"] { --header: #fff; --header-strong: #f7f7f7; --text: #171717; --muted: #666; --border: #d8d8d8; --accent: #333; }
:root[data-theme="gray"] { --header: #dedede; --header-strong: #c9c9c9; --text: #222; --muted: #5f5f5f; --border: #aaa; --accent: #3e3e3e; }
:root[data-theme="dark-gray"] { --header: #575b61; --header-strong: #393d42; --text: #f2f3f4; --muted: #d0d3d6; --border: #747980; --hover: rgba(255, 255, 255, .14); --active-text: #25282c; --menu-text: #171717; --accent: #f2f3f4; --alive: rgba(255, 255, 255, .8); }
:root[data-theme="black"] { --header: #242424; --header-strong: #111; --text: #f4f4f4; --muted: #bbb; --border: #4d4d4d; --hover: rgba(255, 255, 255, .12); --active-text: #171717; --menu-text: #171717; --accent: #fff; --alive: rgba(255, 255, 255, .86); }

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  background: #fff;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, a { font: inherit; }

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  position: fixed;
  z-index: 1000;
  inset: 0 0 auto;
  height: var(--header-height);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 9px 0;
  background: linear-gradient(180deg, var(--header) 0%, var(--header-strong) 100%);
  border-bottom: 0;
  white-space: nowrap;
}

.site-nav {
  flex: 1;
  display: flex;
  gap: 3px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  align-self: stretch;
  align-items: flex-end;
  padding-left: 11px;
}

.site-nav::-webkit-scrollbar { display: none; }

.nav-button, .nav-menu-item {
  position: relative;
}

.nav-button {
  height: 38px;
  margin: 0;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.nav-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 2px;
  text-decoration: none;
  justify-content: center;
}

.nav-button:hover { background: var(--hover); }
.alive-indicator {
  position: absolute;
  left: 50%;
  bottom: 3px;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--alive);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
}
.alive > .alive-indicator { opacity: 1; }
.alive.active > .alive-indicator {
  background: var(--active-text, var(--text));
  opacity: .58;
}
.nav-button.active {
  z-index: 1;
  background: var(--active);
  border-color: var(--border);
  color: var(--active-text, var(--text));
}

.site-nav > .nav-button.active::before,
.site-nav > .nav-button.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 11px;
  height: 11px;
  pointer-events: none;
}

.site-nav > .nav-button.active::before {
  left: -11px;
  border-radius: 0 0 11px 0;
  box-shadow: 5px 5px 0 5px var(--active);
}

.site-nav > .nav-button.active::after {
  right: -11px;
  border-radius: 0 0 0 11px;
  box-shadow: -5px 5px 0 5px var(--active);
}

.nav-label {
  flex: 0 0 auto;
  height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 7px 0 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  user-select: none;
}

.app-icon { width: 20px; height: 20px; object-fit: contain; }

.close-frame {
  flex: 0 0 auto;
  align-self: center;
  width: 34px;
  height: 34px;
  padding: 0 0 2px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-family: "Segoe UI", ui-sans-serif, sans-serif;
  font-size: 24px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
}

.close-frame:hover {
  background: #c42b1c;
  color: #fff;
}

.theme-control {
  position: relative;
  flex: 0 0 auto;
  height: 38px;
  display: flex;
  align-items: center;
}

.theme-toggle {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--text);
  border-radius: 7px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.theme-toggle:hover, .theme-control.open > .theme-toggle { background: var(--hover); }

.theme-menu {
  position: absolute;
  z-index: 20;
  top: 37px;
  right: 0;
  width: 128px;
  max-height: calc(100vh - var(--header-height) - 8px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--active);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .18);
}

.theme-control:not(.open) > .theme-menu { display: none; }

.theme-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--menu-text, #171717);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.theme-menu button:hover, .theme-menu button.active { background: var(--hover); }

.theme-menu button::before {
  content: "";
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border: 1px solid rgba(0, 0, 0, .2);
  border-radius: 4px;
  background: var(--theme-swatch);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22);
}

.theme-menu [data-theme="ocean"] { --theme-swatch: #4c9cdb; }
.theme-menu [data-theme="forest"] { --theme-swatch: #3f8a58; }
.theme-menu [data-theme="sunset"] { --theme-swatch: #ed8c3b; }
.theme-menu [data-theme="lavender"] { --theme-swatch: #9270cf; }
.theme-menu [data-theme="rose"] { --theme-swatch: #cf6687; }
.theme-menu [data-theme="red"] { --theme-swatch: #c52d27; }
.theme-menu [data-theme="white"] { --theme-swatch: #fff; }
.theme-menu [data-theme="gray"] { --theme-swatch: #aaa; }
.theme-menu [data-theme="dark-gray"] { --theme-swatch: #4b4f55; }
.theme-menu [data-theme="black"] { --theme-swatch: #111; }

.brand-mark, .fallback-icon {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--hover);
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
}

.brand-mark {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.nav-separator {
  width: 1px;
  height: 20px;
  margin: 9px 5px;
  flex: 0 0 auto;
  background: var(--border);
}

.nav-group {
  position: relative;
  flex: 0 0 auto;
}

.nav-group.mouse-hover,
.nav-group.touch-open,
.nav-group:focus-within { z-index: 2; }

.nav-group-primary::after { content: "⌄"; color: var(--muted); font-size: 11px; }
.nav-group:has(.active) > .nav-group-primary {
  background: var(--active);
  border-color: var(--border);
  color: var(--active-text, var(--text));
}

.nav-group.mouse-hover > .nav-group-primary,
.nav-group.touch-open > .nav-group-primary,
.nav-group:focus-within > .nav-group-primary {
  background: var(--dropdown-bg);
  border-color: var(--border);
  color: var(--dropdown-text);
}

.nav-menu {
  display: none;
  position: fixed;
  z-index: 10;
  min-width: 180px;
  max-height: min(360px, calc(100vh - 70px));
  margin-top: 0;
  padding: 5px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 9px 9px;
  background: var(--dropdown-bg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .14);
}

.nav-group.mouse-hover > .nav-menu,
.nav-group.touch-open > .nav-menu,
.nav-group:focus-within > .nav-menu { display: block; }

.nav-menu-item {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 6px;
  color: var(--dropdown-text);
  text-decoration: none;
}

.nav-menu-item:hover, .nav-menu-item.active { background: var(--hover); }

.site-icon { width: 20px; height: 20px; object-fit: contain; flex: 0 0 auto; }
.external-mark {
  position: absolute;
  top: 3px;
  right: 3px;
  color: var(--muted);
  font-size: 8px;
  line-height: 1;
}
.main {
  position: fixed;
  z-index: 0;
  inset: var(--header-height) 0 0;
  height: auto;
  min-height: 0;
}
.frame-view { width: 100%; height: 100%; }

.frame-view, .workspace { width: 100%; height: 100%; background: #fff; }
.workspace { position: relative; }
.workspace-frame { width: 100%; height: 100%; display: block; border: 0; background: #fff; }
.frame-failure {
  width: 100%;
  height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  color: #333;
  text-align: center;
}
.frame-failure p { margin: 0; }
.failure-link { margin-left: .25em; color: #1769aa; }
[hidden] { display: none !important; }

@media (max-width: 680px) {
  .site-nav > .nav-button .label,
  .site-nav > .nav-button .external-mark,
  .site-nav > .nav-group > .nav-group-primary .label,
  .site-nav > .nav-group > .nav-group-primary .external-mark { display: none; }
  .site-nav .nav-button { padding: 0 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
