:root {
  color-scheme: dark;
  --bg: #0b0c0c;
  --surface: #131513;
  --surface-2: #191b18;
  --line: rgba(225, 180, 100, .2);
  --line-strong: rgba(239, 183, 83, .55);
  --gold: #eab45b;
  --gold-light: #f4d29a;
  --orange: #df6b32;
  --red: #b8412f;
  --green: #7e9a6a;
  --text: #f3ecdf;
  --muted: #978f82;
  --shadow: 0 28px 80px rgba(0, 0, 0, .38);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  touch-action: pan-y;
  overscroll-behavior-x: none;
  background:
    radial-gradient(circle at 65% -10%, rgba(130, 85, 39, .19), transparent 35%),
    linear-gradient(145deg, #0b0c0c, #11110f 45%, #080909);
  color: var(--text);
}
button, input, textarea, select { font: inherit; }
button { color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 20; opacity: .09;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E");
}
.eyebrow { color: var(--gold); font-size: 11px; letter-spacing: .22em; text-transform: uppercase; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(440px, 100%); padding: 48px; border: 1px solid var(--line-strong);
  background: linear-gradient(160deg, rgba(30, 29, 24, .97), rgba(13, 14, 13, .98));
  box-shadow: var(--shadow); position: relative;
}
.login-card::before { content: ""; position: absolute; inset: 10px; border: 1px solid var(--line); pointer-events: none; }
.login-card h1 { font-family: "STKaiti", "KaiTi", serif; font-size: 52px; margin: 18px 0 4px; letter-spacing: .08em; }
.login-card p { color: var(--muted); margin: 0 0 34px; }
.login-card form { display: grid; gap: 18px; position: relative; z-index: 1; }
.login-card small { display: block; margin-top: 24px; color: #6f6b62; line-height: 1.7; }

label { display: grid; gap: 8px; color: #c8bca9; font-size: 13px; }
input, textarea, select {
  width: 100%; border: 1px solid rgba(210, 179, 126, .2); color: var(--text);
  background: rgba(5, 6, 5, .62); border-radius: 3px; padding: 13px 14px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; line-height: 1.7; }
input:focus, textarea:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(234, 180, 91, .08); }
.primary {
  border: 1px solid #e5b86e; background: linear-gradient(180deg, #d9a555, #a86b27);
  color: #17120b; padding: 14px 18px; font-weight: 750; border-radius: 3px;
  box-shadow: 0 10px 26px rgba(170, 101, 29, .18);
}
.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.ghost { border: 1px solid var(--line); background: transparent; padding: 9px 14px; border-radius: 3px; color: var(--muted); }
.error { min-height: 18px; color: #df7765; font-size: 13px; }

.app-shell {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  overflow-x: clip;
}
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: rgba(9, 10, 9, .86);
  backdrop-filter: blur(18px); padding: 28px 18px 20px;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 10px 30px; }
.brand-mark {
  display: grid; place-items: center; width: 43px; height: 43px; border: 1px solid var(--gold);
  color: var(--gold-light); font: 27px "KaiTi", serif; transform: rotate(-3deg);
}
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .12em; }
.brand small { color: var(--muted); margin-top: 5px; font-size: 11px; }
nav { display: grid; gap: 7px; }
.nav-item {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  text-align: left; padding: 13px 14px; border-radius: 3px; transition: .2s;
}
.nav-item span { color: var(--gold); display: inline-block; width: 27px; }
.nav-item:hover, .nav-item.active {
  color: var(--text); border-color: var(--line); background: linear-gradient(90deg, rgba(234, 180, 91, .12), transparent);
}
.sidebar-footer { margin-top: auto; display: grid; gap: 15px; padding: 16px 8px 0; border-top: 1px solid var(--line); }
.system-dot { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.system-dot i, .live-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px var(--green); }

main { width: 100%; min-width: 0; max-width: 100%; padding: 0 42px 70px; }
.topbar { height: 116px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.topbar h2 { margin: 8px 0 0; font: 30px "STKaiti", "KaiTi", serif; letter-spacing: .08em; }
.operator { text-align: right; }
.operator span, .operator b { display: block; }
.operator span { font-size: 13px; }
.operator b { margin-top: 6px; color: var(--gold); font-size: 10px; letter-spacing: .16em; }
.page { display: none; width: 100%; min-width: 0; max-width: 100%; padding-top: 30px; animation: enter .35s ease; }
.page.active { display: block; }
@keyframes enter { from { opacity: 0; transform: translateY(7px); } }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card, .panel {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line); background: linear-gradient(145deg, rgba(25, 27, 24, .9), rgba(14, 15, 14, .95));
  box-shadow: 0 18px 46px rgba(0, 0, 0, .15);
}
.stat-card { padding: 20px; position: relative; overflow: hidden; }
.stat-card::after { content: ""; position: absolute; right: -25px; bottom: -50px; width: 95px; height: 95px; border: 1px solid rgba(234, 180, 91, .08); transform: rotate(45deg); }
.stat-card small, .stat-card span { display: block; color: var(--muted); }
.stat-card strong { display: block; color: var(--gold-light); font-size: 32px; margin: 9px 0 5px; font-weight: 500; }
.stat-card span { font-size: 11px; }
.stat-card.warning strong { color: #dd7960; }
.studio-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, .8fr); gap: 18px; }
.panel { padding: 23px; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.panel-heading > * { min-width: 0; }
.panel-heading small, .local-usage small { color: var(--gold); letter-spacing: .16em; font-size: 10px; }
.panel h3, .section-intro h3 { margin: 6px 0 0; font-size: 19px; font-weight: 600; }
.badge, .live-pill { border: 1px solid var(--line); background: rgba(0,0,0,.2); color: var(--muted); padding: 7px 10px; font-size: 11px; border-radius: 20px; }
.badge.ok { color: #a6bc91; border-color: rgba(126,154,106,.45); }
.badge.bad { color: #df7765; border-color: rgba(184,65,47,.45); }
.creation-panel form { display: grid; gap: 17px; }
.prompt-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -6px; }
.chip { padding: 7px 10px; border: 1px solid var(--line); color: #c5b9a5; background: rgba(0,0,0,.2); border-radius: 20px; font-size: 11px; }
.chip:hover { border-color: var(--gold); color: var(--gold-light); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; align-items: end; }
.toggle { display: flex; align-items: center; gap: 10px; height: 44px; }
.toggle input { display: none; }
.toggle span { width: 38px; height: 20px; background: #36342e; border-radius: 20px; position: relative; transition: .2s; }
.toggle span::after { content:""; position:absolute; width:14px; height:14px; top:3px; left:3px; border-radius:50%; background:#aaa096; transition:.2s; }
.toggle input:checked + span { background: #956329; }
.toggle input:checked + span::after { left: 21px; background: #ffe0aa; }
.generate { display: flex; justify-content: space-between; align-items: center; margin-top: 3px; }
.generate small { opacity: .66; font-weight: 500; }
.form-message { min-height: 18px; color: var(--muted); font-size: 12px; }
.side-stack { display: grid; gap: 18px; align-content: start; }
.icon-button { border: 1px solid var(--line); background: transparent; color: var(--gold); width: 32px; height: 32px; border-radius: 50%; }
.quota-content { min-height: 122px; }
.skeleton { height: 100px; border-radius: 3px; background: linear-gradient(90deg,#191a18,#25251f,#191a18); background-size:200%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.quota-model { padding: 12px 0; border-bottom: 1px solid var(--line); }
.quota-model:last-child { border-bottom: 0; }
.quota-model header { display: flex; justify-content: space-between; font-size: 12px; }
.meter { display:block; width:100%; height:5px; border:0; background:#262622; margin:10px 0 7px; overflow:hidden; appearance:none; }
.meter::-webkit-progress-bar { background:#262622; }
.meter::-webkit-progress-value { background:linear-gradient(90deg,#9a6327,var(--gold)); }
.meter::-moz-progress-bar { background:linear-gradient(90deg,#9a6327,var(--gold)); }
.quota-model footer { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.quota-note { color: #716c63; line-height: 1.6; font-size: 10px; margin: 15px 0 0; }
.usage-row { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding: 14px 0 3px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.usage-row strong, .usage-row i { color: var(--gold-light); font-style: normal; }
.jobs-panel { margin-top: 18px; }
.live-pill { display: flex; gap: 7px; align-items: center; }
.jobs-list { display: grid; }
.job-row { display: grid; grid-template-columns: minmax(0,1.2fr) minmax(0,.8fr) minmax(0,.7fr) auto; gap: 15px; align-items: center; border-top: 1px solid var(--line); padding: 14px 0; font-size: 12px; }
.job-row:first-child { border-top: 0; }
.job-row > *, .job-row strong, .job-row small { min-width: 0; }
.job-row strong { display: block; margin-bottom: 5px; overflow-wrap: anywhere; }
.job-row small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; }
.job-row .job-prompt { white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; line-height: 1.55; }
.job-meta small, .job-state small { white-space: nowrap; }
.status { display: inline-flex; align-items: center; border: 1px solid var(--line); padding: 5px 8px; border-radius: 16px; font-size: 10px; color: var(--muted); }
.status.ready, .status.approved { color: #a6bc91; }
.status.failed, .status.unknown { color: #df7765; }
.status.running, .status.downloading, .status.queued { color: var(--gold-light); }
.empty-state { color: var(--muted); min-height: 90px; display: grid; place-items: center; }
.section-intro { margin: 3px 0 24px; }
.section-intro h3 { font: 26px "STKaiti", "KaiTi", serif; }
.section-intro p { color: var(--muted); font-size: 13px; }
.assets-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.asset-card { min-width: 0; max-width: 100%; border: 1px solid var(--line); background: var(--surface); padding: 20px; }
.asset-card header { display:flex; justify-content:space-between; gap:15px; }
.asset-card header > * { min-width:0; }
.asset-card h4 { margin:0 0 5px; }
.asset-card header small { color:var(--muted); }
.asset-statuses { display:flex; flex-wrap:wrap; justify-content:flex-end; gap:6px; }
.status.r2-uploaded { color:#a6bc91; }
.status.r2-uploading, .status.r2-pending { color:var(--gold-light); }
.status.r2-failed { color:#df7765; }
.asset-card audio { display:block; width:100%; min-width:0; max-width:100%; height:38px; margin:18px 0; }
.asset-card .meta { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.asset-card .asset-title-field { grid-column:1 / -1; }
.asset-card footer { display:flex; gap:8px; justify-content:flex-end; margin-top:15px; }
.secondary { border:1px solid var(--line-strong); color:var(--gold-light); background:rgba(234,180,91,.08); padding:9px 13px; border-radius:3px; }
.secondary:disabled { opacity:.4; cursor:not-allowed; }
.danger { border:1px solid rgba(205,78,57,.55); color:#e58b79; background:rgba(155,42,27,.12); padding:9px 13px; border-radius:3px; margin-right:auto; }
.levels-list { display:grid; gap:16px; }
.level-card { border:1px solid var(--line); background:var(--surface); padding:24px; display:grid; grid-template-columns:1fr 1.3fr auto; gap:20px; align-items:center; }
.level-card h4 { margin:0 0 6px; font-size:18px; }
.level-card p { margin:0; color:var(--muted); font-size:12px; }
.level-card .binding { display:grid; gap:8px; }
.level-card .actions { display:flex; flex-wrap:wrap; gap:8px; }
.table-panel { padding: 5px 22px; }
.audit-row { display:grid; grid-template-columns:160px 170px 150px 1fr; gap:12px; padding:14px 0; border-bottom:1px solid var(--line); font-size:11px; }
.audit-row > *, .audit-row time, .audit-row span { min-width:0; color:var(--muted); overflow-wrap:anywhere; }
.toast { position:fixed; z-index:50; right:24px; bottom:24px; background:#211e18; border:1px solid var(--line-strong); padding:13px 17px; color:var(--gold-light); box-shadow:var(--shadow); opacity:0; transform:translateY(12px); pointer-events:none; transition:.25s; }
.toast.show { opacity:1; transform:none; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 84px minmax(0,1fr); }
  .sidebar { padding-inline:12px; }
  .brand div, .nav-item:not(.active)::after, .nav-item { font-size:0; }
  .brand { padding-inline:8px; }
  .brand-mark { flex:none; }
  .nav-item span { font-size:17px; width:auto; }
  .nav-item { text-align:center; }
  .sidebar-footer .system-dot span, .sidebar-footer .ghost { display:none; }
  main { padding-inline:25px; }
  .stats-grid { grid-template-columns:1fr 1fr; }
  .studio-grid { grid-template-columns:1fr; }
}
@media (max-width: 680px) {
  .app-shell { display:block; }
  .sidebar { position:fixed; z-index:10; top:auto; right:0; bottom:0; left:0; width:auto; max-width:100%; height:66px; flex-direction:row; padding:8px; border-right:0; border-top:1px solid var(--line); }
  .brand, .sidebar-footer { display:none; }
  .sidebar nav { width:100%; grid-template-columns:repeat(4,1fr); display:grid; }
  .nav-item { padding:8px; }
  main { padding:0 15px 90px; }
  .topbar { height:90px; gap:12px; }
  .topbar > * { min-width:0; }
  .topbar h2 { font-size:26px; }
  .operator { flex:none; }
  .stats-grid { grid-template-columns:1fr 1fr; }
  .stat-card { padding:15px; }
  .form-row { grid-template-columns:1fr; }
  .panel { padding:18px; }
  .panel-heading { flex-wrap:wrap; gap:10px; }
  .generate { align-items:flex-start; gap:12px; }
  .generate small { text-align:right; }
  .job-row { grid-template-columns:1fr auto; }
  .job-row > :nth-child(2), .job-row > :nth-child(3) { display:none; }
  .assets-grid { grid-template-columns:1fr; }
  .asset-card header { flex-wrap:wrap; }
  .asset-statuses { width:100%; justify-content:flex-start; }
  .asset-card .meta { grid-template-columns:1fr; }
  .asset-card .asset-title-field { grid-column:auto; }
  .asset-card footer { flex-wrap:wrap; justify-content:flex-start; }
  .danger { margin-right:0; }
  .level-card { grid-template-columns:1fr; }
  .audit-row { grid-template-columns:1fr 1fr; }
  .toast { right:15px; bottom:81px; left:15px; max-width:calc(100% - 30px); }
}
@media (max-width: 380px) {
  .login-shell { padding:14px; }
  .login-card { padding:34px 24px; }
  .login-card h1 { font-size:42px; }
  main { padding-inline:12px; }
  .stats-grid { gap:10px; }
  .stat-card { padding:13px; }
  .stat-card strong { font-size:27px; }
  .panel { padding:15px; }
  .audit-row { grid-template-columns:1fr; }
}
