:root {
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #0071e3;
  --accent-hover: #0a84ff;
  --danger: #d70015;
  --glass: rgba(255, 255, 255, 0.55);
  --glass-strong: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.75);
  --line: rgba(60, 60, 67, 0.14);
  --shadow: 0 8px 32px rgba(31, 38, 135, 0.12), 0 1px 0 rgba(255, 255, 255, 0.6) inset;
  --radius: 22px;
  --bg1: #e9edff;
  --bg2: #f7e9f4;
}

/* Dark: follows the system unless the user picked a theme (data-theme on <html>, see theme.js). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --danger: #ff453a;
    --glass: rgba(40, 40, 46, 0.55);
    --glass-strong: rgba(48, 48, 54, 0.72);
    --glass-border: rgba(255, 255, 255, 0.14);
    --line: rgba(255, 255, 255, 0.12);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 1px 0 rgba(255, 255, 255, 0.08) inset;
    --bg1: #101018;
    --bg2: #181420;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --danger: #ff453a;
  --glass: rgba(40, 40, 46, 0.55);
  --glass-strong: rgba(48, 48, 54, 0.72);
  --glass-border: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.12);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 1px 0 rgba(255, 255, 255, 0.08) inset;
  --bg1: #101018;
  --bg2: #181420;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* soft color blobs behind the glass */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: -1; }
.bg i { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.55; }
.bg i:nth-child(1) { width: 46vmax; height: 46vmax; left: -12vmax; top: -14vmax; background: #8fb4ff; }
.bg i:nth-child(2) { width: 38vmax; height: 38vmax; right: -10vmax; top: 18vmax; background: #ffb3d9; }
.bg i:nth-child(3) { width: 34vmax; height: 34vmax; left: 30vmax; bottom: -16vmax; background: #b9f0d8; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bg i { opacity: 0.28; } }
:root[data-theme="dark"] .bg i { opacity: 0.28; }

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(28px) saturate(1.7);
  backdrop-filter: blur(28px) saturate(1.7);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand { font-weight: 800; font-size: 26px; letter-spacing: 0.02em; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 4px 0 0; font-size: 14px; }

/* controls */
input[type="text"], input[type="password"] {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  font: inherit;
  color: var(--text);
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.18); }
input::placeholder { color: var(--muted); }

.btn {
  height: 48px;
  padding: 0 22px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, box-shadow 0.15s;
}
.btn:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1); }
.btn:active { transform: scale(0.98); }
.btn.primary { color: #fff; background: var(--accent); border-color: transparent; }
.btn.primary:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.6; cursor: default; }

.link { background: none; border: 0; padding: 0; font: inherit; color: var(--text); text-decoration: underline; cursor: pointer; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); padding: 40px 36px 36px; display: grid; gap: 16px; }
.login-card .brand { text-align: center; font-size: 22px; }
.login-card h1 { margin: 4px 0 8px; font-size: 22px; line-height: 1.25; font-weight: 700; text-align: center; letter-spacing: -0.01em; }
.field { display: grid; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--muted); padding-left: 4px; }
.login-card .btn { margin-top: 6px; }

/* app layout */
.app { display: grid; grid-template-columns: 280px 1fr; gap: 20px; min-height: 100%; padding: 20px; }
.sidebar { position: sticky; top: 20px; align-self: start; height: calc(100vh - 40px); padding: 28px 22px 22px; display: flex; flex-direction: column; gap: 28px; }
.nav { display: grid; gap: 10px; }
.nav-btn {
  height: 46px; font: inherit; font-weight: 600; color: var(--text); cursor: pointer;
  background: var(--glass-strong); border: 1px solid var(--glass-border); border-radius: 14px;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.nav-btn:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1); }
.nav-btn:active { transform: scale(0.98); }
.nav-btn.active { color: #fff; background: var(--accent); border-color: transparent; }

.stats { margin: 0; display: grid; gap: 16px; }
.stats dt { font-weight: 700; font-size: 14px; }
.stats dd { margin: 2px 0 0; color: var(--muted); }
.sidebar-foot { margin-top: auto; display: grid; gap: 6px; justify-items: center; font-size: 14px; }

.content { min-width: 0; }
.view { display: grid; gap: 16px; align-content: start; }
.create { display: flex; gap: 12px; padding: 14px; }
.create input { flex: 1; }
.create .btn { white-space: nowrap; }

.table-wrap { overflow-x: auto; padding: 6px 10px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 14px 8px; line-height: 1.25; }
td { padding: 12px 8px; border-top: 1px solid var(--line); }
td.mono, td:nth-child(n+4) { white-space: nowrap; }
td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.chip { height: 32px; padding: 0 12px; font: inherit; font-size: 13px; color: var(--text); cursor: pointer; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 10px; }
.chip:hover { background: var(--glass); }
.chip.danger { color: var(--danger); }
.empty { text-align: center; padding: 28px 0; margin: 0; }

.placeholder { padding: 40px; }
.placeholder h2 { margin: 0 0 8px; font-size: 24px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .sidebar { position: static; height: auto; padding: 20px; gap: 18px; }
  .sidebar-foot { margin-top: 0; grid-auto-flow: column; justify-content: space-between; justify-items: start; }
  .create { flex-direction: column; }
  .login-card { padding: 32px 22px 26px; }
}

/* forms: generation */
textarea, select {
  width: 100%; padding: 12px 16px; font: inherit; color: var(--text);
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: 14px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; min-height: 56px; }
select { height: 48px; padding: 0 12px; }
textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.18); }
textarea::placeholder { color: var(--muted); }

.panel { padding: 28px; display: grid; gap: 16px; max-width: 860px; }
.panel h2 { margin: 0; font-size: 24px; letter-spacing: -0.01em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: end; }
.check { display: flex; align-items: center; gap: 10px; height: 48px; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.adv summary { cursor: pointer; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
.adv { display: grid; gap: 14px; }
.range { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.range input { accent-color: var(--accent); }
.range b { color: var(--text); margin-left: 6px; }
.counter { text-align: right; font-size: 13px; margin-top: -8px; }
.status { margin: 0; padding: 12px 16px; border-radius: 14px; background: var(--glass-strong); border: 1px solid var(--line); }
.status::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 10px; vertical-align: -1px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.results { display: grid; gap: 16px; max-width: 860px; }
.result { padding: 20px 24px; display: grid; gap: 12px; }
.result h3 { margin: 0; font-size: 18px; }
.result pre { margin: 0; white-space: pre-wrap; font: inherit; line-height: 1.6; }
.result audio { width: 100%; }
.result .cover { width: 72px; height: 72px; border-radius: 14px; object-fit: cover; }
.result .head { display: flex; gap: 14px; align-items: center; }
.result .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chip.link-chip { display: inline-flex; align-items: center; text-decoration: none; }

@media (max-width: 820px) {
  .grid2 { grid-template-columns: 1fr; }
  .panel { padding: 20px; }
}

/* lyrics structure */
.structure-head { display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; }
.structure-head h3 { margin: 0; font-size: 17px; }
.structure { display: grid; gap: 4px; }
.sec { border: 0; margin: 0; padding: 10px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 130px 1fr; gap: 12px; align-items: center; }
.sec legend { float: left; width: 130px; padding: 0; font-weight: 600; font-size: 14px; }
.sec .pills { grid-column: 2; display: flex; flex-wrap: wrap; gap: 6px; }
.pills input { position: absolute; opacity: 0; pointer-events: none; }
.pills label {
  min-width: 40px; height: 34px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer; user-select: none;
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: 12px;
  transition: background 0.12s, color 0.12s, transform 0.1s;
}
.pills label:hover { background: var(--glass); }
.pills label:active { transform: scale(0.96); }
.pills input:checked + label { color: #fff; background: var(--accent); border-color: transparent; }
.pills input:focus-visible + label { box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.35); }
@media (max-width: 820px) {
  .sec { grid-template-columns: 1fr; gap: 6px; }
  .sec legend { float: none; width: auto; }
  .sec .pills { grid-column: 1; }
}

/* mode switch */
.seg { display: inline-flex; padding: 4px; gap: 4px; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 14px; justify-self: start; }
.seg-btn { height: 38px; padding: 0 18px; font: inherit; font-weight: 600; color: var(--text); background: transparent; border: 0; border-radius: 10px; cursor: pointer; transition: background 0.15s, color 0.15s; }
.seg-btn[aria-pressed="true"] { color: #fff; background: var(--accent); }
#pro-block { display: grid; gap: 14px; }
#add-structure { justify-self: start; }

/* library */
.lead { margin: 0; }
.panel + .results, .view > .results { margin-top: 0; }
.result .head.between { justify-content: space-between; align-items: baseline; }
.result .grow { flex: 1; display: grid; gap: 2px; }
.small { font-size: 13px; }
pre.clamp { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }

.player { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 14px; flex-wrap: wrap; }
.play { width: 38px; height: 38px; flex: none; font-size: 13px; color: #fff; background: var(--accent); border: 0; border-radius: 50%; cursor: pointer; transition: transform 0.1s, background 0.15s; }
.play:hover { background: var(--accent-hover); }
.play:active { transform: scale(0.94); }
.seek { flex: 1; min-width: 120px; accent-color: var(--accent); cursor: pointer; }
.time { font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; }
.chip:disabled { opacity: 0.6; cursor: default; }

tr.own td { color: var(--muted); font-style: italic; }

.player .error { flex-basis: 100%; margin: 0; }

/* usage at the bottom of the menu, notices */
.usage { width: 100%; display: grid; gap: 8px; padding: 12px 14px; margin-bottom: 6px; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 14px; text-align: left; }
.usage div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; }
.usage b { font-variant-numeric: tabular-nums; }
.notice { margin: 0; padding: 12px 16px; font-weight: 600; font-size: 14px; border-radius: 14px; background: rgba(255, 176, 32, 0.16); border: 1px solid rgba(255, 176, 32, 0.45); }

/* small screens: the menu scrolls instead of overflowing; action buttons wrap */
.sidebar { overflow-y: auto; scrollbar-width: thin; }
.row-actions { flex-wrap: wrap; }
td:last-child { white-space: normal; min-width: 150px; }
@media (max-height: 900px) { .sidebar { gap: 18px; padding-top: 22px; } .stats { gap: 10px; } }

/* promo banner on the generation pages */
.promo {
  max-width: 860px; padding: 14px 22px; display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px; letter-spacing: 0.01em; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  background: linear-gradient(110deg, #0071e3 0%, #6d5dfc 55%, #ff6fb1 100%);
  border: 1px solid rgba(255, 255, 255, 0.55); border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0, 113, 227, 0.28), 0 1px 0 rgba(255, 255, 255, 0.5) inset;
}
.promo span { font-size: 18px; }
@media (max-width: 820px) { .promo { font-size: 15px; padding: 12px 16px; } }

/* credit dialog, ledger */
.ledger { padding-top: 18px; }
.ledger-title { margin: 0 12px 4px; font-size: 17px; }
dialog.dlg { width: min(440px, 92vw); padding: 26px; border: 1px solid var(--glass-border); color: var(--text); }
dialog.dlg::backdrop { background: rgba(20, 20, 40, 0.35); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
dialog.dlg form { display: grid; gap: 14px; }
dialog.dlg h3 { margin: 0; font-size: 20px; }
dialog.dlg p { margin: 0; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; }
input[type="number"] { width: 100%; height: 48px; padding: 0 16px; font: inherit; color: var(--text); background: var(--glass-strong); border: 1px solid var(--line); border-radius: 14px; outline: none; }
input[type="number"]:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.18); }

/* admin table: compact actions (2 columns) and wrapping dates */
.row-actions { display: grid; grid-template-columns: repeat(2, max-content); gap: 6px; justify-content: end; }
.row-actions .chip { white-space: nowrap; }
td:last-child { min-width: 210px; }
#users-body td:nth-child(4), #users-body td:nth-child(9) { white-space: normal; min-width: 90px; }

/* admin table: tighter so the action buttons fit on a laptop screen */
#view-users table { font-size: 13px; }
#view-users th, #view-users td { padding-left: 6px; padding-right: 6px; }
.row-actions .chip { height: 30px; padding: 0 9px; font-size: 12px; }
td:last-child { min-width: 190px; }

.seg-btn:disabled { opacity: 0.45; cursor: default; }

/* logo: 3x3 MPC pads */
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { flex: none; border-radius: 22%; box-shadow: 0 6px 18px rgba(80, 70, 220, 0.35); }
.brand-login { flex-direction: column; gap: 12px; justify-content: center; }
.brand-login span { font-size: 24px; letter-spacing: 0.04em; }

/* theme toggle under "Выйти" */
.theme-toggle { display: inline-flex; gap: 4px; padding: 4px; margin-top: 6px; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 999px; }
.theme-toggle button { width: 36px; height: 36px; display: grid; place-items: center; color: var(--muted); background: transparent; border: 0; border-radius: 50%; cursor: pointer; transition: background 0.15s, color 0.15s, transform 0.1s; }
.theme-toggle button:hover { color: var(--text); }
.theme-toggle button:active { transform: scale(0.92); }
.theme-toggle button[aria-pressed="true"] { color: #fff; background: var(--accent); }

/* admin: real token balance of the whole system (from the Kie.ai API) */
#kie-balance { gap: 4px; }
#kie-balance > div { display: grid; gap: 2px; justify-items: start; }
#kie-balance #kie-tokens { font-size: 30px; line-height: 1.1; letter-spacing: -0.01em; }
#kie-balance > div:last-child { margin-top: 2px; }
#kie-balance > div:last-child b { font-size: 14px; font-weight: 600; color: var(--muted); }
