:root {
  --ink: #202427;
  --ink-soft: #555b5e;
  --paper: #f4f1e9;
  --paper-bright: #fffdf8;
  --line: #cbc5ba;
  --line-strong: #8d8981;
  --orange: #ff9a3c;
  --orange-deep: #dc671c;
  --green: #4d8c6d;
  --red: #d8574d;
  --shadow: rgba(31, 36, 39, 0.12);
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  --display: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  --body: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  background: var(--paper);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(32, 36, 39, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 36, 39, 0.055) 1px, transparent 1px),
    var(--paper);
  background-size: 48px 48px;
  font-family: var(--body);
  font-size: 16px;
}

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

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

.masthead {
  position: relative;
  display: flex;
  min-height: 118px;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 22px 42px 20px;
  color: #f7f3e9;
  background: var(--ink);
  border-bottom: 7px solid var(--orange);
  overflow: hidden;
}

.masthead::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(40vw, 510px);
  content: "";
  background: var(--orange);
  clip-path: polygon(0 0, 100% 0, 88% 100%, 0 100%);
}

.brand-lockup,
.masthead-meta {
  position: relative;
  z-index: 1;
}

.brand-lockup {
  display: flex;
  min-width: 330px;
  flex-direction: column;
  color: var(--ink);
}

.brand-kicker {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.24em;
}

.brand-title {
  margin-top: 1px;
  font-size: clamp(32px, 3.3vw, 50px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.06em;
}

.masthead-meta {
  display: flex;
  align-items: center;
  gap: 24px;
  color: #d7dbdc;
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 0.04em;
}

.meta-rule {
  width: 110px;
  height: 1px;
  background: #727779;
}

.app-shell {
  display: grid;
  grid-template-columns: 430px minmax(0, 1fr);
  min-height: calc(100vh - 118px);
}

.control-rail {
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
}

.control-section,
.export-section {
  padding: 30px 28px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr);
  align-items: start;
  gap: 18px;
  margin-bottom: 22px;
}

.step-index {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  color: #fff;
  background: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 800;
}

.section-heading h1,
.section-heading h2 {
  margin: 0;
  font-size: 25px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.section-heading p {
  margin: 7px 0 0;
  color: #77736b;
  font-size: 14px;
  line-height: 1.35;
}

.matrix-fields {
  display: grid;
  grid-template-columns: 1fr 28px 1fr;
  align-items: end;
  gap: 8px;
}

.matrix-fields label {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 13px;
}

.matrix-fields select {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper-bright);
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 700;
}

.matrix-times {
  padding-bottom: 12px;
  text-align: center;
  font-family: var(--display);
  font-size: 23px;
}

.matrix-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 14px;
  padding: 12px 14px;
  color: var(--ink);
  background: #ece8de;
  border-left: 5px solid var(--orange);
}

.matrix-summary strong {
  font-family: var(--display);
  font-size: 30px;
  letter-spacing: 0.02em;
}

.matrix-summary span {
  font-family: var(--mono);
  font-size: 13px;
}

.limit-note,
.gesture-note,
.privacy-note {
  margin: 12px 0 0;
  color: #77736b;
  font-size: 12px;
  line-height: 1.6;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 13px;
}

.video-id-input {
  width: 100%;
  min-height: 156px;
  resize: vertical;
  padding: 14px 16px;
  border: 1px solid var(--ink);
  border-radius: 0;
  outline: none;
  color: #f3f0e8;
  background: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.65;
}

.video-id-input:focus {
  box-shadow: 0 0 0 3px rgba(255, 154, 60, 0.38);
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  font-weight: 800;
  text-decoration: none;
  transition: color 120ms ease, background 120ms ease, transform 120ms ease;
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button:focus-visible,
.nudge:focus-visible,
.activate-format:focus-visible,
.order-card:focus-visible,
.clear-foreground:focus-visible {
  outline: 3px solid rgba(255, 154, 60, 0.48);
  outline-offset: 2px;
}

.button-primary {
  width: 100%;
  min-height: 54px;
  margin-top: 12px;
  color: var(--ink);
  background: var(--orange);
  border-width: 2px;
  font-size: 16px;
}

.button-primary:hover:not(:disabled) {
  color: #fff;
  background: var(--ink);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button-quiet {
  padding: 0 13px;
  background: var(--paper-bright);
  font-size: 13px;
}

.button-quiet:hover {
  color: #fff;
  background: var(--ink);
}

.source-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 28px;
  margin-top: 12px;
  color: #6d6b65;
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #a5a19a;
}

.source-status.is-loading .status-dot {
  background: var(--orange);
  animation: pulse 900ms ease-in-out infinite alternate;
}

.source-status.is-success .status-dot {
  background: var(--green);
}

.source-status.is-error {
  color: var(--red);
}

.source-status.is-error .status-dot {
  background: var(--red);
}

.button-download-originals {
  width: 100%;
  min-height: 48px;
  flex-direction: column;
  gap: 1px;
  color: var(--ink);
  background: var(--paper-bright);
  border-color: var(--ink);
}

.button-download-originals:not(:disabled):hover {
  color: #fff;
  background: var(--ink);
}

.button-download-originals span {
  font-size: 14px;
}

.button-download-originals small {
  color: #77736c;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
}

.button-download-originals:not(:disabled):hover small {
  color: #d8d2c8;
}

@keyframes pulse {
  to { transform: scale(1.45); opacity: 0.45; }
}

.local-replace {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px dashed var(--line);
}

.local-replace > div {
  min-width: 0;
}

.local-replace strong,
.local-replace small {
  display: block;
}

.local-replace strong {
  font-size: 14px;
}

.local-replace small {
  margin-top: 4px;
  overflow: hidden;
  color: #77736b;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-grid {
  display: grid;
  grid-template-columns: repeat(var(--columns, 3), minmax(0, 1fr));
  gap: 7px;
}

.order-card {
  position: relative;
  min-width: 0;
  aspect-ratio: 4 / 3;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: #d8d3c8;
  cursor: grab;
}

.order-card:active {
  cursor: grabbing;
}

.order-card.is-active {
  border: 3px solid var(--orange);
}

.order-card.is-dragging {
  opacity: 0.4;
}

.order-card.is-drop-target {
  box-shadow: inset 0 0 0 4px var(--green);
}

.order-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
}

.order-card-placeholder {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: #7e7a72;
  background:
    linear-gradient(135deg, transparent 48%, rgba(32, 36, 39, 0.08) 49%, rgba(32, 36, 39, 0.08) 51%, transparent 52%),
    #ddd8cd;
  font-family: var(--mono);
  font-size: 11px;
}

.order-card-index {
  position: absolute;
  top: 5px;
  left: 5px;
  display: grid;
  min-width: 27px;
  height: 23px;
  padding: 0 5px;
  place-items: center;
  color: var(--ink);
  background: var(--orange);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 900;
  pointer-events: none;
}

.order-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.order-actions .button {
  padding: 0 8px;
}

.active-cell-line,
.range-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.active-cell-line {
  margin-bottom: 22px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--line);
  color: #77736b;
  font-size: 13px;
}

.active-cell-line strong {
  color: var(--ink);
  font-family: var(--mono);
}

.range-field {
  margin-bottom: 9px;
  font-size: 14px;
}

.range-field output {
  font-family: var(--mono);
  font-weight: 800;
}

.range-input {
  width: 100%;
  height: 22px;
  margin: 0;
  accent-color: var(--orange);
}

.nudge-row {
  display: grid;
  grid-template-columns: repeat(4, 48px) minmax(80px, 1fr);
  gap: 8px;
  margin-top: 15px;
}

.nudge {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--paper-bright);
  font-family: var(--mono);
  font-size: 20px;
}

.nudge:hover {
  color: #fff;
  background: var(--ink);
}

.nudge-reset {
  font-family: var(--body);
  font-size: 14px;
  font-weight: 800;
}

.link-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 13px;
  margin-top: 20px;
  padding: 15px;
  background: #ece8de;
  cursor: pointer;
}

.link-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 48px;
  height: 26px;
  background: #aaa69f;
  border: 1px solid var(--ink);
  transition: background 140ms ease;
}

.switch-track span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  transition: transform 140ms ease;
}

.link-control input:checked + .switch-track {
  background: var(--orange);
}

.link-control input:checked + .switch-track span {
  transform: translateX(21px);
}

.link-control input:focus-visible + .switch-track {
  outline: 3px solid rgba(255, 154, 60, 0.48);
  outline-offset: 2px;
}

.link-copy strong,
.link-copy small {
  display: block;
}

.link-copy strong {
  font-size: 14px;
}

.link-copy small {
  margin-top: 3px;
  color: #77736b;
  font-size: 11px;
  line-height: 1.45;
}

.copy-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 9px;
}

.foreground-upload-list {
  display: grid;
  gap: 9px;
}

.foreground-upload {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--paper-bright);
}

.foreground-upload > div:first-child {
  min-width: 0;
}

.foreground-upload strong,
.foreground-upload small {
  display: block;
}

.foreground-upload strong {
  font-size: 13px;
}

.foreground-upload small {
  max-width: 180px;
  margin-top: 4px;
  overflow: hidden;
  color: #77736b;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.foreground-buttons {
  display: flex;
  flex: 0 0 auto;
  gap: 5px;
}

.foreground-buttons .button {
  min-height: 38px;
  padding: 0 10px;
}

.clear-foreground {
  min-height: 38px;
  padding: 0 8px;
  border: 0;
  color: #77736b;
  background: transparent;
  font-size: 12px;
}

.clear-foreground:hover {
  color: var(--red);
}

.same-foreground-upload {
  display: block;
  margin-top: 10px;
  padding: 13px 15px;
  border: 1px dashed var(--ink);
  background: #ece8de;
  cursor: pointer;
}

.same-foreground-upload span,
.same-foreground-upload small {
  display: block;
}

.same-foreground-upload span {
  font-size: 13px;
  font-weight: 800;
}

.same-foreground-upload small {
  margin-top: 4px;
  color: #77736b;
  font-size: 10px;
  line-height: 1.45;
}

.same-foreground-upload:hover {
  color: #fff;
  background: var(--ink);
}

.same-foreground-upload:hover small {
  color: #d6d3cb;
}

.export-section {
  background: rgba(255, 253, 248, 0.97);
}

.button-export {
  width: 100%;
  min-height: 64px;
  flex-direction: column;
  color: var(--ink);
  background: var(--orange);
  border-width: 2px;
}

.button-export:hover:not(:disabled) {
  color: #fff;
  background: var(--ink);
}

.button-export span,
.button-export small {
  display: block;
}

.button-export span {
  font-size: 17px;
}

.button-export small {
  margin-top: 3px;
  font-size: 10px;
  font-weight: 500;
}

#exportHint {
  margin: 9px 0 0;
  color: #77736b;
  font-size: 11px;
  text-align: center;
}

.workspace {
  position: sticky;
  top: 0;
  min-width: 0;
  max-height: 100vh;
  overflow: auto;
  padding: 48px clamp(24px, 4vw, 70px) 34px;
}

.workspace-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 28px;
}

.eyebrow {
  display: block;
  margin-bottom: 7px;
  color: var(--orange-deep);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.25em;
  text-shadow: 1px 1px 0 rgba(255, 154, 60, 0.55);
}

.workspace-heading h2 {
  margin: 0;
  font-size: clamp(29px, 3.5vw, 49px);
  font-weight: 950;
  line-height: 1;
  letter-spacing: -0.055em;
}

.workspace-heading p {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: #6c6a64;
  font-size: 13px;
  white-space: nowrap;
}

.mouse-mark {
  position: relative;
  width: 24px;
  height: 37px;
  border: 1px solid var(--ink);
  border-radius: 12px;
}

.mouse-mark::after {
  position: absolute;
  top: 5px;
  left: 10px;
  width: 2px;
  height: 8px;
  content: "";
  background: var(--orange-deep);
}

.preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 3fr);
  align-items: start;
  gap: 30px;
}

.preview-card {
  min-width: 0;
  border: 1px solid #aaa69e;
  background: var(--paper-bright);
  box-shadow: 0 18px 40px var(--shadow);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.preview-card.is-active {
  border: 3px solid var(--orange-deep);
  box-shadow: 0 22px 50px rgba(31, 36, 39, 0.17);
}

.preview-card-head {
  display: flex;
  min-height: 92px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 24px;
}

.preview-card-head > div {
  display: flex;
  align-items: baseline;
  gap: 18px;
}

.preview-card-head strong {
  font-family: var(--display);
  font-size: clamp(34px, 3.4vw, 52px);
  letter-spacing: 0.01em;
}

.preview-card-head span {
  color: #77736b;
  font-family: var(--mono);
  font-size: 13px;
}

.sync-badge {
  padding: 9px 12px;
  color: var(--ink) !important;
  background: var(--orange);
  font-family: var(--body) !important;
  font-size: 12px !important;
  font-weight: 800;
}

.sync-badge.is-unlinked {
  background: #d9d5cc;
}

.canvas-stage {
  position: relative;
  overflow: hidden;
  background: var(--ink);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.canvas-stage.is-dragging {
  cursor: grabbing;
}

.canvas-stage canvas {
  display: block;
  width: 100%;
  height: auto;
}

.selection-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 33.3333%;
  height: 50%;
  border: 3px solid var(--orange);
  pointer-events: none;
  transition: left 100ms ease, top 100ms ease, width 100ms ease, height 100ms ease;
}

.selection-overlay span {
  position: absolute;
  top: 8px;
  left: 8px;
  display: grid;
  min-width: 38px;
  height: 30px;
  padding: 0 8px;
  place-items: center;
  color: var(--ink);
  background: var(--orange);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 900;
}

.canvas-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #fff;
  background: rgba(32, 36, 39, 0.91);
  pointer-events: none;
  transition: opacity 160ms ease;
}

.canvas-loading.is-hidden {
  opacity: 0;
}

.canvas-loading span {
  width: 54px;
  height: 5px;
  background: var(--orange);
  animation: loading-bar 900ms ease-in-out infinite alternate;
  transform-origin: left;
}

.canvas-loading b {
  font-size: 14px;
}

@keyframes loading-bar {
  from { transform: scaleX(0.32); }
  to { transform: scaleX(1); }
}

.preview-foot {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 20px;
}

.preview-foot span {
  overflow: hidden;
  color: #77736b;
  font-family: var(--mono);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activate-format {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  font-size: 12px;
}

.activate-format:hover {
  color: #fff;
  background: var(--ink);
}
