:root {
  --navy: #102c4b;
  --navy-deep: #071b31;
  --blue: #2f6e9f;
  --gold: #f1c84b;
  --paper: #f7f4ec;
  --white: #ffffff;
  --ink: #172536;
  --muted: #687789;
  --line: #d8e0e8;
  --shadow: 0 18px 40px rgba(7, 27, 49, 0.12);
  --shadow-sm: 0 6px 16px rgba(7, 27, 49, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: #e9eef3; color: var(--ink); font-family: "Avenir Next", "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.app-shell.is-app-open .topbar { display: none; }
.app-shell.is-app-open .shell-body { height: 100%; }
.app-shell.is-app-open .app-rail { display: flex; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 32px;
  color: var(--paper);
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-deep) 100%);
  box-shadow: 0 8px 24px rgba(7, 27, 49, 0.16);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand-lockup { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; color: var(--navy-deep); background: transparent; font: 800 1.5rem Georgia, serif; flex: 0 0 auto; }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; display: block; }
.brand-name, .brand-status { margin: 0; }
.brand-name { font-weight: 800; letter-spacing: .02em; white-space: nowrap; }
.brand-status { margin-top: 3px; color: rgba(247,244,236,.65); font-size: .76rem; white-space: nowrap; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: #74d69d; }

.search-wrap { position: relative; flex: 1 1 320px; max-width: 460px; margin: 0; }
.search-wrap input { width: 100%; padding: 11px 12px 11px 36px; border: 1px solid rgba(255,255,255,.15); border-radius: 9px; outline: 0; color: var(--paper); background: rgba(255,255,255,.09); }
.search-wrap input::placeholder { color: rgba(247,244,236,.55); }
.search-wrap input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(241,200,75,.18); }
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: rgba(247,244,236,.65); font-size: 1.2rem; }

.topbar-meta { display: flex; align-items: center; gap: 14px; margin-left: auto; flex: 0 0 auto; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 8px; color: var(--paper); background: rgba(255,255,255,.1); font-size: 1.15rem; cursor: pointer; }
.icon-button:hover { background: rgba(241,200,75,.24); }
.icon-button:focus-visible { outline: 3px solid rgba(241,200,75,.7); outline-offset: 2px; }
.clock { text-align: right; white-space: nowrap; }
.clock-time { color: var(--paper); font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.clock-date { margin-top: 1px; color: rgba(247,244,236,.6); font-size: .72rem; }

/* ---------- Shell body: rail + workspace/app-view ---------- */
.shell-body { flex: 1; display: flex; min-height: 0; }

.app-rail {
  flex: 0 0 72px;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 0;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  box-shadow: 4px 0 16px rgba(7, 27, 49, .12);
  overflow-y: auto;
  z-index: 5;
}
.rail-home {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 13px;
  background: rgba(255,255,255,.08);
  color: var(--gold);
  font: 800 .82rem Georgia, serif;
  letter-spacing: .03em;
  cursor: pointer;
  position: relative;
  transition: background .2s ease, transform .2s ease;
}
.rail-home img { width: 100%; height: 100%; object-fit: contain; display: block; }
.rail-home:hover { background: transparent; }
.rail-home.is-active { background: transparent; }
.rail-home.is-active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 22px;
  border-radius: 0 4px 4px 0;
  background: var(--gold);
}
.rail-icons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,.12);
}
.rail-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 13px;
  text-decoration: none;
  cursor: pointer;
  transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease;
}
.rail-icon .monogram { width: 46px; height: 46px; font-size: 1.05rem; box-shadow: none; }
.rail-icon .monogram svg { width: 50%; height: 50%; }
.rail-icon:hover { transform: scale(1.08); }
.rail-icon:focus-visible { outline: 3px solid rgba(241,200,75,.7); outline-offset: 2px; }
.rail-icon.is-active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 26px;
  border-radius: 0 4px 4px 0;
  background: var(--gold);
}
.rail-icon.is-active .monogram { box-shadow: 0 0 0 2px rgba(241,200,75,.55); }

/* ---------- Embedded app view ---------- */
.app-view { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.app-view-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.app-view-back {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: var(--paper);
  color: var(--navy-deep);
  font-size: 1rem;
  cursor: pointer;
  flex: 0 0 auto;
}
.app-view-back:hover { background: var(--line); }
.app-view-name { font-weight: 800; color: var(--navy-deep); flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-view-fallback { flex: 0 0 auto; color: var(--blue); font-size: .82rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.app-view-fallback:hover { text-decoration: underline; }
.app-frame { flex: 1; width: 100%; border: 0; background: var(--white); }

/* ---------- Workspace / orbit diagram ---------- */
.workspace {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  padding: clamp(12px, 2.5vw, 28px);
  background: radial-gradient(circle at 95% 0%, rgba(241,200,75,.16), transparent 30%), var(--paper);
}

.orbit {
  position: relative;
  width: var(--orbit-size, min(90vmin, 640px));
  height: var(--orbit-size, min(90vmin, 640px));
  margin: auto;
}

.orbit-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.orbit-lines line {
  stroke: var(--blue);
  stroke-width: .45;
  stroke-dasharray: 2.4 2.2;
  opacity: .4;
  transition: stroke .2s ease, opacity .2s ease, stroke-width .2s ease;
}
.orbit-lines line.is-active { stroke: var(--gold); stroke-width: .85; opacity: 1; }

.orbit-hub {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 21%;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, var(--navy) 0%, var(--navy-deep) 78%);
  color: var(--gold);
  box-shadow: 0 22px 44px rgba(7, 27, 49, .38);
  text-align: center;
  z-index: 2;
  animation: hub-pulse 4.5s ease-in-out infinite;
}
.orbit-hub-mark { font: 800 2.1rem Georgia, serif; letter-spacing: .04em; }
.orbit-hub-label { margin-top: 6px; color: rgba(247,244,236,.75); font: 800 2.1rem Georgia, serif; letter-spacing: .04em; text-transform: uppercase; }

.orbit-nodes { position: absolute; inset: 0; }

.orbit-node {
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: calc(var(--orbit-size, 640px) * .013);
  width: clamp(150px, calc(var(--orbit-size, 640px) * .225), 230px);
  padding: calc(var(--orbit-size, 640px) * .02) calc(var(--orbit-size, 640px) * .022);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: left;
  text-decoration: none;
  color: var(--ink);
  background: var(--white);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform .28s cubic-bezier(.34, 1.56, .64, 1), box-shadow .28s ease, border-color .28s ease, opacity .2s ease;
  z-index: 1;
  animation: node-in .5s cubic-bezier(.2, .8, .3, 1.2) backwards;
  animation-delay: calc(var(--i, 0) * 70ms);
}
.orbit-node:hover, .orbit-node:focus-visible {
  transform: translate(-50%, -50%) scale(1.07) translateY(-5px);
  border-color: transparent;
  box-shadow: var(--shadow);
  z-index: 3;
}
.orbit-node:hover .monogram, .orbit-node:focus-visible .monogram {
  transform: scale(1.1) rotate(-4deg);
}
.orbit-node:hover .card-open, .orbit-node:focus-visible .card-open { opacity: 1; transform: translateX(2px); }
.orbit-node:focus-visible { outline: 3px solid rgba(241,200,75,.7); outline-offset: 3px; }
.orbit-node.is-hidden { opacity: .1; pointer-events: none; transform: translate(-50%, -50%) scale(.9); }

.orbit-node .card-top { display: flex; align-items: center; gap: calc(var(--orbit-size, 640px) * .014); }
.orbit-node .card-text { min-width: 0; flex: 1; }
.orbit-node .monogram {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: clamp(38px, calc(var(--orbit-size, 640px) * .075), 58px);
  height: clamp(38px, calc(var(--orbit-size, 640px) * .075), 58px);
  border-radius: 13px;
  color: var(--white);
  background: var(--gold);
  font: 800 clamp(1rem, calc(var(--orbit-size, 640px) * .028), 1.3rem) Georgia, serif;
  box-shadow: 0 10px 22px rgba(7,27,49,.2);
  transition: transform .28s cubic-bezier(.34, 1.56, .64, 1);
}
.monogram.grad-a { background: linear-gradient(135deg, #7b6ff0, #4f3fd6); }
.monogram.grad-b { background: linear-gradient(135deg, #34d0c6, #1a9e97); }
.monogram.grad-c { background: linear-gradient(135deg, #ff9a56, #ef6a3c); }
.monogram.grad-d { background: linear-gradient(135deg, #5aa9ff, #2f6e9f); }
.monogram.grad-e { background: linear-gradient(135deg, #ff6fa5, #e0447a); }
.monogram.grad-f { background: linear-gradient(135deg, #58c46b, #2f9e4c); }

.orbit-node .card-name { margin: 0; font-size: clamp(.86rem, calc(var(--orbit-size, 640px) * .0185), 1.06rem); font-weight: 800; color: var(--navy-deep); line-height: 1.25; }
.orbit-node .card-open { flex: 0 0 auto; color: var(--blue); font-size: clamp(.9rem, calc(var(--orbit-size, 640px) * .022), 1.2rem); opacity: 0; transition: opacity .2s ease, transform .2s ease; }
.orbit-node .card-desc {
  margin: 0;
  color: var(--muted);
  font-size: clamp(.72rem, calc(var(--orbit-size, 640px) * .0145), .88rem);
  line-height: 1.42;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.orbit-node .card-url {
  margin: 0;
  padding-top: calc(var(--orbit-size, 640px) * .012);
  border-top: 1px solid var(--line);
  color: var(--blue);
  font-size: clamp(.66rem, calc(var(--orbit-size, 640px) * .0125), .78rem);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes hub-pulse {
  0%, 100% { box-shadow: 0 22px 44px rgba(7, 27, 49, .38), 0 0 0 0 rgba(241,200,75,.35); }
  50% { box-shadow: 0 22px 44px rgba(7, 27, 49, .38), 0 0 0 14px rgba(241,200,75,0); }
}
@keyframes node-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

#empty-state { display: none; padding: 40px 10px; text-align: center; color: var(--muted); font-size: .92rem; }

@media (max-width: 900px) {
  .app-shell { height: auto; overflow: visible; }
  .app-shell.is-app-open { height: 100vh; overflow: hidden; }
  .topbar { flex-wrap: wrap; gap: 12px; padding: 14px 16px; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  .workspace { padding: 20px 16px 32px; overflow: visible; display: block; }
  .app-rail { flex-basis: 56px; padding: 10px 0; gap: 8px; }
  .rail-home, .rail-icon, .rail-icon .monogram { width: 38px; height: 38px; }
  .app-view-name { font-size: .92rem; }
  .app-view-fallback { display: none; }

  .orbit { width: 100%; height: auto; display: flex; flex-direction: column; gap: 20px; }
  .orbit-lines { display: none; }
  .orbit-hub {
    position: static;
    transform: none;
    width: 100%;
    aspect-ratio: auto;
    flex-direction: row;
    justify-content: center;
    gap: 10px;
    border-radius: 16px;
    padding: 16px;
    animation: none;
  }
  .orbit-nodes { position: static; display: flex; flex-direction: column; gap: 14px; }
  .orbit-node { position: static; width: 100%; padding: 16px 18px; gap: 10px; animation: none; }
  .orbit-node .card-top { gap: 12px; }
  .orbit-node .monogram { width: 48px; height: 48px; font-size: 1.15rem; }
  .orbit-node .card-name { font-size: 1rem; }
  .orbit-node .card-desc { font-size: .85rem; -webkit-line-clamp: 3; }
  .orbit-node .card-url { font-size: .76rem; }
  .orbit-node:hover, .orbit-node:focus-visible { transform: translateY(-3px) !important; }
}

@media (max-width: 420px) {
  .clock-date { display: none; }
}

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