:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #64748b;
  --line: #d8e1ed;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --soft: #eef4ff;
  --danger: #b91c1c;
  --footer-bg: #eef3f8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Meiryo", "Yu Gothic", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body {
  padding-bottom: 48px;
}

.app-header {
  padding: 26px 20px 18px;
  background: linear-gradient(135deg, #f8fbff 0%, #eaf2ff 100%);
  border-bottom: 1px solid var(--line);
}

.app-header > div {
  max-width: 1100px;
  margin: 0 auto;
}


h1 {
  margin: 0;
  font-size: clamp(1.55rem, 3.6vw, 2.35rem);
  line-height: 1.25;
}

.lead {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.app-shell {
  width: min(1100px, calc(100% - 28px));
  margin: 22px auto;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(310px, 1fr);
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(31, 41, 55, 0.06);
  padding: 18px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 1.08rem;
}

.output-panel {
  grid-column: 1 / -1;
}

.drop-area {
  min-height: 170px;
  border: 2px dashed #9db5d8;
  border-radius: 14px;
  background: #f8fbff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  text-align: center;
  transition: 0.2s ease;
}

.drop-area:hover,
.drop-area.dragover {
  border-color: var(--accent);
  background: #eef5ff;
}

.drop-area input {
  display: none;
}

.drop-main {
  font-weight: 700;
  font-size: 1.05rem;
}

.drop-sub,
.file-info,
.status,
.result-info p,
.small-note {
  color: var(--muted);
  font-size: 0.92rem;
}

.small-note {
  margin: 10px 0 0;
  line-height: 1.55;
}

.file-info {
  margin: 12px 0;
  line-height: 1.6;
}

.preview-wrap {
  display: flex;
  justify-content: center;
}

.checker {
  background-image:
    linear-gradient(45deg, #d9e2ef 25%, transparent 25%),
    linear-gradient(-45deg, #d9e2ef 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d9e2ef 75%),
    linear-gradient(-45deg, transparent 75%, #d9e2ef 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  background-color: #ffffff;
}

.preview-frame {
  width: 240px;
  height: 240px;
  border-radius: 16px;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.preview-frame img {
  max-width: 100%;
  max-height: 100%;
  display: none;
  object-fit: contain;
}

#previewEmpty {
  color: #94a3b8;
}

.form-row {
  margin-bottom: 14px;
}

.form-row label,
.fieldset legend,
.position-title {
  display: block;
  margin-bottom: 7px;
  font-weight: 700;
  color: #334155;
}

input[type="text"],
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #bdcbe0;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  background: #ffffff;
}

input[type="text"]:focus,
select:focus,
input[type="range"]:focus {
  outline: 3px solid rgba(37, 99, 235, 0.16);
  border-color: var(--accent);
}

.fieldset {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin: 0 0 14px;
}

.compact-fieldset {
  padding-bottom: 6px;
}

.size-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 9px;
}

.size-grid label,
.inline-check {
  display: flex;
  align-items: center;
  gap: 7px;
  line-height: 1.4;
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.range-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.range-line input {
  width: 100%;
}

#paddingValue {
  min-width: 42px;
  text-align: right;
  color: var(--muted);
}

.position-editor {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fbfdff;
}

.crop-canvas-wrap {
  width: 220px;
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  display: grid;
  place-items: center;
  position: relative;
  user-select: none;
  touch-action: none;
}

.crop-canvas-wrap.active {
  cursor: grab;
  border-color: var(--accent);
}

.crop-canvas-wrap.active:active {
  cursor: grabbing;
}

.crop-canvas-wrap.disabled {
  opacity: 0.72;
}

#cropCanvas {
  width: 220px;
  height: 220px;
  display: block;
}

#cropHint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  color: #64748b;
  font-size: 0.84rem;
  line-height: 1.6;
  background: rgba(255, 255, 255, 0.72);
  pointer-events: none;
}

.position-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

#positionText {
  color: var(--muted);
  font-size: 0.88rem;
}

.color-row {
  display: grid;
  grid-template-columns: 90px 70px;
  align-items: center;
  margin-top: 12px;
}

.color-row label {
  margin: 0;
}

input[type="color"] {
  width: 64px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  background: #ffffff;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

button,
.download-link {
  min-height: 42px;
  border: 1px solid #b7c5d9;
  border-radius: 11px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: #ffffff;
  color: #1e293b;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover,
.download-link:hover {
  background: #f8fafc;
}

button:disabled,
.download-link.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

button.primary,
.download-link {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

button.primary:hover,
.download-link:hover {
  background: var(--accent-dark);
}

.status {
  min-height: 1.5em;
  margin: 12px 0 0;
}

.status.error {
  color: var(--danger);
  font-weight: 700;
}

.generated-preview {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
}

.icon-preview-box {
  width: 150px;
  height: 150px;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: grid;
  place-items: center;
}

.icon-preview-box canvas {
  width: 128px;
  height: 128px;
  image-rendering: auto;
}

.result-info {
  flex: 1;
  min-width: 230px;
}

.mini-icons {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: end;
}

.mini-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px;
  background: #fbfdff;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.mini-card canvas {
  display: block;
  width: 48px;
  height: 48px;
  margin: 0 auto 6px;
}

/* ▼ 広告枠：広告本体とは独立した操作バー付き */
.ad-panel {
  grid-column: 1 / -1;
  border: 1px solid #d7e6f8;
  border-radius: 14px;
  background: #ffffff;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(31, 41, 55, 0.05);
}

.ad-panel[hidden] {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

.ad-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 26px;
  padding: 5px 8px;
  background: #f4f8ff;
  border-bottom: 1px solid #d7e6f8;
}

.ad-label {
  flex: 0 0 auto;
  color: #4f6f91;
  font-size: 0.72rem;
  line-height: 1;
}

.ad-wait-message {
  flex: 1 1 auto;
  color: #64748b;
  font-size: 0.72rem;
  line-height: 1.2;
  text-align: right;
}

.ad-close-btn {
  flex: 0 0 auto;
  min-height: 0;
  height: auto;
  margin: 0 !important;
  padding: 3px 8px !important;
  border: 1px solid #1565c0;
  border-radius: 999px;
  background: #1565c0;
  color: #ffffff;
  font-size: 0.72rem !important;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  appearance: none;
  -webkit-appearance: none;
}

.ad-close-btn:hover {
  background: #0d47a1;
  border-color: #0d47a1;
}

.ad-close-btn[hidden] {
  display: none !important;
}

.ad-body {
  min-height: 82px;
  padding: 8px;
  background: #ffffff;
}


/* ▼ 著作権フッター */
.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 30px;
  border-top: 1px solid #cfd8e3;
  background: var(--footer-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.app-footer p {
  margin: 0;
  padding: 4px 10px;
  font-size: 0.78rem;
  line-height: 1.2;
  text-align: center;
  color: #1d4ed8;
}

.app-footer a {
  color: #1d4ed8;
  text-decoration: none;
}

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


@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100% - 20px, 1100px);
    margin-top: 14px;
  }

  .two-cols {
    grid-template-columns: 1fr;
  }

  .preview-frame {
    width: min(240px, 100%);
  }

  .crop-canvas-wrap,
  #cropCanvas {
    width: min(220px, 100%);
    height: min(220px, 78vw);
  }

  .generated-preview {
    align-items: flex-start;
  }
}
