:root {
  --ink: #0e0d0b;
  --ivory: #f4efe6;
  --gold: #e2b657;
  --muted: rgba(244, 239, 230, 0.7);
  color-scheme: dark;
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--ivory);
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
}

button { font: inherit; cursor: pointer; }

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

[hidden] { display: none !important; }

.stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transform-origin: 0 0;
}

video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

video.mirror { transform: scaleX(-1); }

.grid .diag { visibility: hidden; }
body[data-guides="diag"] .grid .thirds,
body[data-guides="diag"] .dots { visibility: hidden; }
body[data-guides="diag"] .grid .diag,
body[data-guides="both"] .grid .diag { visibility: visible; }

.cropbox {
  position: absolute;
  z-index: 2;
  border: 1.5px solid var(--gold);
  box-shadow: 0 0 0 200vmax rgba(8, 7, 6, 0.38);
  pointer-events: none;
}

.cropbox span {
  position: absolute;
  top: 8px;
  left: 8px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.65);
}

.grid {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.grid svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.35));
}

.grid path {
  fill: none;
  stroke: rgba(244, 239, 230, 0.38);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

body[data-state="live"] .grid path { stroke: rgba(244, 239, 230, 0.72); }

body[data-state="gate"] .hud { visibility: hidden; }

.dots i {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(244, 239, 230, 0.8);
  transform: translate(-50%, -50%);
}

.dots i[data-col="0"] { left: 33.3333%; }
.dots i[data-col="1"] { left: 66.6667%; }
.dots i[data-row="0"] { top: 33.3333%; }
.dots i[data-row="1"] { top: 66.6667%; }

.dots i.is-hot {
  background: var(--gold);
  box-shadow: 0 0 0 5px rgba(226, 182, 87, 0.28);
}

.mark {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.mark span {
  position: absolute;
  width: var(--corner, 16px);
  height: var(--corner, 16px);
  border: 1.5px solid rgba(244, 239, 230, 0.92);
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.45));
}

.mark.is-good span { border-color: var(--gold); }
.mark span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.mark span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.mark span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.mark span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }

.hud, .foot { position: absolute; z-index: 3; pointer-events: none; }

.hud {
  top: 0;
  left: 0;
  right: 0;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left));
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
}

.markname {
  margin: 0;
  font-family: "Songti SC", "STSong", "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}

#flip {
  pointer-events: auto;
  appearance: none;
  border: 1px solid rgba(244, 239, 230, 0.38);
  background: rgba(14, 13, 11, 0.4);
  color: var(--ivory);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 40px;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

#flip:disabled { opacity: 0.55; }

.tip {
  width: fit-content;
  max-width: min(92vw, 420px);
  margin: 14px auto 0;
  padding: 10px 16px;
  border-radius: 16px;
  background: rgba(14, 13, 11, 0.62);
  border: 1px solid rgba(244, 239, 230, 0.16);
  text-align: center;
  font-size: 16px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  text-shadow: none;
}

.tip:empty { display: none; }

@supports ((backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px))) {
  .tip {
    background: rgba(14, 13, 11, 0.46);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
  }
}

.tip.is-good {
  color: #f8e7bc;
  border-color: rgba(226, 182, 87, 0.75);
}

.foot {
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 0 calc(16px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.65);
}

.dock {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: calc(28px + env(safe-area-inset-bottom));
  display: grid;
  gap: 8px;
  pointer-events: none;
}

body[data-state="gate"] .dock,
body[data-state="gate"] .sheet { display: none; }

.filters, .actions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 calc(16px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left));
  pointer-events: auto;
  touch-action: pan-x;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar, .actions::-webkit-scrollbar { display: none; }

.filters button, .actions button, .sheet button, .key-field input {
  appearance: none;
  border: 1px solid rgba(244, 239, 230, 0.28);
  background: rgba(14, 13, 11, 0.55);
  color: var(--ivory);
  border-radius: 999px;
  min-height: 36px;
  padding: 6px 12px;
  font-size: 14px;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.filters button[aria-checked="true"],
.actions button[aria-pressed="true"] {
  color: #1a160f;
  background: var(--gold);
  border-color: var(--gold);
}

.sheet {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  pointer-events: none;
}

.sheet-card {
  pointer-events: auto;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px;
  border-radius: 18px;
  background: rgba(18, 16, 13, 0.94);
  border: 1px solid rgba(244, 239, 230, 0.16);
}

.sheet-title, .sheet-copy, .sheet-msg { margin: 0; }
.sheet-title { font-size: 16px; letter-spacing: 0.08em; }
.sheet-copy, .sheet-msg { margin-top: 8px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.sheet-msg:empty { display: none; }

.key-field {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.key-field input {
  width: 100%;
  border-radius: 12px;
  min-height: 44px;
  padding: 8px 12px;
  text-align: left;
}

.sheet-card #ask { margin-top: 12px; }

.gate {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  align-items: end;
  justify-items: start;
  padding: calc(28px + env(safe-area-inset-top)) calc(24px + env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) calc(24px + env(safe-area-inset-left));
  background: linear-gradient(to top, rgba(14, 13, 11, 0.94) 0%, rgba(14, 13, 11, 0.62) 38%, rgba(14, 13, 11, 0.18) 100%);
  overflow: auto;
  pointer-events: auto;
}

.gate-card { width: min(100%, 440px); }

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.28em;
}

h1 {
  margin: 0;
  font-family: "Songti SC", "STSong", "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  font-size: 64px;
  font-weight: 500;
  letter-spacing: 0.14em;
  line-height: 1;
}

.rule {
  display: block;
  width: 48px;
  height: 1px;
  margin: 16px 0 18px;
  background: var(--gold);
}

.lede, .fine, .gate-msg {
  margin: 0;
  max-width: 28em;
}

.lede { font-size: 18px; line-height: 1.5; }

#open {
  appearance: none;
  width: 100%;
  max-width: 320px;
  min-height: 52px;
  margin-top: 22px;
  border: 0;
  border-radius: 999px;
  background: var(--ivory);
  color: #16140f;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

#open:hover { background: #fffaf2; }
#open:active { transform: scale(0.985); }
#open:disabled { opacity: 0.55; }

.gate-msg {
  min-height: 1.4em;
  margin-top: 14px;
  color: #f0d2b4;
  font-size: 14px;
  line-height: 1.5;
}

.fine {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

@media (min-width: 800px) {
  .gate { padding-left: calc(64px + env(safe-area-inset-left)); padding-bottom: 72px; }
  h1 { font-size: 88px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  h1 { font-size: 44px; }
  .gate { align-items: center; }
  .lede { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
