:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-alt: #eef2f7;
  --surface: var(--panel);
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --border: #dbe2ea;
  --danger: #b91c1c;
  --button-text: #ffffff;
  --badge-bg: #dff5f1;
  --badge-text: #115e59;
  --diff-add-bg: #ecfdf5;
  --diff-add-text: #166534;
  --diff-del-bg: #fee2e2;
  --diff-del-text: #991b1b;
  --diff-ins-bg: #dcfce7;
  --diff-ins-text: #166534;
  --diff-del-inline-bg: #fee2e2;
  --diff-del-inline-text: #991b1b;
}

html[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #111827;
  --panel-alt: #1f2937;
  --surface: var(--panel);
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #2dd4bf;
  --primary-dark: #14b8a6;
  --border: #334155;
  --danger: #ef4444;
  --button-text: #0f172a;
  --badge-bg: #134e4a;
  --badge-text: #5eead4;
  --diff-add-bg: #052e16;
  --diff-add-text: #86efac;
  --diff-del-bg: #450a0a;
  --diff-del-text: #fca5a5;
  --diff-ins-bg: #052e16;
  --diff-ins-text: #86efac;
  --diff-del-inline-bg: #450a0a;
  --diff-del-inline-text: #fca5a5;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #0f172a;
    --panel: #111827;
    --panel-alt: #1f2937;
    --surface: var(--panel);
    --text: #e5e7eb;
    --muted: #9ca3af;
    --primary: #2dd4bf;
    --primary-dark: #14b8a6;
    --border: #334155;
    --danger: #ef4444;
    --button-text: #0f172a;
    --badge-bg: #134e4a;
    --badge-text: #5eead4;
    --diff-add-bg: #052e16;
    --diff-add-text: #86efac;
    --diff-del-bg: #450a0a;
    --diff-del-text: #fca5a5;
    --diff-ins-bg: #052e16;
    --diff-ins-text: #86efac;
    --diff-del-inline-bg: #450a0a;
    --diff-del-inline-text: #fca5a5;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

a:hover {
  text-decoration: underline;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

.container.narrow {
  max-width: 860px;
}

.container.wide {
  max-width: 1380px;
}

.header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 2rem;
}

.header h1 {
  margin: 0 0 0.4rem;
  font-size: 2rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-brand h1 {
  margin: 0 0 0.4rem;
}

.site-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
}

.site-logo-small {
  width: 20px;
  height: 20px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 0.3rem;
  opacity: 0.75;
}

.back-home {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.header p {
  margin: 0;
  color: var(--muted);
}

.button,
button,
input[type="submit"],
input[type="button"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--primary);
  color: var(--button-text);
  border: 1px solid var(--primary);
  border-radius: 0.6rem;
  padding: 0.75rem 1rem;
  text-decoration: none;
  cursor: pointer;
}

.button:hover,
button:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  text-decoration: none;
}

.button.secondary,
button.secondary {
  background: var(--panel-alt);
  color: var(--text);
  border-color: var(--border);
}

.button.secondary:hover,
button.secondary:hover {
  background: var(--panel);
}

.filters,
.stack {
  display: grid;
  gap: 1rem;
}

.filters {
  grid-template-columns: 1fr 220px auto;
  margin-bottom: 1.5rem;
}

.filters.filters-4 {
  grid-template-columns: 2fr 1fr 220px auto;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: var(--panel);
  color: var(--text);
}

textarea.code-area {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  min-height: 360px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.card-top,
.meta,
.tags,
.actions,
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.card h2 {
  margin: 0.8rem 0 0.5rem;
  font-size: 1.15rem;
}

.badge,
.tag {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
}

.badge {
  background: var(--badge-bg);
  color: var(--badge-text);
}

.tag {
  background: var(--panel-alt);
  color: var(--primary);
}

.snippet-header {
  margin: 1rem 0 1.2rem;
}

.snippet-header h1 {
  margin: 0 0 0.4rem;
}

pre {
  border-radius: 1rem;
  overflow: auto;
  font-size: 0.95rem;
}

.editor-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}

.editor-layout-v2 {
  grid-template-columns: 1.4fr 1fr;
}

.snippet-list {
  margin: 0;
  padding-left: 1rem;
}

.snippet-list li {
  margin: 0 0 0.7rem;
}

.error {
  color: var(--danger);
}

.hint,
.count {
  color: var(--muted);
}

.copy-wrap {
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: flex-end;
}

.tag-cloud {
  margin: 0 0 1rem;
}

.markdown-body {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem 1.2rem;
  margin: 0 0 1rem;
  min-height: 160px;
}

.markdown-body p,
.markdown-body li {
  line-height: 1.7;
}

.markdown-body code {
  background: var(--panel-alt);
  padding: 0.15rem 0.35rem;
  border-radius: 0.3rem;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
}

@media (max-width: 980px) {
  .editor-layout,
  .editor-layout-v2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 800px) {
  .header,
  .filters,
  .filters.filters-4 {
    grid-template-columns: 1fr;
    display: grid;
  }
}

.diff-output {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  line-height: 1.7;
}

.diff-output ins {
  background: var(--diff-ins-bg);
  color: var(--diff-ins-text);
  text-decoration: none;
  padding: 0.08rem 0.1rem;
  border-radius: 0.2rem;
}

.diff-output del {
  background: var(--diff-del-inline-bg);
  color: var(--diff-del-inline-text);
  text-decoration: line-through;
  padding: 0.08rem 0.1rem;
  border-radius: 0.2rem;
}

.diff-code {
  overflow: auto;
}

.code-line-diff {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
  background: var(--panel);
}

.code-line-diff-head,
.diff-row {
  display: grid;
  grid-template-columns: 70px 70px 1fr;
}

.code-line-diff-head {
  background: var(--panel-alt);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.code-line-diff-head span,
.diff-row span,
.diff-row code {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
}

.diff-row code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  display: block;
}

.diff-row-same {
  background: var(--panel);
}

.diff-row-add {
  background: var(--diff-add-bg);
  color: var(--diff-add-text);
}

.diff-row-del {
  background: var(--diff-del-bg);
  color: var(--diff-del-text);
}

.diff-no {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.diff-code-lines .hint {
  padding: 1rem;
}

.diff-collapse {
  border-bottom: 1px solid var(--border);
  background: var(--panel-alt);
}

.diff-collapse summary {
  cursor: pointer;
  list-style: none;
  padding: 0.7rem 0.9rem;
  color: var(--primary);
  font-weight: 600;
}

.diff-collapse summary::-webkit-details-marker {
  display: none;
}

.diff-row-hidden {
  background: var(--panel-alt);
}

.login-inline input {
  max-width: 28rem;
}

.header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
  align-items: center;
}

.login-inline {
  margin: 0 0 1.5rem;
  padding: 1.25rem 1rem;
}

.login-head {
  margin: 0 0 1rem;
}

.login-head h2 {
  margin: 0 0 0.35rem;
}

.login-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 1rem;
  align-items: end;
}

.login-form label {
  display: block;
  margin: 0;
}

.login-form input {
  max-width: none;
}

.login-form .actions {
  margin: 0;
}

.login-inline .hint {
  margin: 0;
}

@media (max-width: 900px) {
  .login-form {
    grid-template-columns: 1fr;
  }

  .header nav {
    justify-content: flex-start;
  }
}

.nav-inline-form {
  display: inline;
  margin: 0;
}

.nav-inline-form button {
  font: inherit;
}

.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 1rem 1rem;
  z-index: 1000;
}

.modal-card {
  width: min(560px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  padding: 1.25rem;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.modal-head h2 {
  margin: 0;
}

.modal-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}

.modal-login-form {
  margin-top: 1rem;
}

.modal-login-form .actions {
  justify-content: flex-end;
}

.modal-login-form input {
  max-width: none;
}

[hidden] {
  display: none !important;
}

.modal-backdrop.is-open {
  display: flex !important;
}

.search-row {
  align-items: center;
}

.search-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-weight: 700;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 42px;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--panel-alt);
}
