:root {
  color-scheme: dark;
  --bg: #080908;
  --panel: rgba(12, 13, 12, 0.74);
  --panel-strong: rgba(20, 22, 20, 0.92);
  --text: #f6f0df;
  --muted: #c5bcaa;
  --line: rgba(246, 240, 223, 0.16);
  --accent: #d9b15d;
  --accent-strong: #f4cf72;
  --good: #78d49b;
  --danger: #e17865;
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", "Noto Sans SC", ui-sans-serif,
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  overflow: hidden;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  font: inherit;
  font-size: 14px;
  line-height: 1.18;
  letter-spacing: 0;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

button:hover {
  border-color: rgba(244, 207, 114, 0.7);
  background: rgba(244, 207, 114, 0.16);
}

button:active {
  transform: translateY(1px);
}

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

button:disabled {
  color: rgba(246, 240, 223, 0.46);
  border-color: rgba(246, 240, 223, 0.08);
  background: rgba(255, 255, 255, 0.04);
  cursor: wait;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 420px;
  background: #050605;
}

.mandala-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #050605;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at 50% 38%, rgba(20, 22, 20, 0.86), rgba(5, 6, 5, 0.97));
  backdrop-filter: blur(6px);
}

.loading-overlay[hidden] {
  display: none;
}

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 360px;
}

.loading-logo {
  border-radius: 16px;
  opacity: 0.95;
}

.loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(246, 240, 223, 0.18);
  border-top-color: var(--accent-strong);
  border-radius: 50%;
  animation: mandala-spin 900ms linear infinite;
}

.loading-spinner[hidden] {
  display: none;
}

@keyframes mandala-spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-title {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0;
}

#loading-title-zh {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

#loading-title-en {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.25;
}

.loading-progress-track {
  position: relative;
  width: min(280px, 70vw);
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(246, 240, 223, 0.12);
}

.loading-progress-track[hidden] {
  display: none;
}

.loading-progress-track span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--good), var(--accent-strong));
  transition: width 200ms ease;
}

.loading-percent {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.loading-percent[hidden] {
  display: none;
}

#retry-button {
  margin-top: 4px;
  min-width: 140px;
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation: none;
  }
}

.control-panel {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  left: max(18px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(160px, 0.8fr) auto;
  gap: 14px;
  align-items: center;
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(18px);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 180ms ease;
}

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

.identity img {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 8px;
}

.identity h1,
.identity p {
  margin: 0;
  letter-spacing: 0;
}

.identity h1 {
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.15;
}

.identity p {
  max-width: 40ch;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  position: relative;
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(246, 240, 223, 0.12);
}

.progress-track span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--good), var(--accent-strong));
  transition: width 200ms ease;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

#cache-button {
  border-color: rgba(217, 177, 93, 0.48);
  background: rgba(217, 177, 93, 0.18);
}

.is-ready #cache-progress {
  width: 100%;
}

.is-saving #cache-button {
  color: var(--accent-strong);
}

.is-cinematic-fullscreen .control-panel {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px);
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100svh;
  }

  .control-panel {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 10px;
  }

  .identity p {
    white-space: normal;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  button {
    width: 100%;
    padding: 0 10px;
    font-size: 13px;
  }
}

@media (max-width: 420px) {
  .control-panel {
    right: 10px;
    bottom: 10px;
    left: 10px;
    padding: 10px;
  }

  .actions {
    grid-template-columns: 1fr;
  }
}
