/* TELEIOS app frame ("Pop Studio"): sidebar, project switcher, quick search, navigation, main area,
   splash, quick-search palette, module loading / fallback states. Markup: js/shell/*.js.
   Colour is the navigation: every module has its palette colour (data-color on .nav-item and on .app). */

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

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}
.app > .sidebar { grid-column: 1; grid-row: 1; }
.app > .main { grid-column: 2; grid-row: 1; }

.main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background-color: var(--canvas);
  background-image: radial-gradient(var(--canvas-dot) 1.1px, transparent 1.3px);
  background-size: 22px 22px;
}
.main > :not(.nav-burger) {
  flex: 1 1 auto;
  min-height: 0;
}

.nav-scrim,
.nav-burger {
  display: none;
}

/* ---------------------------------------------------------------- sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  background: var(--sidebar);
  border-right: var(--bw) solid var(--line);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: none;
  padding: 14px 10px 10px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 2px 4px 2px 0;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--r-sm);
}
.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  color: var(--on-candy);
  background: var(--pink);
  border: var(--bw) solid var(--line);
  border-radius: 11px;
  box-shadow: var(--shadow-sm);
  transform: rotate(-6deg);
  transition: transform 140ms ease-out;
}
/* a little yellow spark on the clapper tile */
.brand-mark::after {
  content: "";
  position: absolute;
  top: -6px;
  right: -6px;
  width: 11px;
  height: 11px;
  background: var(--yellow);
  border: var(--bw-thin) solid var(--line);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
}
.brand:hover .brand-mark { transform: rotate(4deg) scale(1.04); }
.brand-name {
  font: 700 23px/1 var(--font-display);
  letter-spacing: -0.01em;
  white-space: nowrap;
  /* a pink squiggle under the wordmark */
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: var(--pink);
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
  text-decoration-skip-ink: none;
  padding-bottom: 4px;
}
.sidebar-toggle { margin-left: auto; }

/* ----- project switcher: a pressable sticker ----- */

.project-switch {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 10px;
  flex: none;
  margin: 2px 12px 0 12px;
  padding: 7px 8px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: var(--bw) solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  transition: transform 80ms ease-out, box-shadow 80ms ease-out;
}
.project-switch:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 0 var(--shadow-color);
}
.project-switch:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}
.project-dot {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  font: 700 19px/1 var(--font-display);
  color: var(--on-candy);
  background: var(--c);
  border: var(--bw-thin) solid var(--line);
  border-radius: var(--r-sm);
}
.project-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.project-name {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-kind {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-caret { color: var(--text-2); }

/* ----- quick search: looks like a field, acts like a button ----- */

.quick-search {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: none;
  height: 36px;
  margin: 12px 12px 4px;
  padding: 0 6px 0 12px;
  font: 500 13.5px/1 var(--font-ui);
  color: var(--text-muted);
  background: var(--field-bg);
  border: var(--bw-thin) solid var(--field-line);
  border-radius: var(--r-pill);
  transition: background-color 120ms ease;
}
.quick-search:hover {
  color: var(--text-2);
  background: var(--surface);
}
.quick-search > .icon { color: var(--text-2); }
.quick-search-label {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ----- navigation ----- */

.nav {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 10px 12px;
}
.nav-group { display: flex; flex-direction: column; }
.nav-group-title {
  margin: 12px 0 4px;
  padding: 0 8px;
  font: 800 10.5px/16px var(--font-ui);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--text-muted);
}
.nav-group-last {
  margin-top: 10px;
  padding-top: 8px;
  border-top: var(--bw) dotted var(--text-muted);
}
.nav-group-last:empty { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  min-width: 0;
  height: 34px;
  margin: 1px 0;
  padding: 0 8px 0 5px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  border: var(--bw) solid transparent;
  border-radius: var(--r-sm);
  transition: background-color 100ms ease, transform 80ms ease-out;
}
.nav-item:hover {
  background: var(--surface);
  border-color: var(--line);
}
.nav-item:active { transform: translate(1px, 1px); }
.nav-item:focus-visible { outline-offset: 1px; }
.nav-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  color: var(--on-candy);
  background: var(--c);
  border: var(--bw-thin) solid var(--line);
  border-radius: 7px;
  transition: transform 120ms ease-out;
}
.nav-icon .icon { width: 14px; height: 14px; stroke-width: 2.4; }
.nav-item:hover .nav-icon { transform: rotate(-8deg); }
.nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-item.is-active {
  font-weight: 800;
  color: var(--on-candy);
  background: var(--c);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}
.nav-item.is-active .nav-icon {
  color: var(--paper-ink);
  background: var(--paper);
  transform: rotate(-6deg);
}

/* ----- footer: save status + undo / redo / appearance ----- */

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  min-width: 0;
  padding: 10px 10px 10px 12px;
  border-top: var(--bw) solid var(--line);
}
.save-status {
  --save-bg: var(--green-soft);
  --save-icon: var(--ok-text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 1 auto;
  min-width: 0;
  height: 30px;
  padding: 0 11px 0 8px;
  font: 700 12px/1 var(--font-ui);
  color: var(--text);
  background: var(--save-bg);
  border: var(--bw-thin) solid var(--line);
  border-radius: var(--r-pill);
  transition: transform 80ms ease-out, box-shadow 80ms ease-out;
}
.save-status > .icon { color: var(--save-icon); }
.save-status:hover {
  transform: translate(-1px, -1px);
  box-shadow: 2px 2px 0 0 var(--shadow-color);
}
.save-status:active { transform: translate(1px, 1px); box-shadow: none; }
.save-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.save-status.is-ok { --save-bg: var(--green-soft); --save-icon: var(--ok-text); }
.save-status.is-info { --save-bg: var(--yellow-soft); --save-icon: var(--yellow-ink); }
.save-status.is-warn { --save-bg: var(--amber-soft); --save-icon: var(--warn-text); }
.save-status.is-busy { --save-bg: var(--blue-soft); --save-icon: var(--blue-ink); }
.save-status.is-busy > .icon { animation: hs-spin 1s linear infinite; }
.save-status.is-bad {
  --save-bg: var(--red);
  --save-icon: var(--on-candy);
  color: var(--on-candy);
  border-width: var(--bw);
  box-shadow: 2px 2px 0 0 var(--shadow-color);
}
.sidebar-foot-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
  margin-left: auto;
}

/* ---------------------------------------------------------------- collapsed sidebar (wide screens only) */

@media (min-width: 861px) {
  .app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

  .is-collapsed .sidebar-head {
    flex-direction: column;
    gap: 10px;
    padding: 14px 0 6px;
  }
  .is-collapsed .brand { padding: 0; }
  .is-collapsed .brand-name,
  .is-collapsed .project-text,
  .is-collapsed .project-caret,
  .is-collapsed .quick-search-label,
  .is-collapsed .quick-search .kbd,
  .is-collapsed .nav-label,
  .is-collapsed .save-text {
    display: none;
  }
  .is-collapsed .sidebar-toggle { margin: 0; }

  .is-collapsed .project-switch {
    grid-template-columns: 36px;
    justify-content: center;
    width: 46px;
    margin: 2px auto 0;
    padding: 3px;
  }

  .is-collapsed .quick-search {
    justify-content: center;
    width: 40px;
    margin: 12px auto 4px;
    padding: 0;
  }

  .is-collapsed .nav { padding: 4px 0 12px; align-items: center; }
  .is-collapsed .nav-group { align-items: center; width: 100%; }
  .is-collapsed .nav-group-title {
    width: 28px;
    height: 0;
    margin: 10px auto 8px;
    padding: 0;
    overflow: hidden;
    font-size: 0;
    border-top: var(--bw) dotted var(--text-muted);
  }
  .is-collapsed .nav-group-last { width: 44px; }
  .is-collapsed .nav-item {
    justify-content: center;
    width: 44px;
    height: 40px;
    padding: 0;
  }
  .is-collapsed .nav-icon { width: 28px; height: 28px; }
  .is-collapsed .nav-icon .icon { width: 16px; height: 16px; }

  .is-collapsed .sidebar-foot {
    flex-direction: column;
    padding: 10px 0;
  }
  .is-collapsed .save-status {
    justify-content: center;
    width: 34px;
    padding: 0;
  }
  .is-collapsed .sidebar-foot-tools {
    flex-direction: column;
    margin: 0;
  }
}

/* ---------------------------------------------------------------- narrow screens: off-canvas drawer */

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app > .main { grid-column: 1; }

  .app > .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: calc(var(--z-nav) + 1);
    width: min(var(--sidebar-w), 86vw);
    height: auto;
    transform: translateX(calc(-100% - 12px));
    visibility: hidden;
    transition: transform 140ms ease-out, visibility 0s linear 140ms;
  }
  .app.is-nav-open > .sidebar {
    transform: none;
    visibility: visible;
    box-shadow: var(--shadow-lg);
    transition: transform 140ms ease-out, visibility 0s;
  }
  .sidebar-toggle { display: none; }

  .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: var(--z-nav);
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity 140ms ease;
  }
  .app.is-nav-open .nav-scrim {
    opacity: 1;
    pointer-events: auto;
  }

  .main > .nav-burger {
    display: inline-grid;
    position: absolute;
    top: 15px;
    left: 12px;
    z-index: 6;
    color: var(--text);
    background: var(--surface);
    border-color: var(--line);
    box-shadow: 2px 2px 0 0 var(--shadow-color);
  }
  .main > .nav-burger:hover {
    background: var(--hover);
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 0 var(--shadow-color);
  }
  .main > .nav-burger:active { transform: translate(2px, 2px); box-shadow: none; }
  .main .page-head { padding-left: 62px; }
  .main > .module-loading,
  .main > .module-fallback { padding-top: 64px; }
}

/* ---------------------------------------------------------------- module loading and fallback */

.module-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: var(--s-6);
  font: 600 var(--fs-lg)/1.2 var(--font-display);
  color: var(--text-2);
}
/* a candy disc with an ink arc turning on it (readable on both themes) */
.module-loading .spinner {
  box-sizing: content-box;
  padding: 4px;
  background: var(--c);
  border: 4px solid var(--c);
  border-top-color: var(--on-candy);
  outline: var(--bw) solid var(--line);
}

.module-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-4);
  min-height: 0;
  overflow: auto;
  padding: var(--s-7) var(--s-6);
}
.module-fallback > .empty {
  max-width: 560px;
  padding: var(--s-7) var(--s-7) var(--s-6);
  background: var(--surface);
  border: var(--bw) solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
}
.module-error {
  width: 100%;
  max-width: 560px;
  max-height: 180px;
  overflow: auto;
  padding: 10px 12px;
  font: 500 12px/1.5 var(--font-mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--danger-text);
  background: var(--surface-sunken);
  border: var(--bw-thin) dashed var(--text-muted);
  border-radius: var(--r-sm);
}

/* ---------------------------------------------------------------- splash */

.splash {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  padding: var(--s-6);
  text-align: center;
  color: var(--text);
  background-color: var(--canvas);
  background-image: radial-gradient(var(--canvas-dot) 1.1px, transparent 1.3px);
  background-size: 22px 22px;
}
.splash-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  margin-bottom: var(--s-2);
  color: var(--on-candy);
  background: var(--pink);
  border: var(--bw) solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  transform: rotate(-6deg);
  animation: hs-splash-bob 1.4s ease-in-out infinite alternate;
}
.splash-mark::after {
  content: "";
  position: absolute;
  top: -12px;
  right: -12px;
  width: 24px;
  height: 24px;
  background: var(--yellow);
  border: var(--bw) solid var(--line);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
}
@keyframes hs-splash-bob {
  from { transform: rotate(-6deg) translateY(0); }
  to { transform: rotate(-2deg) translateY(-6px); }
}
.splash { z-index: 900; transition: opacity 380ms ease, transform 380ms ease; }
.splash.is-leaving { opacity: 0; transform: scale(1.03); pointer-events: none; }
.splash-logo { display: block; }
.splash-name {
  margin: 0;
  font: 700 clamp(52px, 11vw, 112px)/0.95 var(--font-display);
  letter-spacing: 0.14em;
  padding-left: 0.14em; /* balances the tracking after the last letter */
  color: var(--text);
  text-shadow: 4px 4px 0 var(--pink);
}
.splash-strip { display: flex; width: min(340px, 70vw); height: 12px; border: var(--bw) solid var(--line); border-radius: 999px; overflow: hidden; box-shadow: var(--shadow-sm); }
.splash-strip span { flex: 1; }
.splash-strip [data-s="white"] { background: #FFFFFF; }
.splash-strip [data-s="yellow"] { background: var(--yellow); }
.splash-strip [data-s="blue"] { background: var(--blue); }
.splash-strip [data-s="green"] { background: var(--green); }
.splash-tag {
  margin: 0;
  padding: 8px 18px;
  font: 700 clamp(14px, 2.4vw, 19px)/1.2 var(--font-ui);
  letter-spacing: 0.04em;
  color: var(--on-candy);
  background: var(--yellow);
  border: var(--bw) solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}
.splash-dots { display: flex; gap: 8px; margin-top: var(--s-2); }
.splash-dots span { width: 10px; height: 10px; border-radius: 50%; background: var(--pink); border: 2px solid var(--line); animation: tl-dot 0.9s ease-in-out infinite alternate; }
.splash-dots span:nth-child(2) { background: var(--blue); animation-delay: 0.15s; }
.splash-dots span:nth-child(3) { background: var(--green); animation-delay: 0.3s; }
@keyframes tl-dot { from { transform: translateY(0); } to { transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) { .splash-mark, .splash-dots span { animation: none; } .splash { transition: none; } }
.splash > .spinner { margin-top: var(--s-3); color: var(--accent); }
.splash-error {
  max-width: 52ch;
  margin: var(--s-2) 0;
  font-weight: 600;
  line-height: 1.5;
  color: var(--danger-text);
}

/* ---------------------------------------------------------------- quick search palette */

.palette {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}
.palette-input {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex: none;
  height: 58px;
  padding: 0 var(--s-5);
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: var(--bw) solid var(--line);
}
.palette-input > .icon { color: var(--c-ink); }
.palette-input input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: 0;
  font: 600 17px/1 var(--font-ui);
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
}
.palette-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(440px, 60vh);
  overflow-y: auto;
  padding: 8px;
}
.palette-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 46px;
  padding: 6px 10px 6px 7px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: var(--bw) solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.palette-item.is-active {
  background: var(--c-soft);
  border-color: var(--line);
  box-shadow: 2px 2px 0 0 var(--shadow-color);
}
.palette-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  color: var(--on-candy);
  background: var(--c);
  border: var(--bw-thin) solid var(--line);
  border-radius: 9px;
}
.palette-item.is-active .palette-icon { transform: rotate(-6deg); }
.palette-label {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-hint {
  display: block;
  margin-top: 1px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-kind {
  flex: none;
  padding: 4px 8px;
  font: 800 10px/1 var(--font-ui);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
  background: var(--surface-sunken);
  border-radius: var(--r-pill);
}
.palette-item.is-active .palette-kind { background: var(--surface); }
.palette-empty {
  padding: var(--s-7) var(--s-4);
  text-align: center;
  font-weight: 600;
  color: var(--text-muted);
}
