:root {
  --gold: #ffe566;
  --gold-dim: #d4af37;
  --gold-glow: rgba(255, 229, 102, 0.5);
  --blue-glow: rgba(56, 160, 255, 0.38);
  --card-bg: rgba(6, 8, 22, 0.88);
  --card-border: rgba(212, 175, 55, 0.55);
  --text-primary: #f8f4ec;
  --text-secondary: #e8dcc8;
  --text-muted: #b8b0a0;
  --font-ui: "Segoe UI", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  --font-display: "STSong", "SimSun", "KaiTi", "楷体", serif;
  --font-mono: "Cascadia Mono", Consolas, "Courier New", monospace;
  --danger: #ff7a5c;
  --success: #6ee7a0;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #030108;
  color: var(--text-primary);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

canvas {
  display: block;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

body::before {
  content: '';
  position: fixed;
  inset: 10px;
  border: 1px solid rgba(218, 165, 32, 0.1);
  pointer-events: none;
  z-index: 5;
  box-shadow: inset 0 0 24px rgba(100, 149, 237, 0.04);
}

#ui-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: none;
}

#ui-content {
  position: relative;
  pointer-events: auto;
  width: min(392px, 100%);
  max-height: min(calc(100dvh - 32px), 500px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 22px 24px 16px;
  text-align: center;
  border-radius: 14px;
  background:
    linear-gradient(160deg, rgba(255, 215, 0, 0.04) 0%, transparent 42%),
    linear-gradient(145deg, rgba(3, 5, 18, 0.94) 0%, rgba(10, 6, 24, 0.96) 100%);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 0 48px var(--blue-glow);
  transition:
    opacity 0.9s cubic-bezier(0.25, 1, 0.5, 1),
    transform 0.9s cubic-bezier(0.25, 1, 0.5, 1),
    filter 0.9s ease,
    box-shadow 0.4s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(184, 134, 11, 0.4) transparent;
  animation: card-enter 0.7s ease-out both;
}

#ui-content.is-unlocked {
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 0 56px rgba(255, 215, 0, 0.12),
    0 0 32px var(--blue-glow);
}

#ui-content.is-unlocked .countdown-box {
  border-color: rgba(93, 202, 138, 0.35);
  background: rgba(93, 202, 138, 0.06);
}

#ui-content.is-unlocked #countdown {
  color: var(--success);
  text-shadow: 0 0 14px rgba(93, 202, 138, 0.45);
}

@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

#ui-content::-webkit-scrollbar {
  width: 4px;
}

#ui-content::-webkit-scrollbar-thumb {
  background: rgba(184, 134, 11, 0.45);
  border-radius: 4px;
}

#ui-content.hidden {
  opacity: 0;
  transform: scale(0.94);
  filter: blur(6px) brightness(0.6);
  pointer-events: none;
}

#ui-content.result-reveal .stock-code,
#ui-content.result-reveal .stock-name {
  animation: pop-in 0.55s ease-out both;
}

#ui-content.result-reveal .ai-reason {
  animation: fade-up 0.6s 0.15s ease-out both;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: var(--gold);
  border-style: solid;
  opacity: 0.7;
  pointer-events: none;
}

.corner-tl { top: 8px; left: 8px; border-width: 2px 0 0 2px; }
.corner-tr { top: 8px; right: 8px; border-width: 2px 2px 0 0; }
.corner-bl { bottom: 8px; left: 8px; border-width: 0 0 2px 2px; }
.corner-br { bottom: 8px; right: 8px; border-width: 0 2px 2px 0; }

.panel-header {
  margin-bottom: 16px;
}

.status-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 2px;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
  border: 1px solid transparent;
  font-family: var(--font-ui);
}

.status-badge.closed {
  color: #ffb088;
  background: rgba(255, 107, 74, 0.12);
  border-color: rgba(255, 107, 74, 0.35);
}

.status-badge.open {
  color: #8ef0b0;
  background: rgba(93, 202, 138, 0.12);
  border-color: rgba(93, 202, 138, 0.4);
  animation: badge-pulse 2.4s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(93, 202, 138, 0.2); }
  50% { box-shadow: 0 0 12px 2px rgba(93, 202, 138, 0.25); }
}

h1 {
  font-size: 1.55rem;
  line-height: 1.25;
  margin: 0 0 2px;
  letter-spacing: 4px;
  font-family: var(--font-display);
  font-weight: 700;
  background: linear-gradient(180deg, #fffef5 0%, var(--gold) 50%, var(--gold-dim) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5)) drop-shadow(0 0 12px var(--gold-glow));
}

.sub-title {
  font-size: 0.88rem;
  color: var(--gold-dim);
  margin: 0;
  letter-spacing: 3px;
  font-family: var(--font-display);
  font-weight: 600;
  opacity: 0.95;
}

.header-divider {
  width: 48px;
  height: 2px;
  margin: 12px auto 0;
  background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
  opacity: 0.8;
}

.schedule-chip {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  margin: 0 0 12px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  line-height: 1.45;
}

#status-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.timer-label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--gold-dim);
  margin: 0 0 8px;
  letter-spacing: 1px;
}

.countdown-box {
  width: 100%;
  max-width: 260px;
  padding: 10px 16px;
  margin-bottom: 4px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 107, 74, 0.22);
  box-shadow: inset 0 0 20px rgba(255, 69, 0, 0.06);
}

#countdown {
  font-size: 1.65rem;
  line-height: 1.2;
  color: var(--danger);
  font-weight: 700;
  letter-spacing: 4px;
  font-family: var(--font-mono);
  text-shadow: 0 0 14px rgba(255, 122, 92, 0.45);
  font-variant-numeric: tabular-nums;
}

#stock-result {
  display: none;
  text-align: left;
}

.stock-info {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px dashed rgba(218, 165, 32, 0.25);
  flex-wrap: wrap;
}

.stock-code {
  font-size: 2.0rem;
  line-height: 1.1;
  color: var(--gold);
  font-weight: 700;
  font-family: var(--font-mono);
  text-shadow: 0 0 20px var(--gold-glow), 0 1px 0 rgba(0, 0, 0, 0.8);
  flex-shrink: 0;
}

.stock-name {
  font-size: 1.1rem;
  color: #fff;
  font-weight: 600;
  font-family: var(--font-ui);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  flex-shrink: 1;
  min-width: 0;
}

.ai-reason {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.75;
  max-height: 132px;
  overflow-y: auto;
  padding: 12px 14px 16px;
  border-radius: 10px;
  text-align: justify;
  font-family: var(--font-ui);
  font-weight: 500;
  background:
    linear-gradient(135deg, rgba(40, 130, 255, 0.1) 0%, rgba(255, 215, 0, 0.04) 100%);
  border: 1px solid rgba(56, 160, 255, 0.22);
  border-left: 3px solid #3d9eff;
  scrollbar-width: thin;
  position: relative;
}

.ai-reason::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 22px;
  background: linear-gradient(to bottom, rgba(6, 8, 22, 0), rgba(6, 8, 22, 0.92));
  border-radius: 0 0 10px 10px;
  pointer-events: none;
}

.ai-reason-label {
  color: var(--gold);
  font-weight: 700;
  font-size: 0.84rem;
  margin-bottom: 8px;
  letter-spacing: 1px;
  font-family: var(--font-display);
}

#predict-btn,
.btn-close,
.btn-again {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 204, 0, 0.75);
  background: linear-gradient(135deg, #0a1628 0%, #8b6914 48%, #0a1628 100%);
  color: #fff;
  padding: 11px 24px;
  font-size: 0.98rem;
  font-family: inherit;
  border-radius: 999px;
  cursor: pointer;
  margin-top: 14px;
  letter-spacing: 3px;
  font-weight: bold;
  width: 100%;
  max-width: 260px;
  box-shadow: 0 4px 20px rgba(30, 144, 255, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.btn-glow {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 38%,
    rgba(255, 255, 255, 0.18) 50%,
    transparent 62%
  );
  transform: translateX(-120%);
  animation: btn-shimmer 3.5s ease-in-out infinite;
}

@keyframes btn-shimmer {
  0%, 70%, 100% { transform: translateX(-120%); }
  85% { transform: translateX(120%); }
}

.btn-close {
  display: block;
  margin-left: auto;
  margin-right: auto;
  max-width: 180px;
  padding: 9px 20px;
  font-size: 0.9rem;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #5a0808 0%, #c43800 100%);
  border-color: rgba(255, 120, 80, 0.5);
}


#predict-btn:hover:not(:disabled),
.btn-close:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(255, 215, 0, 0.28);
  border-color: rgba(255, 255, 255, 0.85);
}

#predict-btn:disabled {
  background: #181818 !important;
  border-color: #3a3a3a;
  color: #555;
  cursor: not-allowed;
  box-shadow: none;
}

#predict-btn:disabled .btn-glow {
  display: none;
}

#disclaimer {
  font-size: 0.72rem;
  font-weight: 500;
  color: #7a7a7a;
  margin-top: 16px;
  line-height: 1.55;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

@media (min-width: 768px) {
  #ui-content {
    width: min(372px, 92vw);
    max-height: min(calc(100dvh - 40px), 440px);
    padding: 20px 26px 14px;
  }

  h1 {
    font-size: 1.45rem;
  }

  #countdown {
    font-size: 1.5rem;
  }

  .stock-code {
    font-size: 1.95rem;
  }

  .ai-reason {
    max-height: 118px;
    font-size: 0.86rem;
  }
}

@media (max-height: 700px) {
  #ui-content {
    max-height: calc(100dvh - 20px);
    padding: 16px 20px 12px;
  }

  h1 { font-size: 1.3rem; }
  .panel-header { margin-bottom: 12px; }
  #countdown { font-size: 1.35rem; }
  .ai-reason { max-height: 96px; }
  #disclaimer { margin-top: 12px; }
}

@media (max-width: 480px) {
  #ui-content {
    padding: 18px 18px 14px;
  }

  .stock-code {
    display: block;
    font-size: 1.75rem;
  }

  .stock-name {
    display: block;
    margin: 6px 0 0;
    font-size: 1.05rem;
  }

  #predict-btn,
  .btn-close {
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #ui-content,
  .status-badge.open,
  .btn-glow,
  #ui-content.result-reveal .stock-code,
  #ui-content.result-reveal .ai-reason,
  .hex-label {
    animation: none;
  }
}

/* ── 六十四卦环 ── */
#hexagram-ring {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  z-index: 9;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.7s ease;
  --hex-r: 40vmin;
  isolation: isolate;
}

#hexagram-ring.is-off {
  opacity: 0;
}

#hexagram-ring.is-ritual .hex-label {
  border-color: #ffdf8a;
  box-shadow:
    0 0 0 1px rgba(255, 215, 120, 0.35),
    0 0 14px rgba(255, 200, 80, 0.45),
    0 2px 10px rgba(0, 0, 0, 0.6);
  transition: box-shadow 0.4s ease, border-color 0.4s ease;
  animation: hex-ritual-glow 2.2s ease-in-out infinite;
}

#hexagram-ring.is-ritual .hex-idx {
  color: #ffe070;
  text-shadow: 0 0 3px rgba(255, 200, 80, 0.6);
}

.hex-seq-legend {
  position: absolute;
  left: 50%;
  bottom: calc(50% + var(--hex-r, 40vmin) + 3px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  white-space: nowrap;
}

.hex-seq-title {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  color: rgba(220, 190, 120, 0.7);
  letter-spacing: 0.15em;
}

.hex-seq-dir {
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 600;
  color: rgba(160, 150, 180, 0.6);
  letter-spacing: 0.06em;
}

.hex-order-pin {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, calc(-1 * var(--hex-r, 40vmin) - 3px));
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 9px solid rgba(230, 190, 80, 0.8);
  filter: drop-shadow(0 0 4px rgba(255, 200, 60, 0.35));
}

.hex-order-pin::after {
  content: '1';
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 700;
  color: rgba(255, 220, 140, 0.85);
}

.hex-track {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--hex-r, 40vmin) * 2);
  height: calc(var(--hex-r, 40vmin) * 2);
  border-radius: 50%;
  border: 1px solid rgba(180, 140, 55, 0.18);
  transform: translate(-50%, -50%);
  box-shadow:
    0 0 16px rgba(180, 130, 40, 0.06),
    inset 0 0 24px rgba(80, 50, 120, 0.05);
}

.hex-spinner {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform;
  backface-visibility: hidden;
}

.hex-ticks {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--hex-r, 40vmin) * 2);
  height: calc(var(--hex-r, 40vmin) * 2);
  transform: translate(-50%, -50%);
  pointer-events: none;
  overflow: visible;
}

.hex-tick-ring {
  fill: none;
  stroke: rgba(180, 140, 60, 0.15);
  stroke-width: 0.6;
}

.hex-tick {
  stroke: rgba(180, 150, 100, 0.32);
  stroke-width: 0.5;
  stroke-linecap: round;
}

.hex-tick--major {
  stroke: rgba(230, 190, 90, 0.55);
  stroke-width: 0.9;
}

.hex-label {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 3px 8px 4px;
  border-radius: 4px;
  background: #080512;
  border: 1px solid rgba(230, 195, 90, 0.72);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.9),
    0 2px 8px rgba(0, 0, 0, 0.65);
  transform:
    rotate(var(--a))
    translateY(calc(-1 * var(--hex-r, 40vmin)))
    rotate(calc(-1 * var(--a)))
    translate(-50%, -50%)
    translateZ(0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  backface-visibility: hidden;
  filter: none;
}

.hex-label--double {
  gap: 2px;
  padding: 1px 4px 2px;
}

.hex-label--oct {
  border-color: rgba(255, 215, 100, 0.78);
  padding: 4px 9px 5px;
}

.hex-idx {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #ffcc44;
  line-height: 1;
  flex-shrink: 0;
  text-shadow: 0 1px 2px #000;
}

.hex-idx::after {
  content: '·';
  margin-left: 3px;
  color: rgba(220, 190, 120, 0.85);
  font-weight: 400;
}

.hex-name {
  font-family: "KaiTi", "STKaiti", "PingFang SC", "STSong", "SimSun", var(--font-display);
  font-weight: 400;
  font-size: clamp(13px, 3.2vmin, 16px);
  line-height: 1.15;
  color: rgba(255, 248, 235, 0.95);
  letter-spacing: 0.08em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
}

.hex-label--oct .hex-name {
  font-size: clamp(14px, 3.4vmin, 17px);
}

.hex-label--double.hex-label--oct .hex-name {
  font-size: clamp(13px, 3.1vmin, 15px);
  letter-spacing: 0.06em;
}

@media (max-width: 768px) {
  #hexagram-ring {
    --hex-r: 36vmin;
  }

  .hex-idx {
    font-size: 10px;
  }

  .hex-label--oct .hex-name {
    font-size: clamp(12px, 3.6vmin, 14px);
  }

  .hex-label--double.hex-label--oct .hex-name {
    font-size: clamp(11px, 3.2vmin, 13px);
  }

  .hex-label {
    padding: 3px 7px 4px;
    gap: 3px;
  }
}
