:root {
  color-scheme: light dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans CJK SC", "Noto Sans SC", "Yu Gothic UI", sans-serif;
  font-synthesis: none;
  --surface: #f7f7f5;
  --surface-raised: #ffffff;
  --ink: #16181a;
  --muted: #6b7075;
  --line: #dedfdd;
  --accent: #1269e8;
  --accent-hover: #0f5dce;
  --danger: #c83b35;
  --success: #16805b;
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--surface);
  color: var(--ink);
}

body {
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

button,
input,
textarea { font: inherit; }

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

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 32%, transparent);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.app-shell {
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
}

.app-bar {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.92rem;
  font-weight: 720;
  letter-spacing: -0.01em;
}

.wordmark-mark {
  position: relative;
  width: 17px;
  height: 17px;
  border: 2px solid currentColor;
  border-radius: 4px;
}

.wordmark-mark::after {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 5px;
  height: 5px;
  border-radius: 1px;
  background: var(--accent);
  content: "";
}

.wordmark-context {
  color: var(--muted);
  font-weight: 540;
}

.quiet-button {
  min-width: 44px;
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.quiet-button:hover { color: var(--ink); }

.main-area {
  display: flex;
  width: min(100%, 760px);
  flex: 1;
  align-self: center;
}

.boot-view {
  margin: auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-view {
  width: min(100%, 430px);
  margin: clamp(54px, 14vh, 132px) auto auto;
  padding: 0 24px var(--safe-bottom);
}

.login-copy { margin-bottom: 34px; }

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 750;
  letter-spacing: 0.1em;
}

.login-copy h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 2.8rem);
  font-weight: 730;
  letter-spacing: -0.045em;
  line-height: 1.08;
}

.login-copy p:last-child {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.login-form label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.password-row input {
  min-width: 0;
  height: 50px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--ink);
}

.primary-button,
.secondary-action {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  padding: 0 20px;
  border: 0;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
}

.primary-button:hover:not(:disabled) { background: var(--accent-hover); }

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.form-message,
.publish-message {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.form-message {
  margin: 12px 2px 0;
  color: var(--danger);
}

.composer-view,
.composer-form {
  width: 100%;
  min-height: 0;
  flex: 1;
}

.composer-view { display: flex; }

.composer-form {
  display: flex;
  flex-direction: column;
  padding: 18px max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
}

.composer-meta {
  display: flex;
  min-height: 24px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 0.78rem;
}

.state-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 690;
}

.state-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.state-dot[data-state="saved"],
.state-dot[data-state="online"] { background: var(--success); }

.state-dot[data-state="working"] {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.state-dot[data-state="error"] { background: var(--danger); }

.draft-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#content {
  width: 100%;
  min-height: 0;
  flex: 1;
  resize: none;
  padding: clamp(22px, 4vh, 38px) 0 20px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: clamp(1.22rem, 4.8vw, 1.56rem);
  font-weight: 430;
  letter-spacing: -0.018em;
  line-height: 1.65;
  caret-color: var(--accent);
}

#content::placeholder { color: color-mix(in srgb, var(--muted) 58%, transparent); }

#content:focus { outline: 0; }

.publish-message {
  min-height: 1.35rem;
  margin: 0 0 8px;
}

.publish-message[data-tone="error"] { color: var(--danger); }
.publish-message[data-tone="success"] { color: var(--success); }

.action-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 var(--safe-bottom);
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
}

.character-count {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.character-count[data-invalid="true"] {
  color: var(--danger);
  font-weight: 700;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 9px;
}

.secondary-action {
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid var(--line);
  color: var(--ink);
}

.publish-button {
  gap: 9px;
  min-width: 108px;
}

.shortcut {
  opacity: 0.72;
  font-size: 0.72rem;
  font-weight: 600;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.78); }
}

@media (max-width: 520px) {
  .app-bar { min-height: 52px; }
  .login-view { margin-top: clamp(42px, 10vh, 84px); padding-inline: 20px; }
  .composer-form { padding-top: 14px; }
  .draft-label { max-width: 52vw; }
  .shortcut { display: none; }
  .publish-button { min-width: 92px; }
}

@media (max-width: 360px) {
  .wordmark-context,
  .draft-label { display: none; }
  .password-row { grid-template-columns: 1fr; }
  .password-row .primary-button { width: 100%; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #101112;
    --surface-raised: #191b1d;
    --ink: #f1f2f2;
    --muted: #999fa5;
    --line: #2d3033;
    --accent: #4c91f4;
    --accent-hover: #69a3f5;
    --danger: #f0756d;
    --success: #47b98d;
  }
}

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