:root {
  --bg: #ffffff;
  --page: #fafafa;
  --text: #000000;
  --muted: #737373;
  --line: #dbdbdb;
  --soft: #efefef;
  --input: #fafafa;
  --blue: #0095f6;
  --blue-dark: #1877f2;
  --heart: #ff3040;
  --danger: #ed4956;
  --media: #0b0b0b;
  --overlay: rgba(0, 0, 0, 0.45);
  --toast-bg: #262626;
  --toast-text: #ffffff;
  --shadow: rgba(0, 0, 0, 0.12);
  --tab-h: 50px;
  --top-h: 50px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --page: #000000;
    --text: #f5f5f5;
    --muted: #a8a8a8;
    --line: #262626;
    --soft: #1a1a1a;
    --input: #121212;
    --media: #0b0b0b;
    --toast-bg: #f5f5f5;
    --toast-text: #000000;
    --shadow: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

*[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 14px;
  line-height: 1.4;
  overflow-y: scroll;
  -webkit-tap-highlight-color: transparent;
}

body.no-scroll {
  overflow: hidden;
}

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

button {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
}

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

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

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon.small {
  width: 19px;
  height: 19px;
}

.shell {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 470px;
  margin: 0 auto;
  background: var(--bg);
}

@media (min-width: 680px) {
  .shell {
    box-shadow: 0 0 0 1px var(--line);
  }
}

/* Top bar ------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

@supports (backdrop-filter: blur(10px)) {
  .topbar {
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
  }
}

.topbar-inner {
  height: var(--top-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 0 16px;
}

.brand {
  color: var(--text);
  font-family: "Snell Roundhand", "Savoye LET", "Apple Chancery", "Segoe Script", "Bradley Hand", cursive;
  font-size: 31px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  text-decoration: none;
  transform: translateY(-1px);
}

.brand:hover {
  text-decoration: none;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--text);
}

.icon-btn:active {
  background: var(--soft);
}

.icon-btn .icon {
  width: 23px;
  height: 23px;
}

.icon-btn.spinning .icon {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Main / timeline ----------------------------------------------------- */

.main {
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 8px);
}

.view[hidden] {
  display: none;
}

.feed {
  min-height: 60vh;
}

.post {
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  scroll-margin-top: calc(var(--top-h) + env(safe-area-inset-top) + 10px);
}

.post.is-target {
  box-shadow: inset 3px 0 0 var(--blue);
}

.focus-banner {
  position: sticky;
  top: calc(var(--top-h) + env(safe-area-inset-top));
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.focus-banner-text {
  min-width: 0;
}

.focus-banner strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
}

.focus-banner span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.focus-banner .btn {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 6px 11px;
  font-size: 12.5px;
}

.load-sentinel {
  width: 100%;
  height: 1px;
}

.post-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #feda75 0%, #fa7e1e 24%, #d62976 54%, #962fbf 76%, #4f5bd5 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  user-select: none;
}

.avatar-sm {
  width: 30px;
  height: 30px;
  font-size: 12px;
}

.post-user {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.post-user .name {
  font-size: 13.5px;
  font-weight: 600;
}

.post-user .sub {
  overflow: hidden;
  color: var(--muted);
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.post-more {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-left: auto;
  margin-right: -8px;
  border-radius: 50%;
  color: var(--text);
}

.post-more:active {
  background: var(--soft);
}

.post-media {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--media);
  touch-action: manipulation;
  user-select: none;
}

.post-media img {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(82vh, 760px);
  object-fit: contain;
  background: var(--media);
}

.post-media img.is-lazy,
.grid-tile img.is-lazy {
  color: transparent;
  background: linear-gradient(90deg, var(--soft) 25%, var(--line) 37%, var(--soft) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

.post-media .media-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 240px;
  padding: 24px;
  color: #b9b9b9;
  font-size: 12px;
  text-align: center;
}

.heart-burst {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  pointer-events: none;
  filter: drop-shadow(0 2px 14px rgba(0, 0, 0, 0.45));
}

.heart-burst .icon {
  width: 92px;
  height: 92px;
  fill: currentColor;
  stroke: none;
  animation: heart-pop 0.95s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

@keyframes heart-pop {
  0% {
    opacity: 0;
    transform: scale(0.2);
  }
  16% {
    opacity: 1;
    transform: scale(1.16);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
  72% {
    opacity: 1;
    transform: scale(1.02);
  }
  100% {
    opacity: 0;
    transform: scale(1.1);
  }
}

.post-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 6px 0;
}

.action-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 40px;
  border-radius: 50%;
  color: var(--text);
}

.action-btn:active {
  background: var(--soft);
}

.action-btn .icon {
  width: 25px;
  height: 25px;
}

.action-btn.liked {
  color: var(--heart);
}

.action-btn.liked .icon {
  fill: currentColor;
  stroke: none;
}

.post-likes {
  padding: 0 12px;
  font-size: 13.5px;
  font-weight: 600;
}

.post-caption {
  padding: 3px 12px 0;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.post-caption .name {
  margin-right: 5px;
  font-weight: 600;
}

.post-time {
  padding: 6px 12px 13px;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* Empty / error / skeleton -------------------------------------------- */

.empty,
.error-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 58vh;
  padding: 40px 28px;
  text-align: center;
}

.empty h2,
.error-box h2 {
  margin: 14px 0 4px;
  font-size: 21px;
  font-weight: 600;
}

.empty p,
.error-box p {
  max-width: 300px;
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border: 2px solid var(--text);
  border-radius: 50%;
}

.empty-icon .icon {
  width: 36px;
  height: 36px;
}

.skeleton-post {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.skeleton-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
}

.sk {
  background: linear-gradient(90deg, var(--soft) 25%, var(--line) 37%, var(--soft) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

.sk-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.sk-line {
  width: 120px;
  height: 11px;
  border-radius: 5px;
}

.sk-media {
  width: 100%;
  aspect-ratio: 1;
}

.sk-text {
  width: 42%;
  height: 11px;
  margin: 12px 12px 0;
  border-radius: 5px;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

/* Grid view ----------------------------------------------------------- */

.grid-profile {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 22px 18px 20px;
}

.grid-profile .avatar {
  width: 78px;
  height: 78px;
  font-size: 28px;
}

.grid-profile h2 {
  margin: 0 0 3px;
  font-size: 18px;
  font-weight: 600;
}

.grid-profile p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
}

.grid-tile {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--soft);
}

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

.grid-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--muted);
  font-size: 22px;
}

.grid-tile:active::after {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.14);
  content: "";
}

.grid-empty {
  padding: 54px 28px;
  color: var(--muted);
  text-align: center;
}

/* Tab bar ------------------------------------------------------------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  z-index: 50;
  display: flex;
  width: 100%;
  max-width: 470px;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateX(-50%);
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.tab {
  display: grid;
  flex: 1;
  place-items: center;
  height: var(--tab-h);
  color: var(--muted);
}

.tab .icon {
  width: 25px;
  height: 25px;
}

.tab.active {
  color: var(--text);
}

.tab.active .icon {
  stroke-width: 2.3;
}

/* Buttons / fields ---------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 15px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

.btn.primary {
  background: var(--blue);
  color: #fff;
}

.btn.primary:hover {
  background: var(--blue-dark);
}

.btn.ghost {
  border: 1px solid var(--line);
  background: transparent;
}

.btn:disabled {
  cursor: default;
  opacity: 0.4;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

.text-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--blue);
  font-size: 13px;
  font-weight: 600;
}

.text-link.danger {
  color: var(--danger);
}

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 12.5px;
  font-weight: 600;
}

input[type="password"],
input[type="text"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--input);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}

input[type="password"],
input[type="text"] {
  height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 90px;
  padding: 10px 12px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--muted);
  outline: none;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12.5px;
  line-height: 1.5;
}

code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--soft);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

/* Sheets -------------------------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: fade-in 0.16s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (min-width: 600px) {
  .sheet {
    top: 50%;
    right: auto;
    bottom: auto;
    left: 50%;
    width: min(470px, calc(100vw - 40px));
    height: min(780px, calc(100dvh - 56px));
    transform: translate(-50%, -50%);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 22px 80px var(--shadow);
  }
}

.sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  flex: 0 0 auto;
  min-height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  border-bottom: 1px solid var(--line);
}

.sheet-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}

.sheet-text-btn {
  justify-self: start;
  padding: 10px 4px;
  color: var(--text);
  font-size: 14px;
}

.sheet-text-btn.strong {
  justify-self: end;
  color: var(--blue);
  font-weight: 600;
}

.sheet-text-btn:disabled {
  color: var(--blue);
  cursor: default;
  opacity: 0.45;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

@media (min-width: 600px) {
  .sheet-head {
    min-height: 52px;
    padding-top: 0;
  }

  .sheet-body {
    padding-bottom: 20px;
  }
}

/* Add photo ----------------------------------------------------------- */

.add-body {
  display: flex;
  flex-direction: column;
}

.dropzone {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 360px;
  margin: 16px;
  padding: 42px 22px;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  text-align: center;
}

.dropzone.dragover {
  border-color: var(--blue);
  background: color-mix(in srgb, var(--blue) 7%, transparent);
}

.drop-icon {
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  margin-bottom: 14px;
  border-radius: 50%;
  background: var(--soft);
}

.drop-icon .icon {
  width: 33px;
  height: 33px;
}

.dropzone h3 {
  margin: 0 0 5px;
  font-size: 20px;
  font-weight: 600;
}

.dropzone p {
  max-width: 290px;
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

.drop-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

.compose {
  display: flex;
  flex-direction: column;
}

.preview-pane {
  display: grid;
  place-items: center;
  min-height: 200px;
  max-height: 48vh;
  background: var(--media);
  overflow: hidden;
}

.preview-pane img {
  display: block;
  width: 100%;
  max-height: 48vh;
  object-fit: contain;
}

.compose-fields {
  padding: 13px 14px 0;
}

.caption-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.caption-row textarea {
  min-height: 78px;
  border: 0;
  background: transparent;
  font-size: 15px;
  resize: none;
}

.caption-row textarea:focus {
  border: 0;
}

.caption-row textarea::placeholder {
  color: var(--muted);
}

.file-meta {
  margin-top: 9px;
  color: var(--muted);
  font-size: 11.5px;
}

.inline-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.45;
}

.compose-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

@media (min-width: 600px) and (min-height: 720px) {
  .compose {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    height: 100%;
  }

  .preview-pane {
    max-height: none;
    border-right: 1px solid var(--line);
  }

  .preview-pane img {
    max-height: 660px;
  }

  .compose-fields {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-top: 20px;
  }

  .caption-row textarea {
    min-height: 140px;
  }
}

/* Settings ------------------------------------------------------------ */

.settings-body {
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
}

@media (min-width: 600px) {
  .settings-body {
    padding-bottom: 28px;
  }
}

.settings-card {
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.settings-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
}

.settings-card p {
  margin: 0 0 12px;
}

.settings-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}

.settings-title h3 {
  margin: 0;
}

.settings-title .icon {
  width: 19px;
  height: 19px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.token-status {
  margin-top: 12px;
  font-size: 12.5px;
  line-height: 1.45;
}

.token-status.ok {
  color: #1f7a3a;
}

.token-status.bad {
  color: var(--danger);
}

.token-status.pending {
  color: var(--muted);
}

@media (prefers-color-scheme: dark) {
  .token-status.ok {
    color: #6bd38b;
  }
}

.steps {
  margin: 0 0 12px;
  padding-left: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.steps li {
  margin-bottom: 6px;
  padding-left: 2px;
}

.steps strong {
  color: var(--text);
  font-weight: 600;
}

/* Action sheet -------------------------------------------------------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 105;
  background: var(--overlay);
  animation: fade-in 0.15s ease-out;
}

.action-sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  z-index: 110;
  width: 100%;
  max-width: 470px;
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateX(-50%);
  border-radius: 16px 16px 0 0;
  background: var(--bg);
  box-shadow: 0 -8px 40px var(--shadow);
  overflow: hidden;
  animation: sheet-up 0.2s ease-out;
}

@keyframes sheet-up {
  from {
    transform: translate(-50%, 24px);
    opacity: 0.4;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

.action-sheet button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
}

.action-sheet button:first-of-type {
  border-top: 0;
}

.action-sheet button.danger {
  color: var(--danger);
  font-weight: 600;
}

/* Toast --------------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px);
  left: 50%;
  z-index: 130;
  max-width: calc(100vw - 40px);
  padding: 10px 16px;
  border-radius: 22px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}

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

/* Reduced motion ------------------------------------------------------ */

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