:root {
  color-scheme: light;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  color: #202724;
  background: #f5f6f4;
  font-synthesis: none;
  --page: #f5f6f4;
  --surface: #fcfdfb;
  --text: #202724;
  --muted: #626d67;
  --line: #dce1dd;
  --line-strong: #bdc8c1;
  --primary: #205c45;
  --primary-hover: #174a37;
  --primary-active: #123d2e;
  --focus: #2b7859;
  --danger: #a23838;
  --danger-hover: #862d2d;
  --error: #a13232;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  background: var(--page);
}

body {
  min-width: 0;
  min-height: 100dvh;
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-size: 16px;
  line-height: 1.65;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button,
a,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button,
.button {
  min-height: 44px;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  transition: background-color 150ms ease-out, border-color 150ms ease-out, color 150ms ease-out;
}

.button.primary {
  background: var(--primary);
  color: #fcfdfb;
}

.button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.button.primary:active:not(:disabled) {
  background: var(--primary-active);
}

.button.secondary {
  border-color: var(--line-strong);
  background: var(--surface);
  color: #36423c;
}

.button.secondary:hover:not(:disabled) {
  border-color: #8da197;
  background: #edf1ee;
}

.button.secondary:active:not(:disabled) {
  background: #e2e8e4;
}

.button.danger {
  border-color: #d8b6b6;
  background: var(--surface);
  color: var(--danger);
}

.button.danger:hover:not(:disabled) {
  border-color: var(--danger-hover);
  background: #fff3f3;
  color: var(--danger-hover);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 10px max(16px, calc((100vw - 760px) / 2));
  border-bottom: 1px solid var(--line);
  background: var(--page);
}

.admin-page .topbar {
  padding-right: max(16px, calc((100vw - 960px) / 2));
  padding-left: max(16px, calc((100vw - 960px) / 2));
}

.brand {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.link-button {
  color: inherit;
}

.console-layout,
.admin-layout {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 36px 20px 56px;
}

.admin-layout {
  max-width: 960px;
  padding-top: 28px;
}

.render-section,
.tasks-section,
.admin-section {
  min-width: 0;
}

.render-section {
  padding-bottom: 36px;
  border-bottom: 1px solid var(--line);
}

.tasks-section {
  padding-top: 32px;
}

.admin-section {
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.admin-section:first-child {
  padding-top: 0;
}

.admin-section:last-child {
  border-bottom: 0;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1,
h2 {
  margin: 0;
  color: var(--text);
  line-height: 1.35;
}

h1 {
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 20px;
  font-weight: 650;
}

.intro {
  margin: 8px 0 28px;
  color: var(--muted);
}

.muted {
  margin: 8px 0 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

form {
  min-width: 0;
  margin: 0;
}

.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 20px;
  color: #38433d;
  font-size: 14px;
  font-weight: 600;
}

.optional {
  color: var(--muted);
  font-weight: 400;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 400;
  transition: border-color 150ms ease-out, background-color 150ms ease-out;
}

input:not([type="checkbox"]):not([type="file"]) {
  min-height: 48px;
  padding: 11px 13px;
}

input[type="file"] {
  min-height: 52px;
  padding: 7px;
  line-height: 1.4;
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  min-height: 36px;
  margin-right: 10px;
  border: 0;
  border-radius: 6px;
  padding: 7px 12px;
  background: #e5ebe7;
  color: #294b3c;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

input[type="file"]:hover::file-selector-button {
  background: #d8e2dc;
}

textarea {
  min-height: 144px;
  padding: 12px 13px;
  line-height: 1.65;
  resize: vertical;
}

input:hover,
textarea:hover {
  border-color: #91a198;
}

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

input::placeholder,
textarea::placeholder {
  color: #737e78;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 16px;
}

.duration-field {
  max-width: 240px;
}

.submit-button {
  width: 100%;
  margin-top: 4px;
  font-size: 16px;
}

.form-feedback {
  min-height: 24px;
  margin: 10px 0 0;
  color: #315f4a;
  font-size: 14px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.form-feedback.compact {
  min-height: 22px;
  margin-top: 8px;
}

.form-feedback.is-error,
.task-error {
  color: var(--error);
}

.section-heading {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.section-heading > div {
  min-width: 0;
}

.section-heading .muted {
  margin-bottom: 0;
}

.tasks,
.keys-list {
  display: grid;
  min-width: 0;
  gap: 16px;
  margin-top: 12px;
}

.empty-state {
  margin: 16px 0;
  padding: 24px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: left;
}

.task-card,
.key-item {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 18px;
}

.task-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 13px;
  font-weight: 650;
}

.status-badge.ready {
  background: #e1efe7;
  color: #205c45;
}

.status-badge.running {
  background: #fff0c9;
  color: #76520b;
}

.status-badge.error {
  background: #f8e4e4;
  color: #923636;
}

.task-time,
.key-created {
  color: var(--muted);
  font-size: 13px;
}

.task-prompt {
  margin: 14px 0 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.task-meta {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.task-error {
  margin: 14px 0 0;
  font-size: 14px;
}

.task-card video {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 560px;
  margin-top: 16px;
  border-radius: 8px;
  background: #202724;
}

.admin-form-grid,
.key-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 0.42fr);
  gap: 0 16px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.check-control {
  display: inline-flex;
  min-height: 44px;
  min-width: 0;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  color: #38433d;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.key-heading {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.key-identity {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
}

.key-mask {
  color: #34463d;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.key-enabled-label {
  flex: 0 0 auto;
  margin: 0;
}

.key-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 16px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.key-stats div {
  min-width: 0;
}

.key-stats dt {
  color: var(--muted);
  font-size: 12px;
}

.key-stats dd {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 20px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.key-result {
  margin-bottom: 0;
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 16px;
  }

  .console-layout,
  .admin-layout {
    padding: 28px 16px 44px;
  }

  .admin-layout {
    padding-top: 20px;
  }

  .upload-grid,
  .admin-form-grid,
  .key-fields {
    grid-template-columns: minmax(0, 1fr);
  }

  .duration-field {
    max-width: none;
  }

  .task-card,
  .key-item {
    padding: 16px;
  }

  .key-stats {
    gap: 8px;
  }

  .key-stats dd {
    font-size: 18px;
  }
}

@media (max-width: 420px) {
  .section-heading {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .section-heading > .button {
    align-self: flex-start;
  }

  .key-heading {
    flex-direction: column;
    gap: 8px;
  }

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

  .key-stats div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
  }

  .key-stats dd {
    margin: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
