:root {
  color-scheme: light;
  --aiwa-brand: #137a3d;
  --aiwa-brand-dark: #0e6230;
  --aiwa-brand-soft: #eaf7ee;
  --aiwa-ink: #17211b;
  --aiwa-text: #344039;
  --aiwa-muted: #526057;
  --aiwa-bg: #f7f9f7;
  --aiwa-card: #ffffff;
  --aiwa-line: #d9e1dc;
  --aiwa-line-strong: #a7afa9;
  --aiwa-danger: #b42318;
  --aiwa-warning: #9a4d0c;
  --aiwa-focus: #2563eb;
  --aiwa-radius-sm: 8px;
  --aiwa-radius-md: 12px;
  --aiwa-radius-lg: 16px;
  --aiwa-shadow-low: 0 8px 24px rgba(23, 33, 27, 0.08);
  --aiwa-shadow-high: 0 18px 48px rgba(23, 33, 27, 0.14);
  --aiwa-page: min(1180px, calc(100% - 40px));
  --aiwa-ease: cubic-bezier(0.2, 0, 0, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--aiwa-bg);
  color: var(--aiwa-ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.aiwa-menu-open { overflow: hidden; }
img, svg { display: block; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

:where(a, button, input, textarea, select, summary):focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.32);
  outline-offset: 2px;
}

.aiwa-skip-link {
  position: fixed;
  z-index: 100000;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: var(--aiwa-radius-sm);
  background: var(--aiwa-ink);
  color: #fff;
  text-decoration: none;
  transform: translateY(-150%);
}
.aiwa-skip-link:focus { transform: translateY(0); }

.aiwa-site-header,
.topbar.aiwa-site-header,
.topbar {
  position: sticky;
  z-index: 100;
  top: 0;
  width: 100%;
  border-bottom: 1px solid var(--aiwa-line);
  background: rgba(255, 255, 255, 0.96);
}
.aiwa-header-inner {
  width: var(--aiwa-page) !important;
  max-width: 1180px !important;
  min-height: 64px;
  height: auto !important;
  margin: 0 auto !important;
  padding: 10px 0 !important;
  display: flex;
  align-items: center;
  gap: 22px;
}
.aiwa-site-brand {
  display: inline-flex;
  min-width: max-content;
  align-items: center;
  gap: 10px;
  color: var(--aiwa-ink);
  font-size: 16px;
  font-weight: 760;
  letter-spacing: -0.025em;
  text-decoration: none;
}
.aiwa-site-logo { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; }
.aiwa-menu-toggle {
  display: none;
  width: 42px;
  height: 42px;
  margin-left: auto;
  place-items: center;
  border: 1px solid var(--aiwa-line);
  border-radius: 10px;
  background: #fff;
  color: var(--aiwa-ink);
  cursor: pointer;
}
.aiwa-menu-toggle svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; }
.aiwa-main-nav {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0 !important;
}
.aiwa-main-nav a {
  padding: 9px 11px;
  border-radius: 9px;
  color: var(--aiwa-text);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}
.aiwa-main-nav a:hover { background: var(--aiwa-brand-soft); color: var(--aiwa-brand-dark); }
.aiwa-main-nav a.active,
.aiwa-main-nav a[aria-current="page"] { background: var(--aiwa-brand-soft); color: var(--aiwa-brand-dark); }
.aiwa-header-profile-zone { min-width: 178px; display: flex; justify-content: flex-end; }
.aiwa-tool-status-hidden { display: none !important; }
.aiwa-header-profile-zone:not(.aiwa-auth-ready) .aiwa-profile-fallback { visibility: hidden; }
.aiwa-profile-fallback,
.aiwa-profile-summary {
  min-width: 174px;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 9px 4px 5px;
  border: 1px solid var(--aiwa-line);
  border-radius: 12px;
  background: #fff;
  color: var(--aiwa-ink);
  cursor: pointer;
}
.aiwa-profile-summary:hover { border-color: var(--aiwa-line-strong); background: var(--aiwa-bg); }
.aiwa-profile-menu { position: relative; }
.aiwa-profile-menu > summary { list-style: none; }
.aiwa-profile-menu > summary::-webkit-details-marker { display: none; }
.aiwa-profile-shell { display: flex; align-items: center; gap: 8px; }
.aiwa-avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 9px;
  background: var(--aiwa-brand-soft);
  color: var(--aiwa-brand-dark);
  font-size: 11px;
  font-weight: 800;
}
.aiwa-avatar.guest { background: #eef2ef; color: var(--aiwa-text); }
.aiwa-avatar.pro { background: var(--aiwa-brand); color: #fff; }
.aiwa-avatar img { width: 100%; height: 100%; object-fit: cover; }
.aiwa-profile-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.1; }
.aiwa-profile-text b { max-width: 140px; overflow: hidden; color: var(--aiwa-ink); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.aiwa-profile-text small { max-width: 140px; margin-top: 3px; overflow: hidden; color: var(--aiwa-muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.aiwa-chevron { margin-left: auto; color: var(--aiwa-muted); }
.aiwa-profile-menu[open] .aiwa-chevron { transform: rotate(180deg); }
.aiwa-profile-dropdown {
  position: absolute;
  z-index: 1000;
  top: calc(100% + 8px);
  right: 0;
  width: min(340px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid var(--aiwa-line);
  border-radius: var(--aiwa-radius-lg);
  background: #fff;
  box-shadow: var(--aiwa-shadow-low);
}
.aiwa-dropdown-top { display: flex; align-items: center; gap: 11px; padding-bottom: 12px; border-bottom: 1px solid var(--aiwa-line); }
.aiwa-dropdown-name { font-size: 14px; font-weight: 750; }
.aiwa-dropdown-email { margin-top: 2px; color: var(--aiwa-muted); font-size: 12px; overflow-wrap: anywhere; }
.aiwa-pill-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.aiwa-plan-pill, .aiwa-ad-pill {
  padding: 6px 9px;
  border: 1px solid #b9ddc4;
  border-radius: 8px;
  background: var(--aiwa-brand-soft);
  color: var(--aiwa-brand-dark);
  font-size: 11px;
  font-weight: 700;
}
.aiwa-ad-pill.ads-on { border-color: #f6c899; background: #fff7ed; color: var(--aiwa-warning); }
.aiwa-profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.aiwa-profile-stat { padding: 10px; border: 1px solid var(--aiwa-line); border-radius: 10px; background: var(--aiwa-bg); }
.aiwa-profile-stat b { display: block; font-size: 13px; }
.aiwa-profile-stat span { display: block; margin-top: 3px; color: var(--aiwa-muted); font-size: 10px; }
.aiwa-dropdown-actions { display: grid; gap: 8px; }
.aiwa-drop-btn, .aiwa-btn, .aiwa-form-btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border: 1px solid var(--aiwa-line);
  border-radius: 10px;
  background: #fff;
  color: var(--aiwa-ink);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.aiwa-drop-btn:hover, .aiwa-btn:hover { background: var(--aiwa-bg); }
.aiwa-drop-btn.primary, .aiwa-drop-btn.annual, .aiwa-btn.primary, .aiwa-form-btn {
  border-color: var(--aiwa-brand);
  background: var(--aiwa-brand);
  color: #fff;
}
.aiwa-drop-btn.primary:hover, .aiwa-drop-btn.annual:hover, .aiwa-btn.primary:hover, .aiwa-form-btn:hover { border-color: var(--aiwa-brand-dark); background: var(--aiwa-brand-dark); }
.aiwa-drop-btn.danger { border-color: #f1b7b2; color: var(--aiwa-danger); }
.aiwa-profile-legal { display: flex; justify-content: center; gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--aiwa-line); }
.aiwa-profile-legal a { color: var(--aiwa-muted); font-size: 12px; font-weight: 650; text-decoration: none; }

.site-footer-injected { margin-top: auto; border-top: 1px solid var(--aiwa-line); background: #fff; color: var(--aiwa-muted); }
.site-footer-injected .inner {
  width: var(--aiwa-page) !important;
  max-width: 1180px !important;
  margin: 0 auto !important;
  padding: 30px 0 !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.footer-brand { display: inline-flex; align-items: center; gap: 9px; color: var(--aiwa-ink); font-weight: 750; text-decoration: none; }
.footer-logo { width: 28px; height: 28px; border-radius: 8px; }
.footer-links { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 18px; }
.footer-links a { color: var(--aiwa-muted); font-size: 13px; font-weight: 600; text-decoration: none; }
.footer-links a:hover { color: var(--aiwa-brand-dark); text-decoration: underline; text-underline-offset: 3px; }

.aiwa-limit-modal { position: fixed; z-index: 10000; inset: 0; display: none; place-items: center; padding: 20px; background: rgba(23, 33, 27, 0.55); }
.aiwa-limit-modal.show { display: grid; }
.aiwa-limit-card { width: min(420px, 100%); padding: 24px; border-radius: var(--aiwa-radius-lg); background: #fff; box-shadow: var(--aiwa-shadow-high); text-align: center; }
.aiwa-limit-icon { width: 44px; height: 44px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 12px; background: var(--aiwa-brand-soft); color: var(--aiwa-brand-dark); font-weight: 800; }
.aiwa-limit-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 16px; }
.aiwa-limit-actions a, .aiwa-limit-actions button { min-height: 40px; padding: 9px 14px; border: 1px solid var(--aiwa-line); border-radius: 10px; background: #fff; color: var(--aiwa-ink); font-weight: 700; text-decoration: none; }
.aiwa-limit-actions .pro { border-color: var(--aiwa-brand); background: var(--aiwa-brand); color: #fff; }
.aiwa-debug, .aiwa-debug-btn, .debug-auth, [data-debug], #debugAuth, .debugAuth { display: none !important; }
.aiwa-hidden { display: none !important; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

@media (max-width: 860px) {
  :root { --aiwa-page: min(100% - 28px, 1180px); }
  .aiwa-header-inner { flex-wrap: wrap; gap: 8px 12px; }
  .aiwa-menu-toggle { display: grid; }
  .aiwa-main-nav {
    position: fixed;
    z-index: 120;
    inset: 65px 0 auto;
    display: none;
    max-height: calc(100vh - 65px);
    overflow: auto;
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
    border-bottom: 1px solid var(--aiwa-line);
    background: #fff;
    box-shadow: var(--aiwa-shadow-low);
  }
  .aiwa-main-nav[data-open="true"] { display: flex; }
  .aiwa-main-nav a { min-height: 44px; display: flex; align-items: center; padding: 10px 12px; }
  .aiwa-header-profile-zone { min-width: 0; }
  .aiwa-profile-summary, .aiwa-profile-fallback { min-width: 42px; width: 42px; padding: 4px; }
  .aiwa-profile-text, .aiwa-chevron { display: none; }
  .aiwa-profile-dropdown { right: -2px; }
  .site-footer-injected .inner { flex-direction: column; align-items: flex-start; }
  .footer-links { justify-content: flex-start; }
}

@media (max-width: 480px) {
  .aiwa-site-brand span { max-width: 155px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .aiwa-profile-grid { grid-template-columns: 1fr; }
}

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

/* Shared writing workspace shell */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 160ms; animation-timing-function: var(--aiwa-ease); }
.aiwa-ui-icon { width: 18px; height: 18px; flex: 0 0 18px; object-fit: contain; }
.aiwa-tool-header-inner { width: 100% !important; max-width: none !important; min-height: 64px; padding: 9px 20px !important; gap: 20px; }
.aiwa-tool-header-inner .aiwa-site-brand { font-size: 16px; }
.aiwa-tool-breadcrumb { min-width: 0; display: flex; align-items: center; gap: 10px; color: var(--aiwa-muted); font-size: 13px; white-space: nowrap; }
.aiwa-tool-breadcrumb a { text-decoration: none; }
.aiwa-tool-breadcrumb a:hover { color: var(--aiwa-brand-dark); }
.aiwa-tool-breadcrumb strong { max-width: 220px; overflow: hidden; color: var(--aiwa-ink); text-overflow: ellipsis; }
.aiwa-header-spacer { flex: 1; }
.aiwa-tool-header-inner .aiwa-header-profile-zone { min-width: 150px; }
.aiwa-tool-header-inner .aiwa-profile-summary, .aiwa-tool-header-inner .aiwa-profile-fallback { min-width: 150px; }
.aiwa-tool-header-inner .aiwa-profile-text small { display: none; }
.aiwa-header-upgrade { min-height: 42px; display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--aiwa-brand); border-radius: 10px; color: var(--aiwa-brand-dark); font-size: 13px; font-weight: 750; text-decoration: none; }
.aiwa-header-upgrade[hidden], .aiwa-pro-user .aiwa-header-upgrade { display: none !important; }
.aiwa-header-upgrade:hover { background: var(--aiwa-brand-soft); }
.aiwa-header-upgrade img { width: 17px; height: 17px; filter: invert(35%) sepia(70%) saturate(680%) hue-rotate(97deg) brightness(91%); }
.aiwa-tools-toggle { min-height: 42px; display: none; align-items: center; gap: 7px; padding: 8px 11px; border: 1px solid var(--aiwa-line); border-radius: 10px; background: #fff; color: var(--aiwa-ink); font-size: 12px; font-weight: 750; cursor: pointer; }
.aiwa-tools-toggle img { width: 18px; height: 18px; }

@media (max-width: 900px) {
  .aiwa-tool-header-inner { min-height: 56px; flex-wrap: nowrap; padding: 7px max(12px, env(safe-area-inset-right)) 7px max(12px, env(safe-area-inset-left)) !important; gap: 9px; }
  .aiwa-tool-header-inner .aiwa-site-logo { width: 32px; height: 32px; }
  .aiwa-tool-header-inner .aiwa-site-brand span { display: none; }
  .aiwa-tool-breadcrumb { flex: 1; }
  .aiwa-tool-breadcrumb a, .aiwa-tool-breadcrumb > span { display: none; }
  .aiwa-tool-breadcrumb strong { max-width: 170px; }
  .aiwa-header-spacer, .aiwa-header-upgrade { display: none; }
  .aiwa-tool-header-inner .aiwa-header-profile-zone { min-width: 42px; }
  .aiwa-tool-header-inner .aiwa-profile-summary, .aiwa-tool-header-inner .aiwa-profile-fallback { min-width: 42px; width: 42px; padding: 4px; }
  .aiwa-tools-toggle { display: inline-flex; }
}
@media (max-width: 420px) {
  .aiwa-tool-breadcrumb strong { max-width: 110px; font-size: 12px; }
  .aiwa-tools-toggle span { display: none; }
}
