:root {
  --ink: #1c1c1c;
  --accent: #2563eb;
  --line: #d4d4d4;
  --bg: #faf9f7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.site-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.brand { font-size: 22px; font-weight: 800; color: var(--accent); text-decoration: none; }
.tagline { color: #666; font-size: 14px; }

main { max-width: 1000px; margin: 0 auto; padding: 24px; }

.site-footer {
  max-width: 1000px; margin: 0 auto; padding: 24px;
  color: #999; font-size: 13px; text-align: center;
}
.site-footer a { color: #777; }

/* ---- builder form ---- */
.builder { max-width: 640px; }
.builder h1 { font-size: 26px; margin-top: 0; }
.builder label { display: block; font-weight: 600; margin: 14px 0 6px; }
.hint { font-weight: 400; color: #888; }
textarea, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.field { flex: 1; min-width: 140px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.checkbox input { width: auto; }

button, .primary, .secondary, .link {
  font-size: 15px;
  cursor: pointer;
  border-radius: 8px;
  text-decoration: none;
  display: inline-block;
}
.primary {
  background: var(--accent); color: #fff; border: none;
  padding: 11px 20px; font-weight: 600;
}
.primary:hover { background: #1d4ed8; }
.secondary {
  background: #fff; color: var(--accent);
  border: 1px solid var(--accent); padding: 10px 18px; font-weight: 600;
}
.link { color: #555; padding: 10px 8px; }
.builder .primary { margin-top: 20px; }

.error {
  background: #fee2e2; color: #991b1b;
  padding: 12px 14px; border-radius: 8px; border: 1px solid #fca5a5;
}
.notice {
  background: #dcfce7; color: #166534;
  padding: 10px 14px; border-radius: 8px; border: 1px solid #86efac;
}

.presets { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0 4px; }
.preset {
  background: #eef2ff; color: var(--accent); border: 1px solid #c7d2fe;
  padding: 5px 12px; border-radius: 999px; font-size: 13px; text-decoration: none;
}
.preset:hover { background: #e0e7ff; }
input[type="file"] { width: 100%; padding: 8px 0; font-size: 14px; }

/* ---- preview ---- */
.preview-bar {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.preview-bar h1 { margin: 0 0 4px; font-size: 24px; }
.meta { color: #666; margin: 0; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}
/* ---- admin ---- */
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
}
.admin-table th { color: #666; font-weight: 600; }
.admin-table tr.is-permanent { background: #f0fdf4; }
.admin-table form { margin: 0; }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: #f1f5f9; color: #475569;
}
.badge.perm { background: #dcfce7; color: #166534; }

.card-wrap { display: flex; flex-direction: column; gap: 6px; }
.card-dl {
  align-self: center; font-size: 12px; color: var(--accent);
  text-decoration: none; padding: 2px 6px;
}
.card-dl:hover { text-decoration: underline; }

/* ---- card (preview) ---- */
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card-title { text-align: center; font-weight: 700; margin-bottom: 10px; }
table.board { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.board td {
  border: 1px solid #333;
  text-align: center;
  vertical-align: middle;
  padding: 4px;
  font-size: 12px;
  height: 0;
  position: relative;          /* anchor for absolutely-placed images */
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
/* Square cells: padding-trick keeps each cell's aspect ratio ~1:1 */
table.board td::before { content: ""; float: left; padding-top: 100%; }
table.board td.free { background: #f0f0f0; font-style: italic; }
table.board td.image { padding: 2px; }
/* Fill + center the image in the square cell. Absolute positioning (not
   height:100%) because the cell's height comes from the ::before float. */
.item-img {
  position: absolute; top: 4px; left: 4px; right: 4px; bottom: 4px;
  width: calc(100% - 8px); height: calc(100% - 8px);
  object-fit: contain;            /* fill the cell uniformly, keep aspect */
}

/* ---- QR code ---- */
.qr-cell { display: block; width: 70%; max-width: 84px; margin: 0 auto 2px; }
.qr-caption { display: block; font-size: 9px; font-style: italic; color: #555; }
.card-footer {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  padding-top: 8px; border-top: 1px solid var(--line);
}
.qr-footer { width: 44px; height: 44px; flex: 0 0 auto; }
.qr-url { font-size: 10px; color: #666; word-break: break-all; }
