/* ============================================================
   回声 ECHO · 暮色灯会 — 样式
   配色：深暮青 + 暖灯金，像素硬边，无圆角玻璃
   ============================================================ */

:root {
  --ink:      #0c0f16;
  --sky-top:  #0f1219;
  --sky-mid:  #1a2030;
  --sky-low:  #273041;
  --horizon:  #5c4d38;
  --gold:     #e8b84b;
  --gold-dim: #a8823a;
  --teal:     #9fb8d8;      /* 月白（幽魂/回溯） */
  --cream:    #f2e6c8;      /* 纸白 */
  --dim:      #6b7488;
  --panel:    rgba(12, 15, 22, 0.6);
  --px-font:  "Silkscreen", "ZCOOL QingKe HuangYou", monospace;
  --cn-font:  "ZCOOL QingKe HuangYou", "Silkscreen", monospace;
}

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

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  /* 页面背景 = 墨色夜空的延伸，letterbox 也显得有意为之 */
  background:
    radial-gradient(120% 90% at 50% 110%, rgba(232, 184, 75, 0.10) 0%, rgba(232, 184, 75, 0) 55%),
    linear-gradient(180deg, #0a0d14 0%, #0f1219 40%, #181d29 75%, #232a3a 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: var(--cn-font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

/* 背景星点（纯 CSS，两层 box-shadow 星） */
body::before, body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(199,206,222,.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 34% 8%,  rgba(199,206,222,.35) 50%, transparent 51%),
    radial-gradient(1px 1px at 58% 22%, rgba(199,206,222,.4) 50%, transparent 51%),
    radial-gradient(1px 1px at 76% 12%, rgba(199,206,222,.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 28%, rgba(199,206,222,.3) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 45% 15%, rgba(232,184,75,.4) 50%, transparent 51%);
  opacity: .8;
}

/* ---------- 画布 ---------- */
canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  /* 硬边像素投影，呼应像素风 */
  box-shadow:
    0 0 0 2px rgba(232,184,75,.16),
    0 0 0 4px rgba(12,15,22,.9),
    0 0 42px rgba(232,184,75,.10);
  touch-action: none;
}
canvas:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 5px;
}

/* ---------- 加载屏 ---------- */
#loader {
  position: fixed; inset: 0;
  background: linear-gradient(180deg, #0a1826, #16333f);
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  gap: 18px;
  z-index: 50;
  transition: opacity .45s ease;
}
#loader.done { opacity: 0; pointer-events: none; }

.loader-lantern {
  width: 14px; height: 20px;
  background: linear-gradient(180deg, #ffd98a, #ff8f5c);
  box-shadow: 0 0 18px 6px rgba(255,143,92,.45);
  animation: lantern-float 1.6s ease-in-out infinite;
}
@keyframes lantern-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}
.loader-text {
  font-family: var(--cn-font);
  font-size: 15px;
  letter-spacing: .35em;
  color: var(--gold);
}
.dots::after {
  content: "";
  animation: dots 1.2s steps(4) infinite;
}
@keyframes dots {
  0%   { content: ""; }
  25%  { content: "·"; }
  50%  { content: "··"; }
  75%  { content: "···"; }
}

/* ---------- 竖屏提示 ---------- */
#rotate-hint {
  display: none;
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%);
  padding: 6px 14px;
  background: var(--panel);
  border: 2px solid rgba(159,184,216,.4);
  color: var(--teal);
  font-family: var(--cn-font);
  font-size: 13px;
  letter-spacing: .2em;
  z-index: 40;
  animation: hint-in .4s ease .8s both;
}
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.rotate-icon { display: inline-block; animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate-hint { display: block; }
}

/* ---------- 触控按键 ---------- */
#touch {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 30;
  display: none;              /* 仅触屏设备显示 */
  opacity: 0;
  transition: opacity .5s ease .2s;
}
#touch.visible { opacity: 1; }
@media (pointer: coarse) {
  #touch { display: block; }
}
@media (any-pointer: coarse) {
  #touch { display: block; }
}

.t-left, .t-right {
  position: absolute;
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex;
  pointer-events: auto;
}
.t-left  { left:  calc(14px + env(safe-area-inset-left)); gap: 12px; }
.t-right { right: calc(14px + env(safe-area-inset-right)); gap: 14px; align-items: flex-end; }
.t-col   { display: flex; flex-direction: column; gap: 10px; }

.tbtn {
  pointer-events: auto;
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: var(--px-font);
  color: var(--cream);
  background: var(--panel);
  /* 像素硬边：三层直角 box-shadow 做出阶梯描边 */
  box-shadow:
    0 0 0 2px rgba(245,234,209,.22),
    inset 0 -4px 0 rgba(0,0,0,.35),
    inset 0 2px 0 rgba(245,234,209,.08);
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  gap: 2px;
  touch-action: none;
  transition: transform .06s ease, background .06s ease, box-shadow .06s ease;
}
.tbtn:active, .tbtn.on {
  transform: translateY(3px);
  box-shadow:
    0 0 0 2px rgba(245,234,209,.5),
    inset 0 -1px 0 rgba(0,0,0,.35),
    inset 0 2px 0 rgba(245,234,209,.15);
}
.tbtn:focus-visible {
  outline: 3px solid var(--cream);
  outline-offset: 4px;
}

/* 方向键 */
.t-dir {
  width: 62px; height: 62px;
  font-size: 20px;
  color: var(--dim);
}
.t-dir:active, .t-dir.on { color: var(--cream); background: rgba(42,53,80,.65); }

/* 跳跃（主操作，暖金） */
.t-jump {
  width: 84px; height: 84px;
  background: rgba(60,42,20,.62);
  box-shadow:
    0 0 0 2px rgba(232,184,75,.65),
    inset 0 -5px 0 rgba(0,0,0,.4),
    inset 0 2px 0 rgba(242,212,146,.25),
    0 0 22px rgba(232,184,75,.22);
  color: var(--gold);
}
.t-jump:active, .t-jump.on {
  background: rgba(232,184,75,.85);
  color: #2a1c08;
  box-shadow:
    0 0 0 2px rgba(242,212,146,.95),
    inset 0 -2px 0 rgba(0,0,0,.3),
    0 0 30px rgba(232,184,75,.5);
}

/* 回溯（青） */
.t-rewind {
  width: 58px; height: 58px;
  background: rgba(24,30,45,.6);
  box-shadow:
    0 0 0 2px rgba(159,184,216,.5),
    inset 0 -4px 0 rgba(0,0,0,.35),
    inset 0 2px 0 rgba(230,238,248,.18);
  color: var(--teal);
}
.t-rewind:active, .t-rewind.on {
  background: rgba(159,184,216,.8);
  color: #141a29;
}

/* 撤销（弱化） */
.t-undo {
  width: 48px; height: 48px;
  color: var(--dim);
}
.t-undo:active, .t-undo.on { color: var(--cream); }

.t-ico   { font-size: 19px; line-height: 1; }
.t-jump .t-ico   { font-size: 24px; }
.t-label { font-family: var(--cn-font); font-size: 11px; letter-spacing: .15em; line-height: 1; }
.t-dir .t-label { display: none; }

/* 小屏收紧布局 */
@media (max-height: 420px) {
  .t-left, .t-right { bottom: calc(8px + env(safe-area-inset-bottom)); }
  .t-dir  { width: 54px; height: 54px; }
  .t-jump { width: 72px; height: 72px; }
  .t-rewind { width: 50px; height: 50px; }
  .t-undo   { width: 42px; height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
