* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", sans-serif;
  background: #faf7f2;
  color: #2b2b2b;
}

/* profile page */
.profile-page { padding: 24px; max-width: 720px; margin: 0 auto; }
.child-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; margin-top: 24px; }
.child-card {
  background: #fff; border-radius: 16px; padding: 20px; text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08); cursor: pointer; text-decoration: none; color: inherit;
  display: block;
}
.child-card .avatar { font-size: 40px; margin-bottom: 8px; }
.child-card .name { font-weight: 600; }

/* archive page */
.archive-header {
  display: flex; align-items: center; gap: 12px; padding: 16px 20px;
  background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.06); position: sticky; top: 0; z-index: 10;
}
.archive-header h1 { flex: 1; font-size: 18px; margin: 0; }
.back-link { text-decoration: none; color: #333; font-size: 20px; }
.view-toggle button {
  border: 1px solid #ddd; background: #fff; padding: 6px 12px; border-radius: 20px;
  cursor: pointer; font-size: 13px; margin-left: 6px;
}
.view-toggle button.active { background: #333; color: #fff; border-color: #333; }

.select-toolbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  background: #333; color: #fff; position: sticky; top: 62px; z-index: 9;
}
.select-toolbar #select-count { flex: 1; font-size: 13px; }
.select-toolbar button { padding: 6px 14px; border-radius: 20px; border: 1px solid #fff; background: transparent; color: #fff; cursor: pointer; }
.select-toolbar button.danger { background: #c0392b; border-color: #c0392b; }

.grid-view {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px; padding: 16px;
}
.grid-item {
  background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  cursor: pointer;
}
.grid-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.grid-item .caption { padding: 8px; font-size: 12px; color: #555; }
.grid-item { position: relative; user-select: none; -webkit-user-select: none; }
.grid-item.selected { outline: 3px solid #e74c3c; outline-offset: -3px; }
.grid-item .select-check {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%;
  background: rgba(255,255,255,0.85); border: 2px solid #999; display: none;
  align-items: center; justify-content: center; font-size: 14px; color: #e74c3c;
}
.grid-view.select-mode .select-check { display: flex; }
.grid-item.selected .select-check { background: #e74c3c; border-color: #e74c3c; color: #fff; }

.free-view {
  position: relative; width: 100%; height: calc(100vh - 70px);
  overflow: hidden; background: repeating-linear-gradient(45deg, #f4f0e8, #f4f0e8 10px, #efe9dc 10px, #efe9dc 20px);
}
.free-item {
  position: absolute; width: 140px; touch-action: none; cursor: grab;
}
.free-item.dragging { z-index: 100; }
.free-item img { width: 100%; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); display: block; pointer-events: none; }
.free-item .resize-handle, .free-item .rotate-handle {
  position: absolute; width: 36px; height: 36px; touch-action: none;
  background: #333; border: 2px solid #fff; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.free-item .resize-handle { right: -18px; bottom: -18px; cursor: nwse-resize; }
.free-item .rotate-handle { top: -40px; left: 50%; transform: translateX(-50%); cursor: grab; }

body.drag-over::after {
  content: "여기에 놓아서 등록";
  position: fixed; inset: 0; z-index: 999;
  background: rgba(51,51,51,0.7); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; pointer-events: none;
}

.fab {
  position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px;
  border-radius: 50%; background: #333; color: #fff; font-size: 28px; border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3); cursor: pointer; z-index: 20;
}

#scan-dialog { width: auto; max-width: 95vw; }
#scan-wrap { position: relative; display: inline-block; touch-action: none; }
#scan-wrap img { display: block; max-width: 85vw; max-height: 60vh; }
#scan-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#scan-poly { fill: rgba(231,76,60,0.15); stroke: #e74c3c; stroke-width: 2; }
.scan-handle {
  position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  background: #e74c3c; border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4); cursor: grab; touch-action: none;
}

dialog { border: none; border-radius: 16px; padding: 20px; width: min(90vw, 400px); }
dialog::backdrop { background: rgba(0,0,0,0.4); }
dialog h2 { margin-top: 0; }
dialog input, dialog textarea {
  width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px;
}
dialog img#detail-img { width: 100%; border-radius: 8px; margin-bottom: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions button { padding: 8px 16px; border-radius: 8px; border: 1px solid #ddd; background: #fff; cursor: pointer; }
.dialog-actions button[type="submit"] { background: #333; color: #fff; border-color: #333; }
.dialog-actions button.danger { background: #fff; color: #c0392b; border-color: #c0392b; margin-right: auto; }
