:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: #1d1d1f;
  --line: #dcdcdc;
  --accent: #3b5bdb;
  --chip: #ffffff;
  --chip-active-bg: #1d1d1f;
  --chip-active-text: #ffffff;
  --danger: #c92a2a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --surface: #1f1f22;
    --text: #ececef;
    --muted: #9a9aa1;
    --border: #5a5a60;
    --line: #333338;
    --accent: #8ea8ff;
    --chip: #1f1f22;
    --chip-active-bg: #ececef;
    --chip-active-text: #161618;
    --danger: #ff8787;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  line-height: 1.7;
}

a { color: var(--accent); }
img { max-width: 100%; }
.muted { color: var(--muted); }

/* Header + tag menu */
.site-header, .tag-menu, .frame {
  max-width: 820px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 24px;
}
.site-title { font-size: 1.4rem; font-weight: 700; color: var(--text); text-decoration: none; }
.site-nav { display: flex; gap: 14px; align-items: center; }
.site-nav a { color: var(--text); text-decoration: none; }

.tag-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 20px;
  padding-bottom: 12px;
}
.tag {
  display: inline-block;
  padding: 2px 14px;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--chip);
  color: var(--text);
  text-decoration: none;
  font-size: .95rem;
}
.tag:hover { background: var(--line); }
.tag.active { background: var(--chip-active-bg); color: var(--chip-active-text); }
.tag.small { padding: 0 10px; font-size: .85rem; border-width: 1.5px; }

/* Cards stacked like the sketch */
.frame { padding-bottom: 48px; }
.card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 6px;
  padding: 20px 24px;
  margin-bottom: 14px;
}
.card.narrow { max-width: 420px; margin-left: auto; margin-right: auto; }
.card h1 { margin-top: 0; font-size: 1.4rem; }

.post-head h2 { margin: 0; font-size: 1.25rem; }
.post-head h2 a { color: var(--text); text-decoration: none; }
.meta { color: var(--muted); font-size: .85rem; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.meta a { color: var(--muted); }
.edited { font-style: italic; }
.post-body { overflow-wrap: anywhere; }
.post-body blockquote { margin: 0; padding-left: 14px; border-left: 3px solid var(--line); color: var(--muted); }
.post-body pre { background: var(--bg); padding: 12px; overflow-x: auto; border-radius: 4px; }
/* Markdown images only (embeds keep their own layout) */
.post-body p > img { display: block; margin: 12px 0; border-radius: 4px; cursor: zoom-in; }
.post-body p > a > img { display: block; margin: 12px 0; border-radius: 4px; }
.post-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.pager { display: flex; justify-content: center; gap: 20px; margin-top: 20px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.messages { list-style: none; padding: 0; }
.messages li { padding: 8px 12px; border-radius: 4px; background: var(--surface); border: 1px solid var(--line); margin-bottom: 8px; }
.messages .warning { border-color: #e8a317; }
.messages .success { border-color: #2f9e44; }

/* Forms */
input[type=text], input[type=password], textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
label { display: block; font-weight: 600; margin-bottom: 4px; }
.help { color: var(--muted); }
.errorlist { color: var(--danger); margin: 4px 0; padding-left: 18px; }
button, label.button {
  display: inline-block;
  margin: 0;
  padding: 6px 18px;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--chip-active-bg);
  color: var(--chip-active-text);
  font: inherit;
  font-weight: normal;
  cursor: pointer;
}
button.secondary, label.button.secondary { background: var(--surface); color: var(--text); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.link { background: none; border: none; padding: 0; color: var(--muted); text-decoration: underline; font-size: inherit; }
button:disabled { opacity: .6; cursor: default; }
form.inline { display: inline; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
textarea.dragging { border: 2px dashed var(--accent); }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: -8px 0 16px; }
.tag-picker .help { width: 100%; }
.tag-picker button.tag { font-weight: normal; }
.preview { margin-top: 20px; padding-top: 12px; border-top: 2px dashed var(--line); }

/* X (tweet) card */
.tweet-card {
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 16px;
  margin: 12px 0;
  max-width: 560px;
}
.tweet-card.failed { display: flex; flex-direction: column; font-size: .9rem; overflow-wrap: anywhere; }
.tweet-author { display: flex; align-items: center; gap: 10px; line-height: 1.3; }
.tweet-avatar { width: 40px; height: 40px; border-radius: 50%; }
.tweet-text { margin: 8px 0; white-space: normal; }
.tweet-foot { font-size: .85rem; }
.tweet-media {
  display: grid;
  gap: 2px;
  border-radius: 12px;
  overflow: hidden;
  margin: 8px 0;
  grid-template-columns: 1fr 1fr;
}
.tweet-media.n1 { grid-template-columns: 1fr; }
.tweet-media a { position: relative; display: block; aspect-ratio: 16 / 9; }
.tweet-media.n1 a { aspect-ratio: auto; }
.tweet-media.n3 a:first-child { grid-row: span 2; aspect-ratio: auto; }
.tweet-media img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* YouTube (thumbnail until clicked) */
.youtube {
  position: relative;
  display: block;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 16 / 9;
  margin: 12px 0;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}
.youtube.vertical { max-width: 320px; aspect-ratio: 9 / 16; }
.youtube img { width: 100%; height: 100%; object-fit: cover; display: block; }

.play {
  position: absolute; inset: 0; margin: auto;
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff;
  display: grid; place-items: center; font-size: 1.3rem;
}

.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  display: grid; place-items: center;
  z-index: 100; cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 95vw; max-height: 95vh; }

/* Clap */
.clap { text-align: center; }
.clap-image img { max-height: 420px; border-radius: 6px; }
.clap-image figcaption { color: var(--muted); }
.clap-btn { font-size: 1.2rem; padding: 10px 28px; }
.clap-btn.pop { animation: pop .25s ease; }
@keyframes pop { 50% { transform: scale(1.12); } }
.clap-count { margin-left: 10px; color: var(--muted); }
.guestbook-form { display: grid; gap: 8px; }
.guestbook-form button { justify-self: end; }
.hp { position: absolute; left: -9999px; }
.guestbook { list-style: none; padding: 0; margin-top: 20px; }
.guestbook li { border-top: 1px solid var(--line); padding: 10px 0; }
.guestbook p { margin: 4px 0 0; }

.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.image-grid figure { margin: 0; }
.image-grid img { aspect-ratio: 1; object-fit: cover; width: 100%; border-radius: 4px; }
.image-grid figcaption { font-size: .85rem; color: var(--muted); }

@media (max-width: 600px) {
  .card { padding: 14px 16px; }
  .site-header { flex-wrap: wrap; gap: 8px; }
}
