:root {
  color-scheme: dark;
  font-family: "IBM Plex Mono", "SFMono-Regular", "Menlo", monospace;
  --bg: #0c0f14;
  --bg-soft: #11151f;
  --bg-softer: #161a26;
  --fg: #f5f7ff;
  --fg-muted: #9aa4c2;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --border: rgba(148, 163, 184, 0.12);
  --radius: 10px;
  --shadow: 0 18px 40px -32px rgba(15, 23, 42, 0.9);
}

* {
  box-sizing: border-box;
}

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

body {
  line-height: 1.55;
  letter-spacing: 0.01em;
}

.site-title {
  font-family: "IBM Plex Mono", "SFMono-Regular", "Menlo", monospace;
  font-size: clamp(2.4rem, 5vw, 3.6rem);
  letter-spacing: 0.06em;
  color: var(--accent);
}

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

a:hover,
a:focus {
  text-decoration: underline;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px 96px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  margin-bottom: 32px;
}

/* Author block */
.author-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 20px;
  text-decoration: none;
  color: inherit;
  border-radius: 8px;
  padding: 4px 8px;
  transition: all 0.15s ease;
}

.author-info:hover {
  background: var(--bg-soft);
  transform: translateY(-1px);
}

.author-photo {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.author-name {
  font-size: 0.95rem;
  color: var(--fg-muted);
}

header h1,
article h1,
section h2 {
  margin: 0;
  font-size: clamp(1.5rem, 1.8vw + 1rem, 2.8rem);
}

header nav {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}

header nav a,
header nav form {
  font-size: 0.95rem;
}

p {
  margin: 0 0 1.25rem;
}

.list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
  align-items: flex-start;
}

.post-preview {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.post-preview h2 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 1.25rem;
}

.post-preview p,
.post-preview .article-meta,
.post-preview a {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.article-meta {
  font-size: 0.85rem;
  color: var(--fg-muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-softer);
  color: var(--fg-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.post-body {
  font-size: 1rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.post-body p {
  margin: 0 0 1.25rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.post-body pre {
  background: transparent;
  border: none;
  padding: 0;
  overflow-x: auto;
  font-size: 0.92rem;
}

.post-body code {
  background: transparent;
  padding: 0;
  border: none;
}

.post-body img {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin: 24px auto;
  box-shadow: var(--shadow);
}

footer {
  margin-top: 64px;
  font-size: 0.85rem;
  color: var(--fg-muted);
  text-align: center;
}

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

.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-softer);
  color: var(--fg);
  cursor: pointer;
  transition: border 0.15s ease, transform 0.15s ease;
}

.button:hover,
button:hover {
  transform: translateY(-1px);
  border-color: rgba(148, 163, 184, 0.4);
}

.button.primary {
  background: var(--bg-soft);
  border-color: rgba(59, 130, 246, 0.4);
}

.button.accent {
  background: var(--accent);
  color: #0b1120;
  border-color: transparent;
}

.button.danger {
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fee2e2;
}

.button.post-link {
  min-width: 72px;
}

.button.post-delete {
  min-width: 82px;
}

.muted {
  color: var(--fg-muted);
  margin-top: 12px;
}

.error {
  margin-top: 12px;
  color: #fda4af;
}

input,
textarea {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-softer);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  min-height: 240px;
  line-height: 1.6;
}

.editor-field {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toolbar-button {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(23, 31, 48, 0.8);
  color: var(--fg);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border 0.15s ease, transform 0.15s ease;
}

.toolbar-button:hover {
  transform: translateY(-1px);
  border-color: rgba(148, 163, 184, 0.45);
}

.toolbar-status {
  font-size: 0.8rem;
  color: var(--fg-muted);
}

.toolbar-status[data-variant="error"] {
  color: #fca5a5;
}

.toolbar-status[data-variant="success"] {
  color: #bbf7d0;
}

[data-preview-status] {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.95rem;
}

.auth-shell {
  max-width: 360px;
  margin: 88px auto;
  background: var(--bg-soft);
  padding: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.writer-mode main {
  max-width: 1120px;
}

.admin-header {
  margin-bottom: 40px;
}

.admin-header nav {
  gap: 12px;
}

.writer-shell {
  background: var(--bg-soft);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 24px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 32px;
}

.writer-sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar-actions {
  display: flex;
  justify-content: space-between;
}

.post-groups {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.post-group {
  background: var(--bg-softer);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.count-pill {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.75rem;
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.post-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
}

.post-link-static {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-row {
  color: var(--fg-muted);
  font-size: 0.9rem;
}

.admin-edit {
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(280px, 0.9fr);
  gap: 32px;
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.editor-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.preview-pane {
  background: var(--bg-softer);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100%;
}

.preview-pane h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--fg-muted);
}

.error-page main {
  max-width: 720px;
}

.error-card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.error-card pre {
  background: rgba(15, 23, 42, 0.6);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
}

code {
  font-family: inherit;
}

/* Code block enhancements: container, filename bar, language pill */
.code-container {
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 18px 0;
  box-shadow: var(--shadow);
}

.code-container .code-filename {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.45);
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-container .code-block {
  padding: 14px 16px;
}

/* Position language pill above the code box */
.code-language {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 12px 8px auto;
  padding: 2px 8px;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(59, 130, 246, 0.45);
  border-radius: 999px;
}

@media (max-width: 960px) {
  .admin-grid,
  .admin-edit {
    grid-template-columns: 1fr;
  }

  .post-row {
    grid-template-columns: 1fr auto;
    grid-auto-flow: row;
  }

  .preview-pane {
    min-height: unset;
  }

  header {
    flex-direction: column;
    align-items: flex-start;
  }

  header nav {
    width: 100%;
    justify-content: flex-start;
  }
}
