@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,500;1,400&display=swap');

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

/* ── theme variables ── */
:root {
  --bg:          #fff;
  --text:        #111;
  --text-muted:  #666;
  --text-faint:  #aaa;
  --text-link:   #111;
  --border:      #e8e8e8;
  --border-dot:  #ccc;
  --code-bg:     #f6f6f6;
  --nav-inactive:#bbb;
  --nav-hover:   #555;
}

body.dark {
  --bg:          #151515;
  --text:        #f0f0f0;
  --text-muted:  #c0c0c0;
  --text-faint:  #777;
  --text-link:   #f0f0f0;
  --border:      #2e2e2e;
  --border-dot:  #555;
  --code-bg:     #1e1e1e;
  --nav-inactive:#666;
  --nav-hover:   #ccc;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .4s ease, color .4s ease;
}

*, *::before, *::after {
  transition: background-color .4s ease, color .4s ease,
              border-color .4s ease, text-decoration-color .4s ease;
}

/* ── layout ── */
.layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  min-height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  padding: 64px 40px 120px;
  gap: 0 48px;
}

/* ── nav ── */
nav {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  padding-top: 2px;
  border-right: 1px solid var(--border);
  padding-right: 24px;
}

nav a {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 17px;
  color: var(--nav-inactive);
  text-decoration: none;
  width: fit-content;
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
  transition: color .2s, border-color .2s;
}

nav a:hover { color: var(--nav-hover); }

nav a.on {
  color: var(--text);
  font-weight: 500;
  border-bottom-color: var(--text);
}

/* ── theme toggle ── */
#theme-toggle {
  margin-top: 32px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  color: var(--nav-inactive);
  align-self: flex-end;
}

#theme-toggle:hover { color: var(--nav-hover); }

/* ── page transitions ── */
#main { display: block; }

#main.fadein {
  animation: fadein .25s ease forwards;
}

@keyframes fadein {
  from { opacity: 0; filter: blur(3px); transform: translateY(5px); }
  to   { opacity: 1; filter: blur(0);   transform: translateY(0); }
}

/* ── home ── */
.home-name {
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}

.home-bio {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.8;
  max-width: 480px;
  margin-bottom: 28px;
}

.home-links { display: flex; gap: 20px; }

.home-links a {
  font-size: 13px;
  color: var(--text-link);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border-dot);
  width: fit-content;
  transition: text-decoration-color .15s;
}

.home-links a:hover { text-decoration-color: var(--text); }

/* ── writing list ── */
.post-list { list-style: none; }

.post-list li {
  display: flex;
  align-items: center;
  padding: 9px 0;
}

.post-list li a {
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color .15s;
}

.post-list li a:hover { color: var(--text-faint); }

.dots {
  flex: 1;
  height: 0;
  border-bottom: 1px dotted var(--border-dot);
  margin: 0 12px 2px;
}

.post-date {
  font-size: 13px;
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ── post detail ── */
.back {
  display: inline-block;
  font-size: 13px;
  color: var(--text-faint);
  text-decoration: none;
  margin-bottom: 10px;
  transition: color .15s;
}

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

.pmeta {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}

.ptitle {
  font-size: 22px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin-bottom: 32px;
  color: var(--text);
}

.pbody p {
  font-size: 15px;
  line-height: 1.75;
  color: var(--text-muted);
  margin-bottom: 18px;
}

.pbody h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 36px 0 14px;
}

.pbody em { font-style: italic; }

pre {
  background: var(--code-bg);
  padding: 18px 20px;
  border-radius: 3px;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  margin: 20px 0;
  font-family: "SF Mono", "Fira Mono", monospace;
  color: var(--text-muted);
}

.cm { color: var(--text-faint); }
.kw { color: #07a; }

/* ── coming soon ── */
.cs { font-size: 14px; color: var(--text-faint); }

/* ── mobile ── */
@media (max-width: 600px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 40px 24px 80px;
    gap: 0;
  }
  nav {
    flex-direction: row;
    align-items: center;
    gap: 20px;
    margin-bottom: 48px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 20px;
  }
  #theme-toggle { margin-top: 0; margin-left: auto; }
  .post-date { display: none; }
  .dots { display: none; }
}

/* ── login page ── */
.login-page {
  display: flex !important;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}

.login-box {
  width: 100%;
  max-width: 340px;
}

.login-title {
  font-size: 22px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.login-sub {
  font-size: 13px;
  color: var(--text-faint);
  margin-bottom: 28px;
}

.login-err {
  font-size: 13px;
  color: #c0392b;
  min-height: 18px;
  margin-bottom: 12px;
}

.login-input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 3px;
  outline: none;
  margin-bottom: 10px;
  transition: border-color .15s;
}

.login-input:focus { border-color: var(--text-faint); }

.login-btn {
  width: 100%;
  padding: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity .15s;
}

.login-btn:hover { opacity: .85; }
.login-btn:disabled { opacity: .5; cursor: default; }

/* ── profile page ── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 32px;
}

.profile-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 500;
  flex-shrink: 0;
}

.profile-name {
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
}

.profile-role {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 2px;
}

/* ── section tabs ── */
.section-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.stab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 8px 16px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-faint);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

.stab:hover { color: var(--text); }
.stab.on { color: var(--text); border-bottom-color: var(--text); }

/* ── tab content ── */
.tab-section {
  margin-bottom: 28px;
}

.field-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 10px;
}

.field-val {
  font-size: 15px;
  color: var(--text);
}

.action-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-family: inherit;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  transition: opacity .15s;
  margin-top: 4px;
}

.action-btn:hover { opacity: .8; }

.logout-btn {
  background: none;
  border: none;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0;
  transition: color .15s;
}

.logout-btn:hover { color: #c0392b; }

.msg { font-size: 13px; margin-top: 8px; min-height: 18px; }
.msg.ok  { color: #27ae60; }
.msg.err { color: #c0392b; }

/* ── friends ── */
.friend-list { list-style: none; }

.friend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.friend-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}

.friend-name { flex: 1; font-size: 14px; color: var(--text); }

.friend-chat-btn, .friend-rm-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color .15s, color .15s;
}

.friend-chat-btn:hover { border-color: var(--text); color: var(--text); }
.friend-rm-btn:hover   { border-color: #c0392b; color: #c0392b; }

.role-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.05em;
}

.role-admin { background: var(--text); color: var(--bg); }
.role-user  { border: 1px solid var(--border); color: var(--text-faint); }

/* ── chat ── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.back-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-faint);
  padding: 0;
  transition: color .15s;
}

.back-btn:hover { color: var(--text); }
.chat-name { font-size: 14px; font-weight: 500; color: var(--text); }

.chat-msgs {
  height: 320px;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-row { display: flex; }
.msg-row.mine    { justify-content: flex-end; }
.msg-row.theirs  { justify-content: flex-start; }

.bubble {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
}

.mine .bubble   { background: var(--text); color: var(--bg); border-bottom-right-radius: 3px; }
.theirs .bubble { background: var(--code-bg); color: var(--text); border-bottom-left-radius: 3px; }

.del-msg {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  opacity: 0;
  margin-left: 6px;
  padding: 0;
  color: inherit;
  vertical-align: middle;
  transition: opacity .15s;
}

.bubble:hover .del-msg { opacity: .5; }
.del-msg:hover { opacity: 1 !important; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.chat-inp {
  flex: 1;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 20px;
  outline: none;
  transition: border-color .15s;
}

.chat-inp:focus { border-color: var(--text-faint); }

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  border: none;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .15s;
}

.chat-send-btn:hover { opacity: .8; }