/*
 * App chrome: the lockup, top bar, sidebar and campaign switcher (docs/DESIGN_SYSTEM.md,
 * "Navigation"). The flame is the sidebar's key; the lockup stays visible in every state.
 */

svg.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* Shell grid */
body { --shell-header-height: 64px; --shell-rail-width: 64px; }
.app-container, .app-container.session-reading-mode {
  grid-template-areas: "header header" "nav main";
  grid-template-columns: var(--shell-rail-width) minmax(0, 1fr);
  grid-template-rows: var(--shell-header-height) minmax(calc(100vh - var(--shell-header-height)), auto);
  padding-bottom: 0;
}
.app-container.nav-expanded { --shell-rail-width: 232px; }

/* Top bar: lockup, campaign, search, account */
.app-container .top-bar {
  z-index: 130; display: flex; align-items: center; gap: var(--weave-space-3);
  height: var(--shell-header-height); min-height: var(--shell-header-height); padding: 0 var(--weave-space-5) 0 var(--weave-space-2);
  background: var(--weave-color-paper); border-bottom: 3px double var(--weave-color-rule-strong); box-shadow: none; color: var(--weave-color-ink);
}
.shell-lockup { display: flex; align-items: center; gap: var(--weave-space-1); flex: none; }
.shell-key {
  display: grid; place-items: center; width: 48px; height: 48px; min-height: 48px; padding: 0;
  border: 0; border-radius: var(--weave-radius-md); background: transparent; color: var(--weave-color-spark); cursor: pointer;
}
.shell-key:hover, .shell-key[aria-expanded="true"] { background: var(--weave-color-hover); }
.shell-flame, .weave-brand-flame {
  display: inline-block; width: 28px; height: 28px; flex: none; background: currentColor;
  -webkit-mask: url('/ui/assets/branding/weave-flame.svg') center / contain no-repeat;
  mask: url('/ui/assets/branding/weave-flame.svg') center / contain no-repeat;
}
.shell-brand { display: inline-flex; align-items: center; color: var(--weave-color-ink); text-decoration: none; }
/* The wordmark writes out once per visit. Its clip extends past the box: the tight tracking
   draws the final "e" beyond it. */
.shell-brand span.arriving { animation: weave-write-out 520ms var(--weave-ease) 150ms both; }
@keyframes weave-write-out { from { clip-path: inset(-.3em 100% -.3em 0); } to { clip-path: inset(-.3em -.3em -.3em 0); } }
.shell-campaign { position: relative; display: flex; align-items: center; min-width: 0; padding-left: var(--weave-space-3); border-left: 1px solid var(--weave-color-rule); }
.campaign-control { position: relative; min-width: 0; }
#campaignSelect[hidden], .campaign-picker [hidden], .campaign-picker[hidden] { display: none !important; }
#campaignPickerBtn {
  display: inline-flex; align-items: center; gap: var(--weave-space-1); max-width: 18rem; min-height: 36px; padding: var(--weave-space-1) var(--weave-space-2);
  border: 0; border-radius: var(--weave-radius-sm); background: transparent; color: var(--weave-color-ink);
  font: var(--weave-weight-semibold) var(--weave-text-md)/1.2 var(--weave-font-ui); cursor: pointer;
}
#campaignPickerBtn:hover, #campaignPickerBtn[aria-expanded="true"] { background: var(--weave-color-hover); }
#campaignPickerBtn svg.icon { width: 16px; height: 16px; }
.campaign-picker-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.campaign-picker {
  position: absolute; top: calc(100% + var(--weave-space-2)); left: var(--weave-space-3); width: 22.5rem; max-width: calc(100vw - var(--weave-space-6));
  padding: var(--weave-space-4); border: 1px solid var(--weave-color-rule); border-radius: var(--weave-radius-md);
  background: var(--weave-color-paper); box-shadow: var(--weave-shadow-overlay); color: var(--weave-color-ink); z-index: 160;
}
.campaign-picker-header { display: flex; align-items: center; justify-content: space-between; gap: var(--weave-space-4); margin-bottom: var(--weave-space-2); }
.campaign-picker-header h3 { margin: 0; font: var(--weave-weight-semibold) var(--weave-text-md)/1.3 var(--weave-font-ui); }
#campaignPickerClose { display: grid; place-items: center; width: 32px; height: 32px; min-height: 32px; padding: 0; border: 0; border-radius: var(--weave-radius-full); background: transparent; color: inherit; font: var(--weave-text-xl)/1 var(--weave-font-ui); cursor: pointer; }
.campaign-picker-list { display: grid; gap: var(--weave-space-2); max-height: min(360px, 55vh); overflow-y: auto; }
.campaign-picker-option { display: flex; align-items: center; justify-content: space-between; gap: var(--weave-space-4); width: 100%; min-height: 48px; padding: var(--weave-space-3); border: 1px solid transparent; border-radius: var(--weave-radius-sm); background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.campaign-picker-option span { color: var(--weave-color-secondary); font: var(--weave-weight-semibold) var(--weave-text-2xs)/1.3 var(--weave-font-ui); }
.campaign-picker-option:hover, .campaign-picker-option[aria-pressed="true"] { border-color: var(--weave-color-rule); background: var(--weave-color-hover); }
#campaignPickerMore { width: 100%; min-height: 44px; margin-top: var(--weave-space-2); border: 0; border-top: 1px solid var(--weave-color-rule); background: transparent; color: var(--weave-color-action); font: inherit; cursor: pointer; }
#campaignPickerSearch { width: 100%; margin: var(--weave-space-2) 0 var(--weave-space-4); }

.header-utilities { display: flex; justify-content: flex-end; align-items: center; gap: var(--weave-space-4); min-width: 0; margin-left: auto; }
.header-search {
  display: flex; align-items: center; gap: var(--weave-space-2); width: clamp(11rem, 22vw, 15rem); height: 38px; min-height: 38px; padding: 0 var(--weave-space-3);
  border: 1px solid var(--weave-color-rule); border-radius: var(--weave-radius-sm); background: var(--weave-color-paper); color: var(--weave-color-secondary);
  font: var(--weave-text-sm)/1 var(--weave-font-ui); text-align: left; cursor: pointer;
}
.header-search:hover { border-color: var(--weave-color-action); }
.header-search svg.icon { width: 16px; height: 16px; }
.header-search span { flex: 1; white-space: nowrap; }
.header-search kbd { white-space: nowrap; color: var(--weave-color-secondary); font: var(--weave-text-2xs)/1 var(--weave-font-ui); }
.top-bar .user-controls { display: flex; align-items: center; margin: 0; padding: 0; flex: none; }
.top-bar #authContainer { position: relative; display: flex; align-items: center; }
.app-container .top-bar .profile-btn { width: 36px; height: 36px; min-width: 36px; min-height: 36px; padding: 0; border: 1px solid var(--weave-color-rule); border-radius: var(--weave-radius-full); background: var(--weave-color-selected); box-shadow: none; color: var(--weave-color-action); }
.top-bar .avatar-initials { background: transparent; color: inherit; font: var(--weave-weight-semibold) var(--weave-text-2xs)/1 var(--weave-font-ui); }
.top-bar .profile-btn:hover { background: var(--weave-color-hover); transform: none; box-shadow: none; }
.top-bar .dropdown-menu { top: calc(100% + var(--weave-space-3)); bottom: auto; left: auto; right: 0; }
#userDropdown { width: 17.5rem; max-width: calc(100vw - var(--weave-space-6)); }
#userDropdown #createCampaignBtn { min-height: 44px; }
.top-bar :focus-visible { outline: 2px solid var(--weave-color-action); outline-offset: 3px; }

/* Sidebar: icons with tooltips, or labels when the flame opens it */
.app-container .left-nav {
  grid-area: nav; position: sticky; inset: auto; top: var(--shell-header-height); display: flex; flex-direction: column; align-items: stretch; gap: var(--weave-space-1);
  width: var(--shell-rail-width); height: calc(100dvh - var(--shell-header-height)); min-height: 0; margin: 0; padding: var(--weave-space-4) 10px;
  border: 0; background: var(--weave-color-rail); box-shadow: inset -1px 0 var(--weave-color-rule); overflow: visible;
  transition: width var(--weave-duration-slow) var(--weave-ease);
}
/* Rubric's margin line: the ruled edge of a manuscript page, drawn in faded vermilion. */
.app-container .left-nav::after { content: ""; position: absolute; top: 0; bottom: 0; right: 6px; width: 1px; background: color-mix(in srgb, var(--weave-color-action) 45%, transparent); pointer-events: none; }
.app-container .left-nav .nav-tab {
  position: relative; display: flex; flex-direction: row; align-items: center; justify-content: flex-start; gap: var(--weave-space-3); flex-shrink: 0;
  width: 100%; height: 40px; min-height: 40px; padding: 0 var(--weave-space-3); border: 0; border-radius: var(--weave-radius-md);
  background: transparent; color: var(--weave-color-rail-text); box-shadow: none; white-space: nowrap;
}
.app-container .left-nav .nav-tab .label { opacity: 0; font: var(--weave-weight-medium) var(--weave-text-sm)/1 var(--weave-font-ui); transition: opacity var(--weave-duration-base) ease-out; pointer-events: none; }
.app-container.nav-expanded .left-nav .nav-tab .label { opacity: 1; transition-delay: 100ms; }
.app-container .left-nav .nav-tab:hover { background: var(--weave-color-rail-active); }
.app-container .left-nav .nav-tab:is(.active, [aria-current="page"]) { background: var(--weave-color-rail-active); color: var(--weave-color-action); }
.app-container .left-nav .nav-tab:is(.active, [aria-current="page"])::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 2px; border-radius: var(--weave-radius-sm); background: currentColor; }
.app-container:not(.nav-expanded) .left-nav .nav-tab:is(:hover, :focus-visible)::after {
  content: attr(data-tooltip); position: absolute; left: calc(100% + var(--weave-space-3)); top: 50%; transform: translateY(-50%); z-index: 200;
  padding: 6px 10px; border-radius: var(--weave-radius-sm); background: var(--weave-color-deep-ink); color: var(--weave-color-on-deep);
  font: var(--weave-text-xs)/1.3 var(--weave-font-ui); white-space: nowrap; pointer-events: none;
}
.app-container .left-nav .nav-tab-desk { margin-top: auto; border-top: 1px solid var(--weave-color-rule-strong); border-radius: 0 0 var(--weave-radius-md) var(--weave-radius-md); height: 48px; padding-top: var(--weave-space-2); }
.left-nav :focus-visible { outline: 2px solid var(--weave-color-rail-text) !important; outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  .shell-brand span.arriving { animation: none; }
  .app-container .left-nav, .app-container .left-nav .nav-tab .label { transition: none; }
}

/* Phones: no sidebar. The lockup and account stay on top; labeled tabs sit at the bottom. */
@media (max-width: 680px) {
  body { --shell-header-height: 56px; }
  .app-container, .app-container.session-reading-mode, .app-container.nav-expanded {
    grid-template-areas: "header" "main"; grid-template-columns: minmax(0, 1fr);
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }
  .app-container .top-bar { padding: 0 var(--weave-space-3); }
  .shell-key, .shell-campaign { display: none; }
  .shell-brand::before { content: ""; width: 24px; height: 24px; margin-right: var(--weave-space-2); background: var(--weave-color-spark); -webkit-mask: url('/ui/assets/branding/weave-flame.svg') center / contain no-repeat; mask: url('/ui/assets/branding/weave-flame.svg') center / contain no-repeat; }
  .header-search { width: 38px; padding: 0; justify-content: center; }
  .header-search span, .header-search kbd { display: none; }
  .app-container .left-nav {
    position: fixed; z-index: 120; inset: auto 0 0 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
    width: auto; height: auto; padding: var(--weave-space-1) var(--weave-space-1) calc(var(--weave-space-1) + env(safe-area-inset-bottom));
    border-top: 1px solid var(--weave-color-rule); background: var(--weave-color-paper); box-shadow: none;
  }
  .app-container .left-nav::after { display: none; }
  .app-container .left-nav .nav-tab { flex-direction: column; justify-content: center; gap: 2px; height: 56px; min-height: 56px; padding: 0; color: var(--weave-color-secondary); }
  .app-container .left-nav .nav-tab .label { opacity: 1; font-size: var(--weave-text-2xs); }
  .app-container .left-nav .nav-tab:is(.active, [aria-current="page"]) { background: transparent; }
  .app-container .left-nav .nav-tab:is(.active, [aria-current="page"])::before { left: 30%; right: 30%; top: 0; bottom: auto; width: auto; height: 2px; }
  .app-container .left-nav .nav-tab::after { display: none; }
  .app-container .left-nav .nav-tab-desk { margin-top: 0; border-top: 0; border-radius: var(--weave-radius-md); height: 56px; padding-top: 0; }
  #playerCampaignFacts { grid-template-columns: 1fr; gap: var(--weave-space-4); }
}

/* Profile facts */
#playerCampaignFacts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--weave-space-5); margin-top: var(--weave-space-5); padding: var(--weave-space-5) 0; border-block: 1px solid var(--weave-color-rule); }
.campaign-fact { display: grid; align-content: start; gap: var(--weave-space-2); min-width: 0; }
.campaign-fact span { color: var(--weave-color-secondary); font-size: var(--weave-text-xs); }
.campaign-fact strong { font-size: var(--weave-text-md); font-weight: var(--weave-weight-semibold); overflow-wrap: anywhere; }

/* Quick search */
.quick-search-content { width: min(640px, calc(100vw - var(--weave-space-6))); }
#quickSearchInput { width: 100%; min-height: 48px; font-size: var(--weave-text-lg); }
#quickSearchResults { margin: var(--weave-space-4) 0; max-height: 48vh; overflow-y: auto; }
#quickSearchResults a { display: flex; justify-content: space-between; align-items: center; gap: var(--weave-space-5); padding: var(--weave-space-3) var(--weave-space-2); border-bottom: 1px solid var(--weave-color-rule); color: var(--weave-color-ink); text-decoration: none; }
#quickSearchResults a:hover { background: var(--weave-color-hover); }
#quickSearchResults strong { font-weight: var(--weave-weight-medium); }
#quickSearchResults a span { flex-shrink: 0; color: var(--weave-color-secondary); font-size: var(--weave-text-2xs); }

/* Sign-in and public footer signature */
.weave-brand-flame { width: 32px; height: 32px; }
#landingScreen .weave-ref-footer .weave-brand-flame { color: var(--weave-copper); }
.weave-sign-in-title { display: flex; align-items: center; gap: var(--weave-space-2); }
.weave-sign-in-title .weave-brand-flame { color: var(--weave-color-spark); }

/* Approved lowercase wordmark: the static Fraunces instance from the type study. */
.shell-brand, #landingScreen .weave-ref-brand {
  font-family: var(--weave-font-wordmark); font-size: 26px; font-weight: 600; font-style: normal; line-height: 1.2;
  letter-spacing: -.052em; word-spacing: .035em; font-kerning: normal; font-synthesis: none; white-space: nowrap;
}
#landingScreen .weave-ref-brand { font-size: 29px; }
#landingScreen .weave-ref-footer .weave-ref-brand { font-size: 24px; }
@media (max-width: 680px) {
  .shell-brand { font-size: 22px; }
  #landingScreen .weave-ref-header .weave-ref-brand { font-size: 26px; }
}

/* A DM's player view: a quiet strip that says whose eyes the page uses and how to leave. */
.player-preview-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--weave-space-2) var(--weave-space-4); margin: 0 0 var(--weave-space-5); padding: var(--weave-space-2) var(--weave-space-4); border: 1px solid var(--weave-color-rule); border-left: 3px solid var(--weave-color-action); border-radius: var(--weave-radius-sm); background: var(--weave-color-selected); color: var(--weave-color-ink); font-size: var(--weave-text-sm); }
.player-preview-bar[hidden] { display: none; }
.player-preview-exit { padding: 0; border: 0; background: none; color: var(--weave-color-action); font: inherit; font-weight: var(--weave-weight-semibold); text-decoration: underline; text-decoration-color: var(--weave-color-rule-strong); text-underline-offset: 0.15em; cursor: pointer; }
.player-preview-exit:focus-visible { outline: 2px solid var(--weave-color-action); outline-offset: 2px; }
