:root {
  color-scheme: light;
  --paper: #f8f5ee;
  --paper-deep: #f1ece2;
  --surface: rgba(255, 253, 247, 0.74);
  --surface-strong: #fffdf7;
  --surface-muted: #f1eee7;
  --ink: #11100e;
  --ink-soft: #34302a;
  --muted: #756f66;
  --faint: #9d968c;
  --line: #ddd5c9;
  --line-strong: #cfc4b5;
  --focus: #b9ad9f;
  --danger: #a63a2e;
  --success: #62b33f;
  --warning: #b88419;
  --panel-radius: 28px;
  --card-radius: 22px;
  --field-radius: 18px;
  --pill-radius: 999px;
  --control-h: 44px;
  --page-max: 1500px;
  --content-gap: 20px;
  --panel-shadow: 0 20px 60px rgba(35, 29, 22, 0.07);
  --font-sans: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-serif: "Songti SC", "STSong", "SimSun", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  overflow-x: hidden;
  background: var(--paper);
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 255, 255, 0.62), transparent 32rem),
    linear-gradient(180deg, #fbf8f1 0%, var(--paper) 48%, #f6f1e8 100%);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

a {
  color: inherit;
}

.hidden,
[hidden] {
  display: none !important;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  border-radius: var(--pill-radius);
  background: rgba(207, 196, 181, 0.58);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(185, 173, 159, 0.74);
}

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(207, 196, 181, 0.58) transparent;
}

/* Shared controls */
.btn,
a.btn,
.icon-btn,
.captcha-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  height: var(--control-h);
  min-height: var(--control-h);
  border: 1px solid var(--line);
  border-radius: var(--pill-radius);
  background: rgba(255, 253, 247, 0.62);
  color: var(--ink);
  padding: 0 20px;
  font-size: 14px;
  font-weight: 850;
  line-height: 1;
  text-decoration: none;
  box-shadow: none;
  outline: 0;
  transform: none;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.btn:hover,
a.btn:hover,
.icon-btn:hover,
.captcha-box:hover {
  border-color: var(--line-strong);
  background: rgba(255, 253, 247, 0.94);
  color: var(--ink);
  box-shadow: none;
  transform: none;
}

.btn:focus-visible,
a.btn:focus-visible,
.icon-btn:focus-visible,
.captcha-box:focus-visible {
  border-color: var(--focus);
  outline: 2px solid rgba(185, 173, 159, 0.26);
  outline-offset: 2px;
}

.btn-primary,
.btn-dark,
a.btn-dark {
  border-color: #050505;
  background: #050505;
  color: #fff;
}

.btn-primary:hover,
.btn-dark:hover,
a.btn-dark:hover,
.btn-primary:focus-visible,
.btn-dark:focus-visible {
  border-color: #050505;
  background: #050505;
  color: #fff;
}

.btn-soft,
.btn-ghost {
  background: rgba(255, 253, 247, 0.54);
}

.btn-small {
  min-width: 58px;
  height: 38px;
  min-height: 38px;
  padding: 0 16px;
  font-size: 13px;
}

.full-width {
  width: 100%;
}

.icon-btn {
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  font-size: 22px;
}

.field {
  display: grid;
  min-width: 0;
  gap: 9px;
}

.field > span {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 850;
  line-height: 1.25;
}

.field input,
.field textarea,
.modal-panel input,
.modal-panel textarea,
.user-panel input,
.user-panel textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--field-radius);
  background: rgba(255, 253, 247, 0.54);
  color: var(--ink);
  font-size: 15px;
  font-weight: 760;
  box-shadow: none;
  outline: 0;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.field input,
.modal-panel input,
.user-panel input {
  height: var(--control-h);
  padding: 0 17px;
}

.field textarea,
.modal-panel textarea,
.user-panel textarea {
  min-height: 108px;
  padding: 14px 17px;
  line-height: 1.62;
  resize: vertical;
}

.field input:hover,
.field textarea:hover,
.field input:focus,
.field textarea:focus,
.modal-panel input:focus,
.modal-panel textarea:focus,
.user-panel input:focus,
.user-panel textarea:focus {
  border-color: var(--line-strong);
  background: rgba(255, 253, 247, 0.9);
  box-shadow: none;
  outline: 0;
}

.field input::placeholder,
.field textarea::placeholder,
.modal-panel input::placeholder,
.modal-panel textarea::placeholder {
  color: rgba(117, 111, 102, 0.72);
}

.native-select-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.custom-select {
  position: relative;
  width: 100%;
  min-width: 0;
}

.custom-select-trigger {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 26px;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: var(--control-h);
  min-height: var(--control-h);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  font-size: 15px;
  font-weight: 820;
  text-align: left;
  box-shadow: none;
  outline: 0;
  transition: border-color 0.16s ease, color 0.16s ease;
}

.custom-select-trigger:hover,
.custom-select-trigger:focus-visible,
.custom-select.is-open .custom-select-trigger {
  border-color: var(--line-strong);
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  outline: 0;
}

.custom-select-value,
.custom-select-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-arrow {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: var(--pill-radius);
  color: var(--muted);
  transition: transform 0.16s ease;
}

.custom-select-arrow::before {
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  content: "";
  transform: translateY(-2px) rotate(45deg);
}

.custom-select.is-open .custom-select-arrow::before {
  transform: translateY(2px) rotate(225deg);
}

.custom-select-menu {
  position: absolute;
  z-index: 80;
  top: calc(100% + 8px);
  left: 0;
  display: none;
  min-width: 100%;
  max-height: min(360px, 52vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 247, 0.98);
  padding: 8px;
  box-shadow: 0 18px 44px rgba(34, 29, 22, 0.1);
}

.custom-select.is-open .custom-select-menu {
  display: block;
}

.custom-select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  border-radius: 12px;
  color: var(--ink);
  padding: 0 12px;
  font-size: 14px;
  font-weight: 820;
}

.custom-select-option:hover,
.custom-select-option:focus-visible,
.custom-select-option.is-selected {
  background: var(--surface-muted);
  color: var(--ink);
  outline: 0;
}

.custom-select-option.is-selected::after {
  content: "✓";
  font-weight: 900;
}

/* Header */
.app-header {
  position: sticky;
  z-index: 40;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(var(--page-max), calc(100% - 48px));
  min-height: 72px;
  margin: 0 auto;
  padding: 18px 0 10px;
  background: transparent;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.brand-mark img {
  display: block;
  width: 42px;
  height: 42px;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.brand-title {
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.05;
  white-space: nowrap;
}

.mobile-menu-button {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--pill-radius);
  background: rgba(255, 253, 247, 0.62);
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
}

.account-strip {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  gap: 10px;
}

.message-button,
.account-credit-pill,
.user-menu-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--control-h);
  border: 1px solid var(--line);
  border-radius: var(--pill-radius);
  background: rgba(255, 253, 247, 0.62);
  color: var(--ink);
  font-size: 14px;
  font-weight: 850;
  box-shadow: none;
  outline: 0;
}

.message-button {
  position: relative;
  width: var(--control-h);
  padding: 0;
}

.message-icon,
.message-icon svg {
  display: block;
  width: 18px;
  height: 18px;
}

.message-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.message-button i {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  border-radius: var(--pill-radius);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-style: normal;
  line-height: 16px;
  text-align: center;
}

.account-credit-pill {
  padding: 0 18px;
  white-space: nowrap;
}

.user-menu-button {
  gap: 10px;
  padding: 0 14px 0 7px;
}

.mini-avatar,
.avatar {
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: rgba(235, 229, 217, 0.72);
  color: var(--ink);
  font-weight: 900;
}

.mini-avatar {
  width: 30px;
  height: 30px;
  font-size: 14px;
}

.avatar {
  width: 46px;
  height: 46px;
}

.mini-avatar img,
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-panel,
.user-menu {
  position: absolute;
  z-index: 90;
  top: calc(100% + 10px);
  right: 0;
  width: min(380px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 253, 247, 0.96);
  padding: 18px;
  box-shadow: var(--panel-shadow);
}

.message-panel-head,
.modal-head,
.history-head,
.sidebar-head,
.output-toolbar,
.episode-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.message-panel-head {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.message-panel-head strong {
  font-size: 18px;
  font-weight: 900;
}

.message-list {
  display: grid;
  gap: 12px;
  max-height: 330px;
  overflow: auto;
  padding-top: 12px;
}

.message-item {
  display: grid;
  gap: 5px;
  padding: 0 0 12px;
  border-bottom: 1px solid rgba(221, 213, 201, 0.72);
}

.message-item:last-child {
  border-bottom: 0;
}

.message-item strong {
  font-size: 14px;
  font-weight: 900;
}

.message-item p,
.message-item time {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.user-menu {
  display: grid;
  gap: 12px;
}

.user-menu-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

.user-menu-header strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 16px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-header span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-actions {
  display: grid;
  gap: 9px;
}

/* Workspace */
.app-layout {
  width: 100%;
}

.workspace {
  width: min(var(--page-max), calc(100% - 48px));
  margin: 18px auto 56px;
}

.workspace-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.workspace-head h1,
.user-center-head h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(32px, 4vw, 62px);
  font-weight: 900;
  line-height: 1.05;
}

.workspace-head p,
.user-center-head p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.5;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(330px, 430px) minmax(520px, 1fr);
  align-items: stretch;
  gap: var(--content-gap);
  min-height: calc(100vh - 180px);
}

.script-sidebar,
.control-panel,
.output-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--surface);
  box-shadow: var(--panel-shadow);
}

.script-sidebar {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 180px);
  padding: 22px;
}

.sidebar-head {
  flex: 0 0 auto;
  margin-bottom: 18px;
}

.sidebar-head h2,
.form-card h2,
.output-toolbar h2,
.user-panel h2 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
  line-height: 1.2;
}

.script-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.empty-list {
  color: var(--muted);
  font-size: 14px;
  font-weight: 720;
  padding: 16px 2px;
}

.script-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  min-height: 72px;
  border-radius: 18px;
  background: transparent;
  transition: background 0.16s ease;
}

.script-item:hover,
.script-item.active {
  background: var(--surface-muted);
}

.script-open {
  display: grid;
  min-width: 0;
  gap: 6px;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 13px 8px 13px 15px;
  text-align: left;
}

.script-open strong,
.script-open span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.script-open strong {
  font-size: 15px;
  font-weight: 900;
}

.script-open span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.script-delete {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.script-delete:hover {
  background: rgba(166, 58, 46, 0.09);
  color: var(--danger);
}

.mobile-sidebar-actions,
.mobile-drawer-backdrop,
.mobile-setup-toggle {
  display: none;
}

.control-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding: 0;
}

.form-card {
  display: grid;
  gap: 18px;
  padding: 24px 26px;
  border-bottom: 1px solid rgba(221, 213, 201, 0.72);
}

.form-card:last-child {
  border-bottom: 0;
}

.format-section {
  display: grid;
  gap: 12px;
}

.format-section h3 {
  margin: 0;
  color: var(--ink-soft);
  font-size: 16px;
  font-weight: 900;
}

.format-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}

.episode-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.generate-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding-top: 6px;
}

.btn-generate {
  min-width: 0;
}

.btn-generate-secondary {
  min-width: 78px;
}

.output-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 180px);
  overflow: hidden;
}

.output-toolbar {
  flex: 0 0 auto;
  padding: 24px 26px 18px;
  border-bottom: 1px solid var(--line);
}

.output-toolbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.output-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 22px 26px 28px;
}

.loading-state {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 26px 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 247, 0.72);
}

.loading-state strong,
.loading-state span {
  display: block;
}

.loading-state strong {
  font-weight: 900;
}

.loading-state span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(17, 16, 14, 0.14);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.82s linear infinite;
}

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

.episode-card {
  position: relative;
  margin: 0 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  background: rgba(255, 253, 247, 0.46);
  box-shadow: none;
  color: var(--ink);
}

.episode-card:hover,
.episode-card:focus-within {
  border-color: var(--line-strong);
  box-shadow: none;
  transform: none;
}

.episode-card.empty-output {
  display: grid;
  min-height: 260px;
  place-items: center;
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  text-align: center;
}

.episode-card.empty-output strong {
  color: var(--ink);
  font-size: 18px;
}

.episode-card .collapsed-trigger {
  display: none;
}

.episode-card.is-collapsed {
  display: inline-flex;
  width: auto;
  min-width: 104px;
  max-width: 148px;
  margin: 0 8px 10px 0;
  border-radius: var(--pill-radius);
  vertical-align: top;
}

.episode-card.is-collapsed .expanded-content {
  display: none;
}

.episode-card.is-collapsed .collapsed-trigger {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 16px;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0 13px;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
}

.collapsed-trigger span:first-child {
  min-width: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collapsed-icon,
.action-icon {
  display: inline-grid;
  place-items: center;
  line-height: 1;
}

.expanded-content {
  padding: 24px 26px 28px;
}

.episode-card-head {
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.episode-card-head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 900;
}

.episode-card-head span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 740;
}

.message-actions,
.edit-actions,
.confirm-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.message-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 253, 247, 0.5);
  color: var(--ink);
  padding: 0 13px;
  font-size: 13px;
  font-weight: 850;
  box-shadow: none;
}

.message-action:hover {
  border-color: var(--line-strong);
  background: rgba(255, 253, 247, 0.86);
}

.icon-action {
  gap: 6px;
}

.episode-body {
  margin-top: 22px;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 14pt;
  line-height: 1.78;
  white-space: pre-wrap;
}

.episode-body[data-font="song"] {
  font-family: "Songti SC", "SimSun", "STSong", serif;
}

.episode-body[data-font="hei"] {
  font-family: "Microsoft YaHei", "PingFang SC", "SimHei", sans-serif;
}

.episode-body[data-font="kai"] {
  font-family: "Kaiti SC", "KaiTi", serif;
}

.episode-body[data-font="fangsong"] {
  font-family: "FangSong", "STFangsong", serif;
}

.episode-body[data-font="system"] {
  font-family: var(--font-sans);
}

.edit-box {
  width: 100%;
  min-height: 360px;
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 247, 0.72);
  padding: 16px;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.7;
  outline: 0;
  resize: vertical;
}

.edit-box:focus {
  border-color: var(--line-strong);
  box-shadow: none;
}

/* User center */
.user-center {
  width: min(var(--page-max), calc(100% - 48px));
  margin: 18px auto 70px;
}

.user-page {
  display: block;
}

.user-center-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 26px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.user-center-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-center-tabs {
  display: flex;
  gap: 28px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.user-tab {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--faint);
  padding: 0 0 14px;
  font-size: 18px;
  font-weight: 900;
}

.user-tab.active {
  color: var(--ink);
}

.user-tab.active::after {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 3px;
  border-radius: var(--pill-radius);
  background: var(--ink);
  content: "";
}

.user-center-panel {
  display: none;
}

.user-center-panel.active {
  display: block;
}

.user-center-grid,
.history-grid {
  display: grid;
  gap: 20px;
}

.overview-user-grid {
  margin-bottom: 22px;
}

.history-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.user-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--surface);
  padding: 24px 26px;
  box-shadow: var(--panel-shadow);
}

.account-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.account-metrics > div {
  min-height: 86px;
  padding: 18px 20px 0 0;
}

.account-metrics > div + div {
  border-left: 1px solid var(--line);
  padding-left: 20px;
}

.account-metrics span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.account-metrics strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 28px;
  font-weight: 900;
}

.history-head {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.history-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 780;
}

.history-list {
  min-height: 360px;
}

.record-table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 253, 247, 0.44);
}

.record-table-head,
.record-table-row {
  display: grid;
  align-items: center;
  gap: 16px;
}

.record-table-recharge .record-table-head,
.record-table-recharge .record-table-row {
  grid-template-columns: 1.4fr 0.8fr 0.8fr 1fr 1.3fr 0.7fr 0.8fr 0.8fr;
}

.record-table-consume .record-table-head,
.record-table-consume .record-table-row {
  grid-template-columns: 1.25fr 0.75fr 0.8fr 1.4fr 1fr 0.8fr 0.8fr 0.8fr;
}

.record-table-head {
  min-height: 58px;
  background: var(--surface-muted);
  padding: 0 18px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 900;
}

.record-table-body {
  min-height: 240px;
}

.record-table-row {
  min-height: 72px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(221, 213, 201, 0.72);
  color: var(--ink);
  font-size: 14px;
  font-weight: 780;
}

.record-table-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-table-empty {
  display: grid;
  min-height: 240px;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 760;
}

.record-status-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.record-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.record-positive {
  color: var(--ink);
  font-weight: 900;
}

.record-negative {
  color: var(--danger);
  font-weight: 900;
}

.record-table-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-height: 58px;
  padding: 0 18px;
}

.record-page-prev,
.record-page-next {
  width: 30px;
  height: 30px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 30px;
  line-height: 1;
}

.record-page-current {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 10px;
  font-size: 17px;
  font-weight: 900;
}

.profile-large {
  display: flex;
  align-items: center;
  gap: 18px;
}

.avatar-large {
  width: 72px;
  height: 72px;
  font-size: 24px;
}

.avatar-uploader {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
}

.avatar-uploader input {
  display: none;
}

.profile-large h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
}

.profile-large p {
  margin: 5px 0 0;
  color: var(--muted);
}

.account-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 16px;
  align-items: end;
  margin-top: 18px;
}

.account-save-btn {
  white-space: nowrap;
}

/* Modals and notices */
.modal {
  width: min(520px, calc(100vw - 34px));
  max-width: none;
  border: 0;
  background: transparent;
  padding: 0;
}

.modal::backdrop {
  background: rgba(22, 19, 15, 0.18);
  backdrop-filter: blur(8px);
}

.modal-panel {
  display: grid;
  gap: 17px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 253, 247, 0.98);
  padding: 24px;
  box-shadow: var(--panel-shadow);
}

.modal-head h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
}

.form-notice {
  margin: 0;
  border: 1px solid rgba(166, 58, 46, 0.22);
  border-radius: 14px;
  background: rgba(166, 58, 46, 0.07);
  color: var(--danger);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 760;
  line-height: 1.5;
}

.captcha-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.captcha-box {
  min-width: 116px;
  white-space: nowrap;
}

.card-buy-box,
.contact-card {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.card-buy-box p {
  margin: 0;
}

.contact-card {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.contact-card span {
  font-size: 13px;
  font-weight: 850;
}

.contact-card a {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
}

.confirm-panel {
  gap: 18px;
}

.confirm-message {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.toast {
  position: fixed;
  z-index: 200;
  top: 18px;
  left: 50%;
  max-width: min(520px, calc(100vw - 32px));
  border: 1px solid rgba(17, 16, 14, 0.08);
  border-radius: 999px;
  background: rgba(17, 16, 14, 0.92);
  color: #fff;
  padding: 12px 22px;
  font-size: 14px;
  font-weight: 820;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.18);
  transform: translate(-50%, -20px) scale(0.96);
  opacity: 0;
}

.toast-show {
  animation: toastIn 0.22s ease forwards;
}

.toast-hide {
  animation: toastOut 0.22s ease forwards;
}

@keyframes toastIn {
  to {
    transform: translate(-50%, 0) scale(1);
    opacity: 1;
  }
}

@keyframes toastOut {
  to {
    transform: translate(-50%, -16px) scale(0.96);
    opacity: 0;
  }
}

/* Responsive */
@media (max-width: 1180px) {
  .work-grid {
    grid-template-columns: 280px minmax(320px, 390px) minmax(420px, 1fr);
  }

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

  .account-save-btn {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  body {
    font-size: 14px;
  }

  .app-header {
    width: calc(100% - 28px);
    min-height: 64px;
    padding-top: 12px;
  }

  .mobile-menu-button {
    display: grid;
    place-items: center;
  }

  .brand-mark,
  .brand-mark img {
    width: 36px;
    height: 36px;
  }

  .brand-title {
    font-size: 17px;
  }

  .account-strip {
    gap: 7px;
  }

  .account-credit-pill,
  #registerBtn,
  #loginBtn,
  #workspaceBtn {
    display: none !important;
  }

  .message-button,
  .user-menu-button {
    height: 40px;
  }

  .user-menu-button {
    max-width: 142px;
  }

  .user-menu-button span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workspace,
  .user-center {
    width: calc(100% - 24px);
    margin-top: 12px;
  }

  .workspace-head {
    align-items: flex-start;
  }

  .workspace-head h1,
  .user-center-head h1 {
    font-size: 30px;
  }

  .workspace-head #clearScriptBtn {
    display: none;
  }

  .mobile-setup-toggle {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    height: 44px;
    margin: 0 0 12px;
    border: 1px solid var(--line);
    border-radius: var(--pill-radius);
    background: rgba(255, 253, 247, 0.62);
    color: var(--ink);
    padding: 0 18px;
    font-size: 15px;
    font-weight: 900;
  }

  .mobile-setup-toggle::after {
    content: "⌄";
    line-height: 1;
  }

  .work-grid {
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 14px;
  }

  .script-sidebar {
    position: fixed;
    z-index: 70;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(330px, 86vw);
    max-height: none;
    border-radius: 0 28px 28px 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .sidebar-open .script-sidebar {
    transform: translateX(0);
  }

  .mobile-drawer-backdrop {
    position: fixed;
    z-index: 65;
    inset: 0;
    background: rgba(22, 19, 15, 0.16);
    backdrop-filter: blur(5px);
  }

  .sidebar-open .mobile-drawer-backdrop {
    display: block;
  }

  .mobile-sidebar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
  }

  .control-panel,
  .output-panel {
    max-height: none;
    overflow: visible;
  }

  .setup-collapsed .control-panel {
    display: none;
  }

  .form-card,
  .output-toolbar,
  .expanded-content {
    padding: 20px;
  }

  .format-grid,
  .history-grid,
  .account-metrics,
  .account-form-grid {
    grid-template-columns: 1fr;
  }

  .account-metrics > div + div {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
  }

  .generate-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .btn-generate,
  .btn-generate-secondary {
    height: 42px;
    min-height: 42px;
    font-size: 14px;
  }

  .output-scroll {
    max-height: none;
    overflow: visible;
    padding: 18px 20px 22px;
  }

  .episode-card-head {
    display: grid;
  }

  .message-actions {
    justify-content: flex-start;
  }

  .field input,
  .field textarea,
  .custom-select-trigger,
  .modal-panel input,
  .modal-panel textarea {
    font-size: 16px;
  }

  .field > span {
    font-size: 13px;
  }

  .field textarea {
    min-height: 96px;
  }

  .record-table {
    overflow-x: auto;
  }

  .record-table-head,
  .record-table-row {
    min-width: 900px;
  }

  .user-center-head {
    display: grid;
  }

  .user-center-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 560px) {
  .workspace,
  .user-center {
    width: calc(100% - 18px);
  }

  .app-header {
    width: calc(100% - 18px);
  }

  .brand {
    gap: 8px;
  }

  .brand-title {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .message-panel,
  .user-menu {
    right: -4px;
  }

  .script-sidebar,
  .control-panel,
  .output-panel,
  .user-panel,
  .modal-panel {
    border-radius: 22px;
  }

  .script-sidebar {
    border-radius: 0 22px 22px 0;
  }

  .captcha-row {
    grid-template-columns: 1fr;
  }

  .captcha-box {
    width: 100%;
  }

  .episode-body {
    line-height: 1.72;
  }
}
