/* ===========================================================
   Mo Yuejian’s PORTFOLIO — 简笔画 · 稚拙风 · 白纸感
   =========================================================== */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --paper:      #FDFCF7;
  --paper-2:    #F7F4EB;
  --ink:        #2C2A28;
  --ink-2:      #5C5852;
  --ink-3:      #9A958B;
  --hair:       rgba(44, 42, 40, .13);

  --yellow: #FAF0C6;
  --mint:   #DEF0E4;
  --blue:   #DDEAF6;
  --pink:   #F9E3E9;
  --lilac:  #EAE3F6;
  --peach:  #FCEBDC;

  --font-cn: 'Kaiti SC', 'STKaiti', 'KaiTi', '楷体', 'Kaiti TC', 'Songti SC', ui-serif, serif;
  --font-en: 'Caveat', 'Patrick Hand', 'Segoe Print', 'Bradley Hand', 'Xingkai SC', 'Kaiti SC', cursive;

  --ease: cubic-bezier(.2, .8, .2, 1);
}

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-cn);
  font-size: 16px;
  line-height: 1.85;
  letter-spacing: .02em;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
button { font-family: inherit; }
a { color: inherit; }

/* ---------- 纸张颗粒 ---------- */
.paper-grain {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: .2;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.42'/%3E%3C/svg%3E");
}

/* ===========================================================
   顶栏
   =========================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 30px;
  background: rgba(253, 252, 247, .84);
  backdrop-filter: blur(9px) saturate(1.05);
  -webkit-backdrop-filter: blur(9px) saturate(1.05);
  border-bottom: 1px dashed var(--hair);
}

.brand-wrap {
  position: relative;
  display: inline-flex;
  justify-content: center;
}

.brand {
  font-family: var(--font-en);
  font-size: clamp(1.35rem, 2.9vw, 1.8rem);
  line-height: 1.15;
  letter-spacing: .035em;
  white-space: nowrap;
  text-decoration: none;
  color: var(--ink);
  transform-origin: 50% 50%;
  transition: transform 1.25s cubic-bezier(.62, .02, .18, 1), opacity .55s ease;
  will-change: transform;
}

.brand-line {
  position: absolute;
  left: 1%;
  bottom: -5px;
  width: 98%;
  height: 10px;
  overflow: visible;
  opacity: 0;
}
.brand-line path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-dasharray: 230;
  stroke-dashoffset: 230;
  transition: stroke-dashoffset .9s ease .25s, opacity .3s ease;
}
body.settled .brand-line { opacity: .55; }
body.settled .brand-line path { stroke-dashoffset: 0; }

/* ---------- 分类导航：圆角矩形 ---------- */
.nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
}

.pill {
  position: relative;
  appearance: none;
  padding: 5px 17px 6px;
  font-size: .95rem;
  line-height: 1.6;
  letter-spacing: .06em;
  color: var(--ink);
  background: #fff;
  border: 1.4px solid var(--ink);
  border-radius: 13px 17px 12px 16px / 16px 12px 17px 13px;
  box-shadow: 0 1.5px 0 rgba(44, 42, 40, .12);
  cursor: pointer;
  transition: background .22s var(--ease), color .22s var(--ease),
              transform .28s var(--ease), box-shadow .28s var(--ease);
}

body:not(.settled) .pill { opacity: 0; }

body.settled .pill {
  animation: pillIn .55s var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 85ms + .1s);
}

.pill:hover {
  transform: translateY(-2px) rotate(-1.1deg);
  box-shadow: 0 3px 0 rgba(44, 42, 40, .14);
}
.pill:nth-child(2):hover { background: var(--yellow); }
.pill:nth-child(3):hover { background: var(--mint); }
.pill:nth-child(4):hover { background: var(--blue); }
.pill:nth-child(5):hover { background: var(--pink); }
.pill:nth-child(6):hover { background: var(--lilac); }
.pill:nth-child(1):hover { background: var(--paper-2); }

.pill.is-active {
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 2px 0 rgba(44, 42, 40, .18);
}
.pill.is-active:hover { transform: translateY(-2px) rotate(0); }

@keyframes pillIn {
  from { opacity: 0; transform: translateY(-9px) scale(.94); }
  to   { opacity: 1; transform: none; }
}

/* ===========================================================
   页面主体
   =========================================================== */
main {
  position: relative;
  z-index: 2;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .8s ease .25s, transform .8s var(--ease) .25s;
}
body.settled main { opacity: 1; transform: none; }

/* ===========================================================
   作品区
   =========================================================== */
.works {
  max-width: 1120px;
  margin: 0 auto;
  padding: 46px 24px 40px;
  scroll-margin-top: 120px;
}

.sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  margin-bottom: 30px;
  border-bottom: 1px dashed var(--hair);
}

.sec-title {
  font-family: var(--font-en);
  font-size: clamp(1.7rem, 3.4vw, 2.2rem);
  letter-spacing: .12em;
  font-weight: 600;
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.sec-cn {
  font-family: var(--font-cn);
  font-size: .82rem;
  letter-spacing: .3em;
  font-weight: 400;
  color: var(--ink-3);
}

.sec-note {
  font-size: .84rem;
  letter-spacing: .1em;
  color: var(--ink-3);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 26px 24px;
}

/* ---------- 作品卡 ---------- */
.work {
  position: relative;
  padding: 9px 9px 14px;
  background: #fff;
  border: 1.4px solid var(--ink);
  border-radius: 17px 23px 15px 21px / 21px 15px 23px 17px;
  box-shadow: 0 2px 0 rgba(44, 42, 40, .07), 0 14px 26px -18px rgba(44, 42, 40, .3);
  transform: rotate(-.55deg);
  cursor: pointer;
  transition: transform .38s var(--ease), box-shadow .38s var(--ease);
}
.work:nth-child(3n + 2) { transform: rotate(.55deg); }
.work:nth-child(3n)     { transform: rotate(-.2deg); }

.work:hover,
.work:focus-visible {
  transform: rotate(0deg) translateY(-6px);
  box-shadow: 0 3px 0 rgba(44, 42, 40, .1), 0 24px 36px -20px rgba(44, 42, 40, .34);
  outline: none;
}
.work:focus-visible { outline: 2px dashed var(--ink-3); outline-offset: 4px; }

.work.is-hidden { display: none; }

.work.pop { animation: cardIn .5s var(--ease) backwards; }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to   { opacity: 1; }
}

.idx {
  position: absolute;
  top: -13px;
  right: 10px;
  font-family: var(--font-en);
  font-size: .92rem;
  letter-spacing: .1em;
  color: var(--ink-3);
  background: var(--paper);
  padding: 0 6px;
  transform: rotate(3deg);
  z-index: 2;
}

/* ---------- 缩略图 ---------- */
.thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 11px 15px 10px 14px / 14px 10px 15px 11px;
  background:
    radial-gradient(140% 120% at 30% -20%, rgba(255, 255, 255, .42), rgba(255, 255, 255, 0) 70%),
    var(--tint, var(--paper-2));
  border: 1px solid rgba(44, 42, 40, .1);
}

/* 手绘内框 */
.thumb::before {
  content: '';
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(44, 42, 40, .18);
  border-radius: 8px 12px 7px 11px / 11px 7px 12px 8px;
  pointer-events: none;
  z-index: 2;
}

/* 竖版作品（信息流） */
.work--v .thumb { aspect-ratio: 3 / 4; }

.cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23m)' opacity='.3'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  opacity: .16;
  pointer-events: none;
}

.thumb-doodle {
  width: 40%;
  max-height: 70%;
  color: #4A4740;
  opacity: .52;
  transition: transform .45s var(--ease), opacity .45s ease;
}
.work:nth-child(even) .thumb-doodle { transform: scaleX(-1); }
.work:hover .thumb-doodle { transform: scale(1.07) rotate(-2deg); opacity: .85; }
.work:nth-child(even):hover .thumb-doodle { transform: scale(-1.07, 1.07) rotate(2deg); }

.play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .82);
  border: 1.4px solid var(--ink);
  border-radius: 50% 47% 52% 49% / 49% 52% 47% 51%;
  opacity: 0;
  transform: scale(.82);
  transition: opacity .3s ease, transform .35s var(--ease);
}
.play svg { width: 22px; height: 22px; fill: var(--ink); margin-left: 2px; }
.work:hover .play,
.work:focus-visible .play { opacity: 1; transform: scale(1); }

/* 触屏设备没有 hover，直接显示播放标 */
@media (hover: none) {
  .play { opacity: 1; transform: scale(1); }
}

.dur {
  position: absolute;
  right: 9px;
  bottom: 7px;
  font-family: var(--font-en);
  font-size: .9rem;
  letter-spacing: .06em;
  color: var(--ink);
  background: rgba(255, 255, 255, .78);
  padding: 0 7px;
  border-radius: 7px 9px 8px 10px / 9px 8px 10px 7px;
}

/* ---------- 卡片文字 ---------- */
.cap {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 4px 0;
}

.stat {
  padding: 4px 4px 0;
  font-size: .78rem;
  letter-spacing: .05em;
  color: rgba(44, 42, 40, .55);
}

.cap h3 {
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: .04em;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag {
  flex: none;
  font-size: .72rem;
  letter-spacing: .08em;
  color: var(--ink-2);
  padding: 1px 8px 2px;
  border: 1.1px solid rgba(44, 42, 40, .28);
  border-radius: 8px 11px 9px 12px / 11px 9px 12px 8px;
  white-space: nowrap;
}

.empty-hint {
  margin: 34px 0 0;
  text-align: center;
  color: var(--ink-3);
  font-size: .92rem;
  letter-spacing: .1em;
}

/* ===========================================================
   页脚
   =========================================================== */
.foot {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 24px 60px;
}
.foot-line {
  display: block;
  width: 100%;
  height: 12px;
  color: var(--ink);
  opacity: .28;
  filter: url(#rough);
}
.foot-line path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
}

.foot-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding-top: 22px;
  color: var(--ink-3);
  font-size: .84rem;
  letter-spacing: .08em;
  text-align: center;
}
.foot-doodle { width: 30px; height: 30px; color: var(--ink-3); opacity: .8; }
.foot-doodle--computer { width: 36px; height: 28px; }

/* ===========================================================
   弹窗
   =========================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(253, 252, 247, .86);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  animation: fadeIn .3s ease;
}

.modal-card {
  position: relative;
  width: min(880px, 100%);
  max-height: 88vh;
  overflow: auto;
  padding: 16px 16px 22px;
  background: #fff;
  border: 1.5px solid var(--ink);
  border-radius: 20px 26px 18px 24px / 24px 18px 26px 20px;
  box-shadow: 0 4px 0 rgba(44, 42, 40, .1), 0 40px 70px -40px rgba(44, 42, 40, .5);
  animation: popIn .38s var(--ease);
  transform-origin: 50% 30%;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 3;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  font-size: .95rem;
  color: var(--ink);
  background: rgba(255, 255, 255, .9);
  border: 1.3px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
  transition: transform .25s var(--ease), background .25s ease;
}
.modal-close:hover { transform: rotate(90deg); background: var(--pink); }

.modal-stage {
  position: relative;
  aspect-ratio: var(--stage-ratio, 16 / 9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  overflow: hidden;
  background: var(--paper-2);
  border-radius: 13px 17px 12px 16px / 16px 12px 17px 13px;
  border: 1px solid rgba(44, 42, 40, .1);
  text-align: center;
  padding: 16px;
}
.modal-stage video,
.modal-stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.modal-stage video {
  object-fit: contain;
  background: var(--paper-2);
}

/* 竖屏视频：舞台收窄，按视频原始比例显示 */
.modal-stage.is-portrait {
  width: min(100%, calc(58vh * var(--stage-ratio, .5625)));
  margin: 0 auto;
}
.modal-card:has(.modal-stage.is-portrait) { width: min(500px, 100%); }
.stage-doodle { width: 96px; color: var(--ink-3); }
.stage-text { font-size: .9rem; letter-spacing: .1em; color: var(--ink-3); }

.modal-body { padding: 18px 10px 0; }
.modal-body h3 {
  font-size: 1.25rem;
  font-weight: 400;
  letter-spacing: .05em;
  margin: 10px 0 8px;
}
.modal-body p { color: var(--ink-2); font-size: .94rem; }
.modal-hint {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--hair);
  font-size: .8rem !important;
  color: var(--ink-3) !important;
}
.modal-hint code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .92em;
  background: var(--paper-2);
  padding: 1px 5px;
  border-radius: 5px;
}

@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
}

/* ===========================================================
   响应式
   =========================================================== */
@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .topbar { gap: 8px; padding: 10px 14px; }
  .brand-wrap { flex: none; }
  .brand { font-size: .95rem; flex: none; letter-spacing: .02em; }
  /* 窄屏保持一行：分类横向滑动，不换行 */
  .nav {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .pill { flex: none; font-size: .78rem; padding: 3px 9px 4px; letter-spacing: .01em; }

  .grid { grid-template-columns: 1fr; gap: 20px; }
  .works { padding: 20px 16px 30px; }
  .sec-head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .foot { padding: 18px 16px 44px; }
  .foot-row { flex-direction: column; gap: 8px; }
  .modal { padding: 12px; }
}

/* ===========================================================
   动画可访问性
   =========================================================== */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* 首帧隐藏，避免入场前闪烁 */
html.preload .brand,
html.preload .brand-line { opacity: 0; }
