:root {
  color-scheme: light;
  --accent: #660099;
  --accent-hover: #52007a;
  --accent-soft: #f6eefb;
  --ink: #1d1921;
  --muted: #756e7a;
  --line: #ece8ef;
  --surface: #ffffff;
  --surface-soft: #faf8fb;
  --danger: #a12635;
  --shadow-sm: 0 4px 16px rgba(35, 18, 43, .05);
  --shadow-md: 0 12px 34px rgba(35, 18, 43, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: #fff;
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }

.wrap { width: min(100% - 32px, 1100px); margin: 32px auto 72px; }
.top {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 68px;
  padding: 10px max(24px, calc((100vw - 1100px) / 2));
  border-bottom: 1px solid rgba(236, 232, 239, .9);
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 4px 20px rgba(35, 18, 43, .035);
  backdrop-filter: blur(16px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  flex: none;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.025em;
  text-decoration: none;
  white-space: nowrap;
}
.brand-logo { display:block; width:56px; height:56px; flex:none; object-fit:contain; border:1px solid #eee8f2; border-radius:10px; background:#fff; }
.top nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  min-width: 0;
}
.top nav a, .top nav .link {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #605866;
  font-size: 14px;
  font-weight: 560;
  text-decoration: none;
  white-space: nowrap;
  transition: color .16s ease, background-color .16s ease;
}
.top nav a:hover, .top nav .link:hover { background: #f8f4fa; color: var(--accent); }
.top nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 680; }
.top nav form { display: flex; margin: 0; }
.link { cursor: pointer; }
.profile-menu { position: relative; flex: none; }
.profile-menu summary { display: flex; min-height: 42px; align-items: center; gap: 8px; padding: 4px 9px 4px 5px; border: 1px solid #ece6ef; border-radius: 999px; background: #fff; color: var(--ink); cursor: pointer; list-style: none; }
.profile-menu summary::-webkit-details-marker { display: none; }
.profile-menu summary:hover, .profile-menu[open] summary { border-color: #d8c4e1; background: #fbf7fc; }
.profile-menu summary svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.profile-avatar { display: inline-flex; width: 38px; height: 38px; flex: none; align-items: center; justify-content: center; border: 1px solid #e6d9ed; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 15px; font-weight: 700; text-transform: uppercase; }
.profile-avatar.large { width: 44px; height: 44px; }
.profile-menu-name { max-width: 130px; overflow: hidden; font-size: 13px; font-weight: 650; text-overflow: ellipsis; }
.profile-dropdown { position: absolute; top: calc(100% + 10px); right: 0; z-index: 40; width: min(280px, calc(100vw - 20px)); padding: 10px; border: 1px solid var(--line); border-radius: 15px; background: #fff; box-shadow: var(--shadow-md); }
.profile-dropdown-head { display: flex; align-items: center; gap: 11px; padding: 9px 8px 13px; border-bottom: 1px solid var(--line); }
.profile-dropdown-head strong, .profile-dropdown-head small { display: block; overflow-wrap: anywhere; }
.profile-dropdown-head small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.top nav .profile-dropdown a, .top nav .profile-dropdown .link { display: flex; width: 100%; justify-content: flex-start; min-height: 44px; margin-top: 5px; padding: 10px 11px; border-radius: 9px; font-size: 14px; }
.profile-dropdown form { display: block; }
.profile-page { max-width: 760px; margin: 0 auto; }
.profile-page-head { margin: 14px 0 22px; }
.profile-page-head h1 { margin-bottom: 8px; }
.profile-page-head > p:last-child { margin: 0; color: var(--muted); }
.profile-summary { display: flex; align-items: center; gap: 18px; }
.profile-avatar-xl { width: 64px; height: 64px; font-size: 24px; }
.profile-summary h2 { margin: 0 0 3px; }
.profile-summary p:last-child { margin: 0; color: var(--muted); }
.profile-section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.profile-section-head h2 { margin-bottom: 0; }
.account-count { padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.profile-form { max-width: 560px; }
.profile-form button { margin-top: 4px; }
.authorized-users { margin: 16px 0; }
.authorized-user { display: flex; min-width: 0; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid #eee9f0; }
.authorized-user-info { display: grid; min-width: 0; flex: 1; }
.authorized-user-info strong { overflow-wrap: anywhere; }
.authorized-user-info small { color: var(--muted); }
.authorized-user form { margin: 0; }
.authorized-user .danger { min-height: 38px; padding: 7px 11px; }
.add-account { margin-top: 16px; }
.add-account summary { width: fit-content; cursor: pointer; list-style: none; }
.add-account summary::-webkit-details-marker { display: none; }
.account-form { margin-top: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); }
.account-form .hint { margin: 0 0 12px; font-size: 13px; }

h1, h2 { color: var(--ink); }
h1 { margin: .15em 0 .5em; font-size: clamp(27px, 4vw, 36px); font-weight: 700; letter-spacing: -.045em; line-height: 1.16; }
h2 { margin: 0 0 16px; font-size: 21px; font-weight: 660; letter-spacing: -.025em; line-height: 1.3; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 11px; font-weight: 750; letter-spacing: .15em; }
.panel, .viewer {
  margin: 20px 0;
  padding: clamp(20px, 3vw, 30px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.narrow { max-width: 560px; margin: 8vh auto; }
.panel p { color: #514a56; }
.admin-head, .viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 22px; }
.admin-head { flex-wrap: wrap; margin-bottom: 22px; }
.admin-head h1, .viewer-head h1 { margin-bottom: 7px; }
.admin-head p:not(.eyebrow) { margin: 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 9px; }
.export-note { flex-basis: 100%; max-width: 720px; margin: 0; color: var(--muted); font-size: 13px; }

label { display: grid; gap: 7px; margin: 15px 0; color: #37313b; font-size: 14px; font-weight: 620; }
input, select {
  min-width: 0;
  min-height: 48px;
  padding: 11px 13px;
  border: 1px solid #ded8e2;
  border-radius: 10px;
  outline: 0;
  background: #fff;
  color: var(--ink);
  transition: border-color .16s ease, box-shadow .16s ease;
}
input:hover, select:hover { border-color: #c9b5d3; }
input:focus, select:focus { border-color: #9b61b2; box-shadow: 0 0 0 3px rgba(102, 0, 153, .11); }
input[type="file"] { padding: 8px; }

button, .button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
  transition: transform .16s ease, background-color .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease;
}
button:active, .button:active { transform: translateY(1px); }
.primary { background: var(--accent); color: #fff; box-shadow: 0 3px 9px rgba(102, 0, 153, .17); }
.primary:hover { transform: translateY(-1px); background: var(--accent-hover); box-shadow: 0 6px 14px rgba(102, 0, 153, .22); }
.secondary, .button.secondary { border-color: #e5dce9; background: #fff; color: #403747; }
.secondary:hover, .button.secondary:hover { border-color: #c7a6d6; background: #fbf7fc; color: var(--accent); }
.danger { border-color: #ead1d5; background: #fff; color: var(--danger); }
.danger:hover { border-color: #d8a9b0; background: #fcf3f4; }
button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
button:focus-visible, a:focus-visible { outline: 3px solid rgba(102, 0, 153, .32); outline-offset: 3px; }

.notice { margin: 12px 0; padding: 12px 15px; border: 1px solid var(--line); border-radius: 11px; }
.notice.ok { background: #f7f2fa; color: #382b40; }
.notice.error { border-color: #f0d7da; background: #fcf1f2; color: #781b24; }
.errors { color: #8b1e2a; }
.count, .hint, .empty { color: var(--muted); }
.viewer { max-width: 900px; margin: 18px auto; padding: clamp(18px, 4vw, 36px); }
.viewer-head { margin-bottom: 16px; }
.viewer-head h1 { margin: 0; }
.count { font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.search { display: flex; align-items: center; gap: 8px; margin: 18px 0; }
.search input { flex: 1; }
.viewer-search {
  position: sticky;
  top: 76px;
  z-index: 20;
  margin: 0 0 18px;
  padding: 5px 8px 5px 13px;
  border: 1px solid #e8e2eb;
  border-radius: 12px;
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
  transition: border-color .16s ease, box-shadow .16s ease;
}
.viewer-search:focus-within { border-color: #ad7bc0; box-shadow: 0 0 0 3px rgba(102, 0, 153, .09), var(--shadow-sm); }
.viewer-search input { min-height: 44px; padding: 8px; border: 0; outline: 0; background: transparent; box-shadow: none; }
.viewer-search input:focus { border: 0; box-shadow: none; }
.search-icon { width: 20px; height: 20px; flex: none; fill: none; stroke: #77717b; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-button { width: 40px; min-width: 40px; min-height: 40px; padding: 9px; border: 0; background: transparent; color: #716978; }
.icon-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.icon-button:hover { background: var(--accent-soft); color: var(--accent); }
.card { display: grid; min-height: min(68vh, 760px); grid-template-columns: 52px minmax(0, 1fr) 52px; align-items: center; gap: clamp(8px, 2vw, 18px); touch-action: pan-y; }
.person { display: flex; height: min(68vh, 760px); min-height: 330px; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.person img { width: auto; max-width: 100%; height: calc(100% - 60px); border-radius: 14px; background: #f7f4f8; box-shadow: var(--shadow-md); cursor: zoom-in; object-fit: contain; }
.person h2 { margin: 0; font-size: clamp(21px, 3vw, 29px); text-align: center; }
.arrow { width: 50px; height: 54px; padding: 0; border-color: #ece6ef; border-radius: 13px; background: #fff; color: #4a414d; box-shadow: var(--shadow-sm); font-size: 38px; font-weight: 350; }
.arrow:hover { border-color: #c7a6d6; background: #fbf7fc; color: var(--accent); }
.hint { margin: 12px 0 0; text-align: center; font-size: 13px; }
.empty { text-align: center; }

.gallery { width: min(100% - 32px, 1100px); margin: 20px auto 56px; }
.gallery-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0 16px; }
.gallery-head h1 { margin: 0; }
.gallery-head .count { margin: 0; }
.gallery-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(7px, 1.2vw, 14px); }
.profile-tile { display: block; min-width: 0; overflow: hidden; padding-bottom: 4px; border-radius: 12px; background: #fff; color: var(--ink); text-decoration: none; transition: transform .18s ease, box-shadow .18s ease; }
.profile-tile:hover { transform: translateY(-2px); box-shadow: 0 9px 24px rgba(35, 18, 43, .1); }
.profile-tile img { display: block; width: 100%; aspect-ratio: 1; border-radius: 10px; background: #f5f2f7; object-fit: cover; }
.tile-info { display: block; padding: 9px 8px 10px; }
.tile-name { display: block; overflow: hidden; color: #241d29; font-size: 14px; font-weight: 640; text-overflow: ellipsis; white-space: nowrap; }
.profile-tile:focus-visible { z-index: 1; outline: 3px solid rgba(102, 0, 153, .35); outline-offset: 2px; }
.gallery-controls { display: flex; justify-content: center; padding: 24px 0; }
.gallery-controls button { min-width: 160px; }
.rows { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-top: 1px solid #eee9f0; }
.row img { width: 56px; height: 64px; border-radius: 9px; background: #f5f2f7; object-fit: cover; }
.row form { display: flex; min-width: 0; flex: 1; align-items: center; gap: 8px; }
.row input:not([type="file"]) { width: 100%; }
.file-small { color: var(--muted); font-size: 12px; }
.file-small input { max-width: 180px; }
.userrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid #eee9f0; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; color: var(--muted); }
.add-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.add-form label { min-width: 180px; flex: 1; }
.export-note { flex-basis: 100%; max-width: 720px; margin: 0; color: var(--muted); font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
code { padding: 2px 6px; border-radius: 6px; background: #f5f1f7; color: #44324d; }
dialog { max-width: 96vw; max-height: 96dvh; padding: 48px 12px 12px; border: 1px solid rgba(255, 255, 255, .12); border-radius: 16px; background: #fff; color: var(--ink); box-shadow: 0 24px 80px rgba(0, 0, 0, .24); }
dialog::backdrop { background: rgba(19, 11, 24, .82); backdrop-filter: blur(4px); }
dialog img { display: block; max-width: 92vw; max-height: 88dvh; border-radius: 8px; object-fit: contain; }
.close { position: absolute; top: 7px; right: 7px; width: 40px; min-height: 40px; padding: 0; border-color: #e8e2eb; border-radius: 50%; background: #fff; color: #302735; font-size: 23px; }
.close:hover { background: var(--accent-soft); color: var(--accent); }

@media (min-width: 700px) { .gallery-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; } .tile-info { padding: 10px 9px 12px; } }
@media (min-width: 1080px) { .gallery-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 18px; } }
@media (max-width: 700px) {
  .wrap { width: calc(100% - 20px); margin: 16px auto 36px; }
  .top { min-height: 60px; gap: 10px; padding: 7px 10px; }
  .brand { gap: 8px; font-size: 14px; }
  .brand-logo { width: 48px; height: 48px; }
  .top nav { gap: 2px; overflow-x: auto; scrollbar-width: none; }
  .top nav::-webkit-scrollbar { display: none; }
  .top nav a, .top nav .link { min-height: 38px; padding: 7px 9px; font-size: 12px; }
  .top nav>a:first-child { display: inline-flex; }
  .profile-menu-name, .profile-menu summary svg { display: none; }
  .profile-menu summary { min-height: 38px; padding: 0; border: 0; background: transparent; }
  .profile-dropdown { position: fixed; top: 58px; right: 10px; }
  .profile-summary { gap: 13px; padding: 18px; }
  .authorized-user { gap: 9px; }
  .authorized-user .danger { padding-inline: 9px; font-size: 12px; }
  .add-account summary { width: 100%; }
  .viewer { padding: 16px 12px; border-radius: 14px; box-shadow: none; }
  .viewer-search { top: 60px; }
  .card { min-height: 60dvh; grid-template-columns: 40px minmax(0, 1fr) 40px; gap: 5px; }
  .person { height: 60dvh; min-height: 260px; gap: 12px; }
  .arrow { width: 40px; height: 46px; min-height: 46px; border-radius: 11px; font-size: 32px; }
  .gallery { width: calc(100% - 16px); margin: 12px auto 38px; }
  .gallery-head { padding: 4px 0 12px; }
  .gallery-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .profile-tile { border-radius: 9px; }
  .profile-tile img { border-radius: 8px; }
  .tile-info { padding: 6px 5px 8px; }
  .tile-name { font-size: 12px; }
  .admin-head { align-items: flex-start; flex-direction: column; gap: 14px; }
  .actions { width: 100%; }
  .actions .button { flex: 1; }
  .row { flex-wrap: wrap; }
  .row form { flex-wrap: wrap; }
  .row form:first-of-type { min-width: 55%; }
  .add-form { display: block; }
  .add-form button { width: 100%; }
  .narrow { margin: 5vh auto; }
}
@media (max-width: 390px) {
  .top { gap: 6px; }
  .brand { font-size: 13px; }
  .top nav a, .top nav .link { padding-inline: 7px; font-size: 11px; }
  .viewer-head { gap: 8px; }
  .count { font-size: 12px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .viewer { padding: 12px 18px; }
  .viewer-head { margin-bottom: 6px; }
  .viewer-search { margin-bottom: 8px; }
  .card, .person { height: 68dvh; min-height: 190px; }
  .hint { margin-top: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
