* { box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  margin: 0;
  background: #f5f5f7;
  color: #1d1d1f;
  line-height: 1.5;
}

#security-notice {
  background: #e8f5e9;
  color: #1b5e20;
  text-align: center;
  padding: 8px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid #c8e6c9;
}

header {
  background: #fff;
  padding: 20px 24px;
  border-bottom: 1px solid #e5e5e7;
}

header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.subtitle {
  margin: 4px 0 0;
  color: #6e6e73;
  font-size: 0.9rem;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

section {
  background: #fff;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

section h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.muted {
  color: #6e6e73;
  font-size: 0.9rem;
  margin: 0;
}

#drop-zone {
  border: 2px dashed #c7c7cc;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
}

#drop-zone.dragover {
  border-color: #007aff;
  background: #f0f8ff;
}

#drop-zone p {
  margin: 6px 0;
}

#step-pages label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 6px 16px 6px 0;
}

#custom-pages {
  margin-left: 6px;
  padding: 4px 8px;
  border: 1px solid #c7c7cc;
  border-radius: 4px;
  width: 140px;
}

.preset-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f0f0f0;
  flex-wrap: wrap;
}

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

.preset-row .preset-name {
  flex: 1 1 200px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
}

.preset-row .size-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.9rem;
  color: #6e6e73;
}

.preset-row input[type="number"] {
  width: 70px;
  padding: 4px 6px;
  border: 1px solid #c7c7cc;
  border-radius: 4px;
}

#page-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

#page-nav button {
  padding: 4px 14px;
  border: 1px solid #c7c7cc;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

#page-nav button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.preview-card {
  border: 1px solid #e5e5e7;
  border-radius: 6px;
  padding: 12px;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preview-card h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  align-self: flex-start;
}

.preview-card .canvas-wrap {
  background: #fff;
  border: 1px solid #e5e5e7;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  max-width: 100%;
}

.preview-card canvas {
  display: block;
  cursor: pointer;
}

.preview-card.width-type canvas {
  cursor: default;
  max-width: 100%;
  height: auto;
}

.preview-card .info {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: #6e6e73;
  align-self: flex-start;
}

#download-mode,
#size-target {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: center;
}

#download-mode label,
#size-target label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.size-target-label {
  font-size: 0.9rem;
  color: #6e6e73;
}

#download-btn {
  width: 100%;
  padding: 14px;
  background: #007aff;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}

#download-btn:hover:not(:disabled) { background: #0066d6; }

#download-btn:disabled {
  background: #c7c7cc;
  cursor: not-allowed;
}

#download-status {
  margin-top: 8px;
  text-align: center;
}

#gallery { margin-top: 16px; }

.gallery-notice {
  background: #fff8e1;
  color: #5d4037;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid #ffe082;
  margin: 0 0 12px;
  font-size: 0.9rem;
  text-align: center;
}

#gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.gallery-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #fafafa;
  border: 1px solid #e5e5e7;
  border-radius: 6px;
  padding: 10px;
}

.gallery-item img {
  max-width: 100%;
  height: auto;
  display: block;
  background: #fff;
  border: 1px solid #e5e5e7;
}

.gallery-item .filename {
  margin-top: 6px;
  font-size: 0.75rem;
  color: #6e6e73;
  word-break: break-all;
  text-align: center;
}

.hint {
  margin: 12px 0 0;
  font-size: 0.85rem;
  color: #6e6e73;
}

#reset-presets {
  margin-top: 12px;
  background: none;
  border: 1px solid #c7c7cc;
  color: #1d1d1f;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

#reset-presets:hover { background: #f5f5f7; }

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 12px;
}

#modal-overlay[hidden] { display: none; }

#modal-content {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  max-width: 95vw;
  max-height: 95vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

#modal-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}

#modal-title {
  font-weight: 500;
  font-size: 1rem;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

#modal-reset {
  padding: 8px 14px;
  background: #fff;
  color: #1d1d1f;
  border: 1px solid #c7c7cc;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

#modal-reset:hover { background: #f5f5f7; }

#modal-close {
  padding: 8px 18px;
  background: #007aff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
}

#modal-close:hover { background: #0066d6; }

#modal-body {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #2c2c2e;
  border-radius: 4px;
}

#modal-body canvas {
  display: block;
  touch-action: none;
  max-width: 100%;
  height: auto;
}

body.modal-open { overflow: hidden; }

footer {
  text-align: center;
  padding: 24px;
}

footer a {
  color: #007aff;
  text-decoration: none;
}

footer a:hover { text-decoration: underline; }

@media (max-width: 480px) {
  main { padding: 8px; }
  section { padding: 12px; }
  header { padding: 14px 16px; }
}
