:root {
  --bg: #fff9f2;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-2: #ffffff;
  --border: rgba(255, 160, 90, 0.28);
  --text: #3d2918;
  --muted: #6b5344;
  --accent: #ff8a3d;
  --accent-2: #f4c46b;
  --danger: #e04d4d;
  --shadow: 0 12px 36px rgba(180, 120, 70, 0.18);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 520px at 12% -5%, rgba(255, 200, 140, 0.45), transparent 52%),
    radial-gradient(700px 420px at 88% 8%, rgba(255, 220, 180, 0.5), transparent 48%),
    linear-gradient(180deg, #fff5ea 0%, #ffefe3 35%, #ffe8d6 100%);
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 18px 48px;
}

.hero {
  border-radius: calc(var(--radius) + 6px);
  padding: 26px 24px;
  background: linear-gradient(135deg, #ffb366 0%, #ffcf6b 55%, #ffe08a 100%);
  color: #2b1608;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.65);
}

.hero-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-start;
  justify-content: space-between;
}

.kicker {
  margin: 0 0 6px;
  font-size: 13px;
  letter-spacing: 0.04em;
  font-weight: 600;
  opacity: 0.85;
}

.hero h1 {
  margin: 0 0 10px;
  font-size: 28px;
  letter-spacing: -0.02em;
}

.lead {
  margin: 0;
  max-width: 640px;
  line-height: 1.65;
  font-size: 14px;
  color: #3a1f0f;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

.main {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(255, 170, 120, 0.35);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: 0 4px 20px rgba(200, 140, 90, 0.12);
}

.card h2 {
  margin: 0 0 10px;
  font-size: 17px;
  color: #3d2918;
}

.hint,
.fineprint,
.info,
.footer {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.hint {
  margin: 0 0 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}

.field-label {
  display: block;
  margin: 14px 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.field > span:first-of-type {
  font-weight: 600;
  color: #5a4330;
}

input[type="text"],
textarea,
select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 150, 100, 0.35);
  background: #fffefb;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  box-shadow: inset 0 1px 2px rgba(255, 200, 160, 0.15);
}

textarea {
  resize: vertical;
  min-height: 160px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #f0a050;
  box-shadow: 0 0 0 3px rgba(255, 180, 100, 0.35);
}

.meta {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.ref-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.ref-label {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.dropzone {
  position: relative;
  border-radius: 12px;
  border: 1px dashed rgba(255, 140, 80, 0.45);
  background: linear-gradient(180deg, #fffbf7, #fff3e8);
  min-height: 140px;
  display: grid;
  place-items: center;
  padding: 10px;
  cursor: pointer;
  overflow: hidden;
}

.dropzone.drag {
  border-color: rgba(255, 150, 60, 0.85);
  background: #fff8f0;
}

.dropzone:focus-visible {
  outline: 2px solid rgba(244, 196, 107, 0.9);
  outline-offset: 2px;
}

.placeholder {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 10px;
}

.preview {
  max-width: 100%;
  max-height: 200px;
  border-radius: 8px;
}

.remove {
  position: absolute;
  right: 8px;
  top: 8px;
}

.theme-grid .swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 170, 120, 0.4);
  background: #fffaf5;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
}

.swatch.active {
  border-color: #f0a050;
  color: var(--text);
  background: #fff3e4;
  box-shadow: 0 2px 8px rgba(255, 160, 80, 0.2);
}

.swatch input {
  accent-color: var(--accent);
}

.color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(80, 50, 30, 0.2);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: linear-gradient(135deg, #ff8a3d, #f4c46b);
  color: #2b1608;
  box-shadow: 0 10px 30px rgba(255, 138, 61, 0.35);
}

.btn.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.btn.secondary {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  background: #fff8f2;
  color: var(--text);
  border: 1px solid rgba(255, 150, 100, 0.4);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.75);
  color: var(--text);
  border: 1px solid rgba(255, 150, 100, 0.4);
}

.btn.large {
  padding: 14px 16px;
  font-size: 15px;
}

.btn.small {
  padding: 6px 10px;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.pill.warn {
  background: #ffe8e0;
  color: #8b2e1f;
  border: 1px solid rgba(255, 120, 90, 0.55);
}

/* .pill の display と hidden 属性の相性問題を避ける（Chrome で未設定バッジが消えない対策） */
#apiKeyWarning[data-need-key="false"] {
  display: none !important;
}

#apiKeyWarning[data-need-key="true"] {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.result-wrap {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 170, 120, 0.35);
  background: #fffefb;
  box-shadow: inset 0 0 0 1px rgba(255, 220, 190, 0.35);
}

#resultImage {
  display: block;
  width: 100%;
  height: auto;
}

.result-actions {
  margin-top: 12px;
}

.footer {
  margin-top: 22px;
  padding: 0 4px;
}

.ext-version {
  margin-top: 8px;
  font-size: 12px;
  color: #8a7260;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(90, 60, 40, 0.25);
}

.modal-panel {
  position: relative;
  max-width: 560px;
  margin: 8vh auto 0;
  background: linear-gradient(180deg, #fffefb, #fff5eb);
  border: 1px solid rgba(255, 170, 120, 0.4);
  border-radius: 16px;
  box-shadow: 0 24px 48px rgba(160, 100, 60, 0.2);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 180, 130, 0.35);
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  color: #3d2918;
}

.icon-btn {
  border: none;
  background: transparent;
  color: #5a4330;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 16px;
}

.modal-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 180, 130, 0.35);
}

.modal-foot .btn.secondary {
  margin-right: auto;
}

.info code {
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 60;
  padding: 10px 14px;
  border-radius: 999px;
  background: #fffefb;
  border: 1px solid rgba(255, 170, 120, 0.45);
  color: var(--text);
  font-size: 13px;
  max-width: min(720px, calc(100vw - 32px));
  text-align: center;
  box-shadow: 0 10px 28px rgba(160, 100, 60, 0.18);
}

.toast.error {
  border-color: rgba(224, 77, 77, 0.65);
  background: #fff5f3;
}

.toast[hidden] {
  display: none;
}

.fineprint strong {
  color: #c45a18;
}

a {
  color: #c45a12;
}

/* 生成中オーバーレイ */
.gen-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(255, 245, 235, 0.82);
  backdrop-filter: blur(5px);
}

.gen-overlay[hidden] {
  display: none;
}

.gen-panel {
  width: min(420px, calc(100vw - 40px));
  padding: 22px 20px 20px;
  border-radius: 16px;
  border: 1px solid rgba(255, 170, 120, 0.45);
  background: linear-gradient(180deg, #fffefb, #fff3e6);
  box-shadow: 0 20px 50px rgba(160, 100, 60, 0.22);
  text-align: center;
}

.gen-overlay-title {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 700;
  color: #3d2918;
}

.gen-overlay-sub {
  margin: 12px 0 0;
  min-height: 1.4em;
  font-size: 13px;
  color: #6b5344;
  line-height: 1.5;
}

.gen-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 200, 160, 0.45);
  overflow: hidden;
  border: 1px solid rgba(255, 170, 120, 0.35);
}

.gen-bar-fill {
  display: block;
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff8a3d, #f4c46b, #ff8a3d);
  background-size: 200% 100%;
  animation: genBarSlide 1.1s ease-in-out infinite;
}

@keyframes genBarSlide {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(280%);
  }
}

[hidden] { display: none !important; }
input[type="password"] { width: 100%; padding: 10px 12px; font-size: 16px; box-sizing: border-box; }
.modal-panel { max-height: 90vh; overflow-y: auto; }
