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

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 16px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.25rem calc(5.5rem + env(safe-area-inset-bottom, 0px));
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 2rem;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.logo-img {
  max-height: 64px;
  width: auto;
}

.logo-fallback {
  display: none;
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.05em;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.card-icon {
  font-size: 1.15rem;
  width: 1.35rem;
  text-align: center;
  color: var(--primary);
  line-height: 1;
}

.sub-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 1rem 0 0.625rem;
}

.sub-title:first-of-type {
  margin-top: 0;
}

/* Dropzone */
.dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: #fafbfe;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
  overflow: hidden;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.dropzone-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.dropzone-content {
  padding: 2.5rem 1.5rem;
  text-align: center;
}

.dropzone-icon {
  font-size: 2.25rem;
  margin-bottom: 0.5rem;
  color: var(--primary);
  opacity: 0.55;
}

.dropzone-text {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.dropzone-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.dropzone-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
}

.dropzone-preview {
  position: relative;
  padding: 1rem;
  text-align: center;
}

.dropzone-preview img {
  max-width: 100%;
  max-height: 280px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.btn-remove {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.75rem;
  padding: 0.375rem 1rem;
  font-size: 0.8rem;
  color: #ef4444;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 999px;
  cursor: pointer;
  position: relative;
  z-index: 3;
}

.btn-remove:hover {
  background: #fee2e2;
}

.card-desc {
  margin: -0.25rem 0 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.material-dropzone .dropzone-content {
  padding: 1.75rem 1.25rem;
}

.material-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.material-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}

.material-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.material-remove {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  font-size: 0.75rem;
  color: #fff;
  background: rgba(15, 23, 42, 0.72);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  z-index: 3;
}

.material-remove:hover {
  background: rgba(185, 28, 28, 0.9);
}

/* Checkbox chips */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.checkbox-chip {
  cursor: pointer;
}

.checkbox-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.checkbox-chip span {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s;
  user-select: none;
}

.checkbox-chip input:checked + span {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.checkbox-chip span:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.checkbox-chip input:checked + span:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

/* Palette */
.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.palette-item {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  min-width: 52px;
}

.palette-item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.palette-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
  max-width: 56px;
}

.palette-item input:checked ~ .palette-label {
  color: var(--primary);
  font-weight: 600;
}

.swatch {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color);
  border: 3px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s, border-color 0.15s;
}

.swatch-light {
  box-shadow: inset 0 0 0 1px var(--border);
}

.swatch-none {
  background:
    linear-gradient(
      to top right,
      transparent calc(50% - 1px),
      #94a3b8 calc(50% - 1px),
      #94a3b8 calc(50% + 1px),
      transparent calc(50% + 1px)
    ),
    #f8fafc;
  border: 2px dashed var(--border);
  box-shadow: none;
}

.palette-item input:checked + .swatch {
  border-color: var(--text);
  transform: scale(1.1);
}

.palette-item:hover .swatch {
  transform: scale(1.05);
}

.color-custom {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.color-custom input[type="color"] {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  background: none;
}

/* Textarea */
.textarea {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.2s;
}

.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.textarea::placeholder {
  color: #94a3b8;
}

/* Actions */
.form-actions {
  margin-top: 0.5rem;
  text-align: center;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  max-width: 360px;
  padding: 0.875rem 2rem;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

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

/* Alert */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.alert-warning {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

.usage-status {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem 0.5rem;
  margin-top: 0.75rem;
  padding: 0.5rem 0.875rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 999px;
}

.usage-status strong {
  color: var(--text);
  font-weight: 700;
}

.usage-status-limit {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #9a3412;
}

.usage-status-note {
  font-size: 0.8rem;
}

.alert i {
  margin-top: 0.15rem;
  flex-shrink: 0;
}

/* Result */
.result-card {
  text-align: center;
}

.result-wrap {
  margin-bottom: 1rem;
}

.result-image {
  max-width: 100%;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.result-note {
  text-align: left;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
}

.result-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.btn-link {
  text-decoration: none;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  max-width: 360px;
  padding: 0.75rem 2rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.btn-secondary:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Floating generate button */
.fab-generate {
  position: fixed;
  right: 1.5rem;
  bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  padding: 0;
  font-size: 1.25rem;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.45);
  transition: transform 0.15s, box-shadow 0.15s;
}

.fab-generate:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.55);
}

.fab-generate:active:not(:disabled) {
  transform: translateY(0);
}

.fab-generate:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Footer */
.footer {
  text-align: center;
  margin-top: 2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 480px) {
  .page {
    padding: 1.25rem 1rem calc(5rem + env(safe-area-inset-bottom, 0px));
  }

  .card {
    padding: 1.25rem;
  }

  .dropzone-content {
    padding: 2rem 1rem;
  }
}
