:root {
  --ink: #1a1210;
  --ink-soft: rgba(26, 18, 16, 0.72);
  --ink-mute: rgba(26, 18, 16, 0.5);
  --paper: #f7efe7;
  --champagne: #fff5ea;
  --dust: #f3e2d8;
  --accent: #ff8a7a;
  --accent-dark: #c1452c;
  --accent-deep: #8c2a18;
  --sea: #236b83;
  --sky: #cbe4ef;
  --petal: #f7c7b8;
  --shadow: rgba(26, 18, 16, 0.16);
  --serif-cn: "Noto Serif SC", "Songti SC", "宋体", serif;
  --sans-cn: "Manrope", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --display: "Marcellus", "Noto Serif SC", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--sans-cn);
  color: var(--ink);
  background:
    radial-gradient(circle at 25% 18%, rgba(255, 196, 178, 0.45), transparent 55%),
    radial-gradient(circle at 78% 88%, rgba(247, 199, 184, 0.4), transparent 60%),
    radial-gradient(circle at top, var(--champagne), var(--paper));
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.22;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.1  0 0 0 0 0.07  0 0 0 0 0.06  0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

#hero-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 56px;
  position: relative;
  z-index: 1;
}

.hero {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  padding: 24px;
  border-radius: 24px;
  background: linear-gradient(120deg, #fff2dd, #fbe7f1 55%, #e7f4fb);
  box-shadow: 0 24px 60px -40px rgba(0, 0, 0, 0.45);
}

.hero-text h1 {
  font-family: "Marcellus", serif;
  font-size: clamp(2rem, 4vw, 3.4rem);
  margin: 0 0 12px;
}

.subtitle {
  font-size: 1.05rem;
  max-width: 520px;
  line-height: 1.5;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.75rem;
  margin: 0 0 12px;
  color: var(--accent-dark);
}

.hero-card {
  padding: 18px 22px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 18px;
  min-width: 220px;
  box-shadow: 0 16px 40px -28px var(--shadow);
  backdrop-filter: blur(8px);
}

.badge {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--sea);
}

.model-name {
  font-weight: 700;
  margin: 6px 0 10px;
}

.layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  margin-top: 28px;
}

.panel {
  background: #fff;
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 22px 50px -36px var(--shadow);
  border: 1px solid rgba(255, 138, 122, 0.12);
}

.panel h2 {
  margin: 0 0 16px;
  font-family: "Marcellus", serif;
}

.drop {
  border: 2px dashed #f1c7aa;
  border-radius: 16px;
  padding: 24px;
  display: block;
  text-align: center;
  cursor: pointer;
  background: linear-gradient(140deg, #fff6e8, #fff);
}

.drop.small {
  padding: 16px;
}

.drop input {
  display: none;
}

.preview {
  margin-top: 16px;
  border-radius: 16px;
  overflow: hidden;
  background: #faf1ec;
  min-height: 180px;
  display: grid;
  place-items: center;
}

.preview img {
  width: 100%;
  height: auto;
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.field textarea {
  border-radius: 12px;
  border: 1px solid #eadfd3;
  padding: 12px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fffaf4;
}

.field .input {
  border-radius: 12px;
  border: 1px solid #eadfd3;
  padding: 12px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fffaf4;
}

.count-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.count-control input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.count-value {
  min-width: 60px;
  text-align: center;
  font-weight: 600;
  color: var(--accent-dark);
}

.quick-templates {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  border: 1px solid #e3d4c3;
  width: 112px;
  height: 112px;
  border-radius: 16px;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  background: #fff2ee;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 12px;
  color: #5c3f36;
}

.ratio-groups {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.ratio-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 10px;
}

.ratio-btn {
  border: 1px solid rgba(193, 69, 44, 0.2);
  background: #fff4ef;
  border-radius: 14px;
  padding: 10px 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  color: #5c3f36;
}

.ratio-btn.active {
  background: linear-gradient(120deg, #ff8a7a, #ffd2c4);
  color: #fff;
  border-color: transparent;
}

.ratio-auto {
  margin-top: 10px;
  border: 1px dashed rgba(193, 69, 44, 0.35);
  background: #fff0ea;
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: #5c3f36;
  text-align: center;
}

.ratio-auto.active {
  background: linear-gradient(120deg, #ff8a7a, #ffd2c4);
  color: #fff;
  border-color: transparent;
}

.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button {
  margin-top: 18px;
  width: 100%;
  border: none;
  padding: 14px 16px;
  border-radius: 14px;
  background: linear-gradient(120deg, #ff8a7a, #ffb59e);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px -10px rgba(255, 107, 74, 0.5);
}

.note {
  margin-top: 12px;
  color: #6b6156;
  min-height: 22px;
}

.progress-wrap {
  margin-top: 16px;
  background: #f5e7dd;
  border-radius: 999px;
  padding: 6px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress-bar {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(120deg, #ff8a7a, #ffd2c4);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.progress-wrap span {
  position: relative;
  z-index: 1;
  font-size: 0.85rem;
  color: #6b5b52;
  padding: 2px 10px;
}

.output {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.placeholder,
.result-image {
  border-radius: 18px;
  background: #f7efe8;
  min-height: 240px;
  display: grid;
  place-items: center;
  color: #9d8f81;
  font-weight: 600;
}

.result-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 18px;
}

.output-header span {
  color: #7d6b61;
  font-size: 0.9rem;
}

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

.login-panel {
  max-width: 420px;
  width: 100%;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.history-table th,
.history-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid #f0e2d6;
  vertical-align: top;
}

.tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}

.tab-btn {
  border: 1px solid rgba(193, 69, 44, 0.2);
  background: #fff4ef;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
  color: #5c3f36;
}

.tab-btn.active {
  background: linear-gradient(120deg, #ff8a7a, #ffd2c4);
  color: #fff;
  border-color: transparent;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: 16px;
}

.style-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.style-box {
  display: grid;
  gap: 12px;
}

.style-box img {
  width: 100%;
  border-radius: 16px;
  display: none;
  background: #faf1ec;
}

/* === Mobile breakpoints — editor page === */
@media (max-width: 768px) {
  .page {
    padding: 18px 14px 40px;
  }

  .hero {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 22px 20px;
    border-radius: 18px;
  }

  .hero-text {
    max-width: 100%;
  }

  .hero-text h1 {
    font-size: clamp(1.7rem, 6.5vw, 2.4rem);
    margin-bottom: 10px;
  }

  .subtitle {
    font-size: 0.95rem;
    line-height: 1.7;
  }

  .eyebrow {
    font-size: 0.65rem;
    letter-spacing: 0.28em;
  }

  .hero-card {
    min-width: 0;
    max-width: none;
    width: 100%;
    padding: 18px 20px 22px;
  }

  .hero-card .helper {
    font-size: 0.88rem;
  }

  .hero-card-stamp {
    right: 14px;
    bottom: 12px;
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .layout {
    gap: 16px;
    margin-top: 18px;
  }

  .panel {
    padding: 22px 18px;
    border-radius: 18px;
  }

  .panel-title {
    font-size: 1.2rem;
    gap: 10px;
  }

  .panel-title-num {
    font-size: 0.85rem;
    padding: 1px 8px;
  }

  .tabs {
    flex-wrap: wrap;
  }

  .tab-btn {
    flex: 1 1 auto;
    min-height: 44px;
  }

  .drop {
    min-height: 140px;
  }

  textarea,
  input[type="text"],
  input[type="number"],
  input[type="range"] {
    font-size: 16px; /* keep ≥16px so iOS doesn't auto-zoom */
  }

  .ratio-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .ratio-btn {
    min-width: 44px;
    min-height: 36px;
    flex: 0 0 auto;
  }

  .quick-templates {
    flex-wrap: wrap;
    gap: 6px;
  }

  .chip {
    min-height: 36px;
  }

  .primary-action,
  #generateBtn,
  #styleGenerateBtn {
    min-height: 52px;
    font-size: 0.95rem;
    letter-spacing: 0.14em;
  }

  .grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

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

  .logout-mark {
    top: 16px;
    right: 16px;
    font-size: 11px;
    letter-spacing: 0.28em;
    padding: 6px 4px 7px;
  }
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .panel-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .hero {
    padding: 18px 16px;
  }

  .hero-text h1 {
    font-size: 1.7rem;
  }
}

/* =====================================================================
   v3 redesign — open-book login + editor polish
   ===================================================================== */

/* Universal heading + display fallbacks now use the variable */
.hero-text h1,
.panel-title,
.login-title {
  font-family: var(--display);
}

/* === Editor hero refresh === */
.hero {
  background:
    linear-gradient(120deg, #fff5e6 0%, #fbe7d6 35%, #f7d4cb 70%, #f0e2f5 100%);
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  inset: -2px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.5  0 0 0 0 0.3  0 0 0 0 0.2  0 0 0 0.05 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  pointer-events: none;
  opacity: 0.55;
  mix-blend-mode: multiply;
}

.hero-text {
  position: relative;
  z-index: 2;
  max-width: 60%;
}

.hero-text h1 {
  font-size: clamp(2.2rem, 4.5vw, 3.6rem);
  letter-spacing: 0.02em;
  margin: 0 0 14px;
  line-height: 1.18;
}

.eyebrow {
  font-family: var(--display);
  text-transform: uppercase;
  letter-spacing: 0.32em;
  font-size: 0.72rem;
  margin: 0 0 14px;
  color: var(--accent-deep);
  opacity: 0.85;
}

.subtitle {
  font-family: var(--serif-cn);
  font-size: 1.02rem;
  max-width: 540px;
  line-height: 1.75;
  color: var(--ink-soft);
  margin: 0;
}

/* Hero card → 信封风 */
.hero-card {
  position: relative;
  z-index: 2;
  padding: 22px 26px 24px;
  background: rgba(255, 248, 238, 0.92);
  border-radius: 6px 6px 14px 14px;
  min-width: 260px;
  max-width: 320px;
  box-shadow:
    0 18px 38px -22px rgba(58, 28, 18, 0.4),
    inset 0 0 0 1px rgba(193, 69, 44, 0.08);
  backdrop-filter: blur(6px);
}

.hero-card-flap {
  position: absolute;
  inset: 0 0 auto 0;
  height: 22px;
  background: linear-gradient(180deg, rgba(247, 195, 175, 0.65), transparent);
  clip-path: polygon(0 0, 50% 100%, 100% 0);
  border-radius: 6px 6px 0 0;
}

.hero-card .badge {
  font-family: var(--display);
  font-size: 0.65rem;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin: 0 0 6px;
}

.hero-card .model-name {
  font-family: var(--serif-cn);
  font-weight: 600;
  font-size: 0.95rem;
  margin: 4px 0 12px;
  color: var(--ink);
}

.hero-card .helper {
  font-family: var(--serif-cn);
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--ink-soft);
  margin: 0;
  font-style: italic;
  min-height: 2.4em;
}

.hero-card-stamp {
  position: absolute;
  right: 18px;
  bottom: 14px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 17px;
  color: var(--accent-deep);
  border: 1.5px dashed rgba(140, 42, 24, 0.45);
  border-radius: 50%;
  transform: rotate(-8deg);
  opacity: 0.78;
  letter-spacing: 0;
}

/* === Panel polish === */
.panel-title {
  display: flex;
  align-items: baseline;
  gap: 14px;
  font-size: 1.45rem;
  margin: 4px 0 18px;
  letter-spacing: 0.04em;
}

.panel-title-num {
  font-family: var(--serif-cn);
  font-weight: 600;
  font-size: 1rem;
  padding: 2px 10px;
  border: 1px solid rgba(193, 69, 44, 0.35);
  border-radius: 999px;
  color: var(--accent-dark);
  letter-spacing: 0.1em;
}

/* Primary action button (生成) — wax-stamp/ribbon hybrid */
.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 18px;
  padding: 16px 24px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff8ec;
  font-family: var(--display);
  font-size: 1.02rem;
  letter-spacing: 0.18em;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 18px 30px -18px rgba(193, 69, 44, 0.55);
  transition: transform 0.28s ease, box-shadow 0.28s ease;
}

.primary-action::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence baseFrequency='1.4' numOctaves='1' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.18 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: overlay;
  pointer-events: none;
}

.primary-action:hover {
  transform: translateY(-2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 22px 40px -20px rgba(193, 69, 44, 0.7);
}

.primary-action:disabled {
  opacity: 0.6;
  cursor: progress;
  transform: none;
}

/* === CSS-only sakura petals fallback (when WebGL unavailable) === */
.petals-fallback {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.petals-fallback span {
  position: absolute;
  top: -10%;
  width: 14px;
  height: 14px;
  border-radius: 14px 2px 14px 2px;
  background: radial-gradient(circle at 30% 30%, #ffd5c8, #f7b6a3);
  opacity: 0.55;
  filter: blur(0.3px);
  animation: petalFall linear infinite;
}

.petals-fallback span:nth-child(1)  { left: 5%;  animation-duration: 14s; animation-delay: 0s;   transform: scale(0.9); }
.petals-fallback span:nth-child(2)  { left: 12%; animation-duration: 18s; animation-delay: 2s;   transform: scale(1.1); }
.petals-fallback span:nth-child(3)  { left: 22%; animation-duration: 12s; animation-delay: 4s;   transform: scale(0.7); }
.petals-fallback span:nth-child(4)  { left: 32%; animation-duration: 16s; animation-delay: 1s;   transform: scale(1.2); }
.petals-fallback span:nth-child(5)  { left: 42%; animation-duration: 20s; animation-delay: 3s;   transform: scale(0.9); }
.petals-fallback span:nth-child(6)  { left: 52%; animation-duration: 14s; animation-delay: 5s;   transform: scale(1); }
.petals-fallback span:nth-child(7)  { left: 62%; animation-duration: 17s; animation-delay: 0.5s; transform: scale(0.8); }
.petals-fallback span:nth-child(8)  { left: 70%; animation-duration: 19s; animation-delay: 2.5s; transform: scale(1.1); }
.petals-fallback span:nth-child(9)  { left: 78%; animation-duration: 13s; animation-delay: 4.5s; transform: scale(0.9); }
.petals-fallback span:nth-child(10) { left: 84%; animation-duration: 15s; animation-delay: 1.5s; transform: scale(1.2); }
.petals-fallback span:nth-child(11) { left: 90%; animation-duration: 21s; animation-delay: 3.5s; transform: scale(0.85); }
.petals-fallback span:nth-child(12) { left: 18%; animation-duration: 22s; animation-delay: 6s;   transform: scale(1.05); }
.petals-fallback span:nth-child(13) { left: 38%; animation-duration: 19s; animation-delay: 7s;   transform: scale(0.75); }
.petals-fallback span:nth-child(14) { left: 58%; animation-duration: 16s; animation-delay: 8s;   transform: scale(1); }
.petals-fallback span:nth-child(15) { left: 76%; animation-duration: 23s; animation-delay: 9s;   transform: scale(0.95); }

@keyframes petalFall {
  0%   { transform: translate3d(0, -10vh, 0) rotate(0deg);   opacity: 0; }
  8%   { opacity: 0.55; }
  50%  { transform: translate3d(40px, 50vh, 0) rotate(180deg); opacity: 0.55; }
  100% { transform: translate3d(-30px, 110vh, 0) rotate(360deg); opacity: 0; }
}

/* === Logout — letterpress mark === */
.logout-mark {
  position: fixed;
  top: 24px;
  right: 26px;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  margin: 0;
  padding: 8px 4px 9px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--display);
  font-size: 12px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.35s ease, letter-spacing 0.35s ease;
}

.logout-mark:hover {
  opacity: 1;
  letter-spacing: 0.4em;
  transform: none;
  box-shadow: none;
}

.logout-mark::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 2px;
  height: 1px;
  background: currentColor;
  opacity: 0.55;
  transform-origin: left center;
  transform: scaleX(0.35);
  transition: transform 0.45s cubic-bezier(0.65, 0, 0.35, 1);
}

.logout-mark:hover::after {
  transform: scaleX(1);
}

.logout-mark-icon {
  width: 13px;
  height: 13px;
  transition: transform 0.4s cubic-bezier(0.65, 0, 0.35, 1);
}

.logout-mark:hover .logout-mark-icon {
  transform: translateX(3px);
}

/* === Login overlay — open book spread === */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 196, 178, 0.55), transparent 55%),
    radial-gradient(circle at 80% 85%, rgba(247, 199, 184, 0.5), transparent 60%),
    linear-gradient(180deg, var(--champagne) 0%, var(--paper) 100%);
}

.login-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.32;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.1  0 0 0 0 0.07  0 0 0 0 0.06  0 0 0 0.07 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

.login-overlay.hidden {
  display: none;
}

/* The book — open spread */
.login-book {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 8px 1fr;
  width: min(960px, 100%);
  max-width: 100%;
  border-radius: 6px;
  perspective: 2400px;
  transform-style: preserve-3d;
  background: linear-gradient(180deg, #fdf3e6, #f7e9d7);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 30px 70px -28px rgba(58, 28, 18, 0.45),
    0 14px 30px -14px rgba(193, 69, 44, 0.18);
  animation: bookRise 0.85s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes bookRise {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-page {
  position: relative;
  padding: 56px 50px 48px;
  background: linear-gradient(180deg, #fffaf2 0%, #f9ecd9 100%);
  min-height: 540px;
  transform-origin: 100% 50%;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.login-page-left {
  border-radius: 6px 0 0 6px;
  background:
    radial-gradient(circle at 100% 50%, rgba(193, 69, 44, 0.06), transparent 40%),
    linear-gradient(180deg, #fffaf2 0%, #f9ecd9 100%);
  /* shadow toward spine to suggest book curvature */
  box-shadow: inset -22px 0 30px -20px rgba(58, 28, 18, 0.18);
  /* Page-flip-in animation */
  animation: pageOpenLeft 1.4s cubic-bezier(0.65, 0, 0.35, 1) 0.15s both;
  transform-origin: 100% 50%;
}

.login-page-right {
  border-radius: 0 6px 6px 0;
  background:
    radial-gradient(circle at 0% 50%, rgba(193, 69, 44, 0.06), transparent 40%),
    linear-gradient(180deg, #fffaf2 0%, #f9ecd9 100%);
  box-shadow: inset 22px 0 30px -20px rgba(58, 28, 18, 0.18);
  display: flex;
  flex-direction: column;
  animation: pageSettle 1.1s cubic-bezier(0.16, 1, 0.3, 1) 0.4s both;
  transform-origin: 0% 50%;
}

@keyframes pageOpenLeft {
  0%   { transform: rotateY(-178deg); opacity: 0; }
  40%  { opacity: 0.4; }
  100% { transform: rotateY(0deg); opacity: 1; }
}

@keyframes pageSettle {
  from { transform: rotateY(8deg); opacity: 0.7; }
  to   { transform: rotateY(0deg); opacity: 1; }
}

/* spine */
.login-spine {
  position: relative;
  height: 100%;
  background: linear-gradient(180deg, #d9b89c 0%, #b88560 50%, #d9b89c 100%);
  box-shadow:
    inset 1px 0 0 rgba(0, 0, 0, 0.18),
    inset -1px 0 0 rgba(0, 0, 0, 0.18),
    0 0 18px rgba(58, 28, 18, 0.18);
}

.login-spine-thread {
  position: absolute;
  left: 0;
  right: 0;
  height: 8px;
  background: rgba(58, 28, 18, 0.35);
  border-radius: 1px;
}

.login-spine-thread:nth-child(1) { top: 18%; }
.login-spine-thread:nth-child(2) { top: 50%; transform: translateY(-50%); }
.login-spine-thread:nth-child(3) { bottom: 18%; }

/* === Left page typography === */
.login-logo {
  margin-bottom: 18px;
}

.login-logo-tile {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff8ec;
  box-shadow: 0 8px 18px -8px rgba(193, 69, 44, 0.55);
}

.login-logo-tile svg {
  width: 30px;
  height: 30px;
}

.login-eyebrow {
  font-family: var(--display);
  font-size: 11px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--accent-deep);
  margin: 0 0 14px;
  opacity: 0.78;
}

.login-title {
  font-family: var(--serif-cn);
  font-weight: 600;
  font-size: clamp(1.7rem, 2.5vw, 2.15rem);
  letter-spacing: 0.05em;
  margin: 0 0 14px;
  color: var(--ink);
  line-height: 1.25;
}

.login-sub {
  font-family: var(--serif-cn);
  font-size: 14px;
  line-height: 1.85;
  color: var(--ink-soft);
  margin: 0 0 28px;
}

.login-letter {
  position: relative;
  margin: 0 0 22px;
  padding: 18px 22px;
  background: linear-gradient(180deg, #fff5e8, #fbe9d6);
  border-radius: 4px;
  border-left: 2px solid var(--accent-dark);
  box-shadow: inset 0 0 0 1px rgba(193, 69, 44, 0.08);
}

.login-letter-line {
  font-family: var(--serif-cn);
  font-style: italic;
  font-size: 14.5px;
  line-height: 1.95;
  color: var(--ink-soft);
  margin: 0;
}

.login-letter-line + .login-letter-line {
  margin-top: 8px;
}

.login-signoff {
  font-family: var(--display);
  font-size: 11.5px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--accent-dark);
  text-align: right;
  margin: 0;
  opacity: 0.7;
}

/* === Right page (login form) === */
.login-page-right {
  justify-content: space-between;
}

.login-page-label {
  font-family: var(--display);
  font-size: 10.5px;
  letter-spacing: 0.5em;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin: 0;
  text-align: center;
  opacity: 0.7;
}

.login-page-hint {
  font-family: var(--serif-cn);
  font-style: italic;
  font-size: 13.5px;
  color: var(--ink-mute);
  text-align: center;
  margin: 14px 0 28px;
  min-height: 38px;
  transition: opacity 0.5s ease;
}

.login-page-hint.fading { opacity: 0; }

.login-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  margin: auto 0;
}

#loginPassword {
  width: min(280px, 100%);
  padding: 14px 16px;
  border: none;
  border-bottom: 1.5px solid rgba(26, 18, 16, 0.22);
  background: transparent;
  font-family: var(--display);
  font-size: 30px;
  letter-spacing: 0.6em;
  text-align: center;
  color: var(--ink);
  caret-color: var(--accent-dark);
  transition: border-color 0.3s ease;
  -webkit-text-security: disc;
  -moz-text-security: disc;
  text-security: disc;
}

#loginPassword::placeholder {
  color: rgba(26, 18, 16, 0.18);
  letter-spacing: 0.6em;
}

#loginPassword:focus {
  outline: none;
  border-bottom-color: var(--accent-dark);
}

.login-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(280px, 100%);
  padding: 14px 24px;
  margin-top: 6px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff8ec;
  font-family: var(--display);
  font-size: 14.5px;
  letter-spacing: 0.32em;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 14px 26px -14px rgba(193, 69, 44, 0.55);
  transition: transform 0.28s ease, box-shadow 0.28s ease;
}

.login-submit::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence baseFrequency='1.3' numOctaves='1' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.16 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: overlay;
  pointer-events: none;
}

.login-submit svg {
  width: 16px;
  height: 16px;
  transition: transform 0.3s ease;
  position: relative;
}

.login-submit:hover {
  transform: translateY(-2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 18px 32px -16px rgba(193, 69, 44, 0.7);
}

.login-submit:hover svg {
  transform: translateX(4px);
}

.login-submit:disabled {
  opacity: 0.55;
  cursor: progress;
  transform: none;
  box-shadow: none;
}

.login-status {
  margin: 22px 0 0;
  min-height: 22px;
  font-family: var(--display);
  font-style: italic;
  font-size: 13.5px;
  color: var(--accent-deep);
  letter-spacing: 0.06em;
  text-align: center;
}

.login-page-footer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding-top: 18px;
  margin-top: 22px;
  border-top: 1px dashed rgba(193, 69, 44, 0.28);
}

.login-page-stamp {
  font-family: var(--display);
  font-size: 14px;
  color: var(--accent-dark);
  letter-spacing: 0.2em;
  padding: 4px 10px;
  border: 1px solid rgba(193, 69, 44, 0.4);
  border-radius: 50%;
  transform: rotate(-6deg);
  opacity: 0.7;
}

.login-page-rule {
  height: 1px;
  background: rgba(193, 69, 44, 0.28);
}

.login-page-num {
  font-family: var(--display);
  font-size: 11px;
  letter-spacing: 0.42em;
  color: var(--accent-dark);
  opacity: 0.68;
}

body.locked {
  overflow: hidden;
}

body.locked .page {
  visibility: hidden;
}

@media (max-width: 760px) {
  .login-book {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    width: min(440px, 100%);
  }
  .login-page {
    padding: 36px 28px 30px;
    min-height: 0;
  }
  .login-page-left {
    border-radius: 6px 6px 0 0;
    box-shadow: inset 0 -22px 30px -20px rgba(58, 28, 18, 0.18);
    animation-name: pageSettle;
  }
  .login-page-right {
    border-radius: 0 0 6px 6px;
    box-shadow: inset 0 22px 30px -20px rgba(58, 28, 18, 0.18);
  }
  .login-spine {
    height: 8px;
    width: 100%;
    background: linear-gradient(90deg, #d9b89c 0%, #b88560 50%, #d9b89c 100%);
  }
  .login-spine-thread {
    width: 8px;
    height: 100%;
    top: 0 !important;
    bottom: 0 !important;
    transform: none !important;
  }
  .login-spine-thread:nth-child(1) { left: 18%; }
  .login-spine-thread:nth-child(2) { left: 50%; transform: translateX(-50%) !important; }
  .login-spine-thread:nth-child(3) { right: 18%; left: auto; }
  #loginPassword { font-size: 26px; }
  .login-title { font-size: 1.5rem; }
}
