/* Stack Master: the shell every page shares.

   Tokens, base element styles, the three button looks, form fields, the
   left sidebar (its top half: New chat and the tools nav), the header,
   its popovers, the sign-in dialog, and the shared animations. Each page
   adds its own stylesheet after this one for its content, including the
   sections it puts in the lower half of the sidebar.

   Type: Inter for all interface and reading text. Cinzel is reserved for
   the "Stack Master" wordmark and tool page titles. One monospace stack.

   Breakpoints:
     <= 640px   phone: compact header, popovers pinned to the screen edges
     <= 1023px  the sidebar slides over the content (shell.js uses the same query)
*/

@font-face {
  font-family: 'Phyrexian';
  src: url('/static/fonts/phyrexian.otf') format('opentype');
  font-display: swap;
}

:root {
  /* surfaces */
  --parchment-primary:   #FBF8F3;
  --parchment-secondary: #F5F0E8;
  --parchment-tertiary:  #ECE5D9;
  --surface:             #FFFFFF;

  /* text */
  --ink-primary:   #1F2D3A;
  --ink-secondary: #3A4856;
  --ink-muted:     #5F6B77;
  --ink-faint:     #8A939C;

  /* lines */
  --border-light:  #E6DFD3;
  --border-strong: #D2C8B7;

  /* accents */
  --accent:        #1F6FA0;
  --accent-hover:  #175A84;
  --accent-soft:   rgba(31, 111, 160, 0.08);
  --message-assistant: var(--accent);
  --success:       #1E8449;
  --success-soft:  rgba(30, 132, 73, 0.08);
  --error:         #B03A2E;
  --error-soft:    rgba(176, 58, 46, 0.08);
  --warning:       #8A5310;
  --warning-soft:  rgba(183, 121, 31, 0.12);

  /* type */
  --font-sans:    'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Cinzel', Georgia, serif;
  --font-mono:    ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
  --text-2xs: 0.6875rem;  /* 11px */
  --text-xs:  0.75rem;    /* 12px */
  --text-sm:  0.8125rem;  /* 13px */
  --text-base: 0.9375rem; /* 15px */
  --text-md:  1rem;       /* 16px */
  --text-lg:  1.125rem;   /* 18px */
  --text-xl:  1.5rem;     /* 24px */

  /* shape */
  --radius-sm: 6px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;
  --shadow-sm:   0 1px 2px rgba(31, 45, 58, 0.06);
  --shadow:      0 1px 2px rgba(31, 45, 58, 0.05), 0 4px 12px rgba(31, 45, 58, 0.06);
  --shadow-lift: 0 2px 6px rgba(31, 45, 58, 0.06), 0 12px 32px rgba(31, 45, 58, 0.12);
  --focus-ring:  0 0 0 3px rgba(31, 111, 160, 0.28);

  /* layout */
  --sidebar-width: 272px;
  --header-height: 56px;
  --thread-width:  760px;
  --rail-width:    300px;
  --control-h:     36px;

  --transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

/* =============================================================== base */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--parchment-primary);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--accent); }

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

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
}

.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;
}

/* =============================================================== buttons

   Three looks, shared by every button in the chat UI:
     primary   – filled ink, for the one main action of a surface
     secondary – white with a border, for supporting actions
     tertiary  – no chrome until hovered, for cancel and icon buttons */

.new-chat,
.deck-dialog button[type="submit"],
.sign-in-dialog button[type="submit"],
#bug-report-submit,
#share-copy,
.deck-picker-action.primary-action,
.goldfish-card-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-h);
  padding: 0 14px;
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border: 1px solid var(--ink-primary);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: var(--transition);
}
.new-chat:hover,
.deck-dialog button[type="submit"]:hover,
.sign-in-dialog button[type="submit"]:hover,
#bug-report-submit:hover:not(:disabled),
#share-copy:hover,
.deck-picker-action.primary-action:hover,
.goldfish-card-open:hover {
  background: var(--ink-secondary);
  border-color: var(--ink-secondary);
}
.sign-in-dialog button[type="submit"]:disabled,
#bug-report-submit:disabled { opacity: 0.5; }

.header-action,
.deck-empty button.secondary,
.memory-form button.secondary,
.profile-signout,
.deck-chip-action,
.deck-picker-action,
#unshare-button,
.inline-error-retry {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-h);
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: var(--transition);
}
.header-action:hover,
.deck-empty button.secondary:hover,
.memory-form button.secondary:hover,
.profile-signout:hover,
.deck-chip-action:hover,
.deck-picker-action:hover,
#unshare-button:hover,
.inline-error-retry:hover {
  background: var(--parchment-secondary);
  border-color: var(--ink-faint);
}

.deck-dialog button.tertiary,
.sign-in-dialog button.tertiary {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-h);
  padding: 0 14px;
  background: transparent;
  color: var(--ink-secondary);
  border: none;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: var(--transition);
}
.deck-dialog button.tertiary:hover,
.sign-in-dialog button.tertiary:hover { background: var(--parchment-tertiary); color: var(--ink-primary); }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-h);
  height: var(--control-h);
  flex-shrink: 0;
  padding: 0;
  background: transparent;
  color: var(--ink-secondary);
  border: none;
  border-radius: var(--radius);
  transition: var(--transition);
}
.icon-button:hover { background: var(--parchment-tertiary); color: var(--ink-primary); }

/* =============================================================== fields */

.deck-dialog input[type="text"],
.deck-dialog textarea,
.sign-in-dialog input[type="email"],
.bug-report textarea,
.memory-form select,
.memory-form input {
  width: 100%;
  min-height: var(--control-h);
  padding: 7px 10px;
  background: var(--surface);
  color: var(--ink-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  line-height: 1.45;
  transition: var(--transition);
}
.deck-dialog input[type="text"]:focus,
.deck-dialog textarea:focus,
.sign-in-dialog input[type="email"]:focus,
.bug-report textarea:focus,
.memory-form select:focus,
.memory-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.deck-dialog input::placeholder,
.deck-dialog textarea::placeholder,
.sign-in-dialog input::placeholder,
.bug-report textarea::placeholder,
.memory-form input::placeholder { color: var(--ink-faint); }

/* =============================================================== sidebar

   Layout: .sidebar-header (New chat, collapse), then one scrolling
   .sidebar-body holding the tools nav and the page's own sections. Every
   section grows with its content, so none can squeeze another out of
   view. Pages build their sections from .sidebar-section,
   .sidebar-section-header, .sidebar-label, .sidebar-add, .sidebar-list
   and .sidebar-item. */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  max-width: 86vw;
  background: var(--parchment-secondary);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transform: translateX(0);
  transition: transform 0.22s ease, visibility 0s;
}

/* Hide only after the slide-out; show at once on open. */
body[data-sidebar="closed"] .sidebar {
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform 0.22s ease, visibility 0s linear 0.22s;
}

.sidebar-header {
  flex-shrink: 0;
  height: var(--header-height);
  padding: 0 10px 0 12px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 6px;
}

.new-chat { flex: 1; min-width: 0; }

.sidebar-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

/* --------------------------------------------- tools nav */

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  transition: var(--transition);
}
.sidebar-nav-item:hover { background: var(--parchment-tertiary); color: var(--ink-primary); }
.sidebar-nav-item:focus-visible { outline-offset: -2px; }
.sidebar-nav-item svg { flex-shrink: 0; width: 16px; height: 16px; color: var(--ink-muted); }
.sidebar-nav-item:hover svg { color: var(--ink-primary); }
.sidebar-nav-item[aria-current="page"] {
  background: var(--surface);
  color: var(--ink-primary);
  box-shadow: inset 0 0 0 1px var(--border-light);
}
.sidebar-nav-item[aria-current="page"] svg { color: var(--ink-primary); }

/* --------------------------------------------- page sections */

.sidebar-section {
  padding: 14px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-section + .sidebar-section { border-top: 1px solid var(--border-light); }

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
  padding-left: 4px;
}
.sidebar-label {
  margin: 0;
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}
.sidebar-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  color: var(--ink-muted);
  border: none;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: var(--transition);
}
.sidebar-add:hover,
.sidebar-add[aria-expanded="true"] { background: var(--parchment-tertiary); color: var(--ink-primary); }
.sidebar-note {
  margin: 0;
  padding: 0 4px;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--ink-muted);
}

.sidebar-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sidebar-item {
  display: block;
  width: 100%;
  min-height: 34px;
  padding: 7px 10px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  font-size: var(--text-sm);
  line-height: 1.4;
  text-align: left;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: var(--transition);
}
.sidebar-item:hover { background: var(--parchment-tertiary); color: var(--ink-primary); }
.sidebar-item:focus-visible { outline-offset: -2px; }
.sidebar-item[aria-current] {
  background: var(--surface);
  color: var(--ink-primary);
  font-weight: 500;
  box-shadow: inset 0 0 0 1px var(--border-light);
}
.sidebar-item-meta {
  margin-left: 6px;
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--ink-muted);
}
.sidebar-list .empty {
  padding: 4px;
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 45, 58, 0.32);
  z-index: 15;
  animation: fadeOnly 0.18s ease;
}
.backdrop[hidden] { display: none; }

/* =============================================================== app shell */

/* .app holds the header and the page. Absolute rather than fixed: a
   fixed element always creates its own stacking context, which would
   trap drawers inside .app underneath the shared backdrop. body never
   scrolls, so the two behave the same. */
.app {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--parchment-primary);
  transition: left 0.22s ease;
}

body[data-sidebar="open"] .app { left: var(--sidebar-width); }
body.shared-mode .app { left: 0; }

/* Tool pages scroll their content in .page, under the fixed header. */
.page {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* =============================================================== header */

.app-header {
  flex-shrink: 0;
  height: var(--header-height);
  padding: 0 12px 0 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: var(--parchment-primary);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* The brand never shrinks; the title next to it truncates instead. */
.brand {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 4px 0;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius);
}

.brand-logo { height: 28px; width: auto; flex-shrink: 0; }

.brand-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.tagline {
  margin: 0;
  font-weight: 400;
  padding-left: 10px;
  border-left: 1px solid var(--border-light);
  color: var(--ink-muted);
  font-size: var(--text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-title {
  margin: 0;
  flex: 0 1 auto;
  min-width: 0;
  padding-left: 10px;
  border-left: 1px solid var(--border-light);
  font-size: var(--text-md);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

.header-action { min-height: 34px; }
/* .header-action sets display, which would otherwise beat [hidden]. */
.header-action[hidden] { display: none; }

.patreon-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  color: var(--ink-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius);
  transition: var(--transition);
}
.patreon-link svg { width: 14px; height: 14px; }
.patreon-link:hover { background: var(--parchment-tertiary); color: var(--ink-primary); }

/* --------------------------------------------- header popovers */

.share-control,
.auth-control,
.about { position: relative; }
.share-control[hidden],
.auth-control[hidden] { display: none; }

.share-popover,
.profile-dropdown,
.about-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  color: var(--ink-primary);
  font-size: var(--text-sm);
  animation: popIn 0.14s ease;
}
.share-popover[hidden],
.profile-dropdown[hidden],
.about-dropdown[hidden] { display: none; }

.share-popover {
  width: 300px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.share-help {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink-secondary);
  line-height: 1.5;
}
.share-actions { display: flex; gap: 6px; }
#unshare-button[hidden] { display: none; }
.share-status {
  font-size: var(--text-xs);
  color: var(--ink-muted);
  word-break: break-all;
}
.share-status:empty { display: none; }
.share-status.error { color: var(--error); }
.share-status.success { color: var(--success); }

.profile-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-primary);
  font-weight: 600;
  font-size: var(--text-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  transition: var(--transition);
}
.profile-button:hover { background: var(--parchment-secondary); }
.profile-button[hidden] { display: none; }
.profile-initials { line-height: 1; }

.profile-dropdown { min-width: 260px; padding: 14px; }
.profile-email {
  margin: 0 0 4px;
  font-weight: 600;
  word-break: break-all;
}
.profile-help {
  margin: 0 0 12px;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  line-height: 1.5;
}
.profile-signout { width: 100%; }

.about-dropdown {
  width: 360px;
  /* Cap to the viewport below the header so the whole panel stays
     reachable on short screens. 100dvh follows the mobile address bar. */
  max-height: calc(100dvh - var(--header-height) - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
}
.about-dropdown hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 6px 0;
}

.bug-report {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bug-report label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-primary);
}
.bug-report textarea {
  resize: vertical;
  min-height: 80px;
  max-height: 200px;
}
.bug-report-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.bug-report-status { font-size: var(--text-xs); color: var(--ink-muted); }
.bug-report-status.error { color: var(--error); }
.bug-report-status.success { color: var(--success); }

.about-content { padding: 6px 10px 10px; }
.about-content h3 {
  margin: 12px 0 6px;
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}
.about-content h3:first-child { margin-top: 4px; }
.about-content ul {
  margin: 0 0 4px;
  padding-left: 18px;
  font-size: var(--text-sm);
  color: var(--ink-secondary);
}
.about-content li { margin: 3px 0; }
.about-content li::marker { color: var(--ink-faint); }


.attribution {
  margin: 12px 0 0;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  line-height: 1.5;
}
.attribution a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.attribution a:hover { color: var(--ink-primary); }

.phyrexian-button {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 6px;
  background: none;
  border: none;
  border-radius: var(--radius);
  font-family: 'Phyrexian', serif;
  font-size: var(--text-lg);
  color: var(--ink-muted);
  opacity: 0.45;
  text-align: center;
  transition: var(--transition), opacity 0.15s ease;
}
.phyrexian-button:hover { opacity: 1; color: var(--ink-primary); }

.build-version {
  margin: 4px 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--ink-muted);
  text-align: center;
}

/* Phyrexian mode flips the main text of the app into the Phyrexian font. */
body.phyrexian-mode,
body.phyrexian-mode .brand-name,
body.phyrexian-mode .center-message,
body.phyrexian-mode .message,
body.phyrexian-mode .composer-meta,
body.phyrexian-mode .new-chat,
body.phyrexian-mode .example,
body.phyrexian-mode .card-card-name,
body.phyrexian-mode .sidebar-header,
body.phyrexian-mode input,
body.phyrexian-mode textarea {
  font-family: 'Phyrexian', 'Inter', sans-serif !important;
}

/* =============================================================== dialogs */

.deck-dialog,
.sign-in-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: none;
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--ink-primary);
  box-shadow: var(--shadow-lift);
}
.sign-in-dialog { width: min(440px, calc(100vw - 24px)); }
.deck-dialog[open],
.sign-in-dialog[open] { animation: popIn 0.16s ease; }
.deck-dialog::backdrop,
.sign-in-dialog::backdrop { background: rgba(31, 45, 58, 0.4); }

.deck-dialog form,
.sign-in-dialog form {
  padding: 22px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.deck-dialog h2,
.sign-in-dialog h2 {
  margin: 0 0 2px;
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.deck-help,
.sign-in-help {
  margin: 0 0 8px;
  font-size: var(--text-sm);
  color: var(--ink-secondary);
  line-height: 1.55;
}
.deck-help[hidden] { display: none; }
.deck-help code {
  font-family: var(--font-mono);
  background: var(--parchment-secondary);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}
.deck-dialog label,
.sign-in-dialog label {
  margin-top: 6px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-primary);
}
.deck-dialog label .muted {
  font-weight: 400;
  color: var(--ink-muted);
}
.deck-dialog textarea {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
  resize: vertical;
  min-height: 180px;
}
.deck-error,
.sign-in-status {
  margin: 4px 0 0;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  background: var(--parchment-secondary);
  color: var(--ink-secondary);
}
.deck-error { background: var(--error-soft); color: var(--error); }
.deck-error[hidden],
.sign-in-status[hidden] { display: none; }
.sign-in-status.error { background: var(--error-soft); color: var(--error); }
.deck-dialog-actions,
.sign-in-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* =============================================================== animations */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOnly {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes blink { to { visibility: hidden; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* =============================================================== responsive */

/* Below 1024px the sidebar slides over the content instead of pushing
   it aside. shell.js uses the same query for the backdrop and the
   default closed state. */
@media (max-width: 1023px) {
  body[data-sidebar="open"] .app { left: 0; }
  body[data-sidebar="open"] .sidebar { box-shadow: var(--shadow-lift); }
}

/* With the sidebar pinned open, its own collapse button takes over. */
@media (min-width: 1024px) {
  body[data-sidebar="open"] #toggle-sidebar { display: none; }
}

@media (max-width: 900px) {
  .tagline { display: none; }
}

/* Touch screens: every control gets a finger-sized target. */
@media (hover: none), (pointer: coarse) {
  :root { --control-h: 40px; }
  .sidebar-item,
  .sidebar-nav-item { min-height: 40px; }
  .sidebar-item { padding-top: 10px; padding-bottom: 10px; }
  .sidebar-add { width: 32px; height: 32px; }
}

@media (max-width: 640px) {
  .app-header { gap: 4px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .header-right { gap: 2px; }
  /* On a tool page the page name says more than the wordmark. */
  .app-header:not([data-page="chat"]) .brand-name { display: none; }
  .page-title { padding-left: 0; border-left: none; }
  .page-title-prefix { display: none; }
  .patreon-link span,
  #share-button span { display: none; }
  .patreon-link,
  #share-button {
    width: var(--control-h);
    min-height: var(--control-h);
    padding: 0;
    justify-content: center;
    border-color: transparent;
    background: transparent;
  }
  .patreon-link svg { width: 16px; height: 16px; }

  /* Header popovers anchor to buttons near the right edge; on a phone
     they would spill off the left, so pin them to the viewport edges. */
  .share-popover,
  .profile-dropdown,
  .about-dropdown {
    position: fixed;
    left: 8px;
    right: 8px;
    top: calc(var(--header-height) + 6px);
    width: auto;
    min-width: 0;
    max-width: none;
  }

  .deck-dialog form,
  .sign-in-dialog form { padding: 18px 16px 16px; }

  /* iOS zooms into any focused field under 16px. */
  .deck-dialog input[type="text"],
  .deck-dialog textarea,
  .sign-in-dialog input[type="email"],
  .bug-report textarea,
  .memory-form select,
  .memory-form input { font-size: var(--text-md); }
}

/* Narrow phones: the page title needs the room. Patreon is also linked
   from the About panel. */
@media (max-width: 420px) {
  .brand-name,
  .patreon-link { display: none; }
}

