:root {
  --bg: #f6f3ee;
  --panel: rgba(255, 255, 255, 0.78);
  --text: #222222;
  --muted: #7a756d;
  --accent: #1f2937;
  --border: rgba(31, 41, 55, 0.12);
  --danger: #b42318;
  --shadow: 0 24px 60px rgba(31, 41, 55, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top right, rgba(210, 180, 140, 0.26), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
}

.sidebar-toggle {
  position: fixed;
  z-index: 20;
  top: 22px;
  left: 22px;
  display: grid;
  gap: 4px;
  width: 44px;
  height: 44px;
  place-content: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.sidebar-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--accent);
}

.sidebar {
  position: fixed;
  z-index: 10;
  inset: 0 auto 0 0;
  width: 310px;
  padding: 86px 18px 24px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow-y: auto;
  transition: transform 220ms ease;
}

.sidebar-hidden .sidebar {
  transform: translateX(-100%);
}

.sidebar-hidden .editor {
  margin-left: auto;
}

.sidebar-header {
  margin-bottom: 16px;
  padding: 0 8px;
}

.sidebar-header p {
  margin: 0 0 6px;
  color: var(--muted);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sidebar-header h2 {
  margin: 0;
  color: var(--accent);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1.4rem;
}

.search-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.58);
}

.search-panel label,
.search-count {
  color: var(--muted);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.search-panel input,
.search-panel select {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--accent);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.95rem;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.clear-search {
  padding: 10px 12px;
  background: transparent;
  color: var(--accent);
}

.search-count {
  margin: 0;
  letter-spacing: 0;
  text-transform: none;
}

.publication-list {
  display: grid;
  gap: 10px;
}

.publication-item {
  display: grid;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 18px;
  padding: 14px;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.publication-item:hover {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.78);
  transform: translateY(-1px);
}

.publication-item strong {
  line-height: 1.25;
}

.publication-item em {
  color: var(--muted);
  display: -webkit-box;
  font-size: 0.88rem;
  font-style: normal;
  line-height: 1.35;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.publication-item small {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.publication-item b {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.publication-item span,
.empty-state {
  color: var(--muted);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.86rem;
}

.empty-state {
  padding: 14px 8px;
}

.editor {
  width: min(740px, calc(100% - 32px));
  margin: 0 auto 0 max(340px, calc((100vw - 430px) / 2));
  padding: 64px 0;
  transition: margin 220ms ease;
}

form {
  display: grid;
  gap: 22px;
}

input,
.story-editor {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
}

.title {
  font-size: clamp(2.3rem, 8vw, 4rem);
  line-height: 1.08;
}

.title::placeholder,
.story-editor:empty::before,
.toolbar input::placeholder {
  color: var(--muted);
}

.format-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: fit-content;
  border-radius: 14px;
  padding: 7px;
  background: #1f2937;
  box-shadow: 0 14px 40px rgba(31, 41, 55, 0.22);
}

.format-toolbar button {
  display: grid;
  min-width: 32px;
  height: 32px;
  place-content: center;
  border: 0;
  border-radius: 9px;
  padding: 0 9px;
  background: transparent;
  color: #ffffff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
}

.format-toolbar button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.format-toolbar button:nth-child(4) {
  font-size: 1.18rem;
}

.format-toolbar button:nth-child(5) {
  font-size: 0.88rem;
}

.story-editor {
  min-height: 52vh;
  font-size: 1.35rem;
  line-height: 1.65;
}

.story-editor:empty::before {
  content: attr(data-placeholder);
  pointer-events: none;
}

.story-editor h3,
.story-editor h4,
.story-editor p,
.story-editor blockquote,
.story-editor pre {
  margin: 0 0 1rem;
}

.story-editor h3 {
  font-size: 1.7rem;
  line-height: 1.25;
}

.story-editor h4 {
  font-size: 1.35rem;
  line-height: 1.3;
}

.story-editor blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 18px;
  color: var(--muted);
}

.story-editor pre {
  overflow-x: auto;
  border-radius: 16px;
  padding: 16px;
  background: #1f2937;
  color: #f8fafc;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 1rem;
  line-height: 1.5;
}

.story-editor a {
  color: var(--accent);
}

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.toolbar input {
  min-width: 0;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.95rem;
}

button {
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 10px 18px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  white-space: nowrap;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.result {
  margin-top: 28px;
  border-top: 1px solid var(--border);
  padding-top: 18px;
  font-family: Arial, Helvetica, sans-serif;
}

.result p {
  margin: 0 0 8px;
  color: var(--muted);
}

.result a {
  color: var(--accent);
  overflow-wrap: anywhere;
}

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

@media (max-width: 640px) {
  .sidebar {
    width: min(86vw, 320px);
  }

  .editor {
    width: min(740px, calc(100% - 28px));
    margin: 0 auto;
    padding-top: 36px;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }
}
