/* ==========================================================================
   我爱名场面 · 三国风云 — Desktop Scholar's Desk Frame & Unified Canvas Shell
   ========================================================================== */

@font-face {
  font-family: LocalSong;
  src: local("Songti SC"), local("STSong"), local("Noto Serif CJK SC"), local("Source Han Serif SC"), local("SimSun");
  font-display: swap;
}

:root {
  --desk-bg: #221d18;
  --desk-bg-deep: #171310;
  --desk-ink: #efe6d5;
  --desk-muted: #b6a68d;
  --desk-line: rgba(217, 190, 138, 0.22);
  --paper: #faf4e8;
  --ink: #241f19;
  --gold-bright: #e0b660;
  --radius-shell: 28px;
  --shadow-shell: 0 30px 90px rgba(8, 6, 4, 0.58), 0 8px 24px rgba(10, 8, 5, 0.35), 0 0 0 1px rgba(235, 214, 174, 0.28);
  --serif: LocalSong, "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: radial-gradient(ellipse 68% 72% at 50% 46%, #342c24 0%, var(--desk-bg) 52%, var(--desk-bg-deep) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(32px, 5.2vw, 88px);
  -webkit-font-smoothing: antialiased;
}

.desk-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 18% 22%, rgba(224, 182, 96, 0.08), transparent 44%),
    radial-gradient(circle at 84% 78%, rgba(44, 91, 76, 0.12), transparent 46%),
    repeating-linear-gradient(0deg, rgba(255, 244, 218, 0.015) 0 1px, transparent 1px 4px);
}

.desk-intro,
.desk-note {
  position: relative;
  z-index: 1;
  user-select: none;
}

.desk-intro {
  width: 248px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  color: var(--desk-ink);
}

.desk-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 2.6px;
  color: var(--gold-bright);
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(224, 182, 96, 0.34);
  background: rgba(224, 182, 96, 0.08);
  margin-bottom: 18px;
}

.desk-intro h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 46px;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: 3px;
  color: #f8eed9;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.desk-intro h1 span {
  color: #f4d694;
}

.desk-intro h1 i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-left: 8px;
  vertical-align: 6px;
  font-style: normal;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0;
  color: #fff3dc;
  background: linear-gradient(155deg, #c94635, #9b2c1f);
  border: 1.5px solid rgba(255, 224, 174, 0.55);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(155, 44, 31, 0.45), inset 0 0 0 1.5px rgba(255, 232, 190, 0.2);
  transform: rotate(-6deg);
}

.desk-divider {
  width: 48px;
  height: 2px;
  margin: 20px 0 16px;
  background: linear-gradient(90deg, var(--gold-bright), transparent);
  border-radius: 2px;
}

.desk-intro p {
  margin: 0;
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.95;
  letter-spacing: 1px;
  color: var(--desk-muted);
}

.desk-characters {
  height: 164px;
  display: flex;
  width: 256px;
  position: relative;
  left: -14px;
  margin-top: 22px;
}

.desk-characters::before {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 4px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(244, 219, 166, 0.22), rgba(244, 219, 166, 0.04) 58%, transparent 74%);
  pointer-events: none;
}

.sprite {
  background-image: url("./assets/characters.webp");
  background-size: 500% 400%;
  background-position: var(--sprite-x) var(--sprite-y);
  background-repeat: no-repeat;
  aspect-ratio: 0.8;
}

.desk-characters .sprite {
  width: 106px;
  height: 133px;
  flex: none;
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.48));
}

body[data-chapter="xiyou"] .desk-characters .sprite {
  background-image: var(--journey-portrait);
  background-size: contain;
  background-position: center bottom;
}

.desk-characters .sprite:nth-child(1) {
  transform: rotate(-8deg);
  margin-right: -28px;
  align-self: end;
}

.desk-characters .sprite:nth-child(2) {
  z-index: 2;
  margin-right: -24px;
}

.desk-characters .sprite:nth-child(3) {
  transform: rotate(6deg);
  align-self: end;
}

.desk-footnote {
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 2.2px;
  color: rgba(214, 198, 170, 0.62);
}

.desk-note {
  width: 176px;
  padding: 26px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: var(--desk-ink);
  border: 1px solid var(--desk-line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 248, 232, 0.055), rgba(255, 248, 232, 0.02));
  box-shadow: inset 0 1px 0 rgba(255, 244, 218, 0.08);
  position: relative;
}

.desk-note::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(217, 190, 138, 0.12);
  border-radius: 11px;
  pointer-events: none;
}

.note-number {
  font-size: 10.5px;
  letter-spacing: 3px;
  color: var(--gold-bright);
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--desk-line);
}

.desk-note h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 600;
  letter-spacing: 8px;
  writing-mode: vertical-rl;
  text-orientation: upright;
  color: #f6ebd5;
  line-height: 1.25;
  padding: 4px 0 8px;
  min-height: 124px;
}

.desk-note p {
  margin: 10px 0 0;
  font-family: var(--serif);
  font-size: 12px;
  line-height: 1.85;
  letter-spacing: 1px;
  color: var(--desk-muted);
}

.note-stamp {
  margin: 18px 0 16px;
  padding: 6px 11px;
  border: 1.5px solid rgba(204, 86, 68, 0.78);
  border-radius: 5px;
  color: #e67e6d;
  font-family: var(--serif);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 2px;
  transform: rotate(-5deg);
  background: rgba(184, 59, 44, 0.1);
  box-shadow: inset 0 0 0 1px rgba(204, 86, 68, 0.25);
}

.note-bottom {
  font-size: 11px;
  line-height: 1.8;
  letter-spacing: 0.8px;
  color: rgba(214, 198, 170, 0.65);
}

/* Main Game Shell hosting the single unified Canvas 2D UI */
.game-shell {
  position: relative;
  z-index: 2;
  width: 454px;
  flex: none;
  height: min(904px, calc(100dvh - 34px));
  min-height: 0;
  background: var(--paper);
  border: 1px solid #d4c3a4;
  border-radius: var(--radius-shell);
  box-shadow: var(--shadow-shell);
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  padding: 24px;
  text-align: center;
}

@media (max-width: 1060px) {
  .desk-note {
    display: none;
  }
}

@media (max-width: 900px) {
  .desk-intro,
  .desk-note,
  .desk-grain {
    display: none;
  }

  body {
    background: var(--paper);
    gap: 0;
  }

  .game-shell {
    width: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
}

body.at-home { background: #f7f1e5; }
.at-home .desk-intro, .at-home .desk-note, .at-home .desk-grain { display: none; }
.at-home .game-shell {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  background: #f7f1e5;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
