:root {
  color-scheme: light;
  --bg: #f6f5ef;
  --panel: #fffefa;
  --ink: #171717;
  --muted: #77746b;
  --line: #dedbd2;
  --accent: #111111;
  --warm: #f2c200;
  --accent-hover: #2a2a2a;
  --accent-ink: #fffefa;
  --danger: #a9352b;
  --danger-bg: #fff0ee;
  --danger-border: #e2b0a9;
  --focus: #171717;
  --focus-ring: rgba(17, 17, 17, 0.12);
  --field: #ffffff;
  --header-bg: rgba(246, 245, 239, 0.9);
  --hover-border: #aaa59a;
  --panel-shadow: 0 20px 60px rgba(17, 17, 17, 0.08);
  --toolbar-bg: #f0eee7;
  --preview-bg: #fffefa;
  --pre-bg: #171717;
  --pre-ink: #f4f1dc;
  --code-bg: #ece8dd;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
  scrollbar-width: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
  -ms-overflow-style: none;
}

a {
  color: inherit;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
.primary,
.ghost,
.danger {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.ghost:hover {
  border-color: var(--hover-border);
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.primary:hover {
  background: var(--accent-hover);
}

.danger {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  padding: 12px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--panel-shadow);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: 0;
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--danger-bg);
  color: var(--danger);
}

.form-success {
  margin: 0 0 18px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--accent);
  font-weight: 700;
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
}

.admin-brand {
  font-weight: 900;
  text-decoration: none;
}

.admin-header nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-header nav a,
.admin-header nav button {
  min-height: 36px;
  padding: 0 10px;
  color: var(--muted);
  text-decoration: none;
}

.admin-header nav a.active {
  color: var(--ink);
  font-weight: 800;
}

.admin-header form {
  margin: 0;
}

.admin-page,
.editor-page {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto 72px;
  padding-top: 28px;
}

.admin-title,
.editor-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
}

td span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

tr:last-child td {
  border-bottom: 0;
}

.actions {
  text-align: right;
  white-space: nowrap;
}

.actions a {
  margin-left: 12px;
  color: var(--accent);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.settings-form {
  max-width: 760px;
}

.settings-grid {
  grid-template-columns: 1fr;
}

.settings-grid textarea {
  min-height: 132px;
}

.page-meta-grid {
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 180px;
}

.wide {
  grid-column: span 2;
}

.writer {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.toolbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--toolbar-bg);
  overflow-x: auto;
}

.toolbar button {
  min-width: 40px;
  min-height: 36px;
  padding: 0 10px;
  font-weight: 700;
}

.writer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
  min-height: 620px;
}

.content-field {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  border-right: 1px solid var(--line);
}

.content-field span,
.preview-head {
  padding: 12px 14px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.content-field textarea {
  min-height: 560px;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: var(--field);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.7;
}

.content-field textarea:focus {
  box-shadow: none;
}

.preview-pane {
  min-width: 0;
  background: var(--preview-bg);
  overflow: auto;
}

.preview-body {
  padding: 14px;
}

.content {
  font-size: 16px;
  line-height: 1.8;
}

.content img {
  max-width: 100%;
  border-radius: 7px;
}

.content pre {
  overflow-x: auto;
  padding: 14px;
  border-radius: 7px;
  background: var(--pre-bg);
  color: var(--pre-ink);
}

.content code {
  padding: 0.12em 0.3em;
  border-radius: 4px;
  background: var(--code-bg);
}

.content pre code {
  padding: 0;
  background: transparent;
}

.empty {
  color: var(--muted);
}

@media (max-width: 860px) {
  .admin-header {
    padding: 0 16px;
  }

  .admin-title,
  .editor-top {
    align-items: stretch;
    flex-direction: column;
  }

  .editor-actions {
    justify-content: flex-start;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }

  .writer-grid {
    grid-template-columns: 1fr;
  }

  .content-field {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-pane {
    min-height: 320px;
  }
}

@media (max-width: 560px) {
  .admin-header {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 16px;
  }

  .admin-header nav {
    width: 100%;
    overflow-x: auto;
  }

  h1 {
    font-size: 28px;
  }
}
