/* ------------------------------------------------------------------ */
/* Shared foundation: tokens, background, glass, forms, modals, toast  */
/* ------------------------------------------------------------------ */

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

:root {
  --bg: #08080d;
  --text: #f5f2f8;
  --muted: #a7a2b4;
  --faint: #746f83;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.22);
  --glass: rgba(19, 17, 27, 0.58);
  --glass-soft: rgba(255, 255, 255, 0.045);
  --accent: #fb7299;
  --accent-2: #ff9fba;
  --accent-rgb: 251, 114, 153;
  --accent-ink: #1b0710;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  --font: "Noto Sans SC", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei",
    system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

html[data-theme="blue"] {
  --accent: #4da8ff;
  --accent-2: #8fd4ff;
  --accent-rgb: 77, 168, 255;
  --accent-ink: #04101f;
}
html[data-theme="teal"] {
  --accent: #2fd6b3;
  --accent-2: #8af2d8;
  --accent-rgb: 47, 214, 179;
  --accent-ink: #03140f;
}
html[data-theme="violet"] {
  --accent: #a78bfa;
  --accent-2: #cdbcff;
  --accent-rgb: 167, 139, 250;
  --accent-ink: #100823;
}
html[data-theme="amber"] {
  --accent: #ffb347;
  --accent-2: #ffd08a;
  --accent-rgb: 255, 179, 71;
  --accent-ink: #1d1102;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

::selection {
  background: rgba(var(--accent-rgb), 0.35);
}

:focus-visible {
  outline: 2px solid rgba(var(--accent-rgb), 0.9);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ */
/* Backdrop                                                            */
/* ------------------------------------------------------------------ */

.bg {
  position: fixed;
  inset: 0;
  z-index: -3;
  overflow: hidden;
  background:
    radial-gradient(1100px 760px at 88% -12%, rgba(var(--accent-rgb), 0.2), transparent 62%),
    radial-gradient(900px 700px at 4% 108%, rgba(91, 124, 255, 0.17), transparent 60%),
    radial-gradient(700px 500px at 50% 50%, rgba(var(--accent-rgb), 0.05), transparent 70%),
    #08080d;
}

.bg .orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(84px);
  opacity: 0.5;
  will-change: transform;
  animation: orbFloat 22s ease-in-out infinite alternate;
}
.bg .o1 {
  width: 46vw;
  height: 46vw;
  min-width: 320px;
  min-height: 320px;
  left: -10vw;
  top: -12vw;
  background: rgba(var(--accent-rgb), 0.5);
}
.bg .o2 {
  width: 38vw;
  height: 38vw;
  min-width: 280px;
  min-height: 280px;
  right: -8vw;
  top: 16vh;
  background: rgba(96, 104, 255, 0.34);
  animation-delay: -7s;
  animation-duration: 27s;
}
.bg .o3 {
  width: 40vw;
  height: 40vw;
  min-width: 260px;
  min-height: 260px;
  left: 24vw;
  bottom: -20vw;
  background: rgba(255, 92, 158, 0.26);
  animation-delay: -13s;
  animation-duration: 31s;
}

html[data-preset="sakura"] .bg .o1 {
  background: rgba(255, 92, 138, 0.5);
}
html[data-preset="sakura"] .bg .o2 {
  background: rgba(255, 158, 196, 0.32);
}
html[data-preset="sakura"] .bg .o3 {
  background: rgba(187, 92, 255, 0.28);
}

html[data-preset="ocean"] .bg .o1 {
  background: rgba(40, 140, 255, 0.46);
}
html[data-preset="ocean"] .bg .o2 {
  background: rgba(40, 220, 220, 0.3);
}
html[data-preset="ocean"] .bg .o3 {
  background: rgba(80, 100, 255, 0.32);
}

html[data-preset="forest"] .bg .o1 {
  background: rgba(46, 200, 140, 0.42);
}
html[data-preset="forest"] .bg .o2 {
  background: rgba(180, 220, 90, 0.24);
}
html[data-preset="forest"] .bg .o3 {
  background: rgba(40, 160, 210, 0.3);
}

html[data-preset="midnight"] .bg .o1 {
  background: rgba(120, 100, 255, 0.42);
}
html[data-preset="midnight"] .bg .o2 {
  background: rgba(60, 80, 220, 0.34);
}
html[data-preset="midnight"] .bg .o3 {
  background: rgba(200, 80, 255, 0.22);
}

.bg-custom {
  position: fixed;
  inset: 0;
  z-index: -2;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 0.7s ease;
}
body.has-custom .bg-custom {
  opacity: 1;
}
body.has-custom .bg {
  opacity: 0.25;
  transition: opacity 0.7s ease;
}
.bg-custom::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(6, 6, 12, 0.5), rgba(6, 6, 12, 0.72) 70%, rgba(6, 6, 12, 0.9)),
    radial-gradient(900px 600px at 80% 0%, rgba(var(--accent-rgb), 0.18), transparent 65%);
}

.grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
}

@keyframes orbFloat {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(4vw, 5vh, 0) scale(1.08);
  }
  100% {
    transform: translate3d(-3vw, 8vh, 0) scale(0.96);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bg .orb {
    animation: none;
  }
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------------------ */
/* Glass                                                               */
/* ------------------------------------------------------------------ */

.glass {
  position: relative;
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.105), rgba(255, 255, 255, 0.028) 45%, rgba(255, 255, 255, 0.06)),
    var(--glass);
  border: 1px solid var(--line);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -1px 0 rgba(0, 0, 0, 0.28);
  -webkit-backdrop-filter: blur(26px) saturate(150%);
  backdrop-filter: blur(26px) saturate(150%);
}

.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.16), transparent 28%, transparent 72%, rgba(255, 255, 255, 0.07));
  opacity: 0.5;
  mix-blend-mode: screen;
}

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  transition: transform 0.16s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.34);
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0) scale(0.98);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  border: none;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow:
    0 10px 30px rgba(var(--accent-rgb), 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}
.btn.primary:hover {
  box-shadow:
    0 14px 36px rgba(var(--accent-rgb), 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  filter: brightness(1.04);
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
}
.btn.sm {
  height: 36px;
  padding: 0 15px;
  font-size: 13px;
}
.btn.block {
  width: 100%;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  transition: background 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}
.icon-btn:active {
  transform: scale(0.95);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}

.btn-close {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  transition: background 0.18s, color 0.18s;
}
.btn-close:hover {
  background: rgba(255, 255, 255, 0.13);
  color: var(--text);
}

/* ------------------------------------------------------------------ */
/* Fields                                                              */
/* ------------------------------------------------------------------ */

.field {
  display: block;
}
.field > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.16em;
}
.field input,
.field select {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.field input::placeholder {
  color: var(--faint);
}
.field input:focus,
.field select:focus {
  border-color: rgba(var(--accent-rgb), 0.7);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.13);
}
.field select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 22px, calc(100% - 14px) 22px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 38px;
  cursor: pointer;
}
.field select option {
  background: #17141f;
  color: var(--text);
}

/* ------------------------------------------------------------------ */
/* Modals                                                              */
/* ------------------------------------------------------------------ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal[hidden] {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 4, 9, 0.62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: fadeIn 0.22s ease both;
}
.sheet {
  position: relative;
  z-index: 1;
  width: min(100%, 720px);
  max-height: min(88dvh, 980px);
  border-radius: 26px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: sheetIn 0.28s cubic-bezier(0.2, 0.9, 0.2, 1) both;
}
.sheet-body {
  overflow: auto;
  padding: 26px 28px 30px;
}
.sheet-close {
  position: absolute;
  z-index: 3;
  top: 14px;
  right: 14px;
}
.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-right: 46px;
  margin-bottom: 18px;
}
.sheet-head h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.35;
  letter-spacing: 0.01em;
}
.sheet-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
}
@keyframes sheetIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
}

body.modal-open {
  overflow: hidden;
}

/* ------------------------------------------------------------------ */
/* Toast                                                               */
/* ------------------------------------------------------------------ */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  min-width: 180px;
  max-width: min(88vw, 420px);
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(18, 16, 25, 0.9);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  animation: toastIn 0.24s ease both;
}
.toast.err {
  border-color: rgba(255, 100, 120, 0.5);
  color: #ffd3da;
}
.toast.ok {
  border-color: rgba(var(--accent-rgb), 0.55);
}
.toast.out {
  animation: toastOut 0.2s ease both;
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ------------------------------------------------------------------ */
/* Utility                                                             */
/* ------------------------------------------------------------------ */

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

.muted {
  color: var(--muted);
}
.faint {
  color: var(--faint);
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.24);
  background-clip: content-box;
}
