/* ═══════════════════════════════════════════════════════════
   宣纸 · 墨色 · 朱砂点睛  ─  棋谱风格
   ═══════════════════════════════════════════════════════════ */

/* ---------- design tokens ---------- */
:root {
  /* 宣纸 rice-paper palette */
  --xuan-bg: #f5ecd7;
  --xuan-light: #faf6eb;
  --xuan-mid: #ede2cc;
  --xuan-dark: #ddd0b4;

  /* 墨色 ink palette */
  --ink-deep: #1a1410;
  --ink-main: #2d2a26;
  --ink-light: #4a453c;
  --ink-muted: #7a7264;
  --ink-faint: #a69e90;

  /* 朱砂 cinnabar accent */
  --zhusha: #c23b22;
  --zhusha-dark: #9b2f1b;
  --zhusha-glow: #e05a40;

  /* layout */
  --radius-sm: 6px;
  --radius-md: 12px;

  /* transitions */
  --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ---------- global reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ---------- @font-face / Google Fonts ---------- */
@import url("https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;600;700;900&family=ZCOOL+KuaiLe&family=Ma+Shan+Zheng&display=swap");

html {
  font-size: 16px;
}

body {
  min-height: 100vh;
  font-family: "Noto Serif SC", "Songti SC", "SimSun", serif;
  color: var(--ink-main);
  background: #fff;
}

/* ---------- page wrapper ---------- */
.page {
  max-width: 660px;
  margin: 0 auto;
  padding: 32px 24px 48px;
  text-align: center;
  position: relative;
}

/* decorative ink-splash at top-left corner */
.page::before {
  content: "";
  position: absolute;
  top: -18px;
  left: -12px;
  width: 180px;
  height: 180px;
  background: radial-gradient(
    ellipse at 30% 30%,
    rgba(26, 20, 16, 0.12) 0%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

/* ---------- board column ---------- */
.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 1;
}

/* ---------- title ---------- */
h1 {
  font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 6px;
  color: var(--ink-deep);
  margin: 0 0 4px;
  position: relative;
  text-align: center;
  width: 100%;
}

/* 朱砂 seal stamp after title */
h1::after {
  content: "棋";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-left: 10px;
  font-family: "Noto Serif SC", serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--xuan-light);
  background: var(--zhusha);
  border-radius: 3px;
  vertical-align: middle;
  box-shadow: 1px 1px 3px rgba(194, 59, 34, 0.35);
  transform: rotate(-3deg);
  letter-spacing: 0;
}

/* ---------- fen / turn / step ---------- */
.fen,
.turn {
  margin: 0;
  word-break: break-all;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-light);
}

.fen {
  font-family: "Courier New", monospace;
  font-size: 11px;
  color: var(--ink-muted);
  opacity: 0.8;
}

/* ---------- status bar (turn + progress) ---------- */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 16px auto 32px;
  visibility: visible;
  opacity: 1;
  transition: opacity 0.6s ease;
}

/* hide (but keep space) during intro setup animation */
body[data-setup] .status-bar,
body[data-setup] h1,
body[data-setup] .timer-display {
  visibility: hidden;
  opacity: 0;
}

/* ---------- timer display ---------- */
.timer-display {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: -18px auto 20px; /* pull up closer to the progress bar */
  visibility: visible;
  opacity: 1;
  transition: opacity 0.6s ease;
}

.timer-digits {
  font-family: "Courier New", "SF Mono", monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--ink-faint);
  padding: 3px 10px;
  border: 1px solid rgba(166, 158, 144, 0.25);
  border-radius: 20px;
  background: rgba(245, 236, 215, 0.4);
  transition: color 0.4s ease;
}

/* live: highlight digits while game is running */
.timer-digits.running {
  color: var(--ink-muted);
}

/* stopped at game end */
.timer-digits.stopped {
  color: var(--ink-faint);
  opacity: 0.6;
}

.step {
  font-family: "Noto Serif SC", serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-muted);
  letter-spacing: 1px;
  width: 200px; /* narrowed slightly */
  height: 4px;
  background: rgba(166, 158, 144, 0.2);
  border-radius: 2px;
  position: relative;
  line-height: 0;
  margin: 0; /* reset margin */
}

/* the cinnabar progress bar fill */
#stepLabel::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: calc(var(--progress, 0) * 100%);
  min-width: 5px;
  background: var(--zhusha);
  border-radius: 2px;
  transition:
    width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
    background 0.4s ease,
    box-shadow 0.4s ease;
  box-shadow: 0 0 8px rgba(194, 59, 34, 0.3);
}

/* black's turn: swap to ink */
#stepLabel[data-turn="b"]::after {
  background: var(--ink-deep);
  box-shadow: 0 0 8px rgba(26, 20, 16, 0.3);
}

/* ---------- turn coin flip ---------- */
.turn-marker-wrapper {
  perspective: 1000px;
}

.coin {
  width: 32px; /* shrunken to fit status bar */
  height: 32px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: default;
}

.coin-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  backface-visibility: hidden;
  background: #fff;
  border: 1px solid #ddd;
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.1),
    inset 0 0 4px rgba(0, 0, 0, 0.05);
}

.coin-face img {
  width: 75%;
  height: 75%;
  object-fit: contain;
}

.coin-front {
  /* Red side */
  z-index: 2;
  transform: rotateY(0deg);
}

.coin-back {
  /* Black side */
  transform: rotateY(180deg);
}

/* Flip animation based on state.turn */
[data-turn="b"] .coin {
  transform: rotateY(180deg);
}
[data-turn="w"] .coin {
  transform: rotateY(0deg);
}

/* ---------- board shell ---------- */
.board-shell {
  width: 100%;
  max-width: 560px;
  margin: 8px auto 0;
  position: relative;
}

/* outer decorative frame — like a 棋谱 book border */
.board-frame {
  padding: 14px;
  border: 2px solid var(--ink-faint);
  border-radius: var(--radius-md);
  position: relative;
  background: var(--xuan-mid);
  box-shadow:
    inset 0 0 20px rgba(26, 20, 16, 0.05),
    0 6px 24px rgba(26, 20, 16, 0.12);
}

/* corner ornaments using pseudo-elements on the frame */
.board-frame::before,
.board-frame::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: var(--zhusha);
  border-style: solid;
  opacity: 0.55;
}
.board-frame::before {
  top: 4px;
  left: 4px;
  border-width: 2px 0 0 2px;
}
.board-frame::after {
  bottom: 4px;
  right: 4px;
  border-width: 0 2px 2px 0;
}

.board-wrap {
  width: 100%;
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  /* Fine-tune center alignment */
  --center-offset-x: 0px;
  --center-offset-y: 0px;
}

.board-img {
  display: block;
  width: 100%;
  height: auto;
  /* slight sepia to match rice-paper feel */
  filter: sepia(0.12) contrast(1.02);
}

.turn-marker {
  position: absolute;
  right: -28px;
  top: 10px;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.pieces-layer,
.hints-layer,
.hits-layer {
  position: absolute;
  inset: 0;
}

.piece-img {
  position: absolute;
  transform: translate(-50%, -50%);
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  filter: drop-shadow(1px 1px 2px rgba(26, 20, 16, 0.18));
  transition: transform 0.15s var(--ease-out);
}

.hint-img {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.hit {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 0;
  background: transparent;
  cursor: pointer;
}

/* ---------- modal ---------- */
.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 20, 16, 0.6);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(460px, calc(100vw - 48px));
  transform: translate(-50%, -50%);
  background: var(--xuan-light);
  border: 2px solid var(--xuan-dark);
  border-radius: var(--radius-md);
  padding: 24px 24px 20px;
  box-shadow: 0 20px 60px rgba(26, 20, 16, 0.32);
  text-align: left;
  position: relative;
}

/* top cinnabar accent bar on modal */
.modal-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--zhusha),
    var(--zhusha-glow),
    var(--zhusha)
  );
  border-radius: 0 0 2px 2px;
  transition: background 0.4s ease;
}

/* failure: swap to ink black */
.modal-card[data-outcome="lose"]::before {
  background: linear-gradient(
    90deg,
    var(--ink-deep),
    var(--ink-light),
    var(--ink-deep)
  );
}

.modal-title {
  font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink-deep);
  margin: 4px 0 12px;
  letter-spacing: 3px;
}

.modal-msg {
  margin: 0 0 20px;
  line-height: 1.6;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink-deep);
  letter-spacing: 1px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn {
  border: 1px solid var(--ink-faint);
  background: var(--ink-deep);
  color: var(--xuan-light);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: "Noto Serif SC", serif;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 2px;
  transition: all 0.2s var(--ease-out);
}

.btn:hover {
  background: var(--zhusha-dark);
  border-color: var(--zhusha);
  color: #fff;
}

.btn:active {
  transform: translateY(1px);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-main);
}
.btn-ghost:hover {
  background: var(--xuan-mid);
  color: var(--ink-deep);
  border-color: var(--ink-faint);
}

/* ---------- paper-grain SVG overlay ---------- */
.paper-grain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* ---------- ink-wash atmosphere spots ---------- */
.ink-wash-spot {
  position: fixed;
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    var(--ink-deep) 0%,
    rgba(26, 20, 16, 0.3) 30%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
  filter: blur(30px);
}

/* ---------- responsive ---------- */
@media (max-width: 800px) {
  .page {
    padding: 20px 14px 36px;
  }
  .board-shell {
    max-width: 100%;
  }
  h1 {
    font-size: 24px;
    letter-spacing: 4px;
  }
  .step {
    font-size: 18px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 20px;
  }
}

/* ---------- prefers-reduced-motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0s !important;
    transition-duration: 0s !important;
  }
}
