:root {
  --wall: #f2efe9;
  --wall-2: #e4e0d8;
  --board: #17181a;
  --board-2: #0f1012;
  --edge: rgba(255, 255, 255, 0.10);
  --off: rgba(255, 255, 255, 0.085);
  --on: #fff6e6;
  --glow: rgba(255, 232, 190, 0.55);
  --ink: #26262a;
  --soft: #8b8a86;
  --chip: #26262a;
  --chip-ink: #f7f5f1;
  --serif: "Songti SC", "Source Han Serif SC", Georgia, "Times New Roman", serif;
  --sans: "Helvetica Neue", Inter, "PingFang SC", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(125% 95% at 50% 0%,
      color-mix(in srgb, var(--wall) 54%, #ffffff) 0%,
      var(--wall) 40%,
      var(--wall-2) 100%);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3vh 4vw;
  transition: color 460ms ease;
}

/* 底纹再花，控制条文字也要立得住：用主题底色做描边光晕 */
.seg button {
  text-shadow:
    0 0 3px color-mix(in srgb, var(--wall) 95%, transparent),
    0 0 14px color-mix(in srgb, var(--wall) 80%, transparent);
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(18px, 3.2vh, 44px);
  width: 100%;
  max-width: 1080px;
}

.board {
  position: relative;
  flex: none;
  width: min(84vmin, 820px, 88vh);
  aspect-ratio: 11 / 10;
  /* 表盘底纹：暗罩压在图之上，保证暗字和亮字都读得出来 */
  background-color: var(--board);
  background-image:
    linear-gradient(var(--scrim), var(--scrim)),
    linear-gradient(168deg, color-mix(in srgb, #ffffff 9%, transparent) 0%, transparent 46%),
    var(--face, none);
  background-size: auto, auto, cover;
  background-position: center, center, center;
  background-repeat: no-repeat;
  border-radius: 3px;
  box-shadow:
    0 42px 70px -32px rgba(16, 15, 13, 0.55),
    0 12px 24px -14px rgba(16, 15, 13, 0.35),
    inset 0 0 0 1px var(--edge),
    inset 0 0 90px rgba(0, 0, 0, 0.35);
  container-type: size;
  transition: background-color 460ms ease, box-shadow 460ms ease;
}

.grid {
  position: absolute;
  inset: 7.5% 6.5%;
  z-index: 1;
  display: grid;
  gap: 0;
  align-items: center;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4.3cqw;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  line-height: 1;
  color: var(--off);
  transition: color 420ms ease, text-shadow 420ms ease;
}

.cell.on {
  color: var(--on);
  text-shadow:
    0 0 0.28em var(--glow),
    0 0 0.9em rgba(255, 214, 150, 0.35);
}

.board.zh .cell {
  font-family: var(--serif);
  font-size: 4.05cqw;
  letter-spacing: 0.02em;
  text-indent: 0;
  font-weight: 500;
}

/* 四角分钟点 */
.dot {
  position: absolute;
  z-index: 1;
  width: 0.62cqw;
  height: 0.62cqw;
  min-width: 3px;
  min-height: 3px;
  border-radius: 50%;
  background: var(--off);
  transition: background 260ms ease, box-shadow 260ms ease;
}

.dot.on {
  background: var(--on);
  box-shadow: 0 0 0.5em var(--glow);
}

.dot-tl { left: 3.2%; top: 4.6%; }
.dot-tr { right: 3.2%; top: 4.6%; }
.dot-br { right: 3.2%; bottom: 4.6%; }
.dot-bl { left: 3.2%; bottom: 4.6%; }

/* 控制条挂在右侧，脱离布局流：隐藏时表盘不会跟着动。
   居中用 auto margin 而不是 transform —— 一旦有 transform，
   fixed 定位的弹层和遮罩就会被困在面板里，铺不满整屏。 */
.panel {
  position: fixed;
  right: clamp(16px, 2.2vw, 34px);
  top: 0;
  bottom: 0;
  height: fit-content;
  margin-block: auto;
  z-index: 3;
  opacity: 1;
  transition: opacity 560ms ease, transform 560ms ease;
}

/* 桌面：轨道直接铺开；窄屏才收进 .tray-btn 后面的弹层 */
.tray {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.tray-btn {
  display: none;
  transition: opacity 220ms ease;
}

.scrim { display: none; }

/* 鼠标不动 3 秒后整条控制区淡出，只剩表盘 */
body.idle .panel {
  opacity: 0;
  transform: translateX(18px);
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.controls {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  justify-content: center;
}

.seg {
  display: flex;
  flex: none;
  border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  transition: border-color 460ms ease;
}

.seg button {
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.12em;
  white-space: nowrap;
  color: var(--soft);
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 200ms ease, color 200ms ease;
}

.seg button.on {
  background: var(--chip);
  color: var(--chip-ink);
}

.seg button:hover { color: var(--ink); }

/* 主题色卡 */
.themes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 108px;
}
.themes button {
  width: 48px;
  height: 31px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
  outline: 2px solid transparent;
  outline-offset: 3px;
  transition: outline-color 200ms ease, transform 200ms ease;
}

.themes button:hover { transform: translateY(-1px); }

.themes button.on { outline-color: var(--ink); }

/* 窄屏放不下右侧悬浮条：收成一个按钮，语言和主题进弹层 */
@media (max-width: 1060px) {
  .board { width: min(88vmin, 600px, 70vh); }

  .panel {
    left: 0;
    right: 0;
    top: auto;
    bottom: clamp(14px, 3vh, 30px);
    height: auto;
    width: fit-content;
    margin-block: 0;
    margin-inline: auto;
  }

  /* 移动端同样 3 秒淡出，点一下屏幕唤醒。
     第一次点只唤醒、不会误触按钮：浏览器把 click 派发到 pointerdown/up 目标的共同祖先，
     那一刻按钮还是 pointer-events:none，点不到它 */
  body.idle .panel {
    opacity: 0;
    transform: none;
    pointer-events: none;
  }

  /* 弹层开着的时候不吃闲置淡出，否则用户在看色卡、它自己消失了 */
  body.tray-open .panel {
    opacity: 1;
    pointer-events: auto;
  }

  .tray-btn {
    position: relative;
    z-index: 4;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
    background: color-mix(in srgb, var(--wall) 78%, transparent);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-radius: 999px;
    padding: 9px 17px;
    font: inherit;
    font-size: 13px;
    letter-spacing: 0.1em;
    color: var(--ink);
    cursor: pointer;
  }

  .tray {
    position: fixed;
    left: 50%;
    bottom: 0;
    z-index: 3;
    width: min(94vw, 440px);
    transform: translate(-50%, 110%);
    padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
    border-radius: 20px 20px 0 0;
    border-top: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
    background: color-mix(in srgb, var(--wall) 94%, transparent);
    -webkit-backdrop-filter: blur(16px) saturate(1.15);
    backdrop-filter: blur(16px) saturate(1.15);
    box-shadow: 0 -14px 44px rgba(0, 0, 0, 0.30);
    transition: transform 340ms cubic-bezier(0.22, 0.7, 0.3, 1);
  }

  body.tray-open .tray { transform: translate(-50%, 0); }

  /* 弹层盖住按钮，开着的时候就把按钮收掉，关掉靠点遮罩 */
  body.tray-open .tray-btn {
    opacity: 0;
    pointer-events: none;
  }

  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 2;
    background: rgba(0, 0, 0, 0.38);
    opacity: 0;
    pointer-events: none;
    transition: opacity 340ms ease;
  }

  body.tray-open .scrim { opacity: 1; pointer-events: auto; }

  .themes {
    display: grid;
    grid-template-columns: repeat(4, 46px);
    justify-content: center;
    gap: 12px;
    max-width: none;
  }
}

@media (max-width: 560px) {
  .seg button { padding: 6px 13px; }
  .themes { grid-template-columns: repeat(4, 42px); gap: 10px; }
  .themes button { width: 42px; height: 27px; }
}
