:root {
  --bg: #0f1218;
  --card: #171b24;
  --text: #e8eaef;
  --muted: #9aa3b2;
  --accent: #5b8cff;
  --error: #f87171;
  --border: #2a3142;
  font-family: "Arial Unicode MS", "Noto Sans", "PT Sans", "DejaVu Sans", Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

/* [hidden] must win over .primary { display: inline-block } on the same element */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.workspace-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 390px);
  gap: 1.5rem;
  align-items: start;
}

.settings-column {
  min-width: 0;
}

.preview-column {
  position: sticky;
  top: 1.25rem;
  align-self: start;
}

.preview-column .card {
  margin-top: 1.5rem;
}

.header h1 {
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 650;
}

.lead {
  color: var(--muted);
  margin: 0;
  max-width: 52rem;
}

.card {
  margin-top: 1.5rem;
  padding: 1.25rem 1.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.settings-group {
  margin-top: 1.15rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.settings-group:first-of-type {
  margin-top: 0.75rem;
}

.settings-group h3 {
  margin: 0 0 0.85rem;
  font-size: 1rem;
  color: var(--text);
}

input[type="file"] {
  color: var(--muted);
}

input[type="number"],
input[type="text"] {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.checkbox-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
}

.checkbox-option input {
  margin: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.span-2 {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.primary {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #0a0c10;
  font-weight: 600;
  cursor: pointer;
}

.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.secondary {
  display: inline-block;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

.secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
}

.primary.link {
  text-decoration: none;
  margin-top: 0.75rem;
}

.table-wrap {
  overflow: auto;
  max-height: 320px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

th,
td {
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #1e2430;
  color: var(--muted);
  font-weight: 500;
}

.error {
  margin-top: 0.75rem;
  color: var(--error);
  font-size: 0.9rem;
}

.meta {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.quick-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.quick-preview-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.quick-preview-header h2 {
  margin-bottom: 0;
}

.quick-preview-overlay-control {
  margin-top: 0.75rem;
}

.quick-preview-overlay-control select {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.quick-preview-frame {
  position: relative;
  margin-top: 1rem;
  width: min(100%, 390px, calc((100vh - 12rem) * 9 / 16));
  max-width: 390px;
  aspect-ratio: 9 / 16;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: #0f1218;
}

.quick-preview-frame canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.social-safe-overlay,
.preview-drag-handle {
  position: absolute;
}

.social-safe-overlay {
  inset: 0;
  z-index: 3;
  pointer-events: none;
  color: rgba(242, 244, 248, 0.88);
  font-size: 0.62rem;
  font-weight: 700;
}

.safe-zone {
  position: absolute;
  border: 1px solid rgba(248, 113, 113, 0.58);
  background: rgba(248, 113, 113, 0.12);
  backdrop-filter: blur(1px);
}

.safe-zone-top {
  top: 0;
  left: 0;
  right: 0;
  height: var(--safe-top-h, 11%);
}

.safe-zone-bottom {
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--safe-bottom-h, 26%);
}

.safe-zone-right {
  right: var(--safe-right-r, 2%);
  top: var(--safe-right-t, 32%);
  width: var(--safe-right-w, 22%);
  height: var(--safe-right-h, 42%);
  border-radius: 999px;
}

.social-actions {
  position: absolute;
  right: var(--actions-r, 5%);
  top: var(--actions-t, 38%);
  display: grid;
  gap: 0.45rem;
  justify-items: center;
}

.social-actions span {
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 999px;
  background: rgba(15, 18, 24, 0.58);
  border: 1px solid rgba(242, 244, 248, 0.38);
  font-size: 0.52rem;
}

.social-caption {
  position: absolute;
  left: var(--caption-l, 5%);
  right: var(--caption-r, 24%);
  bottom: var(--caption-b, 5%);
  height: var(--caption-h, 12%);
  border-radius: 10px;
  border: 1px solid rgba(242, 244, 248, 0.28);
  background: rgba(15, 18, 24, 0.42);
}

.preview-drag-handle {
  z-index: 4;
  border: 1px dashed rgba(91, 140, 255, 0.72);
  background: transparent;
  cursor: move;
  touch-action: none;
}

.preview-drag-handle[hidden] {
  display: none !important;
}

.preview-drag-handle.is-dragging {
  border-style: solid;
  background: transparent;
}

.preview-drag-title,
.preview-drag-period,
.preview-drag-extra-text {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  padding: 0;
  border-radius: 999px;
  color: rgba(238, 241, 246, 0.72);
  font-size: 0.68rem;
  font-weight: 700;
}

.preview-drag-period {
  color: rgba(242, 244, 248, 0.82);
  background: transparent;
  border-color: rgba(242, 244, 248, 0.58);
}

.preview-drag-extra-text {
  color: rgba(242, 244, 248, 0.78);
  border-color: rgba(167, 139, 250, 0.72);
}

.preview-drag-chart {
  border-radius: 10px;
}

.layer-label {
  display: none;
  white-space: nowrap;
  line-height: 1;
}

.layer-close {
  position: absolute;
  top: -0.55rem;
  right: -0.55rem;
  display: grid;
  place-items: center;
  width: 1.15rem;
  height: 1.15rem;
  border: 1px solid rgba(248, 113, 113, 0.75);
  border-radius: 999px;
  background: rgba(15, 18, 24, 0.88);
  color: #fca5a5;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}

.preview-resize-handle {
  position: absolute;
  z-index: 5;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(242, 244, 248, 0.86);
  background: rgba(91, 140, 255, 0.92);
  touch-action: none;
}

.resize-left {
  left: -0.35rem;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.resize-right {
  right: -0.35rem;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.resize-top {
  top: -0.35rem;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.resize-bottom {
  bottom: -0.35rem;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.resize-nw {
  top: -0.35rem;
  left: -0.35rem;
  cursor: nwse-resize;
}

.resize-ne {
  top: -0.35rem;
  right: -0.35rem;
  cursor: nesw-resize;
}

.resize-sw {
  bottom: -0.35rem;
  left: -0.35rem;
  cursor: nesw-resize;
}

.resize-se {
  bottom: -0.35rem;
  right: -0.35rem;
  cursor: nwse-resize;
}

.status {
  margin: 0;
  color: var(--muted);
}

.status.is-busy {
  color: var(--text);
  animation: status-pulse 2s ease-in-out infinite;
}

@keyframes status-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.72;
  }
}

.job-status-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  min-height: 2rem;
}

.render-activity {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.render-spinner {
  flex-shrink: 0;
  width: 1.35rem;
  height: 1.35rem;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: render-spin 0.75s linear infinite;
}

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

.render-ellipsis {
  display: inline-flex;
  gap: 0.05rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.render-ellipsis > span {
  display: inline-block;
  animation: render-dot 1.1s ease-in-out infinite;
}

.render-ellipsis > span:nth-child(2) {
  animation-delay: 0.15s;
}

.render-ellipsis > span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes render-dot {
  0%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  35% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.option-group {
  margin-bottom: 1.25rem;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
}

.checkbox-label input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.option-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.toggle-group {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.toggle-btn {
  padding: 0.45rem 1rem;
  border: none;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.toggle-btn + .toggle-btn {
  border-left: 1px solid var(--border);
}

.toggle-btn.active {
  background: var(--accent);
  color: #0a0c10;
}

.toggle-btn:hover:not(.active) {
  background: var(--border);
  color: var(--text);
}

.footer {
  margin-top: 2.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 920px) {
  .page {
    max-width: 960px;
  }

  .workspace-layout {
    grid-template-columns: 1fr;
  }

  .preview-column {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .quick-preview-frame {
    width: min(100%, 360px);
  }
}
