:root {
  color-scheme: light;
  --paper: #f2f6f7;
  --paper-soft: #e7eff2;
  --panel: rgba(255, 254, 253, 0.9);
  --panel-strong: #fffefd;
  --field: rgba(255, 255, 255, 0.82);
  --field-muted: rgba(246, 250, 251, 0.78);
  --ink: #10232e;
  --muted: #5d7079;
  --muted-strong: #405761;
  --line: #d4e2e7;
  --teal: #147b91;
  --teal-dark: #0e4e66;
  --coral: #c35d6f;
  --danger: #9f2f45;
  --success: #147b68;
  --shadow: 0 18px 50px rgba(16, 35, 46, 0.1);
  --shadow-soft: 0 8px 24px rgba(16, 35, 46, 0.07);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(20, 123, 145, 0.08), transparent 280px),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.admin-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: calc(22px + env(safe-area-inset-top)) 0 calc(56px + env(safe-area-inset-bottom));
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.admin-header h1,
.notice h2,
.library-heading h2,
.form-heading h2,
.preview-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.admin-header h1 {
  font-size: clamp(28px, 3.2vw, 48px);
  line-height: 1;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.session-card,
.notice,
.library-card,
.editor-card,
.preview-card,
.deploy-panel {
  border: 1px solid rgba(16, 35, 46, 0.12);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.session-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.notice {
  max-width: 720px;
  padding: 22px;
}

.notice p {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.94fr) minmax(360px, 1.06fr);
  gap: 16px;
  align-items: start;
}

.library-card,
.editor-card,
.preview-card {
  padding: 18px;
}

.library-card {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 14px;
}

.library-heading,
.form-heading,
.library-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.library-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.library-filters label {
  display: grid;
  gap: 5px;
}

.library-filters span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.library-filters select {
  padding: 9px 11px;
  font-size: 13px;
}

.deploy-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 13px;
  box-shadow: var(--shadow-soft);
}

.deploy-panel h3 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.2;
}

.deploy-panel p:last-child {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.45;
}

.deploy-panel a {
  color: var(--teal-dark);
  font-weight: 950;
}

.deploy-panel .is-success {
  color: var(--success);
}

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

.library-heading h2,
.form-heading h2 {
  font-size: 22px;
  line-height: 1.15;
}

.autosave-status {
  display: inline-flex;
  width: fit-content;
  margin-top: 8px;
  border: 1px solid rgba(20, 123, 145, 0.14);
  border-radius: 999px;
  padding: 5px 9px;
  background: rgba(20, 123, 145, 0.08);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.permission-status {
  display: inline-flex;
  width: fit-content;
  margin-top: 8px;
  margin-left: 6px;
  border: 1px solid rgba(93, 126, 112, 0.18);
  border-radius: 999px;
  padding: 5px 9px;
  background: rgba(93, 126, 112, 0.1);
  color: var(--sage);
  font-size: 12px;
  font-weight: 900;
}

.autosave-status.is-success {
  color: var(--success);
}

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

.permission-status.is-readonly {
  border-color: rgba(159, 47, 69, 0.16);
  background: rgba(159, 47, 69, 0.1);
  color: var(--danger);
}

.permission-status.is-owner {
  border-color: rgba(20, 123, 145, 0.18);
  background: rgba(20, 123, 145, 0.1);
  color: var(--teal-dark);
}

.library-actions {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.post-list {
  display: grid;
  gap: 8px;
  max-height: 680px;
  overflow: auto;
  padding-right: 4px;
}

.post-item {
  display: grid;
  gap: 5px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--field);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.post-item:hover,
.post-item.is-active {
  border-color: rgba(20, 123, 145, 0.62);
  box-shadow: 0 0 0 3px rgba(20, 123, 145, 0.09), var(--shadow-soft);
}

.post-item:hover {
  transform: translateY(-1px);
}

.post-title {
  font-weight: 950;
}

.post-meta,
.post-path,
.empty-list {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.post-path {
  word-break: break-all;
}

.post-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.post-chip {
  width: fit-content;
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(20, 123, 145, 0.12);
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 950;
}

.post-chip.is-error {
  background: rgba(159, 47, 69, 0.12);
  color: var(--danger);
}

.post-chip.is-readonly {
  background: rgba(159, 47, 69, 0.1);
  color: var(--danger);
}

.post-chip.is-owner {
  background: rgba(20, 123, 145, 0.12);
  color: var(--teal-dark);
}

.post-chip.is-editable {
  background: rgba(93, 126, 112, 0.12);
  color: var(--sage);
}

.field,
.field-row {
  display: grid;
  min-width: 0;
  gap: 8px;
}

.field-row {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 12px;
}

.editor-card {
  display: grid;
  gap: 14px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

input,
select,
textarea {
  max-width: 100%;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--field);
  color: var(--ink);
  outline: 0;
}

input[type="date"] {
  appearance: none;
  -webkit-appearance: none;
  max-width: 100%;
  min-width: 0;
  padding-right: 38px;
}

input[type="date"]::-webkit-date-and-time-value {
  min-width: 0;
  text-align: left;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  margin: 0;
}

textarea {
  min-height: 420px;
  resize: vertical;
  line-height: 1.6;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 14px;
}

input[readonly] {
  color: var(--muted);
  background: var(--field-muted);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(20, 123, 145, 0.65);
  box-shadow: 0 0 0 4px rgba(20, 123, 145, 0.12);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: 18px;
  height: 18px;
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid rgba(16, 35, 46, 0.12);
  border-radius: 999px;
  padding: 0 18px;
  background: var(--field);
  color: var(--teal-dark);
  font-weight: 950;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 35, 46, 0.05);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.button-small {
  min-height: 34px;
  padding: 0 13px;
  font-size: 12px;
}

.button:hover,
.button:focus-visible {
  border-color: rgba(20, 123, 145, 0.38);
  box-shadow: 0 0 0 3px rgba(20, 123, 145, 0.1);
  outline: 0;
}

.button:hover {
  transform: translateY(-1px);
}

.button-primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  color: white;
}

.button-danger {
  border-color: rgba(159, 47, 69, 0.2);
  color: var(--danger);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.status-line {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

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

.status-line.is-success {
  color: var(--success);
}

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

.upload-panel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: var(--field-muted);
}

.upload-links {
  display: grid;
  gap: 6px;
}

.upload-links code {
  display: block;
  overflow-wrap: anywhere;
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--field);
  color: var(--ink);
  font-size: 12px;
}

.preview-card {
  position: sticky;
  top: 18px;
}

.preview-heading {
  margin-bottom: 12px;
}

.rendered-preview {
  display: grid;
  gap: 14px;
  max-height: min(74vh, 760px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  background: var(--panel-strong);
  color: var(--ink);
}

.rendered-preview h2,
.rendered-preview h3,
.rendered-preview h4,
.rendered-preview h5,
.rendered-preview p,
.rendered-preview ul,
.rendered-preview ol,
.rendered-preview figure,
.rendered-preview blockquote,
.rendered-preview .math-display,
.rendered-preview .entry-callout {
  margin: 0;
}

.rendered-preview h2,
.rendered-preview h3,
.rendered-preview h4,
.rendered-preview h5 {
  color: var(--ink);
  line-height: 1.22;
}

.rendered-preview p,
.rendered-preview li {
  color: var(--muted);
  line-height: 1.7;
}

.rendered-preview ul,
.rendered-preview ol {
  padding-left: 20px;
}

.rendered-preview a {
  color: var(--teal-dark);
  font-weight: 850;
}

.rendered-preview code {
  border-radius: 6px;
  padding: 2px 5px;
  background: rgba(20, 123, 145, 0.1);
  color: var(--teal-dark);
}

.rendered-preview pre {
  max-height: none;
  border-radius: 8px;
}

.rendered-preview hr {
  width: 100%;
  border: 0;
  border-top: 1px solid rgba(16, 35, 46, 0.12);
  margin: 2px 0;
}

.rendered-preview blockquote {
  border-left: 4px solid rgba(20, 123, 145, 0.34);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(20, 123, 145, 0.08);
  color: var(--muted);
}

.rendered-preview .math-display,
.rendered-preview .katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.rendered-preview .table-scroll {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid rgba(16, 35, 46, 0.1);
  border-radius: 8px;
  background: var(--field-muted);
}

.rendered-preview table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13px;
}

.rendered-preview th,
.rendered-preview td {
  border-bottom: 1px solid rgba(16, 35, 46, 0.1);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

.rendered-preview th {
  color: var(--ink);
  font-weight: 950;
  background: rgba(20, 123, 145, 0.08);
}

.rendered-preview img,
.rendered-preview video {
  display: block;
  max-width: 100%;
  border-radius: 10px;
}

.rendered-preview figcaption {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.preview-file {
  display: grid;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  border: 1px solid rgba(20, 123, 145, 0.16);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(20, 123, 145, 0.08);
  color: var(--teal-dark);
  text-decoration: none;
}

.preview-file span {
  font-weight: 950;
}

.preview-file small {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-weight: 750;
}

.rendered-preview .entry-file {
  display: grid;
  gap: 10px;
}

.rendered-preview .file-preview {
  overflow: hidden;
  border: 1px solid rgba(16, 35, 46, 0.12);
  border-radius: 8px;
  background: var(--field-muted);
}

.rendered-preview .file-preview summary {
  cursor: pointer;
  padding: 10px 12px;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 900;
}

.rendered-preview .file-preview iframe {
  display: block;
  width: 100%;
  height: min(62vh, 520px);
  border: 0;
  border-top: 1px solid rgba(16, 35, 46, 0.1);
  background: var(--panel-strong);
}

.rendered-preview .entry-callout {
  --callout-accent: var(--teal);
  --callout-soft: rgba(20, 123, 145, 0.1);
  display: grid;
  gap: 8px;
  border: 1px solid rgba(20, 123, 145, 0.16);
  border-left: 4px solid var(--callout-accent);
  border-radius: 8px;
  padding: 13px 15px;
  background: linear-gradient(135deg, var(--callout-soft), transparent 62%), var(--field);
}

.rendered-preview .entry-callout strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 950;
}

.rendered-preview .entry-callout.callout-proof {
  --callout-accent: var(--moss);
  --callout-soft: rgba(91, 121, 109, 0.12);
}

.rendered-preview .entry-callout.callout-example,
.rendered-preview .entry-callout.callout-tip {
  --callout-accent: var(--gold);
  --callout-soft: rgba(202, 161, 76, 0.14);
}

.rendered-preview .entry-callout.callout-warning,
.rendered-preview .entry-callout.callout-important {
  --callout-accent: var(--coral);
  --callout-soft: rgba(195, 93, 111, 0.13);
}

.raw-preview {
  margin-top: 12px;
}

.raw-preview summary {
  width: fit-content;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.raw-preview pre {
  margin-top: 10px;
}

pre {
  max-height: 720px;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  background: var(--panel-strong);
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #0f171b;
    --paper-soft: #152228;
    --panel: rgba(20, 31, 36, 0.9);
    --panel-strong: #132026;
    --field: rgba(12, 22, 27, 0.82);
    --field-muted: rgba(18, 31, 37, 0.74);
    --ink: #edf7f8;
    --muted: #a8bcc4;
    --muted-strong: #c2d3d8;
    --line: rgba(188, 220, 228, 0.16);
    --teal: #4fb4c5;
    --teal-dark: #8dd8e2;
    --coral: #ee8ea0;
    --danger: #ff9aab;
    --success: #8ed7c4;
    --shadow: 0 20px 56px rgba(0, 0, 0, 0.28);
    --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.22);
  }

  body {
    background:
      linear-gradient(180deg, rgba(79, 180, 197, 0.1), transparent 280px),
      var(--paper);
  }

  .session-card,
  .notice,
  .library-card,
  .editor-card,
  .preview-card,
  .deploy-panel {
    border-color: var(--line);
  }

  input,
  select,
  textarea,
  .post-item,
  .button,
  .rendered-preview,
  pre {
    border-color: var(--line);
  }

  input:focus,
  select:focus,
  textarea:focus,
  .button:hover,
  .button:focus-visible,
  .post-item:hover,
  .post-item.is-active {
    box-shadow: 0 0 0 3px rgba(79, 180, 197, 0.16);
  }

  .button-primary {
    background: linear-gradient(135deg, #248ca0, #186b82);
    color: #f7feff;
  }

  .post-chip {
    background: rgba(79, 180, 197, 0.14);
  }

  .post-chip.is-error {
    background: rgba(255, 154, 171, 0.14);
  }

  .rendered-preview .table-scroll,
  .rendered-preview .file-preview {
    border-color: var(--line);
  }
}

@media (max-width: 820px) {
  .admin-shell {
    width: min(100% - 20px, 1440px);
  }

  .admin-header,
  .workspace,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .admin-header {
    display: grid;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .field-row > .field {
    min-width: 0;
  }

  input[type="date"] {
    min-inline-size: 0;
    padding-right: 14px;
  }

  input[type="date"]::-webkit-calendar-picker-indicator {
    width: 18px;
    padding: 0;
  }

  .library-card,
  .preview-card {
    position: static;
  }
}
