/* ==========================================================================
   Base
   ========================================================================== */
:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #12181f;
  --muted: #5b6875;
  --border: #e2e7ec;
  --border-strong: #cfd7df;
  --accent: #0b6fc2;
  --accent-hover: #085a9e;
  --accent-soft: #e8f2fb;
  --accent-text: #ffffff;
  --danger: #b42318;
  --radius-md: 12px;
  --font: "Noto Sans JP", system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Yu Gothic UI", Meiryo, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1116;
    --surface: #151b22;
    --surface-soft: #111720;
    --text: #e9eef3;
    --muted: #9aa7b5;
    --border: #242e38;
    --border-strong: #33414e;
    --accent: #4da3ff;
    --accent-hover: #78baff;
    --accent-soft: #16283a;
    --accent-text: #06121e;
    --danger: #ff8a80;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

img {
  max-width: 100%;
  display: block;
}

h1,
h2,
p {
  margin: 0;
}

button,
textarea,
input {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ==========================================================================
   Shell
   ========================================================================== */
.frame {
  max-width: 1180px;
  margin: 0 auto;
  padding-inline: clamp(18px, 5vw, 40px);
  padding-bottom: 8px;
}

/* ==========================================================================
   Hero
   ========================================================================== */
.hero {
  padding-block: clamp(32px, 5vw, 56px) clamp(18px, 3vw, 28px);
  max-width: 760px;
}

.hero h1 {
  font-size: clamp(1.15rem, 5.7vw, 2.7rem);
  line-height: 1.18;
  letter-spacing: 0.01em;
  font-weight: 800;
}

/* ==========================================================================
   Cards
   ========================================================================== */
.maker {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 1fr);
  align-items: start;
  gap: clamp(18px, 2.4vw, 28px);
}

.preview {
  position: sticky;
  top: 20px;
}

[hidden] {
  display: none !important;
}

.canvas-shell {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #ffffff;
  overflow: hidden;
}

#previewCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1648 / 1128;
}

/* ==========================================================================
   Panel
   ========================================================================== */
.panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.field label,
.field-label {
  font-size: 0.9rem;
  font-weight: 700;
}

.link {
  padding: 2px;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.link:hover {
  text-decoration: underline;
}

textarea {
  width: 100%;
  min-height: 148px;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  line-height: 1.7;
  transition: border-color 0.15s, background 0.15s;
}

textarea::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Dropzone */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 20px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.dropzone:hover,
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dz-icon {
  width: 26px;
  height: 26px;
  margin-bottom: 6px;
  color: var(--muted);
}

.dropzone:hover .dz-icon,
.dropzone.is-over .dz-icon {
  color: var(--accent);
}

.dz-title {
  font-size: 0.9rem;
  font-weight: 600;
}

.dz-hint {
  color: var(--muted);
  font-size: 0.78rem;
}

.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
}

.file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.83rem;
  color: var(--muted);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
}

.actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  min-height: 52px;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: var(--surface-soft);
  color: var(--text);
}

/* ==========================================================================
   Footer / toast
   ========================================================================== */
.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 20px;
  margin-top: clamp(36px, 5vw, 56px);
  padding-block: 20px 24px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
}

.foot a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
}

.foot a:hover {
  color: var(--accent);
  border-bottom-color: currentColor;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  translate: -50% 0;
  max-width: min(92vw, 460px);
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.87rem;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.18s, transform 0.18s, visibility 0.18s;
  z-index: 10;
}

.toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.toast[data-tone="error"] {
  background: var(--danger);
  color: #ffffff;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 900px) {
  .maker {
    grid-template-columns: minmax(0, 1fr);
  }

  .preview {
    position: static;
  }
}

@media (max-width: 520px) {
  .actions-row {
    grid-template-columns: 1fr;
  }

  .btn {
    min-height: 46px;
  }

  .field-head {
    align-items: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
