:root {
  --paper: #ffffff;
  --surface: #f7f7f8;
  --ink: #1c1c1e;
  --muted: #727277;
  --line: #e4e4e7;
  --line-strong: #c9c9ce;
  --accent: #002fa7;
  --danger: #bd2335;
  --font: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--surface);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--surface);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

::selection {
  color: var(--paper);
  background: var(--accent);
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.quiet-button,
.quiet-link,
.post-action {
  min-height: 32px;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
}

.quiet-button:hover,
.quiet-link:hover,
.post-action:hover {
  color: var(--ink);
}

.form-error {
  min-height: 1.5em;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.form-error:empty {
  display: none;
}

/* App shell */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.topbar-inner {
  display: flex;
  width: min(100% - 32px, 640px);
  height: 52px;
  align-items: center;
  justify-content: space-between;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 750;
  text-decoration: none;
}

.avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
}

.avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 13px;
}

.feed-shell {
  width: min(100%, 640px);
  min-height: calc(100vh - 52px);
  margin: 0 auto;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: var(--paper);
}

.feed-intro {
  display: flex;
  min-height: 72px;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}

.feed-intro h1,
.entry-count {
  margin: 0;
}

.feed-intro h1 {
  font-size: 21px;
  line-height: 1.2;
}

.entry-count {
  color: var(--muted);
  font-size: 13px;
}

/* Composer */
.composer {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  padding: 14px 24px 10px;
  border-bottom: 6px solid var(--surface);
  scroll-margin-top: 64px;
}

.composer .avatar {
  width: 34px;
  height: 34px;
  flex-basis: 34px;
  font-size: 13px;
}

.composer form {
  min-width: 0;
}

.composer textarea,
.composer input[type="text"] {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  background: transparent;
  outline: none;
}

.composer textarea {
  height: 62px;
  min-height: 62px;
  padding: 2px 0 8px;
  resize: vertical;
  font-size: 15px;
  line-height: 1.65;
}

.composer input[type="text"] {
  height: 30px;
  padding: 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.composer-preview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin-top: 8px;
}

.composer-preview[hidden] {
  display: none;
}

.composer-image {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--surface);
}

.composer-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-remove {
  position: absolute;
  right: 4px;
  bottom: 4px;
  min-height: 24px;
  padding: 0 7px;
  border: 0;
  border-radius: 4px;
  color: var(--paper);
  background: rgba(28, 28, 30, 0.82);
  font-size: 11px;
  cursor: pointer;
}

.composer-media-row {
  display: flex;
  min-height: 30px;
  align-items: center;
  gap: 10px;
}

.image-picker {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.image-picker:hover {
  color: var(--ink);
}

.image-count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.composer textarea::placeholder,
.composer input::placeholder,
.feed-controls input::placeholder {
  color: #929298;
  opacity: 1;
}

.composer-footer {
  display: flex;
  min-height: 32px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 3px;
}

.edit-state {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

.publish-button {
  min-width: 58px;
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--ink);
  border-radius: 5px;
  color: var(--paper);
  background: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.publish-button:hover {
  color: var(--ink);
  background: var(--paper);
}

.publish-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.feed-controls {
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
}

.feed-controls input {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
}

.feed-controls input:focus {
  border-color: var(--accent);
  background: var(--paper);
}

/* Personal feed */
.post {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 13px;
  padding: 22px 24px 0;
}

.post-main {
  min-width: 0;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.post:last-child .post-main {
  border-bottom: 0;
}

.post-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.post-header > div {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 8px;
}

.post-header strong {
  font-size: 15px;
  line-height: 1.4;
}

.post-header time {
  color: var(--muted);
  font-size: 12px;
}

.post-header time {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.post h2 {
  margin: 12px 0 4px;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.45;
}

.post-content {
  margin: 12px 0 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.72;
}

.post h2 + .post-content {
  margin-top: 4px;
}

.post-gallery {
  display: grid;
  width: min(100%, 470px);
  gap: 3px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 6px;
  background: var(--line);
}

.post-gallery img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: cover;
}

.post-gallery a {
  display: block;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.post-gallery.gallery-1 {
  width: min(100%, 360px);
  aspect-ratio: 4 / 3;
}

.post-gallery.gallery-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  aspect-ratio: 16 / 9;
}

.post-gallery.gallery-3,
.post-gallery.gallery-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  aspect-ratio: 1 / 1;
}

.post-gallery.gallery-3 a:first-child {
  grid-row: span 2;
}

.post-footer {
  display: flex;
  justify-content: flex-end;
  gap: 18px;
  margin-top: 12px;
}

.post-action {
  min-height: 28px;
  font-size: 12px;
}

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

.empty-state,
.loading-state {
  margin: 0;
  padding: 64px 24px;
  color: var(--muted);
  text-align: center;
}

.empty-state {
  display: grid;
  gap: 4px;
}

.empty-state p {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
}

.empty-state span {
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  padding: 9px 13px;
  border-radius: 5px;
  color: var(--paper);
  background: var(--ink);
  font-size: 13px;
  transform: translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

/* Auth */
.login-body {
  display: grid;
  place-items: center;
  padding: 28px 16px;
}

.login-layout {
  width: min(100%, 420px);
}

.back-link {
  display: inline-block;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.back-link:hover {
  color: var(--ink);
}

.login-panel {
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.login-intro {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.site-name,
.login-description {
  margin: 0;
}

.site-name {
  font-weight: 750;
}

.login-description {
  color: var(--muted);
  font-size: 12px;
}

.login-content h1 {
  margin: 28px 0 18px;
  font-size: 24px;
  line-height: 1.2;
}

.login-form {
  display: grid;
  gap: 7px;
}

.login-form label {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 700;
}

.login-form input {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--ink);
  background: var(--paper);
  outline: none;
}

.login-form input:focus {
  border-color: var(--accent);
}

.login-form .publish-button {
  width: 100%;
  height: 40px;
  margin-top: 8px;
}

@media (max-width: 640px) {
  .topbar-inner {
    width: 100%;
    padding: 0 16px;
  }

  .feed-shell {
    border: 0;
  }

  .feed-intro {
    min-height: 92px;
    padding: 20px 16px 16px;
  }

  .composer,
  .post {
    gap: 11px;
    padding-right: 16px;
    padding-left: 16px;
  }

  .feed-controls {
    padding-right: 16px;
    padding-left: 16px;
  }
}

@media (max-width: 420px) {
  .topbar-actions {
    gap: 14px;
  }

  .feed-intro h1 {
    font-size: 22px;
  }

  .post-header {
    display: block;
  }

  .post-header time {
    display: block;
    margin-top: 1px;
  }

  .post-gallery.gallery-1 {
    width: 100%;
  }

  .composer-preview {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .login-panel {
    padding: 26px 22px;
  }
}
