:root {
  color-scheme: light dark;
  --bg: #e7edf4;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5d6b7c;
  --accent: #1f6aa5;
  --accent-strong: #185684;
  --line: #d5deea;
  --drop: #f4f8fc;
  --drop-line: #4a90d9;
  --shadow: 0 10px 30px rgba(23, 43, 69, 0.08);
  --danger: #9b2c2c;
  font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --card: #1c232d;
    --text: #e8eef6;
    --muted: #a8b3c2;
    --accent: #4a90d9;
    --accent-strong: #78b0ea;
    --line: #2d3846;
    --drop: #171e27;
    --drop-line: #4a90d9;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(74, 144, 217, 0.18), transparent 60%),
    var(--bg);
  color: var(--text);
}

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

.app {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.brand {
  display: block;
  flex: 1;
  min-width: 0;
  line-height: 0;
}

.brand img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 72px;
  object-fit: contain;
  object-position: left center;
}

.header-actions { display: flex; gap: 8px; align-items: center; }

.ghost, .primary, .menu button, .modal-actions button {
  border: 0;
  border-radius: 10px;
  min-height: 40px;
  padding: 8px 14px;
  cursor: pointer;
}

.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.primary {
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.primary:hover, .primary:focus-visible { background: var(--accent-strong); }

.primary:disabled, .controls:disabled .primary { opacity: 0.55; cursor: default; }

.help { position: relative; }

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 5;
  min-width: 240px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
}

.menu button:hover, .menu button:focus-visible { background: var(--drop); }

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 14px;
  align-items: stretch;
}

fieldset.controls {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.stack, .card { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 0.98rem;
}

.choice, .check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 6px 0;
  line-height: 1.45;
}

.hint { margin: 8px 0 0; color: var(--muted); font-size: 0.92rem; }

.field {
  display: grid;
  grid-template-columns: auto 110px;
  gap: 10px;
  align-items: center;
}

input[type="number"] {
  width: 100%;
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 4px 8px;
}

.save-option input {
  appearance: none;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.15rem;
  border: 2px solid var(--accent);
  border-radius: 4px;
  display: grid;
  place-content: center;
  background: transparent;
  flex: 0 0 auto;
}

.save-option input:checked { background: var(--accent); }

.save-option input:checked::after {
  content: "";
  width: 0.55rem;
  height: 0.3rem;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: translateY(-1px) rotate(-45deg);
}

.drop-card {
  min-height: 100%;
  padding: 12px;
}

.dropzone {
  min-height: 460px;
  height: 100%;
  border: 2px dashed var(--drop-line);
  border-radius: 18px;
  background: var(--drop);
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}

.dropzone.dragover {
  background: rgba(74, 144, 217, 0.12);
  border-style: solid;
}

.drop-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 360px;
}

.drop-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 750;
  line-height: 1.5;
}

#select-photos { min-width: 180px; min-height: 46px; font-size: 1rem; }

.drop-status { margin: 0; color: var(--muted); }

.privacy {
  margin: 14px 4px 0;
  color: var(--muted);
  font-size: 0.92rem;
}

dialog {
  width: min(720px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  padding: 18px 18px 14px;
}

dialog::backdrop { background: rgba(10, 16, 24, 0.55); }

dialog h2 { margin: 0 0 10px; font-size: 1.1rem; }

#modal-body {
  margin: 0;
  max-height: min(60vh, 520px);
  overflow: auto;
  white-space: pre-wrap;
  font-family: inherit;
  line-height: 1.55;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.workspace[hidden],
.manual-view[hidden] {
  display: none !important;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}

.tabs button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 16px;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.manual-toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-bottom: 12px;
}

.manual-strength {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.manual-strength input {
  width: 76px;
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 4px 8px;
}

.tool-group {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.tool {
  border: 0;
  background: transparent;
  min-height: 36px;
  padding: 6px 10px;
  cursor: pointer;
}

.tool.is-selected {
  background: var(--accent);
  color: #fff;
}

.manual-stage {
  height: min(68vh, 720px);
  min-height: 420px;
  background: #2b2b2b;
  border-radius: 16px;
  overflow: hidden;
}

.manual-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .dropzone { min-height: 320px; }
  .field { grid-template-columns: 1fr; }
  .manual-stage { min-height: 320px; height: 70vh; }
}
