:root {
  --bg: #f6f7f9;
  --fg: #1d2127;
  --muted: #69707a;
  --card: #fff;
  --line: #dde1e6;
  --accent: #06c755; /* LINE green */
  --accent-fg: #fff;
  --danger: #c62828;
  --notice: #1b7f3b;
  --warn: #9a5b00;
  --check: #d9dde2; /* transparency checkerboard */
  --radius: 8px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --fg: #e8eaed;
    --muted: #9aa1ab;
    --card: #1e2227;
    --line: #333941;
    --notice: #5fd38a;
    --warn: #f0b44c;
    --check: #3a4048;
  }
}
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
}
a { color: inherit; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; text-decoration: none; }
.who { color: var(--muted); margin-right: 0.5rem; }
.inline { display: flex; align-items: center; margin: 0; }

.container { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.narrow { max-width: 380px; margin: 2rem auto; }
.stack { display: grid; gap: 1rem; }
.muted { color: var(--muted); }

label { display: grid; gap: 0.25rem; font-weight: 500; }
input[type=text], input[type=password], select, textarea {
  font: inherit;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
}
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}
.btn-quiet {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line);
  font-weight: 500;
  padding: 0.25rem 0.75rem;
}
.alert {
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--danger);
  color: var(--danger);
}

/* Flash messages */
.flash {
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--notice);
  color: var(--notice);
}
.flash-error { border-color: var(--danger); color: var(--danger); }

/* Layout helpers */
.card + .card, .card + .section, .section + .card, .section + .section, .list + .card, p + .card { margin-top: 1.5rem; }
.row { display: flex; flex-wrap: wrap; align-items: end; gap: 1rem; }
.grow { flex: 1 1 14rem; }
.cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1rem;
  margin: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.cols legend { font-weight: 600; padding: 0 0.25rem; }
.crumbs { margin: 0 0 0.25rem; color: var(--muted); }
.link { text-decoration: underline; color: var(--accent); }
.btn-link {
  font: inherit;
  font-size: 0.8rem;
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}
.btn-link:hover { color: var(--danger); }
.btn-danger { background: var(--danger); }
.danger-zone { border-color: var(--danger); }

/* Project list */
.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.list th, .list td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); }
.list th { font-weight: 600; color: var(--muted); font-size: 0.875rem; }
.list tr:last-child td { border-bottom: 0; }

/* Slots and pool */
.slots, .pool {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.slot {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.25rem;
  padding: 0.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.slot-empty { border-style: dashed; }
.slot-label { display: flex; align-items: center; gap: 0.375rem; font-size: 0.8rem; font-weight: 600; min-width: 0; }
.badge {
  display: inline-block;
  min-width: 1.75rem;
  padding: 0 0.375rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.slot-placeholder {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}
.slot:not(.slot-empty) .slot-placeholder { display: none; }
.pool { min-height: 5rem; border-radius: var(--radius); }
.pool .tile {
  padding: 0.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.tile { margin: 0; display: grid; gap: 0.25rem; min-width: 0; }
.thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
  background-color: var(--card);
  background-image:
    linear-gradient(45deg, var(--check) 25%, transparent 25%),
    linear-gradient(-45deg, var(--check) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--check) 75%),
    linear-gradient(-45deg, transparent 75%, var(--check) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.tile figcaption { display: grid; font-size: 0.8rem; min-width: 0; }
.tile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-meta { color: var(--muted); }
.tile-delete { justify-self: start; }
.tile-move { display: flex; gap: 0.25rem; margin: 0; min-width: 0; }
.tile-move select { flex: 1 1 auto; min-width: 0; font-size: 0.8rem; padding: 0.125rem 0.25rem; }
.tile-move .btn { font-size: 0.8rem; padding: 0.125rem 0.5rem; }
.js .tile-move .btn { display: none; }
.js .move-form { display: none; }

/* Drag and drop */
.tile[draggable=true] { cursor: grab; }
.tile.dragging { opacity: 0.35; }
.dnd .pool { outline: 2px dashed var(--line); outline-offset: 2px; }
.drop-over, .dnd .pool.drop-over {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
}
.section-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-bottom: 0.5rem; }
.section-head h2 { margin: 0; }
.hint { margin: 0 0 0.75rem; font-size: 0.875rem; }
.layout-status { font-size: 0.875rem; }
.layout-status.error { color: var(--danger); }

/* Validation report */
.report { display: grid; gap: 0.5rem; }
.report-status { margin: 0; font-weight: 600; }
.report-error { color: var(--danger); }
.report-warning { color: var(--warn); }
.report-ok { color: var(--notice); }
.issues { margin: 0; padding-left: 1.25rem; font-size: 0.875rem; }
.issue-error { color: var(--danger); }
.issue-warning { color: var(--warn); }
.report .row { align-items: center; margin-top: 0.5rem; }
a.btn { display: inline-block; text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Upload */
.dropzone {
  display: grid;
  gap: 0.25rem;
  justify-items: center;
  text-align: center;
  padding: 2rem 1rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  font-weight: 400;
  cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.upload-status { list-style: none; margin: 0.75rem 0 0; padding: 0; font-size: 0.875rem; }
.upload-status li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.25rem 0; border-bottom: 1px solid var(--line); }
.upload-status li:last-child { border-bottom: 0; }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-state { color: var(--muted); text-align: right; }
.upload-status .ok .upload-state { color: var(--notice); }
.upload-status .error .upload-state { color: var(--danger); }
