:root {
  --paper: #f4f1e9;
  --paper-deep: #e9e3d6;
  --ink: #20231f;
  --muted: #6f7169;
  --line: #d3cdbf;
  --accent: #d85b38;
  --accent-dark: #a83d21;
  --serif: "Newsreader", Georgia, serif;
  --ui: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --body: "Noto Sans Thai Looped", "Noto Sans Thai", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 82% 4%, rgba(216, 91, 56, 0.08), transparent 24rem),
    var(--paper);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: inherit; }

button, input, textarea { font: inherit; }

button { color: inherit; }

.note-header,
footer {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
}

.note-header {
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  text-decoration: none;
  font-size: 20px;
  font-weight: 600;
}

.wordmark-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(216, 91, 56, 0.13);
}

.note-header nav { display: flex; gap: 30px; }

.note-header nav a,
.back-link {
  font-family: var(--ui);
  font-size: 12px;
  letter-spacing: .02em;
  text-decoration: none;
}

.note-header nav a:hover,
.back-link:hover { color: var(--accent-dark); }

main { min-height: calc(100vh - 220px); }

.archive-hero,
.archive-section,
.article-shell,
.admin-shell {
  width: min(1060px, calc(100% - 48px));
  margin-inline: auto;
}

.archive-hero {
  padding: 108px 0 100px;
  display: grid;
  grid-template-columns: 1fr 320px;
  column-gap: 70px;
  align-items: end;
}

.eyebrow,
.article-date {
  margin: 0 0 18px;
  color: var(--accent-dark);
  font-family: var(--ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.archive-hero .eyebrow { grid-column: 1 / -1; }

h1, h2, h3, p { text-wrap: pretty; }

.archive-hero h1 {
  margin: 0;
  font-size: clamp(52px, 7vw, 92px);
  font-weight: 500;
  line-height: .96;
  letter-spacing: -.045em;
}

.intro {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1.45;
}

.archive-section { padding-bottom: 100px; }

.section-heading,
.drafts-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--ink);
}

.section-heading h2,
.drafts-heading h2 { margin: 0; font-size: 19px; font-weight: 600; }

.section-heading span,
.drafts-heading span {
  color: var(--muted);
  font-family: var(--ui);
  font-size: 11px;
  text-transform: uppercase;
}

.note-row {
  display: grid;
  grid-template-columns: 150px 1fr 24px;
  gap: 28px;
  align-items: start;
  padding: 28px 6px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  transition: padding .2s ease, color .2s ease;
}

.note-row:hover { padding-left: 14px; color: var(--accent-dark); }

.note-row time {
  padding-top: 6px;
  color: var(--muted);
  font-family: var(--ui);
  font-size: 11px;
  text-transform: uppercase;
}

.note-row h3 { margin: 0 0 5px; font-size: 29px; font-weight: 500; line-height: 1.1; }

.note-row p { margin: 0; color: var(--muted); font-size: 16px; line-height: 1.45; }

.note-row .arrow { padding-top: 4px; font-size: 22px; transition: transform .2s ease; }
.note-row:hover .arrow { transform: translateX(4px); }

.empty-state { padding: 56px 0; color: var(--muted); }

.loading-state,
.error-state {
  min-height: 60vh;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 40px 24px;
  color: var(--muted);
}

.loading-mark {
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(1turn); } }

.article-shell { max-width: 760px; padding: 70px 0 110px; }

.back-link { display: inline-block; margin-bottom: 72px; color: var(--muted); }

.article-header { margin-bottom: 54px; }

.article-header h1 {
  margin: 0 0 24px;
  font-size: clamp(48px, 7vw, 78px);
  font-weight: 500;
  letter-spacing: -.035em;
  line-height: .98;
}

.article-excerpt { margin: 0; color: var(--muted); font-size: 23px; line-height: 1.45; }

.article-cover {
  display: block;
  width: min(980px, calc(100vw - 48px));
  max-height: 620px;
  margin: 0 0 58px 50%;
  transform: translateX(-50%);
  object-fit: cover;
  border-radius: 3px;
}

.article-body { font-family: var(--body); font-size: 20px; line-height: 1.72; }
.article-body > :first-child { margin-top: 0; }
.article-body h2 { margin: 2.3em 0 .6em; font-size: 36px; line-height: 1.1; }
.article-body h3 { margin: 2em 0 .5em; font-size: 25px; line-height: 1.2; }
.article-body p { margin: 0 0 1.35em; }
.article-body ul, .article-body ol { margin: -.45em 0 1.35em; padding-left: 1.45em; }
.article-body li { margin: .35em 0; padding-left: .18em; }
.article-body li::marker { color: var(--accent-dark); }
.article-body a { color: var(--accent-dark); text-underline-offset: 3px; }
.article-body img { max-width: 100%; border-radius: 3px; }
.article-body blockquote { margin: 2em 0; padding: 2px 0 2px 28px; border-left: 3px solid var(--accent); color: #4f514b; font-size: 25px; }
.article-body code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: .82em; background: var(--paper-deep); padding: .15em .35em; border-radius: 3px; }
.article-body pre { overflow-x: auto; padding: 20px; background: #292b27; color: #f6f1e7; border-radius: 4px; }
.article-body pre code { padding: 0; background: none; }
.article-body u { text-decoration-thickness: .08em; text-underline-offset: .16em; }
.article-body table { display: block; width: 100%; max-width: 100%; margin: 2em 0; overflow-x: auto; border-collapse: collapse; font-family: var(--ui); font-size: 16px; line-height: 1.45; }
.article-body th, .article-body td { padding: 13px 15px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.article-body th { background: var(--paper-deep); font-weight: 600; }
.article-body tr:nth-child(even) td { background: rgba(255,255,255,.24); }

.article-end { display: flex; gap: 8px; margin-top: 76px; }
.article-end span { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }

footer {
  display: flex;
  justify-content: space-between;
  padding: 28px 0 38px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--ui);
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.admin-shell { padding: 72px 0 110px; }
.admin-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 44px; }
.admin-session-actions { display: flex; gap: 20px; }
.admin-heading h1, .login-shell h1 { margin: 0; font-size: 58px; font-weight: 500; line-height: 1; }
.admin-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .85fr); gap: 28px; }
.editor-card, .drafts-card, .login-shell form { padding: 28px; border: 1px solid var(--line); background: rgba(255,255,255,.22); }

label { display: block; margin-bottom: 21px; font-family: var(--ui); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
label span { text-transform: none; letter-spacing: 0; }
input, textarea {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 2px;
  outline: none;
  background: rgba(255,255,255,.38);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  text-transform: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(216,91,56,.08); }
textarea { resize: vertical; }
.body-editor { font-family: var(--body); font-size: 14px; line-height: 1.6; }
.editor-toolbar { display: flex; align-items: center; gap: 5px; margin: -11px 0 0; padding: 8px; border: 1px solid var(--line); border-bottom: 0; background: var(--paper-deep); }
.editor-toolbar button { min-width: 34px; height: 32px; padding: 0 10px; border: 1px solid transparent; border-radius: 2px; background: transparent; color: var(--ink); font-family: var(--ui); cursor: pointer; }
.editor-toolbar button:hover, .editor-toolbar button:focus-visible { border-color: var(--line); background: var(--paper); outline: none; }
.editor-toolbar .code-symbol { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 11px; }
.toolbar-separator { width: 1px; height: 21px; margin: 0 3px; background: var(--line); }
.editor-toolbar + .body-editor { margin-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; }
.editor-help { margin: 7px 0 21px; color: var(--muted); font-family: var(--ui); font-size: 11px; line-height: 1.4; }
.publish-control { display: flex; gap: 10px; align-items: center; }
.publish-control input { width: auto; margin: 0; accent-color: var(--accent); }
.publish-control span { color: var(--ink); }
.form-actions { display: flex; gap: 14px; align-items: center; }
.primary-button, .text-button { border: 0; cursor: pointer; font-family: var(--ui); font-size: 11px; letter-spacing: .03em; }
.primary-button { padding: 12px 18px; color: white; background: var(--ink); border-radius: 2px; }
.primary-button:hover { background: var(--accent-dark); }
.primary-button:disabled { opacity: .55; cursor: wait; }
.text-button { padding: 6px 0; background: transparent; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.form-status { margin: 0 0 0 auto; color: var(--muted); font-family: var(--ui); font-size: 10px; }
.drafts-heading { margin-bottom: 4px; }
.admin-note { padding: 17px 0; border-bottom: 1px solid var(--line); }
.admin-note strong { display: block; font-size: 18px; line-height: 1.2; }
.admin-note-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.admin-note-meta span { font-family: var(--ui); font-size: 9px; color: var(--muted); text-transform: uppercase; }
.admin-note-actions { display: flex; gap: 12px; }
.admin-note-actions button { padding: 0; border: 0; background: none; color: var(--accent-dark); cursor: pointer; font-family: var(--ui); font-size: 10px; }

.login-shell { width: min(480px, calc(100% - 48px)); margin: 0 auto; padding: 100px 0; }
.login-shell > p:not(.eyebrow) { color: var(--muted); }
.login-shell form { margin-top: 24px; }
.login-shell .form-status { margin: 14px 0 0; }
.passkey-button { width: 100%; margin-top: 22px; font-size: 12px; }
.passkey-button span { margin-right: 7px; font-size: 16px; }
.login-global-status { min-height: 1.4em; text-align: center; }
.login-divider { display: flex; align-items: center; gap: 14px; margin: 22px 0; color: var(--muted); font-family: var(--ui); font-size: 10px; text-transform: uppercase; }
.login-divider::before, .login-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.password-fallback { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 17px; }
.password-fallback summary { cursor: pointer; color: var(--muted); font-family: var(--ui); font-size: 11px; }

@media (max-width: 760px) {
  .note-header, footer, .archive-hero, .archive-section, .article-shell, .admin-shell { width: min(100% - 32px, 1060px); }
  .note-header { height: 76px; }
  .note-header nav { gap: 16px; }
  .note-header nav a:first-child { display: none; }
  .archive-hero { grid-template-columns: 1fr; padding: 78px 0 72px; }
  .archive-hero h1 { font-size: clamp(48px, 14vw, 68px); }
  .intro { margin-top: 32px; max-width: 440px; }
  .note-row { grid-template-columns: 1fr 20px; gap: 12px; }
  .note-row time { grid-column: 1 / -1; padding: 0; }
  .note-row h3 { font-size: 25px; }
  .article-shell { padding-top: 48px; }
  .back-link { margin-bottom: 52px; }
  .article-header h1 { font-size: 48px; }
  .article-excerpt { font-size: 20px; }
  .article-body { font-size: 18px; }
  .article-cover { width: calc(100vw - 32px); }
  footer { display: block; }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-heading h1, .login-shell h1 { font-size: 46px; }
  .editor-card, .drafts-card, .login-shell form { padding: 20px; }
}

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