:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --panel: #161a22;
  --panel-2: #1f2532;
  --border: #2a3142;
  --text: #e6edf3;
  --muted: #8b97a8;
  --accent: #6aa6ff;
  --accent-strong: #4b8cff;
  --danger: #ff6e6e;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --panel-2: #f0f3f8;
    --border: #d7dde8;
    --text: #14161c;
    --muted: #5b6473;
    --accent: #2f6fef;
    --accent-strong: #1f5be0;
    --danger: #d6433a;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
    system-ui, sans-serif;
  line-height: 1.5;
}

header {
  padding: 32px 24px 8px;
  text-align: center;
}

header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.04em;
}

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

.header-links {
  margin: 10px 0 0;
}

.header-links a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.header-links .text-link {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  padding: 0;
  cursor: pointer;
}

.header-links a:hover {
  text-decoration: underline;
}

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

.help-dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  max-width: 560px;
  width: calc(100vw - 32px);
  background: var(--panel);
  color: var(--text);
}

.help-dialog::backdrop {
  background: rgba(2, 6, 23, 0.6);
}

.help-dialog__panel {
  padding: 20px;
}

.help-dialog__panel h2 {
  margin: 0 0 10px;
}

.help-dialog__panel ol {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
}

.help-dialog__panel p {
  margin: 14px 0 0;
  color: var(--muted);
}

.help-dialog__panel a {
  color: var(--accent);
}

.help-dialog__actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

main {
  max-width: 960px;
  margin: 24px auto 64px;
  padding: 0 16px;
  display: grid;
  gap: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

/* Dropzone */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 180px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  padding: 24px;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--panel-2);
}

.dropzone__label {
  font-weight: 600;
}

.dropzone__hint {
  color: var(--muted);
  font-size: 13px;
}

/* Preview */
.preview {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

#canvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 70vh;
  background: var(--panel-2);
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: contain;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.turnstile-dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  background: var(--panel);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  max-width: 340px;
  width: calc(100% - 32px);
}

.turnstile-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.turnstile-dialog__panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 28px 24px 20px;
}

.turnstile-dialog__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

button {
  font: inherit;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    opacity 0.12s ease;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-strong);
}

button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

button.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

button.ghost:hover:not(:disabled) {
  background: var(--panel-2);
}

button.small {
  padding: 6px 12px;
  font-size: 13px;
}

.status {
  margin: 0;
  min-height: 1.2em;
  font-size: 13px;
  color: var(--muted);
}

.status.is-error {
  color: var(--danger);
}

/* Gallery */
.gallery__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 10px;
}

.gallery__head h2 {
  margin: 0;
  font-size: 18px;
}

.gallery__tabs {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
}

.gallery__tab {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
}

.gallery__tab.is-active {
  background: var(--accent);
  color: #fff;
}

.gallery__note {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.4em;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.gallery__note.is-visible {
  opacity: 1;
}

.gallery__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  grid-auto-rows: min-content;
  align-items: start;
  gap: 10px;
}

.gallery__item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--panel-2);
  align-self: start;
  height: fit-content;
}

.gallery__item img {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}

.gallery__item .gallery__copy {
  position: absolute;
  inset: 6px 40px auto auto;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.58);
  color: #d5ecff;
  border: none;
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 1;
}

.gallery__copy:hover {
  background: rgba(0, 0, 0, 0.72);
}

.gallery__favorite {
  position: absolute;
  inset: 6px 6px auto auto;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
  border: none;
  background: rgba(0, 0, 0, 0.58);
  color: #ffd54f;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.gallery__favorite:hover {
  background: rgba(0, 0, 0, 0.72);
}

.empty {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  margin: 16px 0 0;
}

.guide h2 {
  margin: 0 0 14px;
  font-size: 20px;
}

.guide h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.guide p {
  margin: 0 0 14px;
  color: var(--muted);
}

.guide__steps {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
}

.toast {
  position: fixed;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%) scale(0.96);
  min-width: 220px;
  max-width: min(92vw, 560px);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid color-mix(in oklab, var(--border) 50%, white 50%);
  background: color-mix(in oklab, var(--panel) 82%, white 18%);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  opacity: 0;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  pointer-events: none;
  z-index: 30;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.toast.is-error {
  border-color: color-mix(in oklab, var(--danger) 45%, var(--border) 55%);
}
