:root {
  --paper: #f4f2eb;
  --ink: #1c211b;
  --green: #8ea72f;
  --youthol-blue: #3389fd;
  --youthol-orange: #f68518;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  color: var(--ink);
  background: var(--paper);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: background 0.8s ease, color 0.8s ease;
}

body.theme-youthol {
  background: var(--youthol-blue);
  color: var(--youthol-orange);
}

.app {
  position: relative;
  width: 100%;
  height: 100svh;
  transition: transform 0.6s ease;
  transform-origin: center center;
}

/* 手机竖屏时，2 秒后自动旋转 90 度，让长边和内容平行 */
body.force-landscape .app {
  transform: rotate(90deg);
  width: 100svh;
  height: 100svw;
}

/* 背景：放大虚化的 youthol */
.bg-word {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0;
  filter: blur(10px);
  pointer-events: none;
}

.bg-word.is-visible { opacity: .6; }

/* 舞台：画布与图标缩放 */
.app-stage {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  transition: transform 0.85s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.65s ease, filter 0.65s ease;
}

.app-stage.is-zoomed {
  transform: scale(2.2);
  opacity: 0.12;
  filter: blur(5px);
  pointer-events: none;
}

#canvas {
  position: relative;
  z-index: 4;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* 顶部手写提示 */
.prompt {
  position: absolute;
  z-index: 2;
  top: max(25px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  color: var(--ink);
  font-size: 13px;
  letter-spacing: .16em;
  white-space: nowrap;
  pointer-events: none;
  transition: color 0.6s ease, opacity 0.4s ease, transform 0.4s ease;
}

.prompt::after {
  content: "";
  display: block;
  width: 28px;
  height: 1px;
  margin: 11px auto 0;
  background: var(--green);
  transition: background 0.6s ease;
}

.prompt.is-hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-6px);
}

/* 右下角写好了 / 再写一次胶囊按钮 */
.done {
  position: absolute;
  z-index: 5;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  min-width: 128px;
  padding: 15px 20px;
  border: 0;
  border-radius: 999px;
  color: var(--paper);
  background: var(--ink);
  box-shadow: 0 10px 28px rgba(28, 33, 27, .16);
  font: inherit;
  font-size: 12px;
  letter-spacing: .08em;
  cursor: pointer;
  transition: transform .2s ease, background .3s ease, color .3s ease, box-shadow .3s ease, opacity .25s ease;
}

.done:hover {
  transform: translateY(-2px);
  background: var(--green);
}

.done:disabled {
  cursor: wait;
  opacity: .62;
}

.done.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

body.theme-youthol .done {
  background: var(--paper);
  color: var(--youthol-blue);
  box-shadow: 0 10px 28px rgba(10, 30, 80, 0.25);
}

body.theme-youthol .done:hover {
  background: var(--youthol-orange);
  color: #fff;
  transform: translateY(-2px);
}

/* 底部中央交互提示胶囊 */
.action-pill {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  color: rgba(255, 255, 255, .78);
  font-size: 13px;
  letter-spacing: .14em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .45s ease, transform .45s ease;
  white-space: nowrap;
}

.action-pill.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 技术栈图标粒子群 */
.stack-burst {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
}

.stack-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--size) * 1px);
  height: calc(var(--size) * 1px);
  opacity: 0;
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%) translate(0, 0) scale(0.1) rotate(0deg);
  will-change: transform, opacity;
  transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.25, 1);
  user-select: none;
  -webkit-user-select: none;
}

.stack-burst.is-visible .stack-icon {
  animation: stack-pop 0.72s cubic-bezier(0.22, 1, 0.36, 1.22) forwards;
  animation-delay: var(--delay, 0ms);
}

@keyframes stack-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) translate(0, 0) scale(0.1) rotate(0deg);
  }
  70% {
    opacity: 1;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1) rotate(var(--rot));
  }
  100% {
    opacity: 1;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(var(--rot));
  }
}

/* 图标：纯色显示，不加透明度 */
.stack-img-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 6%;
  border-radius: 24%;
  background: transparent;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.stack-icon:hover .stack-img-wrap,
.stack-icon:active .stack-img-wrap,
.stack-icon.is-active .stack-img-wrap {
  transform: scale(1.12);
  box-shadow: 0 0 0 2px var(--brand-color, var(--green));
  z-index: 10;
}

.stack-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.stack-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px) scale(0.9);
  padding: 4px 9px;
  border-radius: 999px;
  background: #1c211b;
  color: #f4f2eb;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 20;
}

.stack-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 4px 4px 0 4px;
  border-style: solid;
  border-color: #1c211b transparent transparent transparent;
}

.stack-icon.tip-bottom .stack-tooltip {
  bottom: auto;
  top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-4px) scale(0.9);
}

.stack-icon.tip-bottom .stack-tooltip::after {
  top: auto;
  bottom: 100%;
  border-width: 0 4px 4px 4px;
  border-color: transparent transparent #1c211b transparent;
}

.stack-icon:hover .stack-tooltip,
.stack-icon:active .stack-tooltip,
.stack-icon.is-active .stack-tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

@media (max-width: 600px), (max-height: 500px) {
  .stack-icon {
    width: calc(var(--size) * 0.85px);
    height: calc(var(--size) * 0.85px);
  }
}

/* =========================================
   信件 - 延续原版纯粹信纸美学
   ========================================= */
.letter-overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 30, 80, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  cursor: pointer;
}

.letter-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.letter-card {
  position: relative;
  width: min(340px, 86vw);
  background: #f4f2eb;
  color: #1c211b;
  padding: 44px 34px 40px;
  border-radius: 6px;
  box-shadow: 0 24px 60px rgba(10, 30, 80, 0.32);
  transform: translateY(20px) scale(0.95);
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: left;
  user-select: none;
  -webkit-user-select: none;
}

.letter-overlay.is-visible .letter-card {
  transform: translateY(0) scale(1);
}

.letter-salutation {
  margin: 0;
  font: 400 24px/1.3 Georgia, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", serif;
  color: #1c211b;
  letter-spacing: .03em;
}

.letter-divider {
  width: 28px;
  height: 1px;
  margin: 18px 0 20px;
  background: #f68518;
}

.letter-body {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .08em;
  color: #f68518;
  line-height: 1.6;
}

/* 个人信件：正文较长时加宽并允许滚动 */
.letter-card.is-long {
  width: min(560px, 90vw);
  max-height: 84svh;
  overflow-y: auto;
  padding: 36px 34px 30px;
}

.letter-card.is-long .letter-body {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: .06em;
  line-height: 1.9;
  color: var(--ink);
}

.letter-card.is-long .letter-body p {
  margin: 0 0 .9em;
}

.letter-card.is-long .letter-body p.is-lead {
  color: #f68518;
  font-weight: 500;
}

.letter-footer {
  margin-top: 24px;
  font-size: 12px;
  color: rgba(28, 33, 27, .5);
  letter-spacing: .08em;
}

/* 横屏提示：手机竖屏时显示 2 秒，然后隐藏，允许竖屏继续 */
.rotate {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: none;
  place-items: center;
  padding: 28px;
  color: #f4f2eb;
  background: #1c211b;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.rotate.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.rotate-card { max-width: 280px; }
.phone {
  width: 40px;
  height: 65px;
  margin: 0 auto 24px;
  border: 2px solid var(--green);
  border-radius: 7px;
  transform: rotate(90deg);
}

.rotate h2 { margin: 0 0 9px; font: 400 30px/1.1 Georgia, serif; }
.rotate p { margin: 0; color: rgba(244, 242, 235, .7); font-size: 13px; line-height: 1.6; }
@media (orientation: portrait) and (pointer: coarse) {
  .rotate {
    display: grid;
    opacity: 1;
    pointer-events: auto;
  }
}
@media (orientation: landscape) and (pointer: coarse) {
  .rotate.is-visible {
    opacity: 0;
    pointer-events: none;
  }
}
