/* ==========================================================================
   A.M.A.D.E.U.S — Research Studio
   Bespoke web UI, built on the kyouma45.com design system (site.css tokens).
   Full-height app shell: the site chrome is replaced by an app sidebar / top
   bar; only the content region scrolls. Everything is token-driven so it
   flips cleanly between light and dark.
   ========================================================================== */

:root {
  --am-sidebar-w: 250px;
  --am-sidebar-w-compact: 76px;
  --am-topbar-h: 60px;
  --am-tabbar-h: 62px;
  --am-content-max: 1180px;
  --am-editor-measure: 64rem;
  --am-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --am-radius-lg: 16px;
  --am-shadow-pop: 0 6px 16px rgba(11, 11, 11, 0.08), 0 24px 60px rgba(11, 11, 11, 0.14);

  /* Section accent colors — one per nav destination, tinting the sidebar,
     mobile tab bar, and "More" sheet icons. Mid-tone for light backgrounds. */
  --nav-overview:  #3b82f6;  /* blue    */
  --nav-planner:   #8b5cf6;  /* violet  */
  --nav-notes:     #f59e0b;  /* amber   */
  --nav-library:   #10b981;  /* emerald */
  --nav-journal:   #ec4899;  /* pink    */
  --nav-routine:   #84cc16;  /* lime    */
  --nav-brain:     #a855f7;  /* purple  */
  --nav-workbench: #14b8a6;  /* teal    */
  --nav-writing:   #f97316;  /* orange  */
  --nav-analysis:  #06b6d4;  /* cyan    */
  --nav-settings:  #64748b;  /* slate   */
  --nav-profile:   #64748b;  /* slate   */

  /* Extra chart / mood hues site.css doesn't have, so the 7 Analysis series
     (CHART_VARS) and the 11 Journal moods are pairwise distinct (CIEDE2000
     >= 14 in both themes for normal colour vision; under red-green colour
     blindness some pairs come close) and every mark clears 3:1 on --surface.
     --am-aqua is site.css's dark --phase-3 step, used in both themes: the light
     --phase-3 (#1baf7a) is only 2.74:1 on --surface; #199e70 is 3.32:1. */
  --am-aqua:    #199e70;
  --am-cyan:    #0e7490;  /* 5.22:1 */
  --am-magenta: #d55181;  /* 3.84:1 */
  --am-green:   #008300;  /* 4.82:1 */

  /* Status colors (studio-only; site.css doesn't define them). Also used as
     small text, including on their own Soft chip. Measured WCAG ratios, worst
     case = the Soft tint composited over --page (the darkest base):
       light --warning 4.68:1 on its Soft chip, 5.52 on --page, 5.81 on --surface-raised
       light --error   4.79:1 on its Soft chip, 5.65 on --page, 5.96 on --surface-raised
     As chart marks: warning 5.66:1, error 5.81:1 on --surface. Keep the Soft
     alphas in step with the colors: a darker tint drops the chip ratio first. */
  --warning:     #8a5c00;  /* amber */
  --warningSoft: rgba(138, 92, 0, 0.12);
  --error:       #b82f42;  /* red   */
  --errorSoft:   rgba(184, 47, 66, 0.11);
}
:root[data-theme="dark"] {
  --am-shadow-pop: 0 6px 16px rgba(0, 0, 0, 0.5), 0 24px 60px rgba(0, 0, 0, 0.55);

  /* Brighter section accents so they stay legible on the dark shell. */
  --nav-overview:  #60a5fa;
  --nav-planner:   #a78bfa;
  --nav-notes:     #fbbf24;
  --nav-library:   #34d399;
  --nav-journal:   #f472b6;
  --nav-routine:   #a3e635;
  --nav-brain:     #c084fc;
  --nav-workbench: #2dd4bf;
  --nav-writing:   #fb923c;
  --nav-analysis:  #22d3ee;
  --nav-settings:  #94a3b8;
  --nav-profile:   #94a3b8;

  /* On --surface #1a1a19: aqua 5.11:1, cyan 9.64:1, magenta 4.41:1, green 3.52:1. */
  --am-cyan:    #22d3ee;  /* = --nav-analysis */

  /* Dark: worst case is the Soft tint over --surface-raised (the lightest base):
       --warning 5.33:1 on its Soft chip, 8.86 on --page
       --error   4.72:1 on its Soft chip, 7.47 on --page */
  --warning:     #e3a33b;
  --warningSoft: rgba(227, 163, 59, 0.16);
  --error:       #f47c86;
  --errorSoft:   rgba(244, 124, 134, 0.16);
}

/* Responsive content-width scale — the app shell fills the display instead of
   floating in a narrow column on large monitors. Laptops keep the 1180px
   reading feel; wide/ultrawide viewports progressively widen the content so the
   side gutters stay tight (~80px) rather than ballooning to 300px+. */
@media (min-width: 1440px) { :root { --am-content-max: 1320px; } }
@media (min-width: 1680px) { :root { --am-content-max: 1500px; } }
@media (min-width: 1920px) { :root { --am-content-max: 1680px; } }
@media (min-width: 2400px) { :root { --am-content-max: 1980px; } }

html,
body.amadeus-body {
  height: 100%;
}
body.amadeus-body {
  margin: 0;
  overflow: hidden;
  background: var(--page);
  /* A soft ambient wash so wide viewports never read as flat dead space. */
  background-image:
    radial-gradient(60rem 60rem at 108% -10%, var(--accent-wash), transparent 60%),
    radial-gradient(52rem 52rem at -12% 112%, var(--phase-3-wash), transparent 60%);
  background-attachment: fixed;
}

#amadeus-root {
  height: 100%;
  display: flex;
  min-height: 0;
}

/* Text never breaks out of its box. */
#amadeus-root * { min-width: 0; }
.am-clamp1,
.am-clamp2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.am-clamp1 { -webkit-line-clamp: 1; }
.am-clamp2 { -webkit-line-clamp: 2; }

/* Scrollbars — subtle, theme-aware. */
.am-scroll { scrollbar-width: thin; scrollbar-color: var(--baseline) transparent; }
.am-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.am-scroll::-webkit-scrollbar-thumb {
  background: var(--baseline);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 999px;
}
.am-scroll::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); background-clip: padding-box; }

::selection { background: var(--accent-wash); }

/* ==========================================================================
   Sidebar (desktop)
   ========================================================================== */
.am-sidebar {
  flex: none;
  width: var(--am-sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1.1rem 0.85rem 1rem;
  border-right: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(8px);
  transition: width 0.22s var(--am-ease);
  /* Short viewports (or a long nav) scroll the rail instead of clipping the
     footer/user chip off the bottom. Thin, theme-aware bar; contained so a
     bounce here never scrolls the page behind it. */
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--baseline) transparent;
}
.am-sidebar::-webkit-scrollbar { width: 8px; }
.am-sidebar::-webkit-scrollbar-thumb {
  background: var(--baseline);
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 999px;
}
.am-sidebar::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); background-clip: padding-box; }
.am-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.55rem 0.9rem;
  color: var(--ink);
  text-decoration: none;
}
.am-brand:hover { text-decoration: none; }
.am-brand-mark {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 11px;
  display: grid;
  place-items: center;
  padding: 4px;
  overflow: hidden;
  /* Light "app-icon" tile so the dark line-art logo reads on any theme. */
  background: #ffffff;
  border: 1px solid var(--hairline);
  box-shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
}
:root[data-theme="dark"] .am-brand-mark {
  background: #f4efe6;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.am-brand-img { width: 100%; height: 100%; object-fit: contain; display: block; }
.am-brand-text { display: flex; flex-direction: column; line-height: 1.1; overflow: hidden; }
.am-brand-name { font-family: var(--sans); font-weight: 700; font-size: 0.92rem; letter-spacing: 0.01em; }
.am-brand-sub { font-size: 0.72rem; color: var(--ink-muted); white-space: nowrap; }

.am-nav { display: flex; flex-direction: column; gap: 2px; }
.am-nav-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 0.9rem 0.7rem 0.35rem;
}
.am-nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  color: var(--ink-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.am-nav-item:hover { background: var(--accent-wash); color: var(--ink); text-decoration: none; }
.am-nav-item .am-ico { flex: none; color: var(--nav-clr, currentColor); opacity: 1; }
.am-nav-item .am-nav-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-nav-item[aria-current="page"] {
  background: var(--accent-wash);
  color: var(--accent-strong);
  font-weight: 600;
}
.am-nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.am-nav-spacer { flex: 1 1 auto; min-height: 0.5rem; }

/* Per-section icon color — consumed by .am-ico via --nav-clr across the
   sidebar, mobile tab bar, and "More" sheet (all carry data-route). */
[data-route="overview"]  { --nav-clr: var(--nav-overview); }
[data-route="planner"]   { --nav-clr: var(--nav-planner); }
[data-route="notes"]     { --nav-clr: var(--nav-notes); }
[data-route="library"]   { --nav-clr: var(--nav-library); }
[data-route="journal"]   { --nav-clr: var(--nav-journal); }
[data-route="routine"]   { --nav-clr: var(--nav-routine); }
[data-route="brain"]     { --nav-clr: var(--nav-brain); }
[data-route="workbench"] { --nav-clr: var(--nav-workbench); }
[data-route="writing"]   { --nav-clr: var(--nav-writing); }
[data-route="analysis"]  { --nav-clr: var(--nav-analysis); }
[data-route="settings"]  { --nav-clr: var(--nav-settings); }
[data-route="profile"]   { --nav-clr: var(--nav-profile); }

.am-side-foot { display: flex; flex-direction: column; gap: 2px; padding-top: 0.5rem; border-top: 1px solid var(--hairline); }
.am-userchip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  cursor: pointer;
  color: var(--ink-secondary);
  border: 1px solid transparent;
  text-decoration: none;
}
.am-userchip:hover { background: var(--accent-wash); text-decoration: none; }
.am-avatar {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(150deg, var(--phase-3), #12876a);
}
.am-userchip-text { display: flex; flex-direction: column; line-height: 1.15; overflow: hidden; }
.am-userchip-name { font-size: 0.85rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.am-userchip-sub { font-size: 0.72rem; color: var(--ink-muted); }

/* Compact rail */
.am-sidebar.is-compact { width: var(--am-sidebar-w-compact); }
.am-sidebar.is-compact .am-brand { justify-content: center; padding-inline: 0; }
.am-sidebar.is-compact .am-brand-text,
.am-sidebar.is-compact .am-nav-txt,
.am-sidebar.is-compact .am-nav-label,
.am-sidebar.is-compact .am-userchip-text { display: none; }
.am-sidebar.is-compact .am-nav-item,
.am-sidebar.is-compact .am-userchip { justify-content: center; padding-inline: 0; }

/* ==========================================================================
   Main column + top bar
   ========================================================================== */
.am-main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.am-view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.am-topbar {
  flex: none;
  height: var(--am-topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: blur(10px);
}
/* The page heading lives here, once. */
.am-topbar-title { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 1.3rem; letter-spacing: -0.01em; line-height: 1.1; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.am-topbar-spacer { flex: 1 1 auto; }

/* Sync status chip */
.am-sync-chip {
  display: none; align-items: center; gap: 0.4rem;
  height: 32px; padding: 0 0.7rem; border-radius: 999px;
  border: 1px solid var(--hairline); background: var(--surface);
  color: var(--ink-secondary); font-size: 0.8rem; font-weight: 600; cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.am-sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-muted); flex: none; }
.am-sync-chip.is-online { color: #12876a; background: var(--phase-3-wash); border-color: transparent; }
.am-sync-chip.is-online .am-sync-dot { background: var(--phase-3); }
.am-sync-chip.is-offline { color: var(--warning); background: var(--warningSoft); border-color: transparent; }
.am-sync-chip.is-offline .am-sync-dot { background: var(--warning); }
.am-sync-chip.is-syncing .am-sync-dot { background: var(--accent); animation: am-pulse 1s ease-in-out infinite; }
@keyframes am-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@media (max-width: 900px) { .am-sync-chip .am-sync-label { display: none; } .am-sync-chip { padding: 0 0.55rem; } }
.am-topbar-actions { display: flex; align-items: center; gap: 0.4rem; }

.am-searchbtn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 36px;
  padding: 0 0.7rem 0 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.am-searchbtn:hover { border-color: var(--baseline); color: var(--ink-secondary); }
.am-searchbtn .am-kbd { margin-left: 0.35rem; }

/* Icon button */
.am-iconbtn {
  width: 36px;
  height: 36px;
  flex: none;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink-secondary);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.am-iconbtn:hover { color: var(--ink); background: var(--accent-wash); border-color: var(--accent); }
.am-iconbtn:focus-visible,
.am-nav-item:focus-visible,
.am-searchbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.am-kbd {
  font-family: var(--mono);
  font-size: 0.7rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--hairline);
  background: var(--surface-raised);
  color: var(--ink-muted);
}

/* ==========================================================================
   Content scroll region
   ========================================================================== */
.am-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}
.am-page {
  max-width: var(--am-content-max);
  margin: 0 auto;
  padding: clamp(1.2rem, 3vw, 2.4rem) clamp(1rem, 3vw, 2rem) 4rem;
  animation: am-fade 0.35s var(--am-ease) both;
}
/* A repaint the reader didn't ask for (a background sync) replays no entry
   animation — the flash is what makes it read as the page reloading. */
.am-page.am-no-enter { animation: none; }
@keyframes am-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.am-page-head { margin-bottom: 1.6rem; }
.am-page-head .kicker { color: var(--accent-strong); margin-bottom: 0.5rem; }
.am-page-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.6rem, 3.4vw, 2.3rem);
  line-height: 1.15;
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.am-page-lede { color: var(--ink-secondary); font-size: 1.02rem; margin: 0.5rem 0 0; max-width: 46rem; }
.am-page-head-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* Section heading inside a page */
.am-sec-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.am-sec-label a { font-size: 0.8rem; letter-spacing: 0; text-transform: none; font-weight: 600; }

/* ==========================================================================
   Grid helpers
   ========================================================================== */
.am-grid { display: grid; gap: 1rem; }
.am-stat-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.am-split {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  align-items: start;
}
@media (max-width: 900px) { .am-split { grid-template-columns: 1fr; } }

/* ==========================================================================
   Cards / panels
   ========================================================================== */
.am-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1.35rem;
}
.am-card.is-pad-lg { padding: 1.6rem; }
.am-card-hover { transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
.am-card-hover:hover { border-color: var(--baseline); box-shadow: var(--shadow); }

/* Stat tile with icon */
.am-stat {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
}
.am-stat-ico {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: var(--accent-strong);
  background: var(--accent-wash);
}
.am-stat.tone-2 .am-stat-ico { color: var(--phase-2); background: var(--phase-2-wash); }
.am-stat.tone-3 .am-stat-ico { color: var(--phase-3); background: var(--phase-3-wash); }
.am-stat.tone-4 .am-stat-ico { color: var(--proposed); background: var(--proposed-wash); }
.am-stat-body { display: flex; flex-direction: column; min-width: 0; }
.am-stat-label { font-size: 0.82rem; color: var(--ink-secondary); }
.am-stat-value { font-size: 1.7rem; font-weight: 700; color: var(--ink); line-height: 1.15; margin-top: 0.1rem; }
.am-stat-value small { font-size: 0.8rem; font-weight: 500; color: var(--ink-muted); margin-left: 0.35rem; }

/* Hero panel (accent) */
.am-hero {
  border-radius: var(--radius);
  padding: 1.5rem;
  color: #fff;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  position: relative;
  overflow: hidden;
}
.am-hero::after {
  content: "";
  position: absolute;
  right: -60px;
  top: -60px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
}
.am-hero .am-hero-eyebrow { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.13em; text-transform: uppercase; opacity: 0.85; }
.am-hero h3 { color: #fff; font-family: var(--sans); font-weight: 700; font-size: 1.5rem; margin: 0.3rem 0 0.5rem; }
.am-hero p { color: rgba(255, 255, 255, 0.9); margin: 0 0 1.1rem; font-size: 0.92rem; }
.am-progress { height: 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.28); overflow: hidden; margin-bottom: 1rem; }
.am-progress > i { display: block; height: 100%; border-radius: 999px; background: #fff; transition: width 0.5s var(--am-ease); }

/* Action rows (quick actions / jump back in) */
.am-actionlist { display: flex; flex-direction: column; }
.am-action {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.8rem 0.35rem;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  width: 100%;
  border-radius: 8px;
  transition: background 0.15s;
}
.am-action:last-child { border-bottom: 0; }
.am-action:hover { background: var(--accent-wash); }
.am-action .am-action-ico { width: 34px; height: 34px; flex: none; border-radius: 9px; display: grid; place-items: center; color: var(--accent-strong); background: var(--accent-wash); }
.am-action-txt { display: flex; flex-direction: column; min-width: 0; }
.am-action-title { font-size: 0.92rem; font-weight: 600; }
.am-action-sub { font-size: 0.8rem; color: var(--ink-muted); }
.am-action .am-action-arrow { margin-left: auto; color: var(--ink-muted); flex: none; }

/* ==========================================================================
   Buttons (extends site.css .btn)
   ========================================================================== */
.btn.am-sm { padding: 0.42rem 0.85rem; font-size: 0.85rem; }
.btn.am-block { width: 100%; justify-content: center; }
.btn-soft {
  background: var(--accent-wash);
  color: var(--accent-strong);
  border-color: transparent;
}
.btn-soft:hover { background: color-mix(in srgb, var(--accent-wash) 60%, var(--accent) 18%); }
.btn-danger { background: transparent; color: var(--error); border-color: var(--hairline); }
.btn-danger:hover { background: var(--errorSoft); border-color: var(--error); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ==========================================================================
   Form controls
   ========================================================================== */
.am-input,
.am-textarea,
.am-select {
  width: 100%;
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.am-input::placeholder,
.am-textarea::placeholder { color: var(--ink-muted); }
.am-input:focus,
.am-textarea:focus,
.am-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
.am-textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
.am-field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.am-field-label { font-size: 0.82rem; font-weight: 600; color: var(--ink-secondary); }
.am-field-hint { font-size: 0.78rem; color: var(--ink-muted); }

/* Color swatches (routine blocks) */
.am-swatch { width: 26px; height: 26px; border-radius: 8px; border: 0; padding: 0; cursor: pointer; transition: transform 0.12s, box-shadow 0.12s; }
.am-swatch:hover { transform: scale(1.08); }

/* Custom time picker (routine blocks) — hours never scroll */
.am-timefield { position: relative; }
.am-timetrigger { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; text-align: left; cursor: pointer; }
.am-timetrigger .am-ico { color: var(--ink-muted); flex: none; }
.am-timetrigger.is-empty .am-timetrigger-txt { color: var(--ink-muted); }
.am-timetrigger:hover { border-color: var(--baseline); }
.am-timepop {
  position: fixed;
  z-index: 260;
  width: 232px;
  background: var(--surface-raised);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  animation: am-timepop-in 0.12s var(--am-ease, ease);
}
@keyframes am-timepop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.am-timepop-sec { display: flex; flex-direction: column; gap: 0.3rem; }
.am-timepop-lbl { font-size: 0.64rem; font-weight: 600; letter-spacing: 0.11em; text-transform: uppercase; color: var(--ink-muted); }
.am-timepop-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.3rem; }
.am-timepop-mer { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.3rem; }
.am-timecell {
  font: inherit;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  padding: 0.4rem 0;
  border-radius: 8px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.am-timecell:hover { background: var(--accent-wash); border-color: transparent; }
.am-timecell.is-sel { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.am-search {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0 0.5rem 0 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.am-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.am-search .am-ico { color: var(--ink-muted); flex: none; }
.am-search input { flex: 1; border: 0; background: transparent; font: inherit; font-size: 0.92rem; color: var(--ink); padding: 0.6rem 0; outline: none; }

/* Segmented control */
.am-segment { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--surface-muted, var(--surface)); border: 1px solid var(--hairline); }
.am-segment button {
  border: 0;
  background: transparent;
  color: var(--ink-secondary);
  font: inherit;
  font-size: 0.83rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.am-segment button[aria-pressed="true"] { background: var(--surface-raised); color: var(--ink); box-shadow: var(--shadow); }

/* Switch */
.am-switch { position: relative; width: 42px; height: 24px; flex: none; }
.am-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.am-switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--baseline); transition: background 0.18s; }
.am-switch .thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform 0.18s var(--am-ease); }
.am-switch input:checked ~ .track { background: var(--accent); }
.am-switch input:checked ~ .thumb { transform: translateX(18px); }
.am-switch input:focus-visible ~ .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==========================================================================
   Status pill, chips, badges
   ========================================================================== */
.am-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  color: var(--ink-secondary);
  background: var(--surface);
  white-space: nowrap;
}
.am-pill .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: currentColor; }
.am-pill.is-ok { color: #12876a; background: var(--phase-3-wash); border-color: transparent; }
.am-pill.is-off { color: var(--ink-muted); background: var(--surface); }
.am-pill.is-warn { color: var(--warning); background: var(--warningSoft); border-color: transparent; }

.am-tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.74rem;
  font-weight: 500;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-wash);
  color: var(--accent-strong);
}

/* ==========================================================================
   List rows (tasks, drafts, papers)
   ========================================================================== */
.am-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.am-row + .am-row { margin-top: 0.6rem; }
.am-row:hover { border-color: var(--baseline); }
.am-row-main { min-width: 0; flex: 1; }
.am-row-title { font-size: 0.94rem; font-weight: 600; color: var(--ink); }
.am-row-sub { font-size: 0.82rem; color: var(--ink-muted); margin-top: 0.15rem; }
.am-row-actions { display: flex; align-items: center; gap: 0.3rem; flex: none; }

/* Checkbox */
.am-check {
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 7px;
  border: 1.8px solid var(--baseline);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: #fff;
  transition: background 0.15s, border-color 0.15s;
}
.am-check:hover { border-color: var(--accent); }
.am-check.is-done { background: var(--phase-3); border-color: var(--phase-3); }
.am-check svg { opacity: 0; transform: scale(0.6); transition: opacity 0.15s, transform 0.15s; }
.am-check.is-done svg { opacity: 1; transform: none; }
.am-row.is-done .am-row-title { color: var(--ink-muted); text-decoration: line-through; }

/* Tiny ghost icon action */
.am-tinybtn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 0.15s, background 0.15s;
}
.am-tinybtn:hover { color: var(--ink); background: var(--accent-wash); }
.am-tinybtn.is-danger:hover { color: var(--error); background: var(--errorSoft); }

/* ==========================================================================
   Empty & connect states
   ========================================================================== */
.am-empty {
  text-align: center;
  padding: 2.75rem 1.5rem;
  border: 1px dashed var(--baseline);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}
.am-empty .am-empty-ico {
  width: 54px;
  height: 54px;
  margin: 0 auto 0.9rem;
  border-radius: 15px;
  display: grid;
  place-items: center;
  color: var(--accent-strong);
  background: var(--accent-wash);
}
.am-empty h3 { font-family: var(--sans); font-size: 1.05rem; font-weight: 700; margin: 0 0 0.35rem; color: var(--ink); }
.am-empty p { color: var(--ink-secondary); margin: 0 auto 1.1rem; max-width: 32rem; font-size: 0.92rem; }

.am-connect {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  padding: 1rem 1.1rem;
  border-radius: 12px;
  border: 1px solid var(--hairline);
  background: var(--accent-wash);
  margin-bottom: 1.25rem;
}
.am-connect .am-ico { color: var(--accent-strong); flex: none; margin-top: 2px; }
.am-connect-body { min-width: 0; }
.am-connect-body strong { color: var(--ink); }
.am-connect-body p { margin: 0.2rem 0 0; font-size: 0.88rem; color: var(--ink-secondary); }

/* ==========================================================================
   Writing studio (list + editor)
   ========================================================================== */
.am-writer { display: grid; gap: 1.25rem; grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); align-items: start; }
@media (max-width: 900px) { .am-writer { grid-template-columns: 1fr; } }
.am-draftlist { display: flex; flex-direction: column; gap: 0.5rem; }
.am-draft {
  text-align: left;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface);
  padding: 0.75rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.am-draft:hover { border-color: var(--baseline); }
.am-draft.is-active { border-color: var(--accent); background: var(--accent-wash); }
.am-draft-title { font-size: 0.92rem; font-weight: 600; color: var(--ink); }
.am-draft-meta { font-size: 0.78rem; color: var(--ink-muted); margin-top: 0.2rem; }

.am-editor { border: 1px solid var(--hairline); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.am-editor-toolbar { display: flex; align-items: center; gap: 0.25rem; row-gap: 0.3rem; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--hairline); flex-wrap: wrap; }
.am-editor-toolbar .am-tinybtn { width: 34px; height: 30px; font-weight: 700; color: var(--ink-secondary); }
.am-editor-toolbar .spacer { flex: 1; }
/* Hairline group separators between toolbar clusters. */
.am-tb-sep { width: 1px; align-self: stretch; margin: 0.15rem 0.25rem; background: var(--hairline); flex: none; }
/* Journal reuses the editor toolbar, but as a rounded bar above the textarea. */
.am-journal-toolbar { border: 1px solid var(--hairline); border-bottom: 0; border-radius: 10px 10px 0 0; margin-top: 0.8rem; }
.am-journal-toolbar + .am-editor-panes { border: 1px solid var(--hairline); border-radius: 0 0 10px 10px; overflow: hidden; }
/* Drag an image over the editor → highlight the drop target. */
.am-editor-body.is-dropping { outline: 2px dashed var(--accent); outline-offset: -6px; background: var(--accent-wash); }
.am-editor-wc { font-size: 0.8rem; color: var(--ink-muted); padding-right: 0.4rem; }
.am-editor-title {
  width: 100%;
  border: 0;
  background: transparent;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.6rem;
  color: var(--ink);
  padding: 1.1rem 1.3rem 0.4rem;
  outline: none;
}
.am-editor-title::placeholder { color: var(--ink-muted); }
.am-editor-body {
  width: 100%;
  border: 0;
  background: transparent;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.75;
  color: var(--ink);
  padding: 0.4rem 1.3rem 1.5rem;
  outline: none;
  resize: none;
  min-height: 46vh;
}

/* The editor card fills the (now wider) column, but the writing itself is held
   to a comfortable measure and centered on the canvas — full display use
   without 1600px-wide lines. The toolbar stays full-width so its divider spans
   the card; split mode already halves each pane, so those fill. */
.am-editor-title,
.am-editor-panes:not(.is-split) .am-editor-body,
.am-editor-panes:not(.is-split) .am-editor-preview {
  display: block; /* inputs/textareas are inline-block; block makes margin-inline:auto center */
  max-width: var(--am-editor-measure);
  margin-inline: auto;
}

/* ==========================================================================
   Brain (chat)
   ========================================================================== */
.am-chat { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.am-chat-scroll { flex: 1; overflow-y: auto; padding: clamp(1rem, 3vw, 2rem); }
.am-chat-inner { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.1rem; }
.am-msg { display: flex; gap: 0.7rem; }
.am-msg-av { width: 30px; height: 30px; flex: none; border-radius: 9px; display: grid; place-items: center; font-size: 0.72rem; font-weight: 700; color: #fff; }
.am-msg.user .am-msg-av { background: linear-gradient(150deg, var(--phase-3), #12876a); }
.am-msg.bot .am-msg-av { background: linear-gradient(150deg, var(--accent), var(--accent-strong)); }
.am-msg-bubble { border: 1px solid var(--hairline); background: var(--surface); border-radius: 12px; padding: 0.75rem 0.95rem; font-size: 0.95rem; line-height: 1.6; color: var(--ink); white-space: pre-wrap; }
.am-brain-sources { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.7rem; }
.am-brain-src { display: flex; align-items: center; gap: 0.45rem; font-size: 0.85rem; color: var(--ink-secondary); text-decoration: none; padding: 0.35rem 0.55rem; border: 1px solid var(--hairline); border-radius: 8px; background: var(--surface-raised); white-space: normal; }
.am-brain-src:hover { border-color: var(--accent); color: var(--ink); text-decoration: none; }
.am-brain-src .am-ico { color: var(--accent-strong); flex: none; }
.am-msg.user .am-msg-bubble { background: var(--accent-wash); border-color: transparent; }
.am-composer { flex: none; border-top: 1px solid var(--hairline); padding: 0.85rem clamp(1rem, 3vw, 2rem); background: var(--page); }
.am-composer-inner { max-width: 780px; margin: 0 auto; display: flex; gap: 0.6rem; align-items: flex-end; }
.am-composer .am-textarea { min-height: 46px; max-height: 160px; }

/* ==========================================================================
   Command palette
   ========================================================================== */
.am-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--overlay, rgba(11,11,11,.42));
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(3rem, 12vh, 8rem) 1rem 1rem;
  animation: am-fade 0.15s ease both;
}
.am-palette {
  width: min(600px, 100%);
  background: var(--surface-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--am-radius-lg);
  box-shadow: var(--am-shadow-pop);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 60vh;
}
.am-palette-head { display: flex; align-items: center; gap: 0.6rem; padding: 0.85rem 1rem; border-bottom: 1px solid var(--hairline); }
.am-palette-head .am-ico { color: var(--ink-muted); flex: none; }
.am-palette-head input { flex: 1; border: 0; background: transparent; font: inherit; font-size: 1rem; color: var(--ink); outline: none; }
.am-palette-list { overflow-y: auto; padding: 0.4rem; }
.am-palette-group { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-muted); padding: 0.6rem 0.65rem 0.3rem; }
.am-palette-item { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.65rem; border-radius: 10px; cursor: pointer; color: var(--ink); }
.am-palette-item .am-ico { color: var(--ink-secondary); flex: none; }
.am-palette-item .sub { font-size: 0.8rem; color: var(--ink-muted); }
/* Long titles wrap to two lines (then ellipsis); the full text is the row's tooltip. */
.am-palette-label { flex: 1; min-width: 0; line-height: 1.35; overflow-wrap: anywhere; }
.am-palette-item .am-kbd { margin-left: auto; flex: none; white-space: nowrap; }
.am-palette-item.is-active,
.am-palette-item:hover { background: var(--accent-wash); }
.am-palette-item.is-active .am-ico { color: var(--accent-strong); }
.am-palette-empty { padding: 1.5rem; text-align: center; color: var(--ink-muted); font-size: 0.9rem; }

/* ==========================================================================
   Toasts
   ========================================================================== */
.am-toasts { position: fixed; bottom: 1.1rem; right: 1.1rem; z-index: 300; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(360px, calc(100vw - 2rem)); }
.am-toast {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: var(--surface-raised);
  border: 1px solid var(--hairline);
  box-shadow: var(--am-shadow-pop);
  animation: am-toast-in 0.25s var(--am-ease) both;
}
@keyframes am-toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.am-toast .am-ico { flex: none; margin-top: 1px; }
.am-toast.ok .am-ico { color: var(--phase-3); }
.am-toast.error .am-ico { color: var(--error); }
.am-toast.warning .am-ico { color: var(--warning); }
.am-toast.info .am-ico { color: var(--accent-strong); }
.am-toast-title { font-size: 0.9rem; font-weight: 600; color: var(--ink); }
.am-toast-msg { font-size: 0.83rem; color: var(--ink-secondary); margin-top: 0.1rem; }

/* ==========================================================================
   Planner focus panel + MISO the study cat
   ========================================================================== */
.am-planner-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
}
.am-focus-col { position: sticky; top: 0.5rem; }

.am-focus { display: flex; flex-direction: column; gap: 1rem; overflow: hidden; }
.am-focus-head { display: flex; align-items: center; justify-content: space-between; }
.am-focus-head .am-sec-label { margin: 0; }

/* Cat stage — soft desk vignette behind MISO */
.am-focus-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 0 0.25rem;
  border-radius: var(--radius);
  background:
    radial-gradient(120% 80% at 50% 118%, var(--accent-wash), transparent 70%);
}
.am-focus-stage.is-break { background: radial-gradient(120% 80% at 50% 118%, var(--phase-3-wash), transparent 70%); }

/* Speech bubble */
.am-focus-bubble {
  position: relative;
  max-width: 90%;
  margin-bottom: 0.35rem;
  padding: 0.5rem 0.8rem;
  border-radius: 12px;
  background: var(--surface-raised);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--ink-secondary);
  text-align: center;
  transition: opacity 0.25s ease;
}
.am-focus-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 11px;
  height: 11px;
  transform: translateX(-50%) rotate(45deg);
  background: var(--surface-raised);
  border-right: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}

/* The cat SVG */
.miso { width: 100%; max-width: 208px; }
.miso svg { display: block; width: 100%; height: auto; overflow: visible; }
.miso .m-eyes-closed,
.miso .m-zzz,
.miso .m-prop,
.miso .m-spark,
.miso .m-mouth-sad,
.miso .m-mouth-o,
.miso .m-drop,
.miso .m-tear { opacity: 0; }

/* Animated part origins (view-box units).
   Idle is deliberately calm: slow breathing, the odd blink, a lazy tail. Ears
   twitch only rarely, and the eyes track the cursor via JS (no auto-drift). */
.miso { position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.miso svg { transform-origin: 50% 92%; transition: transform 0.22s var(--am-ease); }
.miso:hover svg { transform: scale(1.035); }
.miso:active svg { transform: scale(0.99); }
.miso:focus-visible { outline: none; }
.miso:focus-visible svg { transform: scale(1.035); filter: drop-shadow(0 0 0 var(--accent)); }

.m-body { transform-box: view-box; transform-origin: 120px 180px; animation: miso-breathe 5.4s ease-in-out infinite; }
.m-head { transform-box: view-box; transform-origin: 120px 132px; animation: miso-headtilt 9s ease-in-out infinite; }
.m-tail { transform-box: view-box; transform-origin: 158px 172px; animation: miso-tail 5.4s ease-in-out infinite; }
.m-ear-l { transform-box: view-box; transform-origin: 92px 60px; animation: miso-ear-l 11s ease-in-out infinite; }
.m-ear-r { transform-box: view-box; transform-origin: 148px 60px; animation: miso-ear-r 13s ease-in-out infinite; }
.m-eyes { transform-box: view-box; transform-origin: 120px 100px; animation: miso-blink 7.2s ease-in-out infinite; }
.m-pupils { transform-box: view-box; transform-origin: 120px 102px; transition: transform 0.14s ease-out; }
.m-cat { transform-box: view-box; transform-origin: 120px 200px; }

@keyframes miso-breathe { 0%, 100% { transform: translateY(0) scaleX(1); } 50% { transform: translateY(-1.4px) scaleX(1.012); } }
@keyframes miso-headtilt { 0%, 100% { transform: rotate(-0.9deg); } 50% { transform: rotate(0.9deg); } }
@keyframes miso-tail { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(7deg); } }
@keyframes miso-ear-l { 0%, 88%, 100% { transform: rotate(0); } 92% { transform: rotate(-8deg); } 95% { transform: rotate(0); } }
@keyframes miso-ear-r { 0%, 90%, 100% { transform: rotate(0); } 94% { transform: rotate(8deg); } 97% { transform: rotate(0); } }
@keyframes miso-blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.08); } 98.5% { transform: scaleY(1); } }
@keyframes miso-paw { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(9deg); } }
@keyframes miso-bounce { 0%, 100% { transform: translateY(0); } 25% { transform: translateY(-12px) scaleX(0.98); } 50% { transform: translateY(0) scaleX(1.03); } 72% { transform: translateY(-5px); } }
@keyframes miso-nuzzle { 0%, 100% { transform: rotate(0) translateY(0); } 25% { transform: rotate(-3.5deg) translateY(-2px); } 60% { transform: rotate(3deg) translateY(0); } }
@keyframes miso-zzz { 0% { opacity: 0; transform: translate(0, 0) scale(0.7); } 20% { opacity: 0.95; } 100% { opacity: 0; transform: translate(6px, -20px) scale(1.15); } }
@keyframes miso-twinkle { 0%, 100% { opacity: 0; transform: scale(0.5); } 50% { opacity: 1; transform: scale(1); } }
@keyframes miso-heart { 0% { opacity: 0; transform: translate(0, 0) scale(0.5); } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--hx, 0), -46px) scale(1.05); } }

/* Interaction — floating hearts + "pet" reaction */
.m-hearts { position: absolute; left: 0; right: 0; top: 8%; height: 0; pointer-events: none; z-index: 2; }
.m-heart { position: absolute; left: 50%; font-size: 15px; color: var(--accent); animation: miso-heart 1.1s ease-out forwards; }
.miso.is-petting .m-cat { animation: miso-nuzzle 0.9s var(--am-ease); }
.miso.is-petting .m-eyes { opacity: 0; }
.miso.is-petting .m-eyes-closed { opacity: 1; }

/* Focus mood — writing paw + prop, a touch livelier tail */
.miso.is-focus .m-paw { transform-box: view-box; transform-origin: 138px 176px; animation: miso-paw 1.1s ease-in-out infinite; }
.miso.is-focus .m-tail { animation-duration: 4s; }
.miso.is-focus .m-prop { opacity: 1; }

/* Break mood — eyes shut, zzz, slower breathing */
.miso.is-break .m-eyes { opacity: 0; }
.miso.is-break .m-eyes-closed { opacity: 1; }
.miso.is-break .m-body { animation-duration: 6.6s; }
.miso.is-break .m-zzz { opacity: 1; }
.miso.is-break .m-zzz .z1 { animation: miso-zzz 2.6s ease-in-out infinite; }
.miso.is-break .m-zzz .z2 { animation: miso-zzz 2.6s ease-in-out 0.6s infinite; }
.miso.is-break .m-zzz .z3 { animation: miso-zzz 2.6s ease-in-out 1.2s infinite; }

/* Celebrate mood — bounce + sparkles + wide eyes */
.miso.is-celebrate .m-cat { animation: miso-bounce 1.1s var(--am-ease); }
.miso.is-celebrate .m-eyes { animation: none; transform: scaleY(1.12); }
.miso.is-celebrate .m-spark { opacity: 1; }
.miso.is-celebrate .m-spark .s1 { animation: miso-twinkle 1s ease-in-out infinite; }
.miso.is-celebrate .m-spark .s2 { animation: miso-twinkle 1s ease-in-out 0.33s infinite; }
.miso.is-celebrate .m-spark .s3 { animation: miso-twinkle 1s ease-in-out 0.66s infinite; }

/* Happy — task completed: quick bounce, squint, sparkles */
.miso.is-happy .m-cat { animation: miso-bounce 0.9s var(--am-ease); }
.miso.is-happy .m-eyes { opacity: 0; }
.miso.is-happy .m-eyes-closed { opacity: 1; }
.miso.is-happy .m-spark { opacity: 1; }
.miso.is-happy .m-spark .s1 { animation: miso-twinkle 0.9s ease-in-out infinite; }
.miso.is-happy .m-spark .s2 { animation: miso-twinkle 0.9s ease-in-out 0.3s infinite; }
.miso.is-happy .m-spark .s3 { animation: miso-twinkle 0.9s ease-in-out 0.6s infinite; }

/* Worried — resting face while the backlog is high: ears back, wide eyes, sweat */
.miso.is-worried .m-ear-l { animation: none; transform: rotate(18deg); }
.miso.is-worried .m-ear-r { animation: none; transform: rotate(-18deg); }
.miso.is-worried .m-eyes { animation: none; transform: scaleY(1.1) scaleX(1.04); }
.miso.is-worried .m-mouth { opacity: 0; }
.miso.is-worried .m-mouth-sad { opacity: 1; }
.miso.is-worried .m-drop { opacity: 0.9; animation: miso-sweat 2.6s ease-in-out infinite; }
.miso.is-worried .m-body { animation-duration: 4.6s; }

/* Scared — backlog just spiked: tremble, ears pinned, mouth open, sweat */
.miso.is-scared .m-cat { animation: miso-tremble 0.34s linear infinite; }
.miso.is-scared .m-ear-l { animation: none; transform: rotate(25deg); }
.miso.is-scared .m-ear-r { animation: none; transform: rotate(-25deg); }
.miso.is-scared .m-eyes { animation: none; transform: scaleY(1.24) scaleX(1.12); }
.miso.is-scared .m-mouth { opacity: 0; }
.miso.is-scared .m-mouth-o { opacity: 1; }
.miso.is-scared .m-drop { opacity: 1; animation: miso-sweat 0.9s ease-in-out infinite; }

/* Sad — session paused: droopy eyes + ears, frown, a slow tear */
.miso.is-sad .m-ear-l { animation: none; transform: rotate(15deg); }
.miso.is-sad .m-ear-r { animation: none; transform: rotate(-15deg); }
.miso.is-sad .m-eyes { animation: none; transform: scaleY(0.5) translateY(2px); }
.miso.is-sad .m-head { animation: none; transform: translateY(1.5px); }
.miso.is-sad .m-mouth { opacity: 0; }
.miso.is-sad .m-mouth-sad { opacity: 1; }
.miso.is-sad .m-tear { opacity: 1; animation: miso-tear 2.8s ease-in infinite; }
.miso.is-sad .m-body { animation-duration: 6.8s; }

@keyframes miso-tremble { 0%, 100% { transform: translateX(-1px); } 50% { transform: translateX(1px); } }
@keyframes miso-sweat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(1.6px); } }
@keyframes miso-tear { 0% { transform: translateY(0); opacity: 0; } 20% { opacity: 1; } 100% { transform: translateY(11px); opacity: 0; } }

/* Timer dial */
.am-focus-dial { position: relative; width: 168px; height: 168px; margin: 0 auto; }
.am-focus-dial svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.am-focus-track { fill: none; stroke: var(--hairline); stroke-width: 10; }
.am-focus-prog { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 0.95s linear, stroke 0.4s ease; }
.am-focus-dial.is-break .am-focus-prog { stroke: var(--phase-3); }
.am-focus-readout { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.15rem; }
.am-focus-mode { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.16em; color: var(--accent-strong); }
.am-focus-dial.is-break .am-focus-mode { color: var(--phase-3); }
.am-focus-count { font-family: var(--sans); font-variant-numeric: tabular-nums; font-size: 2.1rem; font-weight: 700; color: var(--ink); line-height: 1; }

.am-focus-presets { display: flex; justify-content: center; }
.am-focus-controls { display: flex; align-items: center; justify-content: center; gap: 0.6rem; }
.am-focus-controls .am-focus-primary { min-width: 132px; justify-content: center; }
.am-focus-round {
  width: 42px; height: 42px; flex: none;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink-secondary);
  display: grid; place-items: center; cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.am-focus-round:hover { color: var(--ink); background: var(--accent-wash); border-color: var(--accent); }

/* Top-bar running chip */
.am-focus-chip {
  display: none;
  align-items: center;
  gap: 0.4rem;
  height: 32px;
  padding: 0 0.7rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--accent-wash);
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.am-focus-chip.is-visible { display: inline-flex; }
.am-focus-chip.is-break { background: var(--phase-3-wash); color: var(--phase-3); }
.am-focus-chip .am-ico { animation: miso-spin 8s linear infinite; }
@keyframes miso-spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .am-planner-grid { grid-template-columns: 1fr; }
  .am-focus-col { position: static; }
  .am-focus-chip .am-focus-chip-mode { display: none; }
}

/* ==========================================================================
   Planner date picker + backlog
   ========================================================================== */
.am-date-btn {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.3rem 0.55rem;
  margin-left: 0.15rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.am-date-btn:hover { background: var(--accent-wash); color: var(--accent-strong); }

.am-seg-badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 0.4rem;
  border-radius: 999px;
  background: var(--phase-2);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
}

.am-cal {
  width: min(340px, 100%);
  background: var(--surface-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--am-radius-lg);
  box-shadow: var(--am-shadow-pop);
  padding: 0.9rem;
  animation: am-fade 0.15s var(--am-ease) both;
}
.am-cal-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.6rem; }
.am-cal-title { font-family: var(--sans); font-weight: 700; font-size: 0.98rem; color: var(--ink); }
.am-cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 4px; }
.am-cal-dow span { text-align: center; font-size: 0.68rem; font-weight: 600; color: var(--ink-muted); padding: 4px 0; }
.am-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.am-cal-day {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.am-cal-day:hover { background: var(--accent-wash); color: var(--ink); }
.am-cal-day.is-today { border-color: var(--accent); color: var(--accent-strong); font-weight: 700; }
.am-cal-day.is-selected { background: var(--accent); color: #fff; border-color: transparent; }
.am-cal-dot { position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%); width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.am-cal-dot.is-done { background: var(--baseline); }
.am-cal-day.is-selected .am-cal-dot { background: #fff; }
.am-cal-foot { display: flex; justify-content: flex-end; margin-top: 0.7rem; }

/* Overdue surface (Overview) */
.am-overdue { border-color: color-mix(in srgb, var(--warning) 38%, transparent); background: color-mix(in srgb, var(--warning) 4%, var(--surface)); } /* see .am-week-day.is-overdue */
.am-overdue-title { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--warning); }

/* Small checkbox for compact week lines */
.am-check-sm { width: 18px; height: 18px; border-radius: 6px; border-width: 1.6px; }

/* Week board */
.am-week-grid { display: grid; gap: 0.85rem; grid-template-columns: repeat(auto-fill, minmax(216px, 1fr)); }
.am-week-day {
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface);
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  min-height: 118px;
}
.am-week-day.is-today { border-color: var(--accent); }
/* Overdue cells / card: an opaque 4% --warning tint over --surface instead of a translucent
   wash over whatever is behind. The count chip is opaque too (12% --warning over --surface),
   so it keeps its ratio even when a drag-over wash (.is-drop) lands on the cell: measured
   light 4.80:1, dark 6.45:1 (a --warningSoft chip on the old translucent wash was 4.44:1 on --page). */
.am-week-day.is-overdue { border-color: color-mix(in srgb, var(--warning) 40%, transparent); background: color-mix(in srgb, var(--warning) 4%, var(--surface)); }
.am-week-dhead { display: flex; align-items: center; gap: 0.25rem; padding: 0.15rem; }
.am-week-dopen {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 0.4rem;
  border: 0; background: transparent; cursor: pointer;
  padding: 0.3rem 0.4rem; border-radius: 8px; color: var(--ink);
  transition: background 0.15s;
}
.am-week-dopen:hover { background: var(--accent-wash); }
.am-week-add {
  width: 24px; height: 24px; flex: none;
  border: 0; background: transparent; color: var(--ink-muted);
  border-radius: 6px; cursor: pointer; display: grid; place-items: center;
  transition: color 0.15s, background 0.15s;
}
.am-week-add:hover { color: var(--accent-strong); background: var(--accent-wash); }
.am-week-addinput {
  width: 100%; margin-top: 3px;
  border: 1px solid var(--accent); border-radius: 7px;
  background: var(--surface-raised); font: inherit; font-size: 0.85rem;
  color: var(--ink); padding: 0.35rem 0.45rem; outline: none;
}
.am-week-dow { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-muted); }
.am-week-dnum { font-family: var(--sans); font-weight: 700; font-size: 1rem; color: var(--ink); }
.am-week-day.is-today .am-week-dnum { color: var(--accent-strong); }
.am-week-count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent-wash); color: var(--accent-strong); font-size: 0.72rem; font-weight: 700; display: inline-grid; place-items: center; }
.am-week-day.is-overdue .am-week-count { background: color-mix(in srgb, var(--warning) 12%, var(--surface)); color: var(--warning); }
.am-week-check { margin-left: auto; color: var(--phase-3); display: inline-flex; }
.am-week-body { display: flex; flex-direction: column; gap: 1px; padding: 0.2rem 0.1rem 0.1rem; }
.am-week-line { display: flex; align-items: center; gap: 0.45rem; padding: 0.3rem 0.35rem; border-radius: 7px; transition: background 0.12s; }
.am-week-line:hover { background: var(--accent-wash); }
.am-week-ltitle { font-size: 0.85rem; color: var(--ink); }
.am-week-line.is-done .am-week-ltitle { color: var(--ink-muted); text-decoration: line-through; }
.am-week-more { font-size: 0.78rem; color: var(--ink-muted); padding: 0.2rem 0.45rem; }
.am-week-empty { font-size: 0.82rem; color: var(--ink-muted); padding: 0.3rem 0.45rem; }
.am-week-hint { font-size: 0.8rem; margin: 0 0 0.9rem; }

/* Recurring badge */
.am-repeat { display: inline-flex; color: var(--ink-muted); margin-right: 0.32rem; vertical-align: -2px; }
.am-repeat svg { width: 12px; height: 12px; }

/* Drag-to-reschedule affordances */
.am-week-line[draggable="true"] { cursor: grab; }
.am-week-line.is-dragging { opacity: 0.45; }
.am-week-day.is-drop { border-color: var(--accent); background: var(--accent-wash); box-shadow: inset 0 0 0 1px var(--accent); }
@media (hover: none) { .am-week-hint { display: none; } }

/* Day list: drag-to-reorder affordances */
.am-row.is-reorderable { cursor: grab; }
.am-row.is-dragging { opacity: 0.45; }
.am-row.is-drop-before { box-shadow: inset 0 3px 0 -1px var(--accent); }
.am-row.is-drop-after { box-shadow: inset 0 -3px 0 -1px var(--accent); }

/* Month grid */
.am-month-dow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.am-month-dow span { text-align: center; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); }
.am-month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.am-month-cell {
  text-align: left; min-height: 82px;
  border: 1px solid var(--hairline); border-radius: 10px;
  background: var(--surface); padding: 0.35rem 0.4rem;
  display: flex; flex-direction: column; gap: 0.2rem;
  cursor: pointer; overflow: hidden;
  transition: border-color 0.12s, background 0.12s;
}
.am-month-cell:hover { border-color: var(--baseline); background: var(--accent-wash); }
.am-month-cell.is-blank { border: 0; background: transparent; cursor: default; pointer-events: none; }
.am-month-cell.is-today { border-color: var(--accent); }
.am-month-cell.is-selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.am-month-cell.is-overdue { border-color: color-mix(in srgb, var(--warning) 40%, transparent); background: color-mix(in srgb, var(--warning) 4%, var(--surface)); } /* see .am-week-day.is-overdue */
.am-month-top { display: flex; align-items: center; justify-content: space-between; gap: 0.3rem; }
.am-month-num { font-family: var(--sans); font-weight: 600; font-size: 0.85rem; color: var(--ink-secondary); }
.am-month-cell.is-today .am-month-num { color: var(--accent-strong); font-weight: 700; }
.am-month-count { min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--accent-wash); color: var(--accent-strong); font-size: 0.66rem; font-weight: 700; display: inline-grid; place-items: center; }
.am-month-cell.is-overdue .am-month-count { background: color-mix(in srgb, var(--warning) 12%, var(--surface)); color: var(--warning); }
.am-month-evs { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.am-month-ev { font-size: 0.72rem; line-height: 1.3; color: var(--ink-secondary); background: var(--accent-wash); border-radius: 4px; padding: 1px 4px; }
.am-month-more { font-size: 0.68rem; color: var(--ink-muted); padding: 0 2px; }
.am-month-alldone { color: var(--phase-3); display: inline-flex; }
@media (max-width: 640px) {
  .am-month-cell { min-height: 52px; }
  .am-month-ev, .am-month-more { display: none; }
}

/* ==========================================================================
   Overview: momentum heatmap + focus-today ring
   ========================================================================== */
.am-heat-scroll { overflow-x: auto; padding-bottom: 4px; }
/* Grid fills the card width; grid-template-columns is set inline from the week count. */
.am-heat-cols { display: grid; gap: 3px; width: 100%; }
.am-heat-col { display: flex; flex-direction: column; gap: 3px; }
.am-heat-cell { width: 100%; height: auto; aspect-ratio: 1; border-radius: 3px; background: color-mix(in srgb, var(--ink) 7%, transparent); }
.am-heat-cell.is-future { background: transparent; }
.am-heat-cell.lvl-0 { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.am-heat-cell.lvl-1 { background: color-mix(in srgb, var(--accent) 32%, transparent); }
.am-heat-cell.lvl-2 { background: color-mix(in srgb, var(--accent) 56%, transparent); }
.am-heat-cell.lvl-3 { background: color-mix(in srgb, var(--accent) 80%, transparent); }
.am-heat-cell.lvl-4 { background: var(--accent); }
.am-heat-legend { display: flex; align-items: center; gap: 4px; margin-top: 0.75rem; font-size: 0.72rem; color: var(--ink-muted); }
.am-heat-legend .am-heat-cell { width: 11px; height: 11px; }

.am-focustoday-row { display: flex; align-items: center; gap: 1.1rem; }
.am-focustoday-ring { position: relative; width: 92px; height: 92px; flex: none; }
.am-focustoday-ring svg { width: 100%; height: 100%; }
.am-ft-track { fill: none; stroke: var(--hairline); stroke-width: 7; }
.am-ft-prog { fill: none; stroke: var(--accent); stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset 0.6s var(--am-ease); }
.am-focustoday-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.am-focustoday-center strong { font-size: 1.3rem; font-weight: 700; color: var(--ink); }
.am-focustoday-center span { font-size: 0.68rem; color: var(--ink-muted); margin-top: 2px; }
.am-focustoday-meta { min-width: 0; }

/* ==========================================================================
   Library: filter panel, topic picker, paper record
   ========================================================================== */
.am-filter-count {
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 0.15rem;
  display: inline-grid; place-items: center;
  border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 0.7rem; font-weight: 700; line-height: 1;
}
.am-filterpanel {
  border: 1px solid var(--hairline); border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  padding: 0.9rem 1rem; margin-bottom: 0.85rem;
  display: flex; flex-direction: column; gap: 0.9rem;
}
.am-filter-sec { display: flex; flex-direction: column; gap: 0.5rem; }
.am-filter-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.am-filter-label { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-muted); }
.am-filter-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; max-height: 168px; overflow-y: auto; }
.am-filter-chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font: inherit; font-size: 0.8rem; font-weight: 500; line-height: 1.2;
  padding: 0.3rem 0.65rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--hairline); background: var(--surface); color: var(--ink-secondary);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.am-filter-chip:hover { border-color: var(--baseline); color: var(--ink); }
.am-filter-chip.is-on { background: var(--accent-wash); border-color: var(--accent); color: var(--accent-strong); }
.am-filter-chip-n { font-size: 0.7rem; font-weight: 700; opacity: 0.6; }
.am-filter-foot { display: flex; gap: 0.5rem; justify-content: flex-end; border-top: 1px solid var(--hairline); padding-top: 0.75rem; }
.am-segment.am-seg-sm button { padding: 0.22rem 0.6rem; font-size: 0.76rem; }

.am-activefilters { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-bottom: 1rem; }
.am-activechip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font: inherit; font-size: 0.78rem; font-weight: 500; line-height: 1.2;
  padding: 0.28rem 0.5rem 0.28rem 0.65rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent-wash); color: var(--accent-strong);
}
.am-activechip .am-ico { opacity: 0.7; }
.am-activechip:hover .am-ico { opacity: 1; }

.am-paper-card { cursor: pointer; }
.am-paper-titlebtn { font: inherit; color: var(--ink); text-align: left; background: none; border: 0; padding: 0; width: 100%; cursor: pointer; }
.am-paper-titlebtn:hover { color: var(--accent-strong); }
.am-paper-titlebtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.am-tag-quiet { background: var(--surface-muted, var(--surface)); color: var(--ink-muted); }

/* Topic picker (tag input with type-ahead over the library's vocabulary) */
.am-tagfield-wrap { position: relative; }
.am-tagfield {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem;
  min-height: 42px; padding: 0.32rem 0.45rem;
  border: 1px solid var(--hairline); border-radius: 10px; background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.am-tagfield:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.am-tagfield-chips { display: contents; }
.am-tagchip {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.78rem; font-weight: 500; padding: 0.2rem 0.3rem 0.2rem 0.6rem;
  border-radius: 999px; background: var(--accent-wash); color: var(--accent-strong);
}
.am-tagchip-x {
  display: inline-grid; place-items: center; width: 16px; height: 16px;
  border: 0; border-radius: 50%; padding: 0; cursor: pointer;
  background: transparent; color: inherit; opacity: 0.65;
}
.am-tagchip-x:hover { opacity: 1; background: color-mix(in srgb, var(--accent) 22%, transparent); }
.am-tagfield-input { flex: 1; min-width: 140px; border: 0; background: transparent; font: inherit; font-size: 0.9rem; color: var(--ink); padding: 0.32rem 0.25rem; outline: none; }
.am-tagfield-input::placeholder { color: var(--ink-muted); }
.am-tagmenu {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 216px; overflow-y: auto; padding: 0.25rem;
  border: 1px solid var(--hairline); border-radius: 10px;
  background: var(--surface-raised); box-shadow: var(--shadow);
}
.am-tagmenu[hidden] { display: none; }
.am-tagmenu-item {
  display: flex; align-items: center; gap: 0.4rem; width: 100%; text-align: left;
  font: inherit; font-size: 0.85rem; color: var(--ink);
  border: 0; border-radius: 8px; background: transparent; padding: 0.42rem 0.55rem; cursor: pointer;
}
.am-tagmenu-item:hover, .am-tagmenu-item.is-active { background: var(--accent-wash); color: var(--accent-strong); }
.am-tagmenu-item.is-new { color: var(--ink-secondary); font-style: italic; }

/* Paper record (detail modal) */
.am-detail { display: flex; flex-direction: column; gap: 0.85rem; }
.am-detail-title { margin: 0; font-size: 1.22rem; line-height: 1.3; color: var(--ink); }
.am-detail-authors { margin: -0.45rem 0 0; font-size: 0.86rem; color: var(--ink-muted); }
.am-detail-status { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.am-detail-status .chip { cursor: pointer; border: 1px solid transparent; opacity: 0.5; font-family: inherit; font-size: 0.75rem; font-weight: 600; }
.am-detail-status .chip:hover { opacity: 0.85; }
.am-detail-status .chip[aria-pressed="true"] { opacity: 1; border-color: currentColor; }
.am-detail-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.35rem 1rem;
  border-top: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline); padding: 0.7rem 0;
}
.am-detail-meta-row { display: flex; gap: 0.5rem; font-size: 0.82rem; min-width: 0; }
.am-detail-meta-k { color: var(--ink-muted); flex: none; min-width: 74px; }
.am-detail-meta-v { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-detail-sec { display: flex; flex-direction: column; gap: 0.4rem; }
.am-detail-label { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-muted); }
.am-detail-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.am-detail-abs { margin: 0; font-size: 0.9rem; line-height: 1.6; color: var(--ink-secondary); white-space: pre-wrap; }
.am-detail-ai { border-left: 2px solid var(--accent); padding-left: 0.6rem; }
.am-detail-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; border-top: 1px solid var(--hairline); padding-top: 0.85rem; }
@media (max-width: 560px) {
  .am-detail-actions .btn { flex: 1 1 auto; justify-content: center; }
}

/* ==========================================================================
   Writing: Markdown modes + live preview
   ========================================================================== */
.am-editor-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.5rem 0.6rem 0; }
.am-editor-head-actions { display: flex; align-items: center; gap: 0.4rem; }
.am-editor-modeseg button { font-size: 0.8rem; padding: 0.3rem 0.7rem; }
.am-editor-panes { display: block; }
.am-editor-panes.is-split { display: grid; grid-template-columns: 1fr 1fr; }
.am-editor-panes.is-split .am-editor-body { border-right: 1px solid var(--hairline); }
.am-editor-preview {
  padding: 1.1rem 1.3rem 1.5rem; font-family: var(--serif); font-size: 1.05rem;
  line-height: 1.75; color: var(--ink); overflow-y: auto; min-height: 46vh;
}
.am-editor-panes.is-split .am-editor-preview, .am-editor-panes.is-split .am-editor-body { max-height: 62vh; }

/* ---- Focus mode: distraction-free full-window writing -------------------- */
/* The editor card lifts out of the layout and fills the viewport. body.am-zen
   drops the .am-page fade so its transient transform can't turn this fixed
   card into a clipped, offset box (a transformed ancestor is a containing
   block for fixed descendants). Chrome underneath is simply covered. */
body.am-zen { overflow: hidden; }
body.am-zen .am-page { animation: none; }
.am-editor.is-zen {
  position: fixed;
  inset: 0;
  z-index: 150;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  animation: am-fade 0.2s var(--am-ease) both;
}
.am-editor.is-zen .am-editor-panes { flex: 1 1 auto; min-height: 0; }
.am-editor.is-zen .am-editor-panes:not(.is-split) { display: flex; flex-direction: column; }
.am-editor.is-zen .am-editor-panes.is-split { display: grid; grid-template-rows: minmax(0, 1fr); }
.am-editor.is-zen .am-editor-body,
.am-editor.is-zen .am-editor-preview {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}
.am-editor-preview h1 { font-size: 1.6rem; margin: 0 0 0.6rem; }
.am-editor-preview h2 { font-size: 1.3rem; margin: 1.2rem 0 0.5rem; }
.am-editor-preview h3 { font-size: 1.1rem; margin: 1rem 0 0.4rem; }
.am-editor-preview p { margin: 0 0 0.9rem; }
.am-editor-preview ul, .am-editor-preview ol { margin: 0 0 0.9rem 1.2rem; padding: 0; }
.am-editor-preview li { margin: 0.2rem 0; }
.am-editor-preview blockquote { margin: 0 0 0.9rem; padding: 0.35rem 0 0.35rem 1rem; border-left: 3px solid var(--accent); color: var(--ink-secondary); }
.am-editor-preview code { font-family: var(--mono); font-size: 0.9em; background: var(--accent-wash); padding: 0.1em 0.35em; border-radius: 5px; }
.am-editor-preview a { color: var(--accent-strong); }
/* [[Wiki links]] are <a role=link tabindex=0> (no href): Enter opens them. */
.am-wikilink:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
@media (max-width: 760px) {
  .am-editor-panes.is-split { grid-template-columns: 1fr; }
  .am-editor-panes.is-split .am-editor-body { border-right: 0; border-bottom: 1px solid var(--hairline); }
}
@media (max-width: 600px) {
  .am-editor-title { font-size: 1.35rem; padding: 0.9rem 1rem 0.35rem; }
  .am-editor-body,
  .am-editor-preview { padding-inline: 1rem; }
  .am-editor-head { flex-wrap: wrap; }
}

/* Grade buttons show the next interval underneath */
.am-gradebtn { flex-direction: column; gap: 1px; min-width: 84px; padding-top: 0.5rem; padding-bottom: 0.5rem; line-height: 1.15; }
.am-grade-when { display: block; font-size: 0.68rem; font-weight: 500; opacity: 0.8; }

/* Nav due badge */
.am-nav-badge {
  margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--phase-3); color: #fff;
  font-size: 0.68rem; font-weight: 700; display: inline-grid; place-items: center;
}
.am-sidebar.is-compact .am-nav-badge { position: absolute; top: 4px; right: 6px; margin: 0; min-width: 15px; height: 15px; font-size: 0.6rem; }
.am-tab .am-tab-dot { position: absolute; top: 8px; margin-left: 16px; width: 7px; height: 7px; border-radius: 50%; background: var(--phase-3); }

/* ==========================================================================
   Mobile: bottom tab bar + more sheet
   ========================================================================== */
.am-tabbar { display: none; }
.am-sheet { display: none; }

@media (max-width: 900px) {
  .am-sidebar { display: none; }
  .am-content { padding-bottom: calc(var(--am-tabbar-h) + env(safe-area-inset-bottom, 0px)); }
  .am-composer { padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px)); }

  .am-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    height: calc(var(--am-tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--page) 92%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--hairline);
  }
  .am-tab {
    position: relative;
    flex: 1;
    border: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px;
    color: var(--ink-muted);
    font-size: 0.66rem;
    font-weight: 600;
    cursor: pointer;
  }
  .am-tab[aria-current="page"] { color: var(--accent-strong); }
  .am-tab .am-ico { width: 22px; height: 22px; color: var(--nav-clr, currentColor); }

  /* Bottom sheet for "More" */
  .am-sheet {
    position: fixed;
    inset: 0;
    z-index: 130;
    display: flex;
    align-items: flex-end;
    background: var(--overlay, rgba(11,11,11,.42));
    backdrop-filter: blur(2px);
    animation: am-fade 0.15s ease both;
  }
  .am-sheet-panel {
    width: 100%;
    background: var(--surface-raised);
    border-radius: 20px 20px 0 0;
    border-top: 1px solid var(--hairline);
    padding: 0.6rem 0.9rem calc(1rem + env(safe-area-inset-bottom, 0px));
    box-shadow: var(--am-shadow-pop);
    animation: am-sheet-up 0.28s var(--am-ease) both;
  }
  @keyframes am-sheet-up { from { transform: translateY(100%); } to { transform: none; } }
  .am-sheet-grab { width: 40px; height: 4px; border-radius: 999px; background: var(--baseline); margin: 0.4rem auto 0.8rem; }
  .am-sheet-item { display: flex; align-items: center; gap: 0.85rem; padding: 0.8rem 0.6rem; border-radius: 12px; color: var(--ink); cursor: pointer; border: 0; background: transparent; width: 100%; text-align: left; font-size: 0.98rem; }
  .am-sheet-item:hover, .am-sheet-item[aria-current="page"] { background: var(--accent-wash); color: var(--accent-strong); }
  .am-sheet-item .am-ico { color: var(--nav-clr, currentColor); flex: none; }

  .am-toasts { left: 1rem; right: 1rem; bottom: calc(var(--am-tabbar-h) + 0.8rem + env(safe-area-inset-bottom, 0px)); max-width: none; }
  .am-topbar { padding-inline: 1rem; }
  .am-topbar-title { font-size: 1.15rem; }
  .am-searchbtn .am-searchbtn-txt, .am-searchbtn .am-kbd { display: none; }
  .am-searchbtn { width: 36px; padding: 0; justify-content: center; }
  .am-page-title { font-size: 1.55rem; }
}

/* Coarse pointers: hover shouldn't stick */
@media (hover: none) {
  .am-card-hover:hover { box-shadow: none; border-color: var(--hairline); }
}

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

/* User-toggled "interface animations off" (Settings). */
.am-no-anim #amadeus-root *,
.am-no-anim #amadeus-root *::before,
.am-no-anim #amadeus-root *::after,
.am-no-anim .am-overlay, .am-no-anim .am-sheet, .am-no-anim .am-toast {
  animation: none !important;
  transition: none !important;
}

/* ======================================================================
   Analysis tab — reading + focus analytics (native SVG, theme-aware)
   ====================================================================== */
.am-focus-tagrow { display: flex; align-items: center; gap: 0.5rem; width: 100%; max-width: 320px; margin: 0.1rem auto 0; }
.am-focus-taglabel { display: inline-flex; color: var(--ink-muted); flex-shrink: 0; }
.am-focus-tag { flex: 1; height: 34px; padding: 0 0.6rem; font-size: 0.86rem; }

.am-anl-toolbar { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.am-anl-toolbar-lbl { font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); }

.am-anl-grid { display: grid; gap: 1.1rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.am-anl-grid .is-full { grid-column: 1 / -1; }
@media (max-width: 780px) { .am-anl-grid { grid-template-columns: 1fr; } .am-anl-grid .is-full { grid-column: auto; } }

.am-anl-card { display: flex; flex-direction: column; gap: 0.5rem; }
.am-anl-sub { font-size: 0.78rem; letter-spacing: 0; text-transform: none; font-weight: 500; color: var(--ink-muted); }

/* SVG chart primitives */
.am-anl-svg { width: 100%; height: auto; display: block; margin-top: 0.35rem; }
.am-anl-gl { stroke: var(--gridline, var(--hairline)); stroke-width: 1; }
.am-anl-ax { fill: var(--ink-muted); font-size: 11px; font-family: var(--sans); }
.am-anl-goal { stroke: var(--ink-muted); stroke-width: 1.4; stroke-dasharray: 4 4; opacity: 0.75; }
.am-anl-goal-t { fill: var(--ink-muted); font-size: 10.5px; font-family: var(--sans); }
.am-anl-area { opacity: 0.16; stroke: none; }
.am-anl-lp { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.am-anl-dot { stroke: var(--surface); stroke-width: 1.5; }
.am-anl-seg { transition: opacity 0.15s var(--am-ease); }
.am-anl-seg:hover { opacity: 0.82; }

/* Donut */
.am-anl-donut { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.am-anl-donut-chart { position: relative; width: 168px; max-width: 46%; flex-shrink: 0; }
.am-anl-donut-svg { margin-top: 0; }
.am-anl-donut-track { stroke: color-mix(in srgb, var(--ink) 9%, transparent); }
.am-anl-donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.am-anl-donut-center strong { font-size: 1.35rem; font-weight: 700; color: var(--ink); line-height: 1; }
.am-anl-donut-center span { font-size: 0.72rem; color: var(--ink-muted); margin-top: 2px; }

/* Legend */
.am-anl-legend { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; min-width: 130px; }
.am-anl-donut .am-anl-legend { flex-direction: column; }
.am-anl-leg { display: flex; align-items: center; gap: 0.45rem; font-size: 0.82rem; color: var(--ink-secondary, var(--ink)); }
.am-anl-swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.am-anl-leg-lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-anl-leg-val { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.am-anl-card > .am-anl-legend { flex-direction: row; flex-wrap: wrap; gap: 0.4rem 1rem; margin-top: 0.4rem; }
.am-anl-card > .am-anl-legend .am-anl-leg { flex: 0 0 auto; }

/* Horizontal bar list */
.am-anl-bars { display: flex; flex-direction: column; gap: 0.55rem; margin-top: 0.35rem; }
.am-anl-bar { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 0.6rem; }
.am-anl-bar-label { font-size: 0.8rem; color: var(--ink-secondary, var(--ink)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-anl-bar-track { height: 9px; border-radius: 5px; background: color-mix(in srgb, var(--ink) 7%, transparent); overflow: hidden; }
.am-anl-bar-fill { display: block; height: 100%; border-radius: 5px; min-width: 2px; transition: width 0.4s var(--am-ease); }
.am-anl-bar-val { font-size: 0.8rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }

.am-anl-mini-empty { font-size: 0.85rem; color: var(--ink-muted); padding: 1.4rem 0.4rem; text-align: center; }

/* Calendar month labels row (aligns with .am-heat-cols) */
.am-heat-months { margin-bottom: 3px; }
.am-heat-mo { font-size: 0.66rem; color: var(--ink-muted); line-height: 1; overflow: visible; white-space: nowrap; }

/* ======================================================================
   Notes + Journal (Markdown notes, daily journal with moods)
   ====================================================================== */

/* Markdown code blocks + images (Writing / Notes / Journal previews) */
.am-editor-preview pre.am-md-code { margin: 0 0 0.9rem; padding: 0.8rem 0.95rem; background: color-mix(in srgb, var(--ink) 5%, var(--surface)); border: 1px solid var(--hairline); border-radius: 10px; overflow-x: auto; }
.am-editor-preview pre.am-md-code code { display: block; font-family: var(--mono); font-size: 0.86rem; line-height: 1.55; background: none; padding: 0; color: var(--ink); white-space: pre; }
.am-editor-preview .am-md-img { max-width: 100%; height: auto; border-radius: 10px; margin: 0.2rem 0 0.9rem; display: block; border: 1px solid var(--hairline); }
.am-editor-preview del { color: var(--ink-muted); }
.am-editor-preview u { text-decoration-color: var(--accent); text-underline-offset: 2px; }
.am-editor-preview hr { border: 0; border-top: 1px solid var(--hairline); margin: 1.4rem 0; }
/* "or link to one" divider inside the insert-image dialog. */
.am-or-sep { display: flex; align-items: center; gap: 0.6rem; margin: 0.9rem 0 0.6rem; font-size: 0.76rem; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.am-or-sep::before, .am-or-sep::after { content: ""; flex: 1; height: 1px; background: var(--hairline); }
/* arXiv provenance line on a library card (published · version · category). */
.am-paper-meta { font-size: 0.76rem; color: var(--ink-muted); margin: 0.15rem 0 0; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.am-editor-preview hr { border: 0; border-top: 1px solid var(--hairline); margin: 1.2rem 0; }

/* Notes list */
.am-note-search { margin: 0.6rem 0; }
.am-note-tags { margin-bottom: 0.1rem; font-size: 0.85rem; }

/* Journal layout */
.am-journal { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); align-items: start; }
@media (max-width: 900px) { .am-journal { grid-template-columns: 1fr; } }
.am-journal-side { display: flex; flex-direction: column; gap: 1.25rem; }
.am-journal-nav { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.am-journal-nav .am-iconbtn[disabled] { opacity: 0.4; pointer-events: none; }
.am-journal-date { width: auto; max-width: 170px; }
.am-journal-dow { font-weight: 700; font-size: 1.02rem; color: var(--ink); margin-right: auto; }
.am-journal-edithead { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin: 1rem 0 0.5rem; flex-wrap: wrap; }
.am-journal-body { min-height: 220px; }

/* Mood picker */
.am-mood-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.6rem 0 0.2rem; }
.am-mood { --mood: var(--accent); display: inline-flex; flex-direction: column; align-items: center; gap: 0.15rem; min-width: 62px; padding: 0.5rem 0.55rem; border: 1px solid var(--hairline); border-radius: 12px; background: var(--surface); cursor: pointer; transition: transform 0.12s var(--am-ease), border-color 0.12s var(--am-ease), background 0.12s var(--am-ease); }
.am-mood:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--mood) 55%, var(--hairline)); }
.am-mood.is-active { border-color: var(--mood); background: color-mix(in srgb, var(--mood) 14%, transparent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--mood) 30%, transparent); }
.am-mood-emoji { font-size: 1.5rem; line-height: 1; }
.am-mood-label { font-size: 0.72rem; color: var(--ink-secondary); }

/* Recent-moods strip (last 14 days) */
.am-mood-strip { display: flex; gap: 0.4rem; overflow-x: auto; padding-bottom: 4px; }
.am-mood-cell { --mood: var(--ink-muted); flex: 0 0 auto; width: 40px; display: flex; flex-direction: column; align-items: center; gap: 0.15rem; padding: 0.4rem 0; border: 1px solid var(--hairline); border-radius: 10px; background: color-mix(in srgb, var(--mood) 12%, transparent); cursor: pointer; }
.am-mood-cell:hover { border-color: color-mix(in srgb, var(--mood) 55%, var(--hairline)); }
.am-mood-cell.is-current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-wash); }
.am-mood-cell-emoji { font-size: 1.1rem; line-height: 1; }
.am-mood-cell-day { font-size: 0.66rem; color: var(--ink-muted); }

/* ==========================================================================
   Native shell + touch polish
   Scoped so the desktop web build is untouched: `html.am-native` is set only
   by the Capacitor Android shell, and the rest is plain mobile hygiene that
   already only applies to small/coarse-pointer screens.
   ========================================================================== */

html { -webkit-text-size-adjust: 100%; }
/* Android paints a grey box over every tap; the studio has its own :active
   feedback, so suppress it inside the app shell only. */
#amadeus-root, .am-overlay, .am-sheet, .am-toasts { -webkit-tap-highlight-color: transparent; }

/* Don't make a tap wait ~300ms for a double-tap that would do nothing. */
.am-tab, .am-sheet-item, .am-nav-item, .am-iconbtn, .am-tinybtn, .am-searchbtn,
.am-focus-chip, .am-sync-chip, .am-userchip, .btn, .am-switch, .am-segment button {
  touch-action: manipulation;
}

/* App chrome is furniture, not content — a long-press shouldn't select it.
   Deliberately excludes the content area so papers/notes stay selectable. */
.am-tabbar, .am-sidebar, .am-topbar, .am-sheet-grab, .am-segment { -webkit-user-select: none; user-select: none; }

/* Keep momentum scrolling, but stop a pane that has hit its end from dragging
   the page (or firing pull-to-refresh) behind it. */
.am-scroll, .am-content { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

@media (max-width: 900px) {
  /* 0.35s reads as lag on a phone — keep the same motion, just snappier. */
  .am-page { animation-duration: 0.24s; }

  /* Immediate physical feedback, since there's no hover state to lean on. */
  .am-tab { transition: transform 0.12s var(--am-ease), color 0.12s ease; min-height: 44px; }
  .am-tab:active { transform: scale(0.93); }
  .am-sheet-item:active { background: var(--accent-wash); color: var(--accent-strong); }
  .btn:active, .am-iconbtn:active, .am-tinybtn:active { transform: scale(0.97); }

  /* Accessible touch targets + readable fields that don't trigger focus-zoom. */
  .btn { min-height: 42px; }
  .am-input, .am-textarea, .am-select { font-size: 1rem; }
}

/* ---- Capacitor build only --------------------------------------------- */
/* No physical keyboard to hint at. */
html.am-native .am-kbd { display: none; }
/* Defensive: a no-op while the status bar is its own (non-overlaid) strip,
   but self-correcting if the shell ever renders edge-to-edge. */
html.am-native .am-topbar {
  height: calc(var(--am-topbar-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
}
/* Native scrolling shouldn't rubber-band the whole document. */
html.am-native, html.am-native body { overscroll-behavior: none; height: 100%; }
/* Keyboard open (native): the tab bar would otherwise float above the
   keyboard and eat editor space, so it steps out of the way. */
html.am-kb-open .am-tabbar { display: none; }
html.am-kb-open .am-content { padding-bottom: 0.75rem; }
html.am-kb-open .am-toasts { bottom: 0.9rem; }
