:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #2f4f3e;
  --accent-soft: #f3f7f4;
  --danger: #8a3a3a;
  --danger-soft: #fff5f5;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.06);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100vw;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    sans-serif;
  letter-spacing: 0;
}

.file-mode-warning {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #fff;
}

.file-mode-card {
  width: min(520px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.file-mode-card h1 {
  margin-bottom: 12px;
  font-size: 30px;
}

.file-mode-card p {
  color: var(--muted);
  line-height: 1.7;
}

.file-mode-card a {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  text-decoration: none;
  font-weight: 800;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  margin: 0;
  max-width: 820px;
  font-size: 42px;
  line-height: 1.14;
  font-weight: 800;
}

h3 {
  margin-bottom: 10px;
  font-size: 22px;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  width: 100%;
  max-width: 100vw;
  min-height: 100vh;
  overflow-x: hidden;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: var(--panel-soft);
  color: var(--accent);
  font-weight: 800;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  text-transform: uppercase;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.nav-item.is-active {
  color: var(--ink);
  background: var(--panel-soft);
  border-color: var(--line);
  font-weight: 700;
}

.boundary-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.boundary-note strong {
  display: block;
  margin-bottom: 8px;
}

.boundary-note p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.content {
  min-width: 0;
  padding: 34px;
  background: #fff;
}

.section {
  display: none;
}

.section.is-active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.start-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.start-strip div {
  min-height: 58px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}

.start-strip strong {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
}

.start-strip span {
  color: #374151;
  font-weight: 700;
  line-height: 1.35;
}

.date-pill {
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
}

.heading-meta {
  flex: 0 0 auto;
  display: grid;
  gap: 8px;
  justify-items: end;
}

.community-pill {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.dashboard-grid,
.two-column,
.reading-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.surface,
.post-card,
.article-card,
.rule-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.surface-title {
  min-height: 56px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 800;
}

.today-panel,
.route-overview,
.composer,
.onboarding-card,
.reader,
.support-box {
  padding-bottom: 18px;
}

.onboarding-card {
  margin-bottom: 18px;
}

.identity-body {
  display: grid;
  gap: 14px;
  padding-top: 18px;
}

.identity-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 0 18px;
}

.identity-form label {
  margin: 0;
}

.identity-form .primary-action {
  margin: 0;
  min-width: 132px;
}

.session-card {
  margin: 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.session-card p {
  margin-bottom: 12px;
  color: #374151;
  line-height: 1.65;
}

.session-card .secondary-action {
  margin: 0;
}

.task-list {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.task-row {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.task-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.task-row strong {
  display: block;
  margin-bottom: 4px;
}

.task-row span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.primary-action,
.secondary-action {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  transition:
    transform 0.16s ease,
    background 0.16s ease;
}

.primary-action {
  min-height: 44px;
  margin: 0 18px;
  padding: 0 18px;
  color: #fff;
  background: var(--accent);
}

.secondary-action {
  min-height: 34px;
  padding: 0 12px;
  color: var(--accent);
  background: var(--accent-soft);
}

.primary-action:hover,
.secondary-action:hover {
  transform: translateY(-1px);
}

.quiet-text {
  margin: 12px 18px 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.steady-steps {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.steady-steps div {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.steady-steps strong {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font-size: 14px;
}

.steady-steps span {
  color: #374151;
  line-height: 1.6;
}

.route-mini {
  display: grid;
  gap: 9px;
  padding: 18px;
}

.route-mini span {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: #374151;
  font-weight: 700;
}

.composer {
  display: grid;
  gap: 14px;
}

.timeline-composer {
  gap: 0;
}

.composer-entry {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: start;
  padding: 16px 18px 12px;
}

.composer-avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--accent);
  font-weight: 800;
}

.composer-entry textarea {
  min-height: 116px;
  border-color: transparent;
  background: var(--panel-soft);
  resize: vertical;
}

.composer-entry textarea:focus {
  outline: 2px solid rgba(47, 79, 62, 0.18);
  border-color: var(--line-strong);
  background: #fff;
}

.composer-extra {
  display: grid;
  gap: 13px;
  padding: 0 18px 14px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chip-group > span {
  flex: 0 0 42px;
  color: var(--muted);
  font-size: 13px;
}

.chip {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #4b5563;
  font-size: 14px;
}

.chip.is-active {
  border-color: #c9d8cd;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.composer-extra label {
  margin: 0;
}

label {
  display: grid;
  gap: 8px;
  margin: 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.label-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 86px;
  padding: 12px;
  resize: vertical;
  line-height: 1.55;
}

.warning {
  margin: 0 18px;
  padding: 12px;
  border: 1px solid #efcaca;
  border-radius: 8px;
  color: var(--danger);
  background: var(--danger-soft);
  line-height: 1.55;
}

.compact-warning {
  margin: 12px 0 0;
  font-size: 13px;
}

.feed-column {
  display: grid;
  gap: 12px;
}

.comment-rule {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: #374151;
  line-height: 1.6;
}

.feed {
  display: grid;
  gap: 12px;
}

.feed-status {
  padding: 14px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  line-height: 1.6;
}

.post-card {
  overflow: hidden;
}

.post-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.post-header strong {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
}

.post-meta,
.comment-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.post-tag {
  flex: 0 0 auto;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: #4b5563;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.post-body {
  padding: 16px;
}

.post-main-text {
  color: var(--ink);
  font-size: 16px;
  white-space: pre-wrap;
}

.post-detail-list {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.post-body p {
  margin-bottom: 9px;
  line-height: 1.65;
}

.post-body .field {
  display: inline-block;
  margin-right: 6px;
  color: var(--muted);
  font-size: 13px;
}

.reaction-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  padding: 0 16px 16px;
}

.reaction-row button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid #eadfd5;
  border-radius: 999px;
  background: #fffaf6;
  color: #374151;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(17, 24, 39, 0.04);
}

.reaction-row button.is-active {
  border-color: #d8b99b;
  background: #fff1e6;
  color: #6b4b31;
  font-weight: 700;
}

.post-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 16px 14px;
  justify-content: flex-end;
}

.text-action {
  min-height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.danger-action {
  color: var(--danger);
}

.comment-list {
  display: grid;
  gap: 8px;
  padding: 0 16px 14px;
}

.comment {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--panel-soft);
  color: #4b5563;
  line-height: 1.55;
}

.comment .text-action {
  margin-top: 8px;
}

.comment-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 0 16px 16px;
}

.comment-form input {
  height: 38px;
}

.comment-form button {
  margin: 0;
  min-height: 38px;
}

.admin-actions {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.admin-actions .secondary-action {
  margin: 0;
}

.article-grid,
.rules-grid {
  display: grid;
  gap: 12px;
}

.article-card,
.rule-card {
  padding: 18px;
}

.article-card {
  text-align: left;
  cursor: pointer;
}

.article-card h3,
.rule-card h3 {
  margin: 0 0 8px;
  font-size: 20px;
}

.article-card p,
.rule-card p,
.reader p,
.support-box p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.75;
}

.article-card:nth-child(3n + 1) {
  border-left: 4px solid var(--accent);
}

.article-card:nth-child(3n + 2) {
  border-left: 4px solid #64748b;
}

.article-card:nth-child(3n) {
  border-left: 4px solid #9ca3af;
}

.reader {
  padding: 24px;
}

.reader h3 {
  font-size: 28px;
}

.rules-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
}

.rule-card {
  background: var(--panel-soft);
  box-shadow: none;
}

.support-box p {
  padding: 18px;
}

#ai.section.is-active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.ai-panel {
  width: min(780px, 100%);
  min-height: min(720px, calc(100vh - 172px));
  min-height: min(720px, calc(100svh - 172px));
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto auto minmax(220px, 1fr) auto auto;
  overflow: hidden;
}

.ai-panel-header {
  min-height: 64px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-panel-header h2,
.ai-panel-header h3 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.ai-panel-note {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fffaf6;
  color: #5f422b;
  font-size: 13px;
  line-height: 1.6;
}

.ai-messages {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  background: #fff;
}

.ai-empty {
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel-soft);
  line-height: 1.6;
}

.ai-empty p {
  margin-bottom: 10px;
}

.ai-quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-quick-prompts button,
.ai-suggestion-action {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid #eadfd5;
  border-radius: 999px;
  background: #fffaf6;
  color: #5f422b;
  font-size: 13px;
}

.ai-suggestion-action {
  justify-self: start;
  margin-top: 2px;
}

.ai-message {
  max-width: 92%;
  padding: 11px 12px;
  border-radius: 8px;
  line-height: 1.65;
}

.ai-message.is-user {
  justify-self: end;
  background: var(--accent);
  color: #fff;
}

.ai-message.is-assistant {
  justify-self: start;
  border: 1px solid #eadfd5;
  background: #fffaf6;
  color: #374151;
}

.ai-message-role {
  margin-bottom: 4px;
  font-size: 12px;
  opacity: 0.72;
}

.ai-message-text p {
  margin-bottom: 8px;
}

.ai-message-text p:last-child {
  margin-bottom: 0;
}

.ai-status {
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.ai-form {
  display: grid;
  gap: 10px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
}

.ai-form textarea {
  min-height: 78px;
  resize: vertical;
}

.ai-form-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.ai-form-actions .primary-action,
.ai-form-actions .secondary-action {
  margin: 0;
}

.ai-form-actions .primary-action {
  min-width: 92px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 20;
  transform: translate(-50%, 20px);
  padding: 12px 16px;
  border-radius: 999px;
  color: #fff;
  background: rgba(17, 24, 39, 0.92);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    z-index: 10;
    width: 100%;
    max-width: 100vw;
    height: auto;
    padding: 12px 14px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    gap: 10px;
  }

  .brand-block {
    gap: 10px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }

  .brand-block .eyebrow {
    display: none;
  }

  h1 {
    font-size: 19px;
  }

  .nav-list {
    display: flex;
    gap: 8px;
    margin: 0 -14px;
    padding: 0 14px 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .nav-list::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    min-height: 36px;
    padding: 0 13px;
    white-space: nowrap;
  }

  .boundary-note {
    display: none;
  }

  .content {
    width: 100%;
    max-width: 100vw;
    padding: 20px 16px 32px;
  }

  .dashboard-grid,
  .two-column,
  .reading-layout {
    grid-template-columns: 1fr;
  }

  .identity-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  h2 {
    font-size: 26px;
    line-height: 1.18;
  }

  .sidebar {
    top: 0;
    padding: 10px 14px;
  }

  .nav-list {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 40;
    margin: 0;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 12px 30px rgba(17, 24, 39, 0.14);
    backdrop-filter: blur(10px);
  }

  .nav-item {
    flex: 1 0 58px;
    min-height: 46px;
    padding: 0 6px;
    text-align: center;
    font-size: 0;
  }

  .nav-item::before {
    content: attr(data-mobile-label);
    font-size: 13px;
  }

  .content {
    padding-bottom: calc(108px + env(safe-area-inset-bottom));
  }

  .section-heading {
    display: grid;
    gap: 12px;
    margin-bottom: 18px;
  }

  .start-strip {
    grid-template-columns: 1fr;
  }

  .heading-meta {
    justify-items: start;
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  .date-pill {
    justify-self: start;
    padding: 8px 12px;
    font-size: 13px;
  }

  .community-pill {
    border-radius: 8px;
    white-space: normal;
  }

  .surface-title {
    min-height: 50px;
    padding: 0 14px;
  }

  input,
  select {
    height: 46px;
  }

  textarea {
    min-height: 96px;
  }

  #postForm {
    gap: 10px;
  }

  #postForm textarea {
    min-height: 72px;
  }

  .task-list,
  .steady-steps,
  .route-mini {
    padding: 14px;
  }

  .composer-entry {
    grid-template-columns: 36px 1fr;
    padding: 14px;
  }

  .composer-avatar {
    width: 36px;
    height: 36px;
  }

  .composer-entry textarea {
    min-height: 104px;
  }

  .composer-extra {
    padding-left: 14px;
    padding-right: 14px;
  }

  .chip-group > span {
    flex-basis: 100%;
  }

  label,
  .primary-action,
  .quiet-text {
    margin-left: 14px;
    margin-right: 14px;
  }

  .identity-form {
    padding: 0 14px;
  }

  .identity-form .primary-action {
    margin: 0;
  }

  .session-card {
    margin-left: 14px;
    margin-right: 14px;
  }

  .comment-form {
    grid-template-columns: 1fr;
  }

  .comment-form input,
  .comment-form button {
    min-height: 44px;
  }

  .post-header {
    display: grid;
    gap: 10px;
  }

  .post-tag {
    justify-self: start;
  }

  .post-body {
    padding: 15px;
  }

  .reaction-row {
    gap: 10px;
    padding-left: 15px;
    padding-right: 15px;
  }

  .reaction-row button {
    min-height: 42px;
    padding: 0 14px;
  }

  .ai-panel {
    min-height: calc(100vh - 252px - env(safe-area-inset-bottom));
    min-height: calc(100svh - 252px - env(safe-area-inset-bottom));
    margin: 0;
    grid-template-rows: auto auto minmax(180px, 1fr) auto auto;
  }

  .ai-messages {
    min-height: 0;
  }

  .ai-form textarea {
    min-height: 70px;
  }
}
