/* mujun.study - skeuomorphic scholar's desk meets sci-fi HUD */

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

:root {
  --desk: #F0E6D8;
  --walnut: #3A2818;
  --walnut-dark: #2A1A10;
  --sage: #B8C8B0;
  --blush: #D4B0A8;
  --brass: #C8A848;
  --brass-soft: rgba(200, 168, 72, 0.4);
  --ink: #2A2018;
  --lamp: #FFF5E0;
  --hud: #4A7A8A;
  --hud-glow: rgba(74, 122, 138, 0.45);
  --base: 12px;

  --lamp-x: 50%;
  --lamp-y: 28%;
}

html, body {
  background: var(--desk);
  color: var(--ink);
  font-family: 'Libre Baskerville', Georgia, serif;
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  position: relative;
  overflow-x: hidden;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(58, 40, 24, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(58, 40, 24, 0.03) 0%, transparent 40%),
    repeating-linear-gradient(
      45deg,
      rgba(58, 40, 24, 0.012) 0px,
      rgba(58, 40, 24, 0.012) 1px,
      transparent 1px,
      transparent 4px
    );
}

/* ----- Lamp + shadow overlays ---------------------------------------- */
.lamp-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background:
    radial-gradient(
      circle at var(--lamp-x) var(--lamp-y),
      var(--lamp) 0%,
      rgba(255, 245, 224, 0.55) 18%,
      rgba(240, 230, 216, 0.18) 38%,
      transparent 65%
    );
  mix-blend-mode: soft-light;
  transition: opacity 0.6s ease;
  opacity: 0;
}
body.lamp-on .lamp-overlay { opacity: 1; }

.shadow-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background: rgba(20, 14, 8, 0.4);
  mix-blend-mode: multiply;
  transition: opacity 1s ease;
  opacity: 1;
}
body.lamp-on .shadow-overlay { opacity: 0; }

/* ----- Bookshelf sidebar --------------------------------------------- */
.bookshelf {
  position: fixed;
  top: 0; left: 0;
  width: 280px;
  height: 100vh;
  background-color: var(--walnut);
  background-image:
    linear-gradient(180deg, rgba(0,0,0,0.18) 0%, transparent 8%, transparent 92%, rgba(0,0,0,0.22) 100%),
    repeating-linear-gradient(
      90deg,
      rgba(20, 12, 6, 0.18) 0px,
      rgba(20, 12, 6, 0.18) 1px,
      transparent 1px,
      transparent 7px
    ),
    repeating-linear-gradient(
      180deg,
      rgba(80, 56, 36, 0.06) 0px,
      rgba(80, 56, 36, 0.06) 2px,
      transparent 2px,
      transparent 9px
    );
  box-shadow: 8px 0 24px rgba(20, 12, 6, 0.35), inset -2px 0 0 rgba(0,0,0,0.4);
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  transform: translateX(-280px);
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.3, 1);
  overflow-y: auto;
}
body.shelf-in .bookshelf { transform: translateX(0); }

.shelf-cap {
  height: 14px;
  background: linear-gradient(180deg, var(--walnut-dark), var(--walnut));
  border-top: 1px solid rgba(0,0,0,0.5);
  border-bottom: 1px solid rgba(0,0,0,0.45);
  margin: 0 14px;
  flex-shrink: 0;
}
.shelf-cap.bottom { margin-top: auto; border-top: 1px solid rgba(0,0,0,0.6); }

.shelf-stamp {
  text-align: center;
  padding: 18px 12px 22px;
  border-bottom: 1px solid rgba(200, 168, 72, 0.18);
  margin: 0 14px 18px;
}
.stamp-glyph {
  display: block;
  font-family: 'Libre Baskerville', serif;
  font-size: 36px;
  color: var(--brass);
  text-shadow: 0 1px 0 rgba(0,0,0,0.6);
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.stamp-label {
  display: block;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 11px;
  color: var(--blush);
  letter-spacing: 0.22em;
  opacity: 0.85;
}

.spines {
  display: flex;
  flex-direction: row;
  gap: 6px;
  padding: 0 18px;
  align-items: stretch;
  height: 360px;
  flex-wrap: nowrap;
  justify-content: center;
}

.spine {
  position: relative;
  width: 36px;
  flex: 1 1 36px;
  max-width: 42px;
  text-decoration: none;
  border-radius: 1px 1px 0 0;
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.18),
    inset -1px 0 0 rgba(255,255,255,0.06),
    2px 2px 6px rgba(0,0,0,0.35);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.3, 1), filter 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 4px;
  overflow: hidden;
}
.spine::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    180deg,
    rgba(0,0,0,0.08) 0px,
    rgba(0,0,0,0.08) 1px,
    transparent 1px,
    transparent 5px
  );
  pointer-events: none;
}
.spine::after {
  content: "";
  position: absolute;
  left: 4px; right: 4px;
  top: 8px;
  height: 1px;
  background: rgba(200, 168, 72, 0.55);
  box-shadow: 0 18px 0 rgba(200, 168, 72, 0.55);
  pointer-events: none;
}

.spine-text {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 14px;
  letter-spacing: 0.08em;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  color: var(--ink);
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(255,255,255,0.18);
}

.spine-sage  { background: linear-gradient(90deg, #98AC8E 0%, var(--sage) 100%); }
.spine-blush { background: linear-gradient(90deg, #B89890 0%, var(--blush) 100%); }
.spine-brass { background: linear-gradient(90deg, #A88838 0%, var(--brass) 100%); }
.spine-cool  { background: linear-gradient(90deg, #3A6A78 0%, var(--hud) 100%); }
.spine-cool .spine-text { color: var(--lamp); }

.spine:hover {
  transform: translateX(8px);
  filter: brightness(1.08);
}
.spine.active {
  transform: translateX(4px);
  filter: brightness(1.04) saturate(1.05);
}

/* ----- Desk surface (main) -------------------------------------------- */
.desk {
  margin-left: 280px;
  padding: 64px clamp(24px, 4vw, 72px) 96px;
  position: relative;
  z-index: 5;
  min-height: 100vh;
}

.desk-header {
  position: relative;
  padding: 24px 0 56px;
  max-width: 880px;
}

.study-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 22px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.05;
}
.study-title .kanji {
  font-size: clamp(48px, 6vw, 92px);
  color: var(--walnut);
  text-shadow:
    0 1px 0 rgba(255, 245, 224, 0.4),
    0 2px 6px rgba(58, 40, 24, 0.22);
  letter-spacing: 0.05em;
}
.study-title .latin {
  font-size: clamp(22px, 2.5vw, 40px);
  color: var(--ink);
  font-style: italic;
  font-weight: 400;
}

.lede {
  font-size: clamp(15px, 1vw, 16px);
  line-height: 1.8;
  max-width: 56ch;
  color: var(--ink);
  margin-bottom: 28px;
}

/* HUD readouts ---------------------------------------------------------- */
.hud {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--walnut-dark);
  color: var(--hud);
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  border: 1px solid rgba(74, 122, 138, 0.45);
  border-radius: 1px;
  box-shadow:
    inset 0 0 12px rgba(74, 122, 138, 0.18),
    0 1px 2px rgba(0,0,0,0.4),
    0 0 0 2px rgba(40, 28, 20, 0.7);
  text-shadow: 0 0 6px var(--hud-glow);
  position: relative;
  margin-bottom: 14px;
}
.hud.small {
  padding: 3px 8px;
  font-size: 9px;
  letter-spacing: 0.1em;
  margin-bottom: 0;
}
.hud-label {
  color: var(--blush);
  opacity: 0.78;
}
.hud-value {
  color: var(--hud);
  font-weight: 400;
  font-feature-settings: "tnum";
  min-width: 40px;
  text-align: right;
}
.hud-pulse {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--hud);
  box-shadow: 0 0 6px var(--hud), 0 0 12px var(--hud-glow);
  animation: hudPulse 1.6s ease-in-out infinite;
}
@keyframes hudPulse {
  0%, 100% { opacity: 0.4; transform: scale(0.8); }
  50%      { opacity: 1.0; transform: scale(1.1); }
}

.hud.flicker {
  animation: hudFlicker 0.6s steps(8, end) 1;
}
@keyframes hudFlicker {
  0%   { opacity: 0; }
  10%  { opacity: 1; }
  20%  { opacity: 0.2; }
  30%  { opacity: 1; }
  45%  { opacity: 0.4; }
  60%  { opacity: 1; }
  100% { opacity: 1; }
}

/* Brass rule ornament -------------------------------------------------- */
.brass-rule {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 24px 0;
  position: relative;
}
.brass-rule::before,
.brass-rule::after {
  content: "";
  flex: 1;
  height: 4px;
  border-top: 1px solid var(--brass);
  border-bottom: 1px solid var(--brass);
  background: transparent;
  max-width: 320px;
}
.brass-rule .diamond {
  width: 8px; height: 8px;
  background: var(--brass);
  transform: rotate(45deg);
  box-shadow: 0 0 0 2px rgba(200, 168, 72, 0.18);
}
.brass-rule.small::before,
.brass-rule.small::after {
  max-width: 120px;
  height: 3px;
}
.brass-rule.small .diamond { width: 6px; height: 6px; }

.brass-rule.shimmer .diamond {
  animation: brassShimmer 2.4s ease-in-out infinite;
}
@keyframes brassShimmer {
  0%, 100% { opacity: 0.85; box-shadow: 0 0 0 2px rgba(200, 168, 72, 0.18); }
  50%      { opacity: 1.0; box-shadow: 0 0 0 4px rgba(200, 168, 72, 0.4); }
}

/* Section headers ------------------------------------------------------- */
.section-head {
  margin: 64px 0 36px;
  max-width: 720px;
}
.section-tag {
  display: inline-block;
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--walnut);
  background: rgba(200, 168, 72, 0.18);
  padding: 3px 10px;
  border: 1px solid var(--brass-soft);
  margin-bottom: 14px;
}
.section-title {
  font-size: clamp(22px, 2.2vw, 32px);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.01em;
  line-height: 1.25;
}

/* Study cards ---------------------------------------------------------- */
.cards-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px 24px;
  margin-top: 16px;
  max-width: 1100px;
}

.study-card {
  background: #FBF4E6;
  border: 1px solid #E0D2BE;
  border-top: 1px solid #C8B89E;
  border-radius: 2px;
  padding: 22px 24px 18px;
  position: relative;
  box-shadow:
    0 1px 0 rgba(58, 40, 24, 0.12),
    0 4px 8px rgba(58, 40, 24, 0.08),
    0 12px 22px rgba(58, 40, 24, 0.10);
  transition: transform 0.35s ease, box-shadow 0.35s ease, opacity 0.6s ease;
  opacity: 0;
  transform: translateY(8px) rotate(0deg);
}
.study-card.in {
  opacity: 1;
  transform: translateY(0) rotate(var(--rot, 0deg));
}
.study-card:hover {
  transform: translateY(-2px) rotate(var(--rot, 0deg));
  box-shadow:
    0 1px 0 rgba(58, 40, 24, 0.14),
    0 8px 14px rgba(58, 40, 24, 0.14),
    0 20px 36px rgba(58, 40, 24, 0.18);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--walnut);
  border-bottom: 1px solid rgba(58, 40, 24, 0.18);
  padding-bottom: 8px;
  margin-bottom: 12px;
}
.card-classification { color: var(--brass); font-weight: 700; }
.card-stamp {
  color: var(--blush);
  filter: contrast(0.95) saturate(0.8);
  border: 1px dashed rgba(212, 176, 168, 0.7);
  padding: 1px 6px;
  transform: rotate(-2deg);
  display: inline-block;
}

.card-title {
  font-size: clamp(18px, 1.6vw, 22px);
  font-weight: 700;
  color: var(--walnut);
  margin-bottom: 10px;
  letter-spacing: 0.01em;
}

.card-body {
  font-size: 15px;
  line-height: 1.8;
  color: var(--ink);
  margin-bottom: 14px;
}

.paradox-line {
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 13px;
  color: var(--walnut);
  line-height: 1.6;
  border-left: 2px solid var(--brass);
  padding: 6px 0 6px 12px;
  margin: 12px 0 18px;
  letter-spacing: 0.02em;
  font-style: italic;
  position: relative;
  min-height: 1.6em;
}
.paradox-line.cursor::after {
  content: "_";
  margin-left: 2px;
  color: var(--brass);
  animation: blinkCursor 0.7s steps(2) infinite;
}
@keyframes blinkCursor {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}
.paradox-line.struck { animation: keyStrike 0.06s ease-out; }
@keyframes keyStrike {
  0% { background: rgba(200, 168, 72, 0.0); }
  50% { background: rgba(200, 168, 72, 0.16); }
  100% { background: rgba(200, 168, 72, 0); }
}

.card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-top: 1px dashed rgba(58, 40, 24, 0.16);
  padding-top: 10px;
  flex-wrap: wrap;
}
.card-tag {
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--blush);
  filter: saturate(0.7);
}

/* Instruments grid ----------------------------------------------------- */
.instruments-section { margin-top: 64px; }

.instruments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  max-width: 1100px;
}

.instrument-card {
  background: #FBF4E6;
  border: 1px solid #E0D2BE;
  border-top: 1px solid #C8B89E;
  padding: 18px;
  text-align: left;
  box-shadow:
    0 2px 4px rgba(58, 40, 24, 0.08),
    0 8px 16px rgba(58, 40, 24, 0.10);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
  opacity: 0;
  transform: translateY(8px);
}
.instrument-card.in {
  opacity: 1;
  transform: translateY(0);
}
.instrument-card:hover {
  transform: translateY(-2px);
  box-shadow:
    0 4px 8px rgba(58, 40, 24, 0.10),
    0 14px 28px rgba(58, 40, 24, 0.16);
}

.instrument-icon {
  width: 60px; height: 60px;
  margin: 0 auto 12px;
  filter: drop-shadow(0 1px 2px rgba(58, 40, 24, 0.18));
}
.instrument-icon svg { width: 100%; height: 100%; }

.instrument-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--walnut);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  text-align: center;
}
.instrument-body {
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink);
  margin-bottom: 12px;
  text-align: center;
}
.instrument-card .hud { margin: 0 auto; display: flex; }

/* Specimen list -------------------------------------------------------- */
.specimens-section { margin-top: 64px; }

.specimen-list {
  list-style: none;
  max-width: 880px;
  background: #FBF4E6;
  border: 1px solid #E0D2BE;
  padding: 8px 16px;
  box-shadow:
    0 2px 4px rgba(58, 40, 24, 0.08),
    0 8px 16px rgba(58, 40, 24, 0.10);
}

.specimen {
  display: grid;
  grid-template-columns: 78px 1fr auto auto;
  gap: 14px;
  padding: 12px 4px;
  border-bottom: 1px dashed rgba(58, 40, 24, 0.18);
  align-items: center;
}
.specimen:last-child { border-bottom: 0; }

.specimen-id {
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 12px;
  color: var(--brass);
  letter-spacing: 0.12em;
}
.specimen-name { font-size: 15px; color: var(--ink); line-height: 1.6; }
.specimen-stat {
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 11px;
  color: var(--hud);
  background: var(--walnut-dark);
  padding: 3px 8px;
  letter-spacing: 0.08em;
  border: 1px solid rgba(74, 122, 138, 0.4);
  text-shadow: 0 0 6px var(--hud-glow);
}
.specimen-open {
  background: transparent;
  border: 1px solid var(--brass);
  color: var(--walnut);
  padding: 4px 12px;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 12px;
  letter-spacing: 0.18em;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}
.specimen-open:hover {
  background: var(--brass);
  color: var(--walnut);
  transform: translateY(-1px);
}

/* Log entries ---------------------------------------------------------- */
.log-section { margin-top: 64px; }

.log-entries {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  max-width: 1100px;
}

.log-entry {
  background: #FBF4E6;
  border: 1px solid #E0D2BE;
  border-left: 3px solid var(--blush);
  padding: 14px 18px;
  box-shadow:
    0 2px 4px rgba(58, 40, 24, 0.06),
    0 6px 12px rgba(58, 40, 24, 0.08);
}
.log-date {
  display: block;
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--walnut);
  margin-bottom: 8px;
}
.log-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
}

/* Colophon ------------------------------------------------------------- */
.colophon {
  margin-top: 80px;
  text-align: center;
  padding-top: 12px;
}
.colophon-text {
  max-width: 64ch;
  margin: 0 auto 18px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--walnut);
}
#hudFoot { display: inline-flex; }

/* Specimen modal ------------------------------------------------------- */
.specimen-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 8, 0.55);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.specimen-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.specimen-page {
  position: relative;
  width: min(720px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: #FBF4E6;
  background-image:
    linear-gradient(180deg, rgba(58, 40, 24, 0.04) 0%, transparent 8%),
    radial-gradient(ellipse at center, transparent 60%, rgba(58, 40, 24, 0.06) 100%);
  border: 1px solid #C8B89E;
  border-radius: 1px;
  padding: 36px clamp(24px, 5vw, 56px);
  box-shadow:
    0 4px 12px rgba(20, 14, 8, 0.4),
    0 22px 48px rgba(20, 14, 8, 0.45);
  transform: scale(0.95) translateY(8px);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.specimen-modal.open .specimen-page {
  transform: scale(1) translateY(0);
}
.binding-spine {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 18px;
  transform: translateX(-50%);
  background:
    linear-gradient(90deg,
      transparent 0%,
      rgba(58, 40, 24, 0.16) 30%,
      rgba(58, 40, 24, 0.28) 50%,
      rgba(58, 40, 24, 0.16) 70%,
      transparent 100%);
  pointer-events: none;
}

.specimen-close {
  position: absolute;
  top: 12px; right: 12px;
  background: transparent;
  border: 1px solid var(--brass);
  width: 30px; height: 30px;
  font-family: 'Libre Baskerville', serif;
  font-size: 18px;
  color: var(--walnut);
  cursor: pointer;
  line-height: 1;
  transition: background 0.2s, color 0.2s;
}
.specimen-close:hover {
  background: var(--brass);
  color: var(--walnut);
}

.specimen-page-head { text-align: center; margin-bottom: 18px; }
.specimen-classification {
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--brass);
  display: inline-block;
  border: 1px dashed var(--brass-soft);
  padding: 2px 10px;
  margin-bottom: 10px;
}
.specimen-page-title {
  font-size: clamp(20px, 2vw, 28px);
  font-weight: 700;
  color: var(--walnut);
  margin-bottom: 14px;
  letter-spacing: 0.01em;
}

.specimen-page-text {
  font-size: 15px;
  line-height: 1.85;
  color: var(--ink);
  margin-bottom: 18px;
  position: relative;
  z-index: 2;
}
.specimen-page-quote {
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 13px;
  color: var(--walnut);
  border-left: 2px solid var(--brass);
  padding: 6px 0 6px 12px;
  margin-top: 14px;
  min-height: 1.6em;
  position: relative;
  z-index: 2;
}
.specimen-page-quote.cursor::after {
  content: "_";
  margin-left: 2px;
  color: var(--brass);
  animation: blinkCursor 0.7s steps(2) infinite;
}

/* ----- Responsive ----------------------------------------------------- */
@media (max-width: 900px) {
  .bookshelf {
    width: 100%;
    height: auto;
    position: relative;
    transform: translateY(-100%);
    flex-direction: row;
    align-items: stretch;
    padding: 14px 14px;
    gap: 12px;
  }
  body.shelf-in .bookshelf { transform: translateY(0); }
  .shelf-cap, .shelf-stamp { display: none; }
  .spines {
    flex-direction: row;
    gap: 6px;
    height: 80px;
    padding: 0;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    justify-content: flex-start;
  }
  .spine { min-width: 36px; }
  .desk { margin-left: 0; padding: 32px 18px 64px; }
  .cards-row { grid-template-columns: 1fr; }
  .specimen { grid-template-columns: 1fr; gap: 6px; }
  .study-title .kanji { font-size: 64px; }
}
