@font-face {
  font-family: "QE Antony Lark";
  src: url("/assets/fonts/QEAntonyLark.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Dancing Script";
  src: url("/assets/fonts/DancingScript-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --paper: #c9964f;
  --ink: #120a05;
  --brass: #b98742;
  --brass-dark: #4f3216;
  --cover: #111219;
  --cover-deep: #050507;
  --desk: #211714;
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell {
  width: 100%;
  min-width: 320px;
  height: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--desk);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.desk {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 48% 42%, rgba(177, 105, 37, 0.22), transparent 34rem),
    radial-gradient(circle at 15% 12%, rgba(191, 147, 82, 0.13), transparent 22rem),
    linear-gradient(135deg, #312016 0%, #160f0d 47%, #241610 100%);
}

.desk::before {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  opacity: 0.34;
  background-image:
    repeating-linear-gradient(8deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 18px),
    repeating-linear-gradient(96deg, rgba(0,0,0,0.09) 0 2px, transparent 2px 34px);
  mix-blend-mode: overlay;
}

.book-stage {
  position: relative;
  width: min(62vw, calc((100vh - 180px) / 1.52), 680px);
  aspect-ratio: 1 / 1.34;
  perspective: 1600px;
  transform: translateY(-28px);
}

.book-block,
.back-cover,
.front-cover,
.page-wrap {
  position: absolute;
  inset: 0;
}

.book-block {
  inset: -54px -70px -52px -22px;
  border-radius: 16px;
  background:
    repeating-linear-gradient(180deg, rgba(242, 184, 91, 0.16) 0 1px, transparent 1px 12px),
    linear-gradient(90deg, #2f1e10, #120b06 45%, #3d2918);
  box-shadow: 18px 32px 32px rgba(0, 0, 0, 0.5);
  transform: translate(26px, 28px);
}

.back-cover,
.front-cover {
  inset: -62px -52px -60px -52px;
  border-radius: 18px;
  background:
    radial-gradient(ellipse at 54% 30%, rgba(255,255,255,0.06), transparent 22%),
    repeating-linear-gradient(18deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 15px),
    linear-gradient(145deg, var(--cover), var(--cover-deep) 50%, #0d0b11);
  border: 1px solid rgba(206, 152, 74, 0.24);
  box-shadow: 8px 34px 42px rgba(0, 0, 0, 0.7);
  transform-style: preserve-3d;
}

.back-cover::before,
.front-cover::before {
  position: absolute;
  inset: 10px;
  content: "";
  border-radius: 14px;
  border: 4px solid rgba(0, 0, 0, 0.62);
  filter: blur(2px);
}

.back-cover::after,
.front-cover::after {
  position: absolute;
  inset: 0 auto 0 0;
  width: 78px;
  content: "";
  border-radius: 18px 0 0 18px;
  background: linear-gradient(90deg, rgba(0,0,0,0.48), rgba(255,255,255,0.035), transparent);
}

.front-cover {
  z-index: 5;
  transform-origin: left center;
  transition: transform 1050ms ease-in-out, translate 1050ms ease-in-out, box-shadow 1050ms ease-in-out;
}

.book-stage[data-open="true"] .front-cover {
  translate: -18% -8px;
  transform: rotateY(-112deg);
  box-shadow: -18px 32px 28px rgba(0, 0, 0, 0.36);
}

.page-wrap {
  z-index: 3;
  opacity: 0.08;
  scale: 0.985;
  translate: 0 -24px;
  transition: opacity 500ms ease, scale 500ms ease, translate 500ms ease;
}

.book-stage[data-open="true"] .page-wrap {
  opacity: 1;
  scale: 1;
  translate: 18px -24px;
}

.page {
  position: absolute;
  inset: 0;
  border-radius: 5px;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 44% 36%, rgba(255, 214, 122, 0.22), transparent 52%),
    repeating-linear-gradient(8deg, rgba(71, 27, 7, 0.055) 0 1px, transparent 1px 16px),
    radial-gradient(ellipse at 18% 72%, rgba(111, 42, 9, 0.08), transparent 16%),
    linear-gradient(135deg, #f0bb61 0%, var(--paper) 43%, #8c521f 100%);
  border: 2px solid rgba(79, 27, 8, 0.62);
  box-shadow:
    20px 30px 36px rgba(0, 0, 0, 0.82),
    -22px -16px 24px rgba(255, 158, 64, 0.14);
}

.page::before {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(43, 12, 2, 0.42), rgba(130, 68, 20, 0.12), transparent 14%),
    linear-gradient(270deg, rgba(43, 12, 2, 0.22), transparent 12%),
    linear-gradient(135deg, transparent 72%, rgba(50, 18, 4, 0.22));
  z-index: 4;
}

.page::after {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 28%;
  height: 22%;
  content: "";
  pointer-events: none;
  background: linear-gradient(135deg, transparent 42%, rgba(59, 20, 5, 0.26));
  clip-path: polygon(0 100%, 100% 0, 100% 100%);
  z-index: 5;
}

.ink-layer {
  position: absolute;
  inset: 5.5%;
  z-index: 2;
  display: block;
  width: 89%;
  height: 89%;
}

.draw-layer {
  cursor: crosshair;
  touch-action: none;
  z-index: 6;
}

.cover-corner {
  position: absolute;
  width: 92px;
  height: 92px;
  background:
    radial-gradient(circle at 24% 24%, rgba(0,0,0,0.64) 0 4px, transparent 5px),
    linear-gradient(135deg, #cf9347, var(--brass-dark) 54%, #a87538);
  clip-path: polygon(0 0, 100% 0, 82% 24%, 54% 38%, 39% 63%, 12% 56%, 0 86%);
  filter: drop-shadow(0 3px 3px rgba(0,0,0,0.42));
}

.cover-corner.top {
  top: 22px;
  left: 22px;
}

.cover-corner.bottom {
  bottom: 22px;
  left: 22px;
  rotate: 180deg;
}

.title-plaque {
  position: absolute;
  left: 50%;
  bottom: 42px;
  width: min(360px, 58%);
  min-height: 42px;
  translate: -50% 0;
  display: grid;
  place-items: center;
  padding: 8px 18px;
  border-radius: 3px;
  border: 1px solid rgba(194, 145, 74, 0.64);
  background: rgba(10, 9, 8, 0.88);
  color: #e0b86b;
  font: 700 clamp(14px, 2vw, 22px) / 1 "Courier New", monospace;
  letter-spacing: 2px;
  text-align: center;
  text-shadow: 0 1px 1px #000;
}

.controls {
  position: absolute;
  left: 50%;
  bottom: 28px;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: min(92vw, 720px);
  translate: -50% 0;
}

.control,
.panel-close {
  min-width: 44px;
  min-height: 38px;
  border: 1px solid rgba(222, 178, 104, 0.28);
  border-radius: 6px;
  padding: 9px 14px;
  background: rgba(17, 13, 10, 0.78);
  color: #efd8ad;
  box-shadow: 0 10px 22px rgba(0,0,0,0.28);
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.control:hover:not(:disabled),
.panel-close:hover {
  border-color: rgba(239, 199, 121, 0.58);
  background: rgba(49, 33, 22, 0.86);
}

.control:disabled {
  cursor: default;
  opacity: 0.38;
}

.control.primary {
  background: rgba(90, 55, 24, 0.88);
}

.control.danger {
  color: #f1bca8;
}

.control.icon,
.panel-close {
  width: 42px;
  padding: 8px;
  font-size: 22px;
  line-height: 1;
}

.history-panel {
  position: absolute;
  top: 46px;
  right: 28px;
  z-index: 30;
  width: min(380px, calc(100vw - 38px));
  max-height: calc(100vh - 112px);
  overflow: hidden;
  border: 1px solid rgba(225, 176, 96, 0.22);
  border-radius: 8px;
  background: rgba(19, 14, 11, 0.86);
  box-shadow: 0 28px 50px rgba(0,0,0,0.45);
  backdrop-filter: blur(18px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 14px 10px 18px;
  border-bottom: 1px solid rgba(225, 176, 96, 0.14);
}

.panel-head h2 {
  margin: 0;
  color: #efcf9b;
  font-size: 16px;
}

.history-list,
.read-list {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding: 16px 18px 20px;
}

.history-item {
  display: grid;
  gap: 7px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(225, 176, 96, 0.12);
}

.history-item time {
  color: rgba(239, 216, 173, 0.54);
  font-size: 12px;
}

.history-item p,
.read-item p {
  margin: 0;
  overflow-wrap: anywhere;
}

.history-item .user {
  color: #f2d7a2;
}

.history-item .reply {
  color: #c9b087;
}

.read-panel {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(5, 4, 4, 0.58);
  backdrop-filter: blur(8px);
}

.read-sheet {
  width: min(760px, 94vw);
  max-height: min(820px, 90vh);
  overflow: hidden;
  border-radius: 8px;
  border: 2px solid rgba(79, 27, 8, 0.46);
  background:
    repeating-linear-gradient(8deg, rgba(71, 27, 7, 0.04) 0 1px, transparent 1px 16px),
    linear-gradient(135deg, #edbb68, #c9964f 58%, #9d6129);
  box-shadow: 0 38px 80px rgba(0,0,0,0.55);
}

.read-sheet .panel-head {
  border-bottom-color: rgba(79, 27, 8, 0.22);
}

.read-sheet .panel-head h2 {
  color: #281306;
}

.read-sheet .panel-close {
  color: #331808;
  background: rgba(255, 228, 172, 0.36);
  border-color: rgba(79, 27, 8, 0.26);
}

.read-list {
  max-height: min(720px, calc(90vh - 78px));
}

.read-item {
  display: grid;
  gap: 10px;
  padding: 12px 0 18px;
  border-bottom: 1px solid rgba(80, 28, 8, 0.18);
}

.read-user {
  color: #3a1a08;
  font-weight: 700;
}

.read-reply {
  color: #251006;
  font-family: "QE Antony Lark", "Dancing Script", cursive;
  font-size: clamp(28px, 4.2vw, 42px);
  line-height: 1.05;
}

[hidden] {
  display: none !important;
}

@media (max-width: 720px) {
  .book-stage {
    width: min(78vw, calc((100vh - 158px) / 1.48), 520px);
    transform: translateY(-50px);
  }

  .front-cover,
  .back-cover {
    inset: -44px -34px -42px -34px;
  }

  .book-block {
    inset: -36px -48px -34px -16px;
  }

  .cover-corner {
    width: 62px;
    height: 62px;
  }

  .title-plaque {
    bottom: 28px;
    letter-spacing: 1px;
  }

  .controls {
    bottom: 16px;
  }

  .control {
    min-height: 36px;
    padding: 8px 10px;
  }
}
