/* ============================================================
   官海浮沉 · 2048  —  样式
   纸本设色 / 朱砂 / 泥金 / 髹漆，手机竖屏优先
   ============================================================ */

:root {
  --paper: #fdf6e6;
  --paper-2: #f5e6c8;
  --paper-3: #efdcba;
  --ink: #3a2a1d;
  --ink-2: #6b5744;
  --ink-3: rgba(90, 45, 36, 0.55);
  --cinnabar: #a8322a;
  --cinnabar-2: #7c1f1a;
  --cinnabar-3: #c0534a;
  --gold: #c99a4b;
  --gold-2: #e7c98f;
  --lacquer: #4a241d;
  --lacquer-2: #2c130f;
  --line: rgba(90, 45, 36, 0.16);
  --board: 320px;
  --tile: 68px;
  --gap: 7px;
  --pad: 8px;
  --ease: cubic-bezier(0.25, 0.7, 0.35, 1);
  --serif: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  --brush: "STXingkai", "华文行楷", "Kaiti SC", "STKaiti", "KaiTi", "楷体", "Songti SC", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  color-scheme: light;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(120% 70% at 50% -10%, #fdf7e9 0%, #f6ead2 38%, #eeddbc 72%, #e6d3ae 100%);
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* 纸张纤维质感 */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='180' height='180' filter='url(%23n)' opacity='0.16'/></svg>");
  background-size: 180px 180px;
}

button {
  font-family: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--cinnabar);
  outline-offset: 2px;
}

/* ---------------- 装饰 ---------------- */
.deco {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.deco svg {
  position: absolute;
  width: 74%;
  max-width: 420px;
  color: rgba(140, 96, 55, 0.16);
}

.deco .cloud-a {
  left: -14%;
  top: 4%;
  animation: drift 46s ease-in-out infinite alternate;
}

.deco .cloud-b {
  right: -18%;
  bottom: 8%;
  transform: scaleX(-1);
  animation: drift 62s ease-in-out infinite alternate-reverse;
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(4%, -2.5%, 0);
  }
}

.deco .cloud-b {
  animation-name: drift-flip;
}

@keyframes drift-flip {
  from {
    transform: scaleX(-1) translate3d(0, 0, 0);
  }
  to {
    transform: scaleX(-1) translate3d(-4%, 2.5%, 0);
  }
}

/* ---------------- 页面骨架 ---------------- */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 14px calc(env(safe-area-inset-bottom, 0px) + 10px);
}

/* ---------------- 抬头 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-seal {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: linear-gradient(150deg, var(--cinnabar-3), var(--cinnabar-2));
  color: #fbeed1;
  font-family: var(--brush);
  font-size: 21px;
  line-height: 1;
  transform: rotate(-3deg);
  box-shadow: 0 2px 7px rgba(124, 31, 26, 0.35), inset 0 0 0 1px rgba(255, 218, 168, 0.45);
}

.brand-text {
  min-width: 0;
}

.brand-text h1 {
  margin: 0;
  font-family: var(--brush);
  font-size: clamp(25px, 7.4vw, 33px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 1px;
  color: #241a12;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55), 0 2px 6px rgba(90, 45, 36, 0.18);
  white-space: nowrap;
}

.brand-num {
  font-family: "Bahnschrift", "DIN Alternate", "Georgia", serif;
  font-weight: 800;
  font-style: italic;
  font-size: 0.86em;
  letter-spacing: 0;
  color: var(--cinnabar);
  margin-left: 4px;
  text-shadow: 0 1px 0 rgba(255, 240, 214, 0.75), 0 2px 8px rgba(124, 31, 26, 0.28);
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 9.5px;
  letter-spacing: 3.4px;
  color: rgba(90, 45, 36, 0.6);
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 7px;
  flex: 0 0 auto;
}

.icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-2);
  background: linear-gradient(#fdf6e6, #f0ddbd);
  border: 1px solid rgba(90, 45, 36, 0.2);
  box-shadow: inset 0 1px 0 #fff, 0 1px 3px rgba(58, 20, 14, 0.14);
  transition: transform 0.1s var(--ease);
}

.icon-btn[aria-pressed="false"]::after {
  content: "";
  position: absolute;
  width: 19px;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
  transform: rotate(-45deg);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn[aria-pressed="false"] {
  color: rgba(90, 45, 36, 0.35);
  background: linear-gradient(#f4e9d4, #e9d7b6);
}

/* ---------------- 分数 ---------------- */
.scorebar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  flex: 0 0 auto;
}

.pane {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 11px;
  background: linear-gradient(#fdf6e6, #f2e1c2);
  border: 1px solid rgba(90, 45, 36, 0.15);
  box-shadow: inset 0 1px 0 #fff, 0 2px 6px rgba(58, 20, 14, 0.1);
  overflow: hidden;
}

.pane::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(201, 154, 75, 0.75), transparent);
}

.pane-k {
  font-size: 10.5px;
  letter-spacing: 1.5px;
  color: var(--ink-3);
  white-space: nowrap;
}

.pane-v {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(18px, 5.2vw, 24px);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: #2b1b12;
}

.pane-best .pane-v {
  color: #6b4a32;
}

.pane.bump {
  animation: bump 0.25s var(--ease);
}

@keyframes bump {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.035);
  }
  100% {
    transform: scale(1);
  }
}

/* ---------------- 棋盘 ---------------- */
.board-area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 2px 0;
}

.board {
  position: relative;
  width: var(--board);
  height: var(--board);
  flex: 0 0 auto;
  border-radius: calc(var(--board) * 0.032);
  background: linear-gradient(158deg, #612f24 0%, #48211a 46%, #2c130f 100%);
  box-shadow:
    0 16px 34px -12px rgba(58, 20, 14, 0.55),
    0 2px 0 rgba(255, 232, 196, 0.09) inset,
    0 0 0 1px rgba(255, 216, 160, 0.16) inset,
    0 0 0 5px rgba(201, 154, 75, 0.1);
  touch-action: none;
  transform: translateZ(0);
}

.board::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: calc(var(--board) * 0.026);
  border: 1px solid rgba(201, 154, 75, 0.3);
  pointer-events: none;
  z-index: 3;
}

.cells {
  position: absolute;
  inset: var(--pad);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
}

.cell {
  border-radius: calc(var(--tile) * 0.13);
  background: rgba(255, 238, 208, 0.065);
  box-shadow: inset 0 0 0 1px rgba(255, 235, 200, 0.05), inset 0 3px 8px rgba(0, 0, 0, 0.22);
}

.tiles {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.danger-glow {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s ease;
  box-shadow: inset 0 0 34px rgba(168, 50, 42, 0.55), inset 0 0 6px rgba(214, 96, 62, 0.45);
}

.board[data-danger="2"] .danger-glow {
  opacity: 0.35;
}

.board[data-danger="3"] .danger-glow {
  opacity: 0.6;
}

.board[data-danger="4"] .danger-glow {
  opacity: 0.9;
  animation: warn-pulse 1.15s ease-in-out infinite;
}

.tile {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--tile);
  height: var(--tile);
  border-radius: calc(var(--tile) * 0.135);
  transform: translate(
    calc(var(--pad) + var(--c) * (var(--tile) + var(--gap))),
    calc(var(--pad) + var(--r) * (var(--tile) + var(--gap)))
  );
  transition: transform 95ms var(--ease);
  background: #f8efdb;
  box-shadow: 0 3px 8px -2px rgba(40, 16, 10, 0.35), 0 0 0 1px rgba(90, 45, 36, 0.16);
  overflow: hidden;
  will-change: transform;
  backface-visibility: hidden;
}

.tile-inner {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
}

/* 卡面图缺失时的文字牌兜底 */
.tile-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: linear-gradient(150deg, #fdf6e6, #efdcba);
  color: #4a241d;
}

.tile-fallback b {
  font-family: var(--serif);
  font-size: calc(var(--tile) * 0.34);
  line-height: 1;
  color: var(--cinnabar-2);
  font-variant-numeric: tabular-nums;
}

.tile-fallback span {
  font-family: var(--brush);
  font-size: calc(var(--tile) * 0.14);
  letter-spacing: 1px;
  color: rgba(90, 45, 36, 0.72);
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(90, 45, 36, 0.18), inset 0 -10px 14px -10px rgba(58, 20, 14, 0.4);
  pointer-events: none;
}

.tile[data-v="256"] {
  box-shadow: 0 3px 10px -2px rgba(40, 16, 10, 0.4), 0 0 0 1px rgba(201, 154, 75, 0.55);
}

.tile[data-v="512"] {
  box-shadow: 0 4px 14px -2px rgba(124, 31, 26, 0.45), 0 0 0 1px rgba(201, 154, 75, 0.7);
}

.tile[data-v="1024"] {
  box-shadow: 0 4px 18px -2px rgba(124, 31, 26, 0.55), 0 0 0 2px rgba(213, 170, 90, 0.8);
}

.tile[data-v="1024"]::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 16px rgba(201, 154, 75, 0.5);
  pointer-events: none;
}

.tile[data-v="2048"] {
  box-shadow: 0 0 0 2px rgba(226, 183, 96, 0.95), 0 0 22px rgba(201, 154, 75, 0.55),
    0 6px 22px -4px rgba(60, 10, 6, 0.7);
}

.tile[data-v="2048"]::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(255, 224, 160, 0.55);
  box-shadow: inset 0 0 18px rgba(255, 208, 120, 0.35);
  animation: shine 2.8s ease-in-out infinite;
  pointer-events: none;
  z-index: 2;
}

@keyframes shine {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 0.85;
  }
}

.tile.pop .tile-inner {
  animation: pop 0.2s var(--ease);
}

@keyframes pop {
  0% {
    transform: scale(0.82);
  }
  62% {
    transform: scale(1.07);
  }
  100% {
    transform: scale(1);
  }
}

.tile.appear .tile-inner {
  animation: appear 0.16s var(--ease);
}

@keyframes appear {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.board.shake {
  animation: shake 0.22s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateZ(0) translateX(0);
  }
  25% {
    transform: translateZ(0) translateX(-4px);
  }
  50% {
    transform: translateZ(0) translateX(4px);
  }
  75% {
    transform: translateZ(0) translateX(-2px);
  }
}

.fx {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
}

.float-score {
  position: absolute;
  font-family: var(--serif);
  font-weight: 700;
  font-size: calc(var(--tile) * 0.26);
  color: #ffe9bb;
  text-shadow: 0 1px 3px rgba(40, 10, 6, 0.65), 0 0 10px rgba(255, 200, 120, 0.35);
  transform: translate(-50%, -50%);
  animation: float-up 0.9s ease-out forwards;
  white-space: nowrap;
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.7);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -150%) scale(1);
  }
}

/* ---------------- 官阶谱 ---------------- */
.ladder {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 4px;
  min-height: 30px;
}

.ladder-k {
  flex: 0 0 auto;
  font-size: 9.5px;
  letter-spacing: 2px;
  color: var(--ink-3);
  writing-mode: vertical-rl;
  line-height: 1;
  padding: 2px 0;
}

.ladder-rail {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding-top: 1px;
}

.ladder-rail::before {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  top: 4px;
  height: 1px;
  background: linear-gradient(
    90deg,
    rgba(201, 154, 75, 0.45),
    rgba(90, 45, 36, 0.16) 70%,
    rgba(168, 50, 42, 0.3)
  );
}

.node {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 0 0 auto;
}

.node i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(90, 45, 36, 0.16);
  box-shadow: 0 0 0 2px rgba(250, 241, 224, 0.95);
  transition: background 0.25s, box-shadow 0.25s;
}

.node b {
  font-size: 8.5px;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  color: rgba(90, 45, 36, 0.42);
  transition: color 0.25s;
}

.node.unlocked i {
  background: var(--gold);
}

.node.unlocked b {
  color: rgba(74, 36, 29, 0.78);
}

.node.on i {
  background: var(--cinnabar);
  box-shadow: 0 0 0 2px rgba(250, 241, 224, 0.95), 0 0 0 3.5px rgba(168, 50, 42, 0.22);
}

.node.on b {
  color: var(--cinnabar);
  font-weight: 700;
}

.node.on::after {
  content: "";
  position: absolute;
  top: 11px;
  width: 12px;
  height: 1px;
  background: rgba(168, 50, 42, 0.45);
}

/* ---------------- 史鉴引文 ---------------- */
.quote {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  text-align: center;
}

.quote-text {
  position: relative;
  max-width: 340px;
  font-family: var(--brush);
  font-size: 12.5px;
  line-height: 1.55;
  letter-spacing: 0.6px;
  color: rgba(90, 45, 36, 0.62);
}

.quote-text::before,
.quote-text::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 18px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(168, 50, 42, 0.35));
}

.quote-text::before {
  right: 100%;
  margin-right: 8px;
}

.quote-text::after {
  left: 100%;
  margin-left: 8px;
  transform: scaleX(-1);
}

.quote-from {
  font-size: 9px;
  letter-spacing: 1.2px;
  color: rgba(90, 45, 36, 0.36);
}

@media (max-height: 740px) {
  .quote {
    display: none;
  }
}

/* ---------------- 底部面板 ---------------- */
.panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px 11px 8px;
  border-radius: 13px;
  background: linear-gradient(#fcf3e1, #f1dfbf);
  border: 1px solid rgba(90, 45, 36, 0.16);
  box-shadow: inset 0 1px 0 #fff, 0 6px 16px -8px rgba(58, 20, 14, 0.4);
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-item {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
  font-size: 11.5px;
}

.status-item .k {
  color: var(--ink-3);
  letter-spacing: 1px;
  white-space: nowrap;
}

.status-item .v {
  font-size: 13.5px;
  font-weight: 700;
  color: #2b1b12;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-item .v .fam {
  font-weight: 400;
  color: var(--ink-2);
}

.warn .v {
  color: #4f6b4a;
  transition: color 0.25s;
}

.warn[data-level="1"] .v {
  color: #9a6b1f;
}

.warn[data-level="2"] .v {
  color: #b5561f;
}

.warn[data-level="3"] .v {
  color: #a8322a;
}

.warn[data-level="4"] .v {
  color: var(--cinnabar-2);
}

.warn[data-level="3"] .v,
.warn[data-level="4"] .v {
  animation: warn-pulse 1.1s ease-in-out infinite;
}

@keyframes warn-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

.warn-pips {
  display: flex;
  gap: 3px;
  margin-left: 2px;
}

.warn-pips i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(90, 45, 36, 0.18);
  transition: background 0.2s;
}

.warn-pips i.on {
  background: var(--cinnabar);
}

.crime-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 11px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
}

.crime-row .k {
  color: var(--ink-3);
  letter-spacing: 1px;
}

.crime-row b {
  color: #4a241d;
  font-weight: 600;
}

.crime-row .sep {
  color: rgba(90, 45, 36, 0.28);
  margin: 0 2px;
}

.actions {
  display: flex;
  gap: 7px;
}

.action {
  position: relative;
  flex: 1 1 0;
  padding: 8px 6px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #4a241d;
  background: linear-gradient(#fdf6e8, #eedcb9);
  border: 1px solid rgba(90, 45, 36, 0.2);
  box-shadow: inset 0 1px 0 #fff, 0 2px 4px rgba(58, 20, 14, 0.12);
  transition: transform 0.12s var(--ease), filter 0.12s;
}

.action:active {
  transform: translateY(1px) scale(0.99);
  filter: brightness(0.97);
}

.action.primary {
  color: #fdf0d4;
  background: linear-gradient(#b23c30, #8a2520);
  border-color: #74201a;
  box-shadow: inset 0 1px 0 rgba(255, 220, 180, 0.28), 0 2px 6px rgba(124, 31, 26, 0.3);
}

.action[disabled] {
  opacity: 0.45;
  filter: grayscale(0.4);
}

.action .badge {
  position: absolute;
  top: -5px;
  right: -4px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 8px;
  font-size: 10px;
  font-style: normal;
  line-height: 15px;
  text-align: center;
  color: #fff3d8;
  background: var(--cinnabar);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.hint {
  margin: 0;
  text-align: center;
  font-size: 10px;
  letter-spacing: 1.6px;
  color: rgba(90, 45, 36, 0.5);
}

/* ---------------- 浮动提示 ---------------- */
.toast {
  position: absolute;
  left: 50%;
  top: 106px;
  z-index: 20;
  min-width: 62%;
  max-width: min(92%, 460px);
  transform: translate(-50%, -6px) scale(0.97);
  padding: 8px 14px;
  border-radius: 10px;
  text-align: center;
  color: #fbeed1;
  background: linear-gradient(150deg, rgba(74, 36, 29, 0.97), rgba(44, 19, 15, 0.97));
  border: 1px solid rgba(201, 154, 75, 0.6);
  box-shadow: 0 10px 26px -8px rgba(30, 10, 6, 0.7), inset 0 0 0 1px rgba(255, 226, 176, 0.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s var(--ease);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.toast .t-title {
  display: block;
  font-family: var(--brush);
  font-size: 16px;
  letter-spacing: 2px;
  color: var(--gold-2);
}

.toast .t-sub {
  display: block;
  margin-top: 3px;
  font-size: 10.5px;
  letter-spacing: 1px;
  color: rgba(251, 238, 209, 0.72);
}

/* ---------------- 弹层 ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 14px calc(env(safe-area-inset-bottom, 0px) + 14px);
  background: rgba(26, 12, 9, 0.58);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade 0.18s ease-out;
}

.overlay[hidden] {
  display: none;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.sheet {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: 86vh;
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  border-radius: 14px;
  animation: rise 0.26s var(--ease);
}

.sheet:focus {
  outline: none;
}

.sheet.wide {
  max-width: 430px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* 开屏：首次入局时的标题 logo */
.splash {
  position: relative;
  padding: 16px 18px 20px;
  text-align: center;
  border-radius: 14px;
  background: linear-gradient(#fdf7e8, #f4e5c8);
  box-shadow: 0 24px 60px -20px rgba(20, 6, 3, 0.8), inset 0 0 0 1px rgba(201, 154, 75, 0.55),
    inset 0 0 0 6px rgba(255, 248, 232, 0.85), inset 0 0 0 7px rgba(201, 154, 75, 0.45);
  animation: rise 0.3s var(--ease);
}

.splash-logo {
  display: block;
  width: min(78%, 300px);
  margin: 2px auto 14px;
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(201, 154, 75, 0.6), 0 12px 28px -12px rgba(58, 20, 14, 0.55);
  -webkit-user-drag: none;
  user-select: none;
}

.splash-tag {
  margin: 0;
  font-family: var(--brush);
  font-size: 17px;
  letter-spacing: 4px;
  color: #4a241d;
}

/* 标题 logo 缺失时的书法字兜底 */
.splash-fallback {
  margin: 8px auto 18px;
  font-family: var(--brush);
  font-size: clamp(34px, 10vw, 44px);
  line-height: 1.15;
  letter-spacing: 5px;
  color: #8c2620;
  text-shadow: 0 1px 0 #fff6e2;
}

.splash-fallback em {
  display: block;
  margin-top: 4px;
  font-family: var(--serif);
  font-size: 22px;
  font-style: normal;
  letter-spacing: 4px;
  color: var(--cinnabar);
}

.splash-sub {
  margin: 6px 0 16px;
  font-size: 10.5px;
  letter-spacing: 2.2px;
  color: rgba(90, 45, 36, 0.58);
}

.splash-start {
  width: min(64%, 220px);
  padding: 11px 6px;
  font-size: 15px;
  letter-spacing: 5px;
}

/* 圣旨 */
.edict {
  position: relative;
  padding: 20px 20px 16px;
  text-align: center;
  color: #3a2a1d;
  background: linear-gradient(#fdf7e8, #f4e4c6 58%, #edd9b5);
  border-radius: 12px;
  box-shadow: 0 24px 60px -20px rgba(20, 6, 3, 0.8), inset 0 0 0 1px rgba(201, 154, 75, 0.55),
    inset 0 0 0 6px rgba(255, 248, 232, 0.85), inset 0 0 0 7px rgba(201, 154, 75, 0.45);
}

.edict::before,
.edict::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  height: 2px;
  background: repeating-linear-gradient(90deg, rgba(201, 154, 75, 0.75) 0 6px, transparent 6px 11px);
  opacity: 0.5;
}

.edict::before {
  top: 9px;
}

.edict::after {
  bottom: 9px;
}

.edict-kicker {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 3px;
  font-family: var(--brush);
  font-size: 12px;
  letter-spacing: 4px;
  color: #fbeed1;
  background: linear-gradient(#a8322a, #7c1f1a);
  box-shadow: 0 2px 6px rgba(124, 31, 26, 0.35);
}

.edict h2 {
  margin: 12px 0 4px;
  font-family: var(--brush);
  font-size: clamp(30px, 9.6vw, 40px);
  font-weight: 700;
  letter-spacing: 6px;
  color: #8c2620;
  text-shadow: 0 1px 0 #fff6e2;
}

.edict-sub {
  margin: 0 0 12px;
  font-size: 11px;
  letter-spacing: 3px;
  color: rgba(90, 45, 36, 0.6);
}

.edict-body {
  position: relative;
  margin: 0 auto;
  max-width: 320px;
  padding: 10px 4px 6px;
  font-family: var(--brush);
  font-size: 15px;
  line-height: 1.95;
  color: #4a3423;
  text-align: left;
}

.edict-body .lead {
  display: block;
  font-size: 14px;
  letter-spacing: 2px;
  color: #7c1f1a;
  margin-bottom: 2px;
}

.edict-body mark {
  background: none;
  color: #a8322a;
  font-weight: 700;
}

.edict-seal {
  position: absolute;
  right: 14px;
  top: 14px;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  border: 3px solid rgba(168, 50, 42, 0.82);
  color: rgba(168, 50, 42, 0.85);
  font-family: var(--brush);
  font-size: 11px;
  line-height: 1.08;
  letter-spacing: 0;
  transform: rotate(-8deg);
  opacity: 0.88;
  background: rgba(168, 50, 42, 0.04);
  pointer-events: none;
}

.edict-stats {
  display: flex;
  justify-content: center;
  gap: 0;
  margin: 12px 0 14px;
  border-top: 1px dashed rgba(90, 45, 36, 0.22);
  border-bottom: 1px dashed rgba(90, 45, 36, 0.22);
  padding: 9px 0;
}

.edict-stats div {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.edict-stats div + div {
  border-left: 1px solid rgba(90, 45, 36, 0.12);
}

.edict-stats .k {
  font-size: 10px;
  letter-spacing: 1px;
  color: rgba(90, 45, 36, 0.55);
}

.edict-stats .v {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 700;
  color: #2b1b12;
}

.edict-actions {
  display: flex;
  gap: 9px;
}

.edict-actions .action {
  padding: 11px 6px;
  font-size: 13.5px;
}

/* 终局卡牌 */
.victory {
  position: relative;
  padding: 18px 18px 16px;
  text-align: center;
  border-radius: 14px;
  background: linear-gradient(160deg, #3a1a14, #1d0c09 70%);
  box-shadow: 0 26px 60px -18px rgba(10, 3, 2, 0.85), inset 0 0 0 1px rgba(201, 154, 75, 0.55);
  color: #f6e6c6;
}

.victory h2 {
  margin: 12px 0 2px;
  font-family: var(--brush);
  font-size: clamp(30px, 9vw, 38px);
  letter-spacing: 6px;
  color: #e9c789;
  text-shadow: 0 2px 12px rgba(255, 180, 90, 0.35);
}

.victory .v-sub {
  margin: 0 0 12px;
  font-size: 11px;
  letter-spacing: 3px;
  color: rgba(246, 230, 198, 0.62);
}

.victory .v-art {
  position: relative;
  width: min(58%, 190px);
  aspect-ratio: 1;
  margin: 2px auto 12px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(201, 154, 75, 0.65), 0 10px 30px -8px rgba(0, 0, 0, 0.8);
  animation: v-glow 3s ease-in-out infinite;
}

.victory .v-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

@keyframes v-glow {
  0%,
  100% {
    box-shadow: 0 0 0 1px rgba(201, 154, 75, 0.55), 0 10px 30px -8px rgba(0, 0, 0, 0.8);
  }
  50% {
    box-shadow: 0 0 0 2px rgba(233, 199, 137, 0.9), 0 0 34px rgba(201, 154, 75, 0.45),
      0 10px 30px -8px rgba(0, 0, 0, 0.8);
  }
}

.victory p.v-text {
  margin: 0 auto 14px;
  max-width: 300px;
  font-family: var(--brush);
  font-size: 14px;
  line-height: 1.9;
  color: rgba(246, 230, 198, 0.82);
}

.victory .v-stats {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-bottom: 14px;
  font-size: 12px;
  color: rgba(246, 230, 198, 0.7);
}

.victory .v-stats b {
  display: block;
  margin-top: 3px;
  font-family: var(--serif);
  font-size: 16px;
  color: #f3d9a4;
}

.victory .action {
  color: #f3dcb2;
  background: rgba(255, 240, 210, 0.08);
  border-color: rgba(201, 154, 75, 0.45);
  box-shadow: none;
}

.victory .action.primary {
  color: #2b100c;
  background: linear-gradient(#f0cf94, #d7a75c);
  border-color: #b98b42;
}

/* 图鉴 / 规则 */
.codex {
  display: flex;
  flex-direction: column;
  max-height: inherit;
  border-radius: 14px;
  background: linear-gradient(#fdf7e8, #f5e7ca);
  box-shadow: 0 24px 60px -20px rgba(20, 6, 3, 0.8), inset 0 0 0 1px rgba(201, 154, 75, 0.5);
  overflow: hidden;
}

.codex-head {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 15px 11px;
  border-bottom: 1px solid rgba(90, 45, 36, 0.14);
  background: linear-gradient(#fdf8ea, #f4e5c8);
}

.codex-head h2 {
  margin: 0;
  font-family: var(--brush);
  font-size: 22px;
  letter-spacing: 3px;
  color: #2b1b12;
}

.codex-head .codex-count {
  margin-left: 8px;
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: 1px;
  color: var(--ink-3);
}

.close-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 15px;
  color: var(--ink-2);
  border: 1px solid rgba(90, 45, 36, 0.2);
  background: rgba(255, 252, 244, 0.7);
}

.codex-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 11px 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rank-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
  background: rgba(255, 252, 244, 0.62);
  border: 1px solid rgba(90, 45, 36, 0.13);
}

.rank-row.locked {
  opacity: 0.66;
}

.rank-art {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 9px;
  overflow: hidden;
  background: #f2e4c8;
  box-shadow: 0 2px 6px -2px rgba(58, 20, 14, 0.35);
}

.rank-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.rank-row.locked .rank-art img {
  filter: grayscale(1) brightness(0.72) blur(1.2px);
}

.rank-art .lock-mark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--brush);
  font-size: 13px;
  letter-spacing: 1px;
  color: rgba(253, 246, 230, 0.92);
  background: rgba(44, 19, 15, 0.34);
}

/* 图鉴 / 终局卡图片缺失时的占位 */
.rank-art.art-missing::after,
.v-art.art-missing::after {
  content: "缺图";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--brush);
  font-size: 12px;
  letter-spacing: 1px;
  color: rgba(90, 45, 36, 0.55);
  background: #f2e4c8;
}

.v-art.art-missing::after {
  font-size: 14px;
  color: rgba(246, 230, 198, 0.75);
  background: rgba(255, 240, 210, 0.12);
}

.rank-main {
  min-width: 0;
}

.rank-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.rank-title .val {
  font-family: var(--serif);
  font-size: 12px;
  font-weight: 700;
  color: #9a6b1f;
  min-width: 26px;
}

.rank-title .name {
  font-family: var(--brush);
  font-size: 17px;
  letter-spacing: 1.5px;
  color: #2b1b12;
}

.rank-title .rank-official {
  font-size: 10px;
  letter-spacing: 0.5px;
  color: rgba(90, 45, 36, 0.56);
}

.rank-meta {
  margin-top: 3px;
  font-size: 10.5px;
  line-height: 1.6;
  color: var(--ink-2);
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
}

.rank-meta b {
  color: #8c2620;
  font-weight: 600;
}

.rank-meta i {
  font-style: normal;
  color: rgba(90, 45, 36, 0.4);
}

.rank-quote {
  margin-top: 3px;
  font-family: var(--brush);
  font-size: 11px;
  line-height: 1.5;
  color: rgba(90, 45, 36, 0.62);
}

.rank-quote span {
  font-family: var(--sans);
  font-size: 9.5px;
  letter-spacing: 0.3px;
  color: rgba(90, 45, 36, 0.42);
}

.rules {
  padding: 16px 16px 18px;
  border-radius: 14px;
  background: linear-gradient(#fdf7e8, #f4e5c8);
  box-shadow: 0 24px 60px -20px rgba(20, 6, 3, 0.8), inset 0 0 0 1px rgba(201, 154, 75, 0.5);
}

.rules h2 {
  margin: 0 0 12px;
  text-align: center;
  font-family: var(--brush);
  font-size: 22px;
  letter-spacing: 4px;
  color: #2b1b12;
}

.rules ol {
  margin: 0;
  padding: 0 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 12.5px;
  line-height: 1.75;
  color: #4a3423;
}

.rules ol b {
  color: #8c2620;
}

.rules .rules-note {
  margin: 14px 0 0;
  padding-top: 11px;
  border-top: 1px dashed rgba(90, 45, 36, 0.22);
  font-family: var(--brush);
  font-size: 12.5px;
  line-height: 1.8;
  color: rgba(90, 45, 36, 0.68);
  text-align: center;
}

/* ---------------- 横屏 ---------------- */
@media (orientation: landscape) and (max-height: 560px) {
  .app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "head board"
      "score board"
      "panel board";
    column-gap: 16px;
    row-gap: 8px;
    max-width: 940px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .topbar {
    grid-area: head;
  }

  .scorebar {
    grid-area: score;
  }

  .board-area {
    grid-area: board;
  }

  .panel {
    grid-area: panel;
    align-self: end;
  }

  .brand-sub {
    display: none;
  }

  .ladder {
    display: none;
  }

  .toast {
    top: 56px;
  }

  .edict-body {
    font-size: 14px;
    line-height: 1.8;
  }
}

/* ---------------- 窄屏微调 ---------------- */
@media (max-width: 400px) {
  .status-row {
    flex-wrap: wrap;
    row-gap: 3px;
  }

  .status-item {
    flex: 1 1 auto;
  }
}

@media (max-width: 350px) {
  .app {
    padding-left: 10px;
    padding-right: 10px;
    gap: 7px;
  }

  .brand-seal {
    width: 30px;
    height: 30px;
    font-size: 19px;
    border-radius: 4px;
  }

  .brand-text h1 {
    font-size: 22px;
    letter-spacing: 0.5px;
  }

  .brand-num {
    font-size: 0.78em;
    margin-left: 3px;
  }

  .brand-sub {
    letter-spacing: 2px;
  }

  .topbar-actions {
    gap: 5px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .pane {
    padding: 6px 9px;
  }

  .pane-k {
    letter-spacing: 0.5px;
  }

  .status-item .v {
    font-size: 12.5px;
  }

  .action {
    font-size: 11.5px;
  }

  .hint {
    letter-spacing: 0.8px;
  }

  .node b {
    font-size: 7.5px;
  }

  .node i {
    width: 6px;
    height: 6px;
  }
}

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