/* ───────────────────────────────────────────────
   Те же токены, что на bekhruzabdullaev.uz
   ─────────────────────────────────────────────── */
:root {
  --bg: #ffffff;
  --ink: #0a0a0b;
  --body: #55555f;
  --muted: #86868f;
  --line: #e6e6ea;
  --wash: #f7f7f9;
  --pad: 24px;

  --font-body: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Instrument Serif', Georgia, 'Times New Roman', serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--body);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.rise {
  opacity: 0;
  animation: rise 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: calc(var(--i, 0) * 70ms + 80ms);
}

@media (prefers-reduced-motion: reduce) {
  .rise {
    opacity: 1;
    animation: none;
  }
}

.wrap {
  width: min(100% - calc(var(--pad) * 2), 700px);
  margin-inline: auto;
  padding: 56px 0 88px;
}

.wrap--admin,
.wrap--editor {
  width: min(100% - calc(var(--pad) * 2), 820px);
}

.wrap--login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ───────────── Общие элементы ───────────── */
a {
  color: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
  background: var(--wash);
}

.btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.btn--primary:hover {
  background: #23232a;
}

.btn--ghost {
  color: var(--body);
}

.btn--danger {
  color: #b4232a;
  border-color: #f0d6d7;
}

.btn--danger:hover {
  background: #fdf3f3;
}

.empty {
  margin: 40px 0 0;
  color: var(--muted);
}

/* ───────────── Шапка публичных страниц ───────────── */
.top__back {
  display: inline-block;
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.top__back:hover {
  color: var(--ink);
}

.top__title {
  margin: 22px 0 0;
  font-family: var(--font-display);
  font-size: clamp(32px, 7.5vw, 44px);
  font-weight: 400;
  line-height: 1.1;
  color: var(--ink);
}

.top__sub {
  margin: 8px 0 0;
  font-size: 17px;
  color: var(--muted);
}

/* ───────────── Карточки ───────────── */
.cards {
  display: grid;
  gap: 14px;
  margin-top: 40px;
}

.card {
  display: block;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  text-decoration: none;
  background: #fff;
  transition: border-color 0.18s ease, transform 0.18s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.18s ease;
}

.card:hover {
  border-color: #d5d5dd;
  transform: translateY(-2px);
  box-shadow: 0 18px 40px -30px rgba(10, 10, 11, 0.5);
}

.card__lang {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.card__title {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--ink);
}

.card__excerpt {
  margin: 10px 0 0;
  font-size: 16px;
  color: var(--body);
}

.card__meta {
  display: block;
  margin-top: 14px;
  font-size: 14px;
  color: var(--muted);
}

/* ───────────── Панель чтения ───────────── */
.tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 26px;
}

.modes {
  display: inline-flex;
  padding: 3px;
  background: var(--wash);
  border-radius: 999px;
}

.modes__btn {
  height: 32px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.modes__btn.is-on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(10, 10, 11, 0.08);
}

.share {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--body);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.share:hover {
  color: var(--ink);
  border-color: #d5d5dd;
}

/* ───────────── Текст сочинения ───────────── */
.essay {
  margin-top: 34px;
}

.essay__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(30px, 6.5vw, 42px);
  font-weight: 400;
  line-height: 1.14;
  letter-spacing: -0.005em;
  color: var(--ink);
}

.essay__meta {
  margin: 10px 0 0;
  font-size: 15px;
  color: var(--muted);
}

.essay__body {
  margin-top: 30px;
}

.essay__body p {
  margin: 0 0 22px;
  font-size: 18px;
  line-height: 1.62;
}

.essay__body h2,
.essay__body h3 {
  margin: 34px 0 12px;
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.2;
  color: var(--ink);
}

.essay__body h2 {
  font-size: 27px;
}

.essay__body h3 {
  font-size: 22px;
}

.essay__body strong,
.essay__body b {
  color: var(--ink);
  font-weight: 600;
}

.essay__body u {
  text-underline-offset: 3px;
}

.essay__body a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: #c9c9d1;
  transition: text-decoration-color 0.15s ease;
}

.essay__body a:hover {
  text-decoration-color: currentColor;
}

.essay__body blockquote {
  margin: 26px 0;
  padding-left: 20px;
  border-left: 2px solid var(--line);
  font-family: var(--font-display);
  font-size: 21px;
  line-height: 1.45;
  color: var(--ink);
}

.essay__body ul,
.essay__body ol {
  margin: 0 0 22px;
  padding-left: 22px;
  font-size: 18px;
}

.essay__body li {
  margin-bottom: 8px;
}

/* ───────────── Режим книги ───────────── */
.book {
  margin-top: 30px;
}

.book[hidden] {
  display: none;
}

/* Рамка обрезает лист: у .book__stage есть perspective,
   а элемент с perspective не обрезает свои 3D-потомки. */
.book__frame {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  overflow: hidden;
}

.book__stage {
  position: relative;
  perspective: 2200px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

.book__stage:active {
  cursor: grabbing;
}

.book__spread {
  position: relative;
  display: flex;
  height: 100%;
}

.book__side {
  position: relative;
  overflow: hidden;
  flex: 1 1 50%;
}

.book__side + .book__side {
  border-left: 1px solid var(--line);
}

/* Тонкая тень у сгиба — как в книге */
.book__spread--double .book__side:first-child::after,
.book__spread--double .book__side:last-child::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 26px;
  pointer-events: none;
}

.book__spread--double .book__side:first-child::after {
  right: 0;
  background: linear-gradient(90deg, rgba(10, 10, 11, 0), rgba(10, 10, 11, 0.05));
}

.book__spread--double .book__side:last-child::before {
  left: 0;
  background: linear-gradient(270deg, rgba(10, 10, 11, 0), rgba(10, 10, 11, 0.05));
}

.book__view {
  position: absolute;
  inset: 0;
  padding: var(--book-pad, 32px);
  overflow: hidden;
}

.book__flow {
  columns: var(--page-w, 320px) auto;
  column-gap: var(--page-gap, 64px);
  column-fill: auto;
  height: var(--page-h, 520px);
  width: var(--page-w, 320px);
}

.book__flow > * {
  break-inside: avoid-column;
}

.book__num {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* Переворачивающийся лист — положение задаёт JS, чтобы он шёл за рукой */
.book__leaf {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 50%;
  transform-style: preserve-3d;
  will-change: transform;
  z-index: 3;
  pointer-events: none;
}

.book__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.book__face > .book__side {
  position: absolute;
  inset: 0;
}

.book__face--back {
  transform: rotateY(180deg);
}

/* Блик и тень на самом листе: у корешка темнее, к краю светлее */
.book__gloss {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.book__gloss--front {
  background: linear-gradient(to left, rgba(10, 10, 11, 0) 52%, rgba(10, 10, 11, 0.2));
}

.book__gloss--back {
  background: linear-gradient(to right, rgba(10, 10, 11, 0) 52%, rgba(10, 10, 11, 0.24));
}

.book__leaf[data-spine='right'] .book__gloss--front {
  background: linear-gradient(to right, rgba(10, 10, 11, 0) 52%, rgba(10, 10, 11, 0.2));
}

.book__leaf[data-spine='right'] .book__gloss--back {
  background: linear-gradient(to left, rgba(10, 10, 11, 0) 52%, rgba(10, 10, 11, 0.24));
}

/* Тень, которую лист бросает на открывающуюся страницу */
.book__cast {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 130px;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(to right, rgba(10, 10, 11, 0.22), rgba(10, 10, 11, 0));
}

.book__nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 18px;
}

.book__arrow {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.book__arrow:hover:not(:disabled) {
  background: var(--wash);
}

.book__arrow:disabled {
  opacity: 0.35;
  cursor: default;
}

.book__count {
  min-width: 76px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Книжный текст наследует стиль сочинения */
.book__flow p {
  margin: 0 0 18px;
  font-size: 17px;
  line-height: 1.62;
}

.book__flow h1 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 400;
  line-height: 1.15;
  color: var(--ink);
}

.book__flow h2,
.book__flow h3 {
  margin: 22px 0 10px;
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--ink);
}

.book__flow h2 {
  font-size: 23px;
}

.book__flow h3 {
  font-size: 20px;
}

.book__flow strong,
.book__flow b {
  color: var(--ink);
  font-weight: 600;
}

.book__flow blockquote {
  margin: 20px 0;
  padding-left: 16px;
  border-left: 2px solid var(--line);
  font-family: var(--font-display);
  font-size: 19px;
  color: var(--ink);
}

.book__flow a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: #c9c9d1;
}

.book__flow ul,
.book__flow ol {
  margin: 0 0 18px;
  padding-left: 20px;
  font-size: 17px;
}

.book__meta {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--muted);
}

/* Книга шире колонки текста */
body:has(.wrap--read[data-mode='book']) .wrap--read {
  width: min(100% - calc(var(--pad) * 2), 1080px);
}

.wrap--read[data-mode='book'] .essay {
  display: none;
}

/* ───────────── Toast ───────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(10px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 20;
}

.toast[hidden] {
  display: none;
}

.toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ───────────── Вход ───────────── */
.login {
  width: min(100% - 40px, 340px);
  text-align: center;
}

.login__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 400;
  color: var(--ink);
}

.login__sub {
  margin: 8px 0 22px;
  font-size: 15px;
  color: var(--muted);
}

.login__code {
  display: block;
  width: 100%;
  height: 54px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 26px;
  font-weight: 500;
  letter-spacing: 0.35em;
  text-align: center;
  text-indent: 0.35em;
}

.login__code:focus {
  outline: none;
  border-color: #c9c9d1;
}

.login .btn {
  width: 100%;
}

.login__again {
  display: inline-block;
  margin-top: 14px;
  font-size: 14px;
  color: var(--muted);
}

.login__error {
  margin: 14px 0 0;
  font-size: 14px;
  color: #b4232a;
}

/* ───────────── Админка ───────────── */
.adminhead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.adminhead__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 400;
  line-height: 1.1;
  color: var(--ink);
}

.adminhead__sub {
  margin: 6px 0 0;
  font-size: 15px;
  color: var(--muted);
}

.adminhead__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.items {
  margin-top: 34px;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
}

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  flex-wrap: wrap;
}

.item + .item {
  border-top: 1px solid var(--line);
}

.item__title {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--ink);
  text-decoration: none;
}

.item__title:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.item__meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
}

.views {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
}

.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.pill--live {
  background: #eaf6ef;
  color: #1c7a49;
}

.pill--draft {
  background: var(--wash);
  color: var(--muted);
}

.item__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.item__actions form {
  margin: 0;
}

/* ───────────── Редактор ───────────── */
.edhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.edhead__back {
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
}

.edhead__back:hover {
  color: var(--ink);
}

.edhead__right {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.lang {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--body);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.titlefield {
  display: block;
  width: 100%;
  margin: 34px 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(30px, 6.5vw, 42px);
  font-weight: 400;
  line-height: 1.14;
}

.titlefield::placeholder {
  color: #c9c9d1;
}

.titlefield:focus {
  outline: none;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 20px;
  padding: 8px 0;
  background: var(--bg);
}

.toolbar button {
  min-width: 36px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--body);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.toolbar button:hover {
  background: var(--wash);
  color: var(--ink);
}

.toolbar button.is-on {
  background: var(--ink);
  color: #fff;
}

.toolbar__sep {
  width: 1px;
  height: 20px;
  margin: 0 6px;
  background: var(--line);
}

.paper {
  margin-top: 6px;
  padding-bottom: 120px;
}

.editable {
  min-height: 60vh;
  outline: none;
  font-size: 18px;
  line-height: 1.62;
}

.editable:empty::before,
.editable:has(> p:only-child:empty)::before {
  content: attr(data-placeholder);
  color: #c9c9d1;
  pointer-events: none;
}

.editable p {
  margin: 0 0 22px;
}

.editable h2 {
  margin: 34px 0 12px;
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 400;
  color: var(--ink);
}

.editable strong,
.editable b {
  color: var(--ink);
  font-weight: 600;
}

.editable a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: #c9c9d1;
}

.editable blockquote {
  margin: 26px 0;
  padding-left: 20px;
  border-left: 2px solid var(--line);
  font-family: var(--font-display);
  font-size: 21px;
  color: var(--ink);
}

.editable ul,
.editable ol {
  margin: 0 0 22px;
  padding-left: 22px;
}

@media (max-width: 640px) {
  .wrap {
    padding: 36px 0 64px;
  }

  .item {
    align-items: flex-start;
  }

  .adminhead__actions,
  .item__actions {
    width: 100%;
  }
}
