:root {
  --bg-page: #fbfbfd;
  --bg-card: #ffffff;
  --bg-surface: #f5f5f7;
  --bg-surface-active: #ebebed;
  
  --border-line: rgba(0, 0, 0, 0.07);
  --border-subtle: rgba(0, 0, 0, 0.04);
  --border-focus: #0071e3;
  
  --text-main: #1d1d1f;
  --text-dim: #86868b;
  --text-tertiary: #a1a1a6;
  
  --apple-blue: #0071e3;
  --apple-green: #34c759;
  
  --radius-card: 20px;
  --radius-element: 12px;
  --radius-pill: 9999px;
  
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-menu: 0 14px 40px rgba(0, 0, 0, 0.12), 0 3px 8px rgba(0, 0, 0, 0.04);
  --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  height: 52px;
  border-bottom: 1px solid var(--border-line);
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  position: sticky;
  top: 0;
  z-index: 90;
}

.header-inner {
  max-width: 1400px;
  height: 100%;
  margin: 0 auto;
  padding: 0 1.75rem;
  display: flex;
  align-items: center;
}

.brand-group {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
}

.brand-title {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.025em;
  color: var(--text-main);
}

.brand-divider {
  color: var(--text-tertiary);
  font-size: 0.9rem;
  font-weight: 300;
}

.brand-subtitle {
  color: var(--text-dim);
  font-size: 0.84rem;
  font-weight: 400;
  letter-spacing: -0.01em;
}

/* Main Workspace */
main {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 2.25rem 1.75rem;
}

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 980px) {
  .split-grid {
    grid-template-columns: 1fr;
    gap: 2.5rem;
  }
}

/* Apple Card Container */
.apple-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-card);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-card);
}

.card-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.card-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-main);
}

.card-desc {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

/* Custom Apple Popover Dropdown */
.apple-dropdown {
  position: relative;
  user-select: none;
}

.dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 32px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-pill);
  padding: 0 0.85rem;
  cursor: pointer;
  transition: all 0.2s var(--ease-spring);
  outline: none;
}

.dropdown-trigger:hover {
  background-color: #ededf0;
  border-color: rgba(0, 0, 0, 0.12);
}

.dropdown-trigger.open {
  background-color: #ffffff;
  border-color: var(--apple-blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.trigger-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

.trigger-value {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
}

.chevron {
  color: var(--text-dim);
  transition: transform 0.2s var(--ease-spring);
}

.dropdown-trigger.open .chevron {
  transform: rotate(180deg);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 210px;
  background-color: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 14px;
  padding: 5px;
  box-shadow: var(--shadow-menu);
  z-index: 200;
  display: none;
  flex-direction: column;
  gap: 2px;
  animation: popoverFadeIn 0.18s var(--ease-spring);
}

@keyframes popoverFadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dropdown-menu.open {
  display: flex;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.82rem;
  color: var(--text-main);
}

.menu-item:hover:not(.disabled) {
  background-color: var(--bg-surface);
}

.menu-item.active {
  font-weight: 600;
}

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

.item-text {
  flex: 1;
}

.item-badge {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-right: 0.4rem;
}

.item-badge.soon {
  background-color: rgba(0, 0, 0, 0.05);
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-pill);
}

.checkmark {
  font-size: 0.85rem;
  color: var(--apple-blue);
  visibility: hidden;
}

.menu-item.active .checkmark {
  visibility: visible;
}

/* Preview Stage Viewport (Aspect Fit, Shows Full Original Image) */
.preview-stage {
  width: 100%;
  height: 380px;
  background-color: #f5f5f7;
  border-radius: var(--radius-element);
  border: 1px solid var(--border-line);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-stage canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 4px;
}

.resolution-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  color: var(--text-main);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
  pointer-events: none;
}

.crt-scanline {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 2px;
  background: var(--apple-blue);
  box-shadow: 0 0 10px var(--apple-blue);
  pointer-events: none;
  display: none;
}

/* Controls Stack */
.controls-stack {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.input-actions-row {
  display: flex;
  gap: 0.75rem;
}

.apple-input {
  flex: 1;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-element);
  padding: 0.65rem 0.95rem;
  font-size: 0.88rem;
  color: var(--text-main);
  outline: none;
  transition: all 0.2s ease;
}

.apple-input:focus {
  background-color: #ffffff;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

.apple-input::placeholder {
  color: var(--text-tertiary);
}

/* Apple Buttons */
.apple-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.68rem 1.25rem;
  border-radius: var(--radius-element);
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--ease-spring);
  text-decoration: none;
  white-space: nowrap;
}

/* High-contrast Apple Black Button */
.apple-btn-primary {
  background-color: #1d1d1f;
  color: #ffffff;
}

.apple-btn-primary:hover {
  background-color: #000000;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.apple-btn-primary:active {
  transform: translateY(0);
}

.apple-btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.apple-btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-line);
}

.apple-btn-secondary:hover {
  background-color: #ededf0;
  border-color: rgba(0, 0, 0, 0.15);
}

.apple-btn-secondary:active {
  background-color: #e4e4e7;
}

/* Audio Panel */
.audio-panel {
  margin-top: 1.25rem;
  padding: 1.2rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-element);
  display: none;
}

.audio-panel-header {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
  display: flex;
  justify-content: space-between;
}

.audio-tag {
  color: var(--apple-blue);
}

audio {
  width: 100%;
  margin-bottom: 0.75rem;
  outline: none;
}

.audio-action-row {
  display: flex;
  gap: 0.75rem;
}

/* Dropzone (Right Decode Card) */
.apple-dropzone {
  width: 100%;
  border: 2px dashed #d2d2d7;
  border-radius: var(--radius-element);
  padding: 2.25rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background-color: var(--bg-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.apple-dropzone:hover, .apple-dropzone.dragover {
  border-color: var(--apple-blue);
  background-color: rgba(0, 113, 227, 0.03);
}

.dropzone-arrow-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: #ffffff;
  border: 1px solid var(--border-line);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--apple-blue);
  margin-bottom: 0.65rem;
  transition: transform 0.2s ease;
}

.apple-dropzone:hover .dropzone-arrow-icon {
  transform: translateY(-2px);
}

.dropzone-main-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.dropzone-sub-text {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

/* Progress Indicator */
.progress-bar-card {
  margin-top: 1.25rem;
  display: none;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.progress-track-bg {
  width: 100%;
  height: 4px;
  background-color: #e5e5ea;
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background-color: var(--apple-blue);
  border-radius: var(--radius-pill);
  transition: width 0.15s ease;
}

/* Decoded Gallery Cards */
.gallery-container {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.gallery-card {
  background-color: #ffffff;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-element);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
  overflow: hidden;
}

.gallery-card-top {
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-line);
  background-color: var(--bg-surface);
}

.sync-pill {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
  background-color: rgba(52, 199, 89, 0.12);
  color: #248a3d;
  border: 1px solid rgba(52, 199, 89, 0.3);
}

.gallery-canvas-wrap {
  width: 100%;
  height: 380px;
  background-color: #f5f5f7;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.gallery-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 4px;
}

.gallery-card-bottom {
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-line);
  background-color: #ffffff;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* iOS Segmented Control */
.pill-switch {
  display: inline-flex;
  background-color: #eeeeef;
  border-radius: var(--radius-pill);
  padding: 2px;
}

.pill-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.28rem 0.8rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all 0.2s ease;
}

.pill-btn.active {
  background-color: #ffffff;
  color: var(--text-main);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.gallery-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-tertiary);
  font-size: 0.84rem;
}
