:root {
  color-scheme: light;
  --canvas: #f7f6f3;
  --surface: #fbfbfa;
  --paper: #ffffff;
  --ink: #111111;
  --muted: #787774;
  --line: #eaeaea;
  --line-strong: #d8d8d5;
  --success: #346538;
  --success-soft: #edf3ec;
  --warning: #956400;
  --warning-soft: #fbf3db;
  --danger: #9f2f2d;
  --danger-soft: #fdebec;
  --accent: #ff2442;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  height: 100dvh;
  background: var(--canvas);
}

body {
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
  font-family: "SF Pro Display", "Helvetica Neue", "PingFang SC", sans-serif;
  line-height: 1.6;
}

button,
input {
  font: inherit;
}

button,
a,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
a:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

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

.app-shell {
  width: min(1380px, calc(100% - 48px));
  height: 100dvh;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
}

.topbar {
  min-height: 56px;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  justify-self: start;
  color: var(--ink);
  text-decoration: none;
}

.brand strong {
  font-family: Newsreader, "Instrument Serif", "Songti SC", serif;
  font-size: 23px;
  font-weight: 600;
  line-height: 1;
}

.brand span,
.retention-note {
  color: var(--muted);
  font-size: 12px;
}

.retention-note {
  margin: 0;
  justify-self: center;
  white-space: nowrap;
}

.activation-form,
.activation-state {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
}

.activation-form input {
  width: 176px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
}

.activation-form input::placeholder {
  color: #aaa9a5;
}

.activation-form button,
.activation-state button,
.primary-button,
.secondary-button,
.text-button,
.compact-button {
  min-height: 34px;
  padding: 6px 13px;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.activation-form button,
.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.activation-form button:hover:not(:disabled),
.primary-button:hover:not(:disabled) {
  border-color: #d01e36;
  background: #d01e36;
}

.activation-form button:active:not(:disabled),
.primary-button:active:not(:disabled),
.secondary-button:active:not(:disabled),
.compact-button:active:not(:disabled) {
  transform: scale(0.98);
}

.activation-state {
  color: var(--success);
  font-size: 13px;
}

.activation-valid,
.wallet-summary,
.wallet-summary span {
  display: inline-flex;
  align-items: center;
}

.activation-valid {
  gap: 7px;
  white-space: nowrap;
}

.activation-state i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.wallet-summary {
  gap: 8px;
  padding: 0 8px;
  border-left: 1px solid var(--line-strong);
  border-right: 1px solid var(--line-strong);
  color: var(--muted);
  white-space: nowrap;
}

.wallet-summary span {
  gap: 3px;
}

.wallet-summary strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.activation-state button,
.secondary-button,
.compact-button {
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink);
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}

.text-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}

.activation-state button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.compact-button:hover:not(:disabled) {
  border-color: var(--ink);
}

.text-button:hover:not(:disabled) {
  color: var(--ink);
}

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

.message {
  margin: 0 0 10px;
  padding: 8px 12px;
  border: 1px solid #f2d4d5;
  border-radius: 5px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  flex: 0 0 auto;
}

.account-panel {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) minmax(220px, 1fr);
  gap: 14px;
  align-items: start;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.account-panel > header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-panel > header strong {
  white-space: nowrap;
}

.account-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.package-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.package-button {
  min-height: 52px;
  padding: 7px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.package-button strong,
.package-button span {
  display: block;
}

.package-button span,
.order-row span,
.ledger-row span {
  color: var(--muted);
  font-size: 12px;
}

.package-button:hover:not(:disabled) {
  border-color: var(--accent);
}

.order-history,
.points-ledger {
  display: grid;
  gap: 6px;
}

.order-row,
.ledger-row {
  min-height: 30px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

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

.payment-form-host {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #ffffff;
}

.workbench {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  margin-bottom: 12px;
}

.queue-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
  margin-bottom: 10px;
}

.queue-header > div {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.queue-header span,
.queue-header strong {
  font-size: 12px;
}

.queue-header span {
  color: var(--muted);
}

.compact-button {
  min-height: 30px;
  padding: 4px 8px;
  flex: 0 0 auto;
  font-size: 12px;
}

.queue-list {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  overflow-y: auto;
  align-content: start;
}

.queue-item {
  position: relative;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f0f0ee;
}

.queue-item.is-selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.queue-select {
  width: 100%;
  height: 100%;
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.queue-item > img,
.queue-select > img,
.preview-slot > img,
.preview-slot > video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.queue-status {
  position: absolute;
  top: 5px;
  left: 5px;
  z-index: 2;
  max-width: calc(100% - 10px);
  overflow: hidden;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-item.is-completed .queue-status {
  background: var(--success-soft);
  color: var(--success);
}

.queue-item.is-processing .queue-status,
.queue-item.is-queued .queue-status {
  background: var(--warning-soft);
  color: var(--warning);
}

.queue-item.is-failed .queue-status {
  background: var(--danger-soft);
  color: var(--danger);
}

.queue-item strong {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  overflow: hidden;
  padding: 18px 6px 6px;
  background: rgba(17, 17, 17, 0.7);
  color: #ffffff;
  font-size: 10px;
  line-height: 1.4;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-button {
  position: absolute;
  top: 5px;
  right: 5px;
  z-index: 3;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  background: rgba(17, 17, 17, 0.68);
  color: #ffffff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

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

.queue-empty {
  flex: 0 0 auto;
  margin: 10px 2px 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.stage-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 20px 28px;
  background: var(--paper);
}

.stage-panel.is-dragging {
  background: var(--success-soft);
}

.stage-panel.is-busy {
  cursor: progress;
}

.empty-workspace {
  width: min(100%, 520px);
  min-height: 260px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  padding: 32px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.empty-workspace:hover {
  border-color: var(--ink);
  background: var(--paper);
}

.empty-workspace[aria-disabled="true"] {
  cursor: wait;
  opacity: 0.5;
}

.add-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-size: 24px;
  font-weight: 300;
  line-height: 1;
}

.empty-workspace strong {
  font-size: 15px;
}

.empty-workspace p,
.empty-workspace small {
  margin: 0;
  color: var(--muted);
}

.empty-workspace p {
  font-size: 13px;
}

.empty-workspace small {
  font-size: 11px;
}

.preview-workspace {
  width: 100%;
  max-height: 100%;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0;
}

.preview-slot {
  position: relative;
  width: min(100%, 560px, calc((100dvh - 220px) * 0.75));
  overflow: hidden;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f0f0ee;
  cursor: pointer;
}

.preview-slot > img,
.preview-slot > video {
  position: absolute;
  inset: 0;
}

.preview-slot > video {
  z-index: 1;
  visibility: hidden;
}

.preview-slot.is-playing > video {
  visibility: visible;
}

.preview-hint,
.preview-status {
  position: absolute;
  z-index: 2;
  left: 50%;
  max-width: calc(100% - 24px);
  transform: translateX(-50%);
  border-radius: 4px;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.preview-hint {
  bottom: 12px;
  padding: 6px 10px;
  background: rgba(17, 17, 17, 0.76);
  color: #ffffff;
  white-space: nowrap;
  transition: opacity 140ms ease;
}

.preview-slot.is-playing .preview-hint {
  opacity: 0;
}

.preview-status {
  top: 50%;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
}

.preview-meta,
.item-actions,
.failed-detail {
  width: min(100%, 560px, calc((100dvh - 220px) * 0.75));
}

.preview-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 6px;
  border-bottom: 1px solid var(--line);
}

.preview-meta > div {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.preview-meta strong {
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.5;
}

.preview-meta span {
  color: var(--muted);
  font-size: 12px;
}

.preview-meta > span {
  flex: 0 0 auto;
  white-space: nowrap;
}

.item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
}

.failed-detail {
  margin-top: 8px;
  padding: 8px 12px;
  border: 1px solid #f2d4d5;
  border-radius: 5px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
}

.batch-actions {
  grid-column: 1 / -1;
  min-height: 56px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.batch-actions > div:first-child {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.batch-actions strong {
  overflow-wrap: anywhere;
  font-size: 13px;
}

.batch-actions span {
  color: var(--muted);
  font-size: 11px;
}

.batch-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 960px) {
  body {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
  }

  .app-shell {
    width: min(100% - 32px, 920px);
    min-height: 100dvh;
    height: auto;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    min-height: 50px;
  }

  .retention-note {
    display: none;
  }

  .workbench {
    min-height: 680px;
    flex: 1;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .queue-panel {
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .queue-header {
    margin-bottom: 8px;
  }

  .queue-list {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
    padding-bottom: 2px;
    overscroll-behavior-inline: contain;
  }

  .queue-item {
    flex: 0 0 100px;
  }

  .queue-empty {
    margin: 6px 0 2px;
  }

  .stage-panel {
    min-height: 420px;
    padding: 16px 20px;
  }

  .empty-workspace {
    min-height: 200px;
  }

  .preview-slot,
  .preview-meta,
  .item-actions,
  .failed-detail {
    width: min(100%, 420px);
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: 100%;
    min-height: 100dvh;
    height: auto;
  }

  .topbar {
    min-height: 0;
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }

  .brand {
    width: 100%;
    justify-content: space-between;
  }

  .brand strong {
    font-size: 21px;
  }

  .activation-form,
  .activation-state {
    width: 100%;
    justify-content: flex-end;
  }

  .activation-state {
    flex-wrap: wrap;
  }

  .account-panel {
    grid-template-columns: 1fr;
    padding: 10px 16px;
  }

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

  .activation-form input {
    min-width: 0;
    flex: 1 1 auto;
  }

  .workbench {
    margin-bottom: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    flex: 1;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .queue-panel {
    padding: 8px 10px;
  }

  .queue-list {
    gap: 6px;
  }

  .queue-item {
    flex: 0 0 80px;
  }

  .stage-panel {
    min-height: 0;
    padding: 10px 12px;
  }

  .empty-workspace {
    min-height: 160px;
    padding: 20px 16px;
  }

  .preview-slot,
  .preview-meta,
  .item-actions,
  .failed-detail {
    width: 100%;
  }

  .preview-meta {
    display: grid;
    gap: 4px;
  }

  .preview-meta > span {
    justify-self: start;
  }

  .item-actions {
    flex-wrap: wrap;
  }

  .batch-actions {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
  }

  .batch-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .batch-buttons > :only-child,
  .batch-buttons > .primary-button:last-child {
    grid-column: 1 / -1;
  }

  .batch-buttons > * {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 640px) {
  .package-list {
    grid-template-columns: 1fr;
  }
}

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