@import url('https://fonts.googleapis.com/css2?family=IM+Fell+English:ital@0;1&display=swap');
@import url('https://cdn.jsdelivr.net/npm/lxgw-wenkai-webfont@1.7.0/lxgwwenkaimedium.css');

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

/* ── Design tokens ── */
:root {
  --font-cn:      'LXGW WenKai', '霞鹜文楷', 'STKaiti', serif;
  --font-display: 'IM Fell English', Georgia, serif;

  /* Kraft paper palette — light */
  --bg:         #f0ddb5;
  --fg:         #2a1406;
  --fg-muted:   #7a5028;
  --accent:     #8b3e0e;
  --accent-lt:  #a8521a;
  --border:     rgba(139, 62, 14, 0.22);
  --header-bg:  rgba(240, 221, 181, 0.90);
  --html-bg:    #6b2c10;
  --glow:       rgba(175, 110, 40, 0.22);

  /* Admin compat aliases */
  --ink:        #2a1406;
  --ink-light:  #5e2c10;
  --ink-faint:  #9a6835;
  --gold:       #8b3e0e;
  --gold-light: #a8521a;
  --shadow-soft:rgba(42, 20, 6, 0.15);
  --shadow-med: rgba(30, 12, 2, 0.30);
}

html.dark {
  --bg:         #1c1008;
  --fg:         #e8cf96;
  --fg-muted:   #9a7838;
  --accent:     #d49038;
  --accent-lt:  #e8a84a;
  --border:     rgba(212, 144, 56, 0.20);
  --header-bg:  rgba(28, 16, 8, 0.93);
  --html-bg:    #0e0804;
  --glow:       rgba(212, 144, 56, 0.13);

  --ink:        #e8cf96;
  --ink-light:  #b89455;
  --ink-faint:  #7a5e28;
  --gold:       #d49038;
  --gold-light: #e8a84a;
  --shadow-soft:rgba(0, 0, 0, 0.42);
  --shadow-med: rgba(0, 0, 0, 0.65);
}

/* ── html: dark bark chrome — peeks at rounded bottom ── */
html {
  background: var(--html-bg);
  min-height: 100%;
  transition: background 0.3s;
}

/* Kraft paper grain — more prominent than a typical site */
html::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.09;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='280' height='280'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.68' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='280' height='280' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 160px 160px;
}
html.dark::before { opacity: 0.07; }

/* ── body — mottled paper surface ── */
body {
  font-family: var(--font-cn);
  color: var(--fg);
  background:
    radial-gradient(ellipse at 15% 22%, rgba(185, 135, 55, 0.07) 0%, transparent 48%),
    radial-gradient(ellipse at 84% 75%, rgba(165, 100, 30, 0.08) 0%, transparent 42%),
    radial-gradient(ellipse at 58% 8%,  rgba(210, 165, 75, 0.05) 0%, transparent 38%),
    var(--bg);
  margin: 0;
  border-bottom-left-radius: 2.5rem;
  border-bottom-right-radius: 2.5rem;
  transition: color 0.3s;
}
html.dark body {
  background:
    radial-gradient(ellipse at 15% 22%, rgba(85, 42, 8, 0.18) 0%, transparent 48%),
    radial-gradient(ellipse at 84% 75%, rgba(65, 28, 4, 0.22) 0%, transparent 42%),
    var(--bg);
}

body:not(.admin-body) {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

body.admin-body {
  min-height: 100dvh;
  overflow-y: auto;
}

/* ── Header ── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 2rem;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.site-logo {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
}

.site-title {
  font-family: var(--font-display);
  font-size: clamp(1.12rem, 2.4vw, 1.48rem);
  font-weight: 400;
  font-style: normal;
  letter-spacing: 0.06em;
  line-height: 1;
}
.site-title a {
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
  transition: opacity 0.2s;
}
.site-title a:hover { opacity: 0.72; }
.title-accent { color: var(--accent); }
.title-dim    { color: var(--fg); opacity: 0.45; }

.site-subtitle {
  font-size: clamp(0.58rem, 1.05vw, 0.67rem);
  letter-spacing: 0.38em;
  color: var(--fg-muted);
  font-family: var(--font-cn);
  font-weight: 700;
  padding-left: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.18s, color 0.18s;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: rgba(139, 62, 14, 0.10);
  color: var(--accent);
}
html.dark .icon-btn:hover {
  background: rgba(212, 144, 56, 0.12);
  color: var(--accent);
}

/* ── Main page ── */
.page {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 clamp(24px, 6vw, 80px) 7vh;
  min-height: 0;
  overflow: hidden;
}

/* Warm center glow — candlelight on paper */
.page::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 58% 52% at 50% 48%, var(--glow) 0%, transparent 70%);
  z-index: 0;
}

/* ── Quote frame — letterpress stamp border ── */
.quote-frame {
  position: relative;
  z-index: 1;
  max-width: 580px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(16px, 2.5vh, 26px);

  /* Main frame border — like a printed ink rule */
  border: 1px solid rgba(139, 62, 14, 0.32);
  padding: clamp(26px, 4vh, 48px) clamp(22px, 5vw, 54px);

  /* Inner shadow creates slight letterpress depth */
  box-shadow:
    inset 0 0 0 4px transparent,
    inset 0 1px 3px rgba(139, 62, 14, 0.05);
}

/* Top-left corner registration mark */
.quote-frame::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  width: 14px;
  height: 14px;
  border-top: 1px solid rgba(139, 62, 14, 0.55);
  border-left: 1px solid rgba(139, 62, 14, 0.55);
  pointer-events: none;
}
/* Bottom-right corner registration mark */
.quote-frame::after {
  content: '';
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  border-bottom: 1px solid rgba(139, 62, 14, 0.55);
  border-right: 1px solid rgba(139, 62, 14, 0.55);
  pointer-events: none;
}
html.dark .quote-frame::before,
html.dark .quote-frame::after {
  border-color: rgba(212, 144, 56, 0.50);
}
html.dark .quote-frame {
  border-color: rgba(212, 144, 56, 0.22);
}

/* Thin ornament rule with centered diamond */
.quote-line {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  opacity: 0.38;
  flex-shrink: 0;
}
.quote-line::before,
.quote-line::after {
  content: '';
  flex: 1;
  height: 1px;
  background: currentColor;
}
.quote-line-dot {
  width: 5px;
  height: 5px;
  background: currentColor;
  transform: rotate(45deg);
  flex-shrink: 0;
}

/* ── Quote text ── */
.quote-text {
  font-family: var(--font-cn);
  font-size: clamp(1.06rem, 2.2vw, 1.28rem);
  line-height: 2.15;
  color: var(--fg);
  text-align: justify;
  text-justify: inter-ideograph;
  font-weight: 700;
  letter-spacing: 0.07em;
  overflow-y: auto;
  max-height: calc(100dvh - 300px);
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 62, 14, 0.20) transparent;
  width: 100%;
}
html.dark .quote-text {
  scrollbar-color: rgba(212, 144, 56, 0.20) transparent;
}

.quote-loading {
  text-align: center;
  color: var(--fg-muted);
  font-style: italic;
  font-size: 0.92rem;
  opacity: 0.55;
}

/* ── Footer ── */
.site-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: clamp(9px, 1.4vh, 15px) 24px clamp(11px, 2vh, 20px);
  border-top: 1px solid var(--border);
}
.footer-text {
  font-size: 0.82rem;
  color: var(--fg-muted);
  letter-spacing: 0.14em;
  font-style: italic;
  font-family: var(--font-cn);
}
.footer-copy {
  margin-top: 5px;
  font-size: 0.67rem;
  color: var(--fg-muted);
  opacity: 0.52;
  letter-spacing: 0.07em;
  font-family: var(--font-display);
  font-style: italic;
}
.footer-copy a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: 1px;
  transition: opacity 0.2s;
}
.footer-copy a:hover { opacity: 1; }

/* ══════════════════════════════
   ADMIN STYLES
   ══════════════════════════════ */
.admin-page {
  position: relative;
  z-index: 1;
  max-width: 820px;
  margin: 0 auto;
  padding: 44px 24px 60px;
  width: 100%;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}
.admin-title {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--fg);
  font-family: var(--font-cn);
}
.admin-subtitle {
  font-size: 0.75rem;
  color: var(--fg-muted);
  margin-top: 3px;
  letter-spacing: 0.06em;
}

/* Password slide-down */
.pwd-section {
  background: rgba(240, 210, 160, 0.35);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0 24px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  margin-bottom: 0;
}
.pwd-section.open {
  max-height: 380px;
  padding: 22px 24px;
  margin-bottom: 20px;
}
html.dark .pwd-section { background: rgba(60, 35, 10, 0.45); }

/* Login card */
.login-card {
  background: linear-gradient(150deg, rgba(250, 232, 190, 0.90) 0%, rgba(232, 210, 162, 0.86) 100%);
  border: 1px solid rgba(139, 62, 14, 0.28);
  border-radius: 2px;
  padding: 44px 48px;
  max-width: 400px;
  margin: 56px auto;
  box-shadow:
    0 4px 16px var(--shadow-soft),
    0 14px 44px var(--shadow-med);
}
html.dark .login-card {
  background: linear-gradient(150deg, rgba(38, 22, 8, 0.96) 0%, rgba(28, 16, 5, 0.94) 100%);
  border-color: rgba(212, 144, 56, 0.22);
}
.login-card h2 {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 28px;
  letter-spacing: 0.20em;
  color: var(--fg);
  font-family: var(--font-cn);
}

/* Form elements */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.74rem;
  letter-spacing: 0.10em;
  color: var(--ink-light);
  margin-bottom: 6px;
  font-family: var(--font-cn);
}
.form-group input,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  background: rgba(250, 238, 208, 0.72);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-family: var(--font-cn);
  font-size: 0.88rem;
  color: var(--fg);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
html.dark .form-group input,
html.dark .form-group textarea {
  background: rgba(255, 255, 255, 0.05);
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 62, 14, 0.12);
}
html.dark .form-group input:focus,
html.dark .form-group textarea:focus {
  box-shadow: 0 0 0 3px rgba(212, 144, 56, 0.14);
}
.form-group textarea { resize: vertical; min-height: 86px; line-height: 1.7; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 18px;
  border: 1px solid transparent;
  border-radius: 2px;
  font-family: var(--font-cn);
  font-size: 0.84rem;
  letter-spacing: 0.07em;
  cursor: pointer;
  transition: all 0.18s;
  outline: none;
  font-weight: 700;
  white-space: nowrap;
}
.btn-primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
  width: 100%;
  justify-content: center;
}
.btn-primary:hover { opacity: 0.80; }
.btn-add     { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-add:hover { background: var(--accent-lt); border-color: var(--accent-lt); }
.btn-danger  { background: transparent; color: #8a2c2c; border-color: rgba(138, 44, 44, 0.28); font-size: 0.74rem; padding: 4px 10px; }
.btn-danger:hover { background: rgba(138, 44, 44, 0.07); border-color: #8a2c2c; }
.btn-ghost   { background: transparent; color: var(--fg-muted); border-color: var(--border); }
.btn-ghost:hover { background: rgba(139, 62, 14, 0.07); }
.btn-warning { background: transparent; color: var(--accent); border-color: rgba(139, 62, 14, 0.30); }
.btn-warning:hover { background: rgba(139, 62, 14, 0.07); }
html.dark .btn-warning { border-color: rgba(212, 144, 56, 0.30); }
html.dark .btn-warning:hover { background: rgba(212, 144, 56, 0.08); }
html.dark .btn-ghost:hover { background: rgba(212, 144, 56, 0.07); }

.error-msg   { color: #8a2c2c; font-size: 0.78rem; margin-top: 8px; text-align: center; min-height: 16px; }
.success-msg { color: var(--accent); font-size: 0.78rem; margin-top: 8px; text-align: center; min-height: 16px; }

/* Panel */
.panel {
  background: rgba(240, 220, 175, 0.45);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 22px 26px;
  margin-bottom: 20px;
}
html.dark .panel { background: rgba(55, 32, 10, 0.45); }
.panel h3 {
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.10em;
  color: var(--ink-light);
  margin-bottom: 14px;
  font-family: var(--font-cn);
}
.panel-toggle { cursor: pointer; display: flex; align-items: center; justify-content: space-between; margin-bottom: 0; }
.panel-toggle.open { margin-bottom: 14px; }
.panel-body { display: none; }
.panel-body.open { display: block; }

.add-quote-form { display: flex; gap: 12px; align-items: flex-end; }
.add-quote-form .form-group { flex: 1; margin-bottom: 0; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 5px; margin-top: 18px; flex-wrap: wrap; }
.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 7px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: rgba(245, 228, 190, 0.55);
  color: var(--ink-light);
  font-family: var(--font-display);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
html.dark .page-btn { background: rgba(55, 32, 10, 0.45); }
.page-btn:hover   { background: rgba(139, 62, 14, 0.12); border-color: var(--accent); color: var(--accent); }
html.dark .page-btn:hover { background: rgba(212, 144, 56, 0.12); }
.page-btn.active  { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.page-btn:disabled { opacity: 0.32; cursor: default; pointer-events: none; }

.quotes-count { font-size: 0.74rem; color: var(--fg-muted); margin-left: 7px; font-weight: 400; }
.quote-list   { display: flex; flex-direction: column; gap: 7px; }
.quote-item   { display: flex; align-items: flex-start; gap: 11px; padding: 12px 15px; background: rgba(245, 228, 188, 0.55); border: 1px solid var(--border); border-radius: 2px; transition: background 0.15s; }
html.dark .quote-item { background: rgba(55, 32, 10, 0.38); }
.quote-item:hover { background: rgba(250, 235, 198, 0.88); }
html.dark .quote-item:hover { background: rgba(70, 42, 14, 0.60); }
.quote-item-text { flex: 1; font-size: 0.84rem; line-height: 1.75; color: var(--ink-light); word-break: break-all; font-family: var(--font-cn); }
.quote-item-num  { font-size: 0.66rem; color: var(--ink-faint); min-width: 26px; padding-top: 3px; font-style: italic; font-family: var(--font-display); text-align: right; }

.back-link { display: inline-flex; align-items: center; gap: 4px; font-size: 0.76rem; color: var(--fg-muted); text-decoration: none; letter-spacing: 0.06em; transition: color 0.2s; font-family: var(--font-display); }
.back-link:hover { color: var(--accent); }

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--fg);
  color: var(--bg);
  padding: 8px 20px;
  border-radius: 2px;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  opacity: 0;
  transition: all 0.28s ease;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
  font-family: var(--font-cn);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty-state { text-align: center; padding: 36px 0; color: var(--fg-muted); font-style: italic; font-size: 0.86rem; font-family: var(--font-cn); }

@media (max-width: 600px) {
  .quote-text { max-height: calc(100dvh - 280px); }
  .header-inner { padding: 0 1rem; }
  .login-card { padding: 30px 22px; }
  .add-quote-form { flex-direction: column; align-items: stretch; }
  .admin-header { flex-direction: column; align-items: flex-start; }
}
