* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #007AFF;
  --primary-dark: #0056CC;
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --text: #1C1C1E;
  --text-secondary: #8E8E93;
  --border: #E5E5EA;
  --success: #34C759;
  --warning: #FF9500;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'YuGothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  max-width: 100%;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Header */
header {
  text-align: center;
  padding: 20px 0;
}

header h1 {
  font-size: 24px;
  font-weight: 700;
}

header .subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Main */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Upload Section */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 48px 24px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 200px;
}

.upload-area:active {
  background: var(--bg);
  border-color: var(--primary);
}

.upload-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.upload-text {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.upload-hint {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Preview Section */
#preview-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-container {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
}

.preview-container h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.preview-container canvas {
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #000;
}

/* Full-size original image - fit to screen width */
.preview-container.full-size {
  overflow-x: hidden;
}

.preview-container.full-size canvas {
  width: 100%;
  height: auto;
  max-width: 100%;
}

/* Settings Section */
.settings-container {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
}

.settings-container h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-row label {
  font-size: 15px;
  font-weight: 500;
}

.slider-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-wrapper input[type="range"] {
  width: 120px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.slider-wrapper input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
}

.slider-wrapper span {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  min-width: 36px;
  text-align: right;
}

/* Progress Section */
#progress-section {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s ease;
}

#progress-text {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
}

/* Action Section */
#action-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 20px;
}

.btn-primary,
.btn-secondary {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  background: var(--border);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--card);
  color: var(--primary);
  border: 1px solid var(--border);
}

.btn-secondary:active {
  background: var(--bg);
}

/* Footer */
footer {
  text-align: center;
  padding: 16px 0;
  font-size: 12px;
  color: var(--text-secondary);
}

/* Utility */
.hidden {
  display: none !important;
}

/* Output Containers (Multiple Pages) */
.output-container {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
}

.output-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-align: center;
}

.output-canvas-wrapper {
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

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