:root {
  color-scheme: light;
  --paper: #f8f5ee;
  --paper-deep: #eee8dc;
  --surface: #fffdf8;
  --surface-raised: #fffefa;
  --ink: #29251f;
  --muted: #746c60;
  --faint: #a2998b;
  --line: rgba(59, 50, 37, 0.13);
  --accent: #b64d29;
  --accent-dark: #86361d;
  --accent-soft: #f5dfd2;
  --yolk: #eab64e;
  --sage: #647b62;
  --sage-soft: #e3eadf;
  --danger: #b3292f;
  --danger-soft: #fae4e3;
  --focus: #166b85;
  --shadow-soft: 0 8px 30px rgba(59, 43, 24, 0.09);
  --shadow-float: 0 16px 50px rgba(42, 31, 19, 0.18), 0 2px 9px rgba(42, 31, 19, 0.08);
  --radius-sm: 0.65rem;
  --radius-md: 1rem;
  --radius-lg: 1.4rem;
  --header-height: 4.5rem;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --app-header-height: calc(var(--header-height) + var(--safe-area-top));
  --gallery-row-height: clamp(7.7rem, 31vw, 10.75rem);
  font-family: ui-rounded, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  font-size: 100%;
  font-optical-sizing: auto;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  scroll-behavior: smooth;
}

body {
  min-width: 18rem;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 8% 0%, rgba(234, 182, 78, 0.11), transparent 26rem),
    var(--paper);
  color: var(--ink);
  accent-color: var(--accent);
}

body.viewer-open,
body.sheet-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  touch-action: manipulation;
}

button {
  color: inherit;
}

svg {
  display: block;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.7rem 1rem;
  border-radius: 0.7rem;
  background: var(--ink);
  color: white;
  font-weight: 700;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

:where(button, input, select, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.pressable {
  transition: transform 110ms ease-out, filter 110ms ease-out, background-color 160ms ease;
}

.pressable:active:not(:disabled) {
  transform: scale(0.965);
  filter: brightness(0.94);
  transition-duration: 50ms;
}

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

.app-header {
  position: sticky;
  z-index: 30;
  top: 0;
  height: var(--app-header-height);
  padding-top: var(--safe-area-top);
  background: rgba(248, 245, 238, 0.79);
  backdrop-filter: blur(1.35rem) saturate(145%);
  -webkit-backdrop-filter: blur(1.35rem) saturate(145%);
}

.header-inner {
  display: flex;
  width: min(100%, 88rem);
  height: var(--header-height);
  margin: 0 auto;
  padding: 0.55rem clamp(0.85rem, 3vw, 2rem);
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.scroll-edge {
  position: absolute;
  right: 0;
  bottom: -0.9rem;
  left: 0;
  height: 0.95rem;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(67, 49, 28, 0.07), transparent);
  opacity: 0;
  transition: opacity 180ms ease;
}

.app-header.is-scrolled .scroll-edge {
  opacity: 1;
}

.brand {
  min-width: 0;
}

.brand-kicker,
.brand-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-kicker {
  max-width: 13rem;
  color: var(--muted);
  font-size: 0.63rem;
  font-weight: 650;
  letter-spacing: 0.055em;
}

.brand-title {
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.22;
}

.identity-button {
  display: flex;
  min-width: 0;
  min-height: 3rem;
  max-width: 15rem;
  padding: 0.38rem 0.58rem;
  align-items: center;
  gap: 0.43rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.83);
  box-shadow: 0 2px 8px rgba(50, 39, 27, 0.04);
  cursor: pointer;
}

.identity-copy {
  min-width: 0;
  text-align: left;
}

.identity-label,
.identity-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity-label {
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 650;
  line-height: 1.15;
}

.identity-name {
  max-width: 12.2rem;
  font-size: 0.8rem;
  font-weight: 750;
  line-height: 1.35;
}

.identity-edit-icon {
  width: 1rem;
  flex: 0 0 auto;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.connection-banner {
  position: sticky;
  z-index: 29;
  top: var(--app-header-height);
  display: flex;
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: #514b42;
  color: white;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.connection-banner svg {
  width: 1.15rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

main {
  width: min(100%, 88rem);
  min-height: calc(100svh - var(--app-header-height));
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 1.7rem) clamp(0.7rem, 2.6vw, 2rem) calc(7.5rem + env(safe-area-inset-bottom));
}

.gallery-heading {
  display: flex;
  margin-bottom: 0.85rem;
  padding: 0 0.15rem;
  align-items: end;
  justify-content: space-between;
  gap: 0.75rem;
}

.gallery-heading h1 {
  margin: 0.03rem 0 0;
  font-size: clamp(1.38rem, 4vw, 1.85rem);
  font-weight: 850;
  letter-spacing: -0.045em;
  line-height: 1.16;
}

.organize-button {
  display: inline-flex;
  min-height: 2.75rem;
  padding: 0.53rem 0.74rem;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.77rem;
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
}

.organize-button svg {
  width: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
}

.loading-state {
  display: grid;
  grid-template-columns: 1.25fr 0.8fr;
  grid-auto-rows: 8rem;
  gap: 0.24rem;
  overflow: hidden;
  border-radius: var(--radius-md);
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: #e9e3d8;
}

.skeleton::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.55) 47%, transparent 73%);
  content: "";
  transform: translateX(-100%);
  animation: shimmer 1.35s infinite;
}

.skeleton-wide {
  grid-column: span 2;
}

.skeleton-tall {
  grid-row: span 2;
}

@keyframes shimmer {
  to { transform: translateX(100%); }
}

.state-card {
  width: min(100%, 36rem);
  margin: clamp(1rem, 7vh, 4rem) auto 0;
  padding: clamp(1.5rem, 5vw, 2.4rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 253, 248, 0.77);
  box-shadow: var(--shadow-soft);
  text-align: center;
}

.state-card h2 {
  margin: 0.65rem 0 0.3rem;
  font-size: 1.32rem;
  letter-spacing: -0.025em;
}

.empty-state h2 {
  margin-top: 0;
}

.state-card p {
  max-width: 29rem;
  margin: 0 auto 1.1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.state-icon {
  display: grid;
  width: 3.25rem;
  height: 3.25rem;
  margin: 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 1.35rem;
  font-weight: 850;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  min-height: 45px;
  padding: 0.65rem 1rem;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border-radius: 0.78rem;
  font-size: 0.86rem;
  font-weight: 780;
  cursor: pointer;
}

.primary-button {
  border: 1px solid var(--accent-dark);
  background: var(--accent);
  color: white;
  box-shadow: 0 3px 9px rgba(134, 54, 29, 0.18);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.danger-button {
  border: 1px solid #8d1f25;
  background: var(--danger);
  color: white;
}

.primary-button svg,
.secondary-button svg {
  width: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.gallery {
  display: grid;
  gap: 1.7rem;
}

.person-section {
  min-width: 0;
}

.person-heading {
  position: sticky;
  z-index: 20;
  top: var(--app-header-height);
  display: flex;
  min-height: 2.5rem;
  margin: 0 -0.35rem;
  padding: 0.25rem 0.53rem 0.32rem;
  align-items: center;
  gap: 0.55rem;
  border-bottom: 1px solid rgba(59, 50, 37, 0.07);
  background: rgba(248, 245, 238, 0.9);
  backdrop-filter: blur(1rem) saturate(135%);
  -webkit-backdrop-filter: blur(1rem) saturate(135%);
}

.person-copy {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.7rem;
}

.person-identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.32rem;
}

.person-name {
  display: block;
  min-width: 0;
  overflow: hidden;
  font-size: 0.9rem;
  font-weight: 820;
  letter-spacing: -0.015em;
  line-height: 1.28;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-meta {
  display: inline-flex;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
}

.you-badge {
  display: inline-flex;
  min-height: 1.45rem;
  flex: 0 0 auto;
  padding: 0.15rem 0.45rem;
  align-items: center;
  border-radius: 999px;
  font-size: 0.64rem;
  font-weight: 760;
}

.you-badge {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.photo-grid {
  display: flex;
  width: 100%;
  min-width: 0;
  flex-flow: row wrap;
  gap: 0.2rem;
}

.photo-grid::after {
  min-width: 0;
  flex-grow: 999999;
  content: "";
}

.photo-card {
  position: relative;
  height: var(--gallery-row-height);
  min-width: 5.2rem;
  max-width: 100%;
  flex-basis: calc(var(--photo-ratio, 1) * var(--gallery-row-height));
  flex-grow: var(--photo-ratio, 1);
  overflow: hidden;
  border-radius: 0.35rem;
  background: #e7e0d5;
  box-shadow: inset 0 0 0 1px rgba(46, 37, 26, 0.03);
}

.photo-open {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.photo-open::after {
  position: absolute;
  inset: 0;
  border: 0 solid var(--surface);
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.13);
  content: "";
  pointer-events: none;
  transition: border-width 120ms ease, background-color 120ms ease;
}

.photo-open:active::after {
  background: rgba(28, 20, 13, 0.12);
}

.photo-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.015);
  transition: opacity 230ms ease, transform 450ms cubic-bezier(0.2, 0.75, 0.22, 1);
}

.photo-image.is-loaded {
  opacity: 1;
  transform: scale(1);
}

.photo-error {
  position: absolute;
  inset: 0;
  display: none;
  padding: 0.7rem;
  place-items: center;
  color: var(--muted);
  font-size: 0.74rem;
  text-align: center;
}

.photo-card.is-error .photo-error {
  display: grid;
}

.photo-card.is-error .photo-image {
  display: none;
}

.selection-check {
  position: absolute;
  z-index: 2;
  top: 0.52rem;
  right: 0.52rem;
  display: grid;
  width: 1.8rem;
  height: 1.8rem;
  place-items: center;
  border: 2px solid white;
  border-radius: 50%;
  background: rgba(35, 30, 24, 0.58);
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.7);
  transition: opacity 130ms ease, transform 160ms cubic-bezier(0.2, 0.8, 0.2, 1), background-color 130ms ease;
}

.selection-check svg {
  width: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.gallery.is-selecting .photo-card.is-owned .selection-check {
  opacity: 1;
  transform: scale(1);
}

.gallery.is-selecting .photo-card:not(.is-owned) {
  opacity: 0.42;
  filter: grayscale(0.45);
}

.gallery.is-selecting .photo-card:not(.is-owned) .photo-open {
  cursor: not-allowed;
}

.gallery.is-selecting .photo-card.is-selected .selection-check {
  border-color: var(--surface);
  background: var(--accent);
}

.gallery.is-selecting .photo-card.is-selected .photo-open::after {
  border-width: 4px;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.gallery-end {
  margin-top: 2.5rem;
  color: var(--faint);
  font-size: 0.72rem;
  font-weight: 650;
  text-align: center;
}

.upload-fab {
  position: fixed;
  z-index: 35;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  display: inline-flex;
  min-width: 8.5rem;
  min-height: 3.35rem;
  padding: 0.75rem 1.05rem;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px solid #87391f;
  border-radius: 1rem;
  background: var(--accent);
  box-shadow: var(--shadow-float);
  color: white;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}

.upload-fab svg {
  width: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-panel {
  position: fixed;
  z-index: 70;
  right: max(0.7rem, env(safe-area-inset-right));
  bottom: max(0.7rem, env(safe-area-inset-bottom));
  display: flex;
  width: min(calc(100% - 1.4rem), 29rem);
  max-height: min(80svh, 47rem);
  padding: 0.55rem 1rem 1rem;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 1.45rem;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow-float);
  backdrop-filter: blur(1.6rem) saturate(145%);
  -webkit-backdrop-filter: blur(1.6rem) saturate(145%);
  animation: panel-in 280ms cubic-bezier(0.2, 0.8, 0.25, 1);
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(1.5rem) scale(0.97); }
}

.panel-handle {
  width: 2.6rem;
  height: 0.26rem;
  margin: 0 auto 0.35rem;
  border-radius: 999px;
  background: rgba(67, 58, 48, 0.24);
}

.upload-panel-header,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.upload-panel-header h2,
.dialog-header h2 {
  margin: 0;
  font-size: 1.16rem;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.panel-kicker {
  margin: 0 0 0.05rem;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 750;
  letter-spacing: 0.04em;
}

.icon-button {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(93, 80, 64, 0.09);
  cursor: pointer;
}

.icon-button svg {
  width: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.sharing-note {
  margin: -0.15rem 0 0.7rem;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.5;
}

.field-label + input {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.6rem 0.72rem;
  border: 1px solid rgba(63, 52, 40, 0.2);
  border-radius: 0.68rem;
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 560;
}

.upload-list {
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.upload-item {
  display: grid;
  min-height: 4.65rem;
  padding: 0.45rem 0;
  grid-template-columns: 3.8rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.65rem;
  border-top: 1px solid var(--line);
}

.upload-preview {
  position: relative;
  width: 3.8rem;
  height: 3.8rem;
  overflow: hidden;
  border-radius: 0.65rem;
  background: var(--paper-deep);
}

.upload-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-file-copy {
  min-width: 0;
}

.upload-file-name,
.upload-file-status {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-file-name {
  font-size: 0.78rem;
  font-weight: 750;
}

.upload-file-status {
  margin-top: 0.1rem;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
}

.upload-item[data-status="done"] .upload-file-status {
  color: var(--sage);
}

.upload-item[data-status="error"] .upload-file-status,
.upload-item[data-status="rejected"] .upload-file-status {
  color: var(--danger);
  white-space: normal;
}

.upload-progress {
  width: 100%;
  height: 0.28rem;
  margin-top: 0.35rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--paper-deep);
}

.upload-progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 120ms linear;
}

.upload-item[data-status="processing"] .upload-progress-bar {
  width: 78% !important;
  animation: processing 1.15s ease-in-out infinite alternate;
}

.upload-item[data-status="done"] .upload-progress-bar {
  width: 100% !important;
  background: var(--sage);
}

.upload-item[data-status="error"] .upload-progress-bar,
.upload-item[data-status="rejected"] .upload-progress-bar {
  background: var(--danger);
}

@keyframes processing {
  to { opacity: 0.45; transform: translateX(22%); }
}

.upload-status-icon {
  display: grid;
  width: 2.25rem;
  min-height: 2.25rem;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

button.upload-status-icon {
  background: var(--danger-soft);
  color: var(--danger);
  cursor: pointer;
}

.upload-check {
  width: 1.45rem;
  height: 1.45rem;
  fill: none;
  stroke: var(--sage);
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-panel-actions {
  display: flex;
  padding-top: 0.75rem;
  justify-content: flex-end;
  gap: 0.5rem;
  border-top: 1px solid var(--line);
}

.selection-bar {
  position: fixed;
  z-index: 45;
  right: 50%;
  bottom: max(0.7rem, env(safe-area-inset-bottom));
  display: grid;
  width: min(calc(100% - 1.4rem), 38rem);
  min-height: 4.25rem;
  padding: 0.65rem;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 1.15rem;
  background: rgba(255, 253, 248, 0.91);
  box-shadow: var(--shadow-float);
  backdrop-filter: blur(1.5rem) saturate(150%);
  -webkit-backdrop-filter: blur(1.5rem) saturate(150%);
  transform: translateX(50%);
  animation: selection-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes selection-in {
  from { opacity: 0; transform: translate(50%, 1.2rem); }
}

.selection-bar p {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 760;
  text-align: center;
}

dialog {
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(26, 22, 17, 0.46);
  backdrop-filter: blur(0.15rem);
  -webkit-backdrop-filter: blur(0.15rem);
}

.dialog-card {
  width: min(calc(100% - 1.4rem), 28rem);
  max-height: calc(100svh - 1.4rem);
  margin: auto;
  padding: 1.2rem;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 1.35rem;
  background: var(--surface-raised);
  box-shadow: var(--shadow-float);
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 170ms ease, transform 230ms cubic-bezier(0.2, 0.82, 0.2, 1), overlay 230ms allow-discrete, display 230ms allow-discrete;
}

.dialog-card[open] {
  opacity: 1;
  transform: scale(1);
}

@starting-style {
  .dialog-card[open] {
    opacity: 0;
    transform: scale(0.96);
  }
}

.dialog-description {
  margin: 0.8rem 0 1rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.shuffle-current {
  display: flex;
  margin: 0;
  padding: 0.75rem 0.85rem;
  justify-content: space-between;
  gap: 1rem;
  border-radius: 0.8rem;
  background: var(--paper-deep);
  color: var(--muted);
  font-size: 0.78rem;
}

.shuffle-current strong {
  color: var(--ink);
  font-weight: 780;
}

.handoff-entry {
  display: flex;
  margin-top: 0.45rem;
  justify-content: flex-end;
}

.quiet-button {
  min-height: 2.75rem;
  padding: 0.48rem 0.6rem;
  border: 0;
  border-radius: 0.65rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: rgba(93, 80, 64, 0.3);
  text-underline-offset: 0.2rem;
  cursor: pointer;
}

.quiet-button:hover {
  background: rgba(93, 80, 64, 0.07);
  color: var(--ink);
}

.handoff-panel {
  margin-top: 0.35rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--paper-deep);
}

.handoff-copy h3,
.handoff-copy p {
  margin: 0;
}

.handoff-copy h3 {
  font-size: 0.92rem;
  letter-spacing: -0.02em;
}

.handoff-copy p {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.71rem;
  line-height: 1.55;
}

.handoff-qr {
  display: grid;
  width: min(12.5rem, 72vw);
  margin: 0.75rem auto;
  padding: 0.35rem;
  place-items: center;
  border: 1px solid rgba(44, 39, 32, 0.12);
  border-radius: 0.75rem;
  background: #fff;
}

.handoff-qr svg {
  display: block;
  width: 100%;
  height: auto;
  color: #171614;
}

#handoffLink {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid rgba(63, 52, 40, 0.2);
  border-radius: 0.68rem;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 0.68rem;
}

.handoff-status {
  min-height: 1.1rem;
  margin: 0.45rem 0 0;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 700;
}

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

.handoff-actions {
  display: flex;
  margin-top: 0.35rem;
  justify-content: flex-end;
  gap: 0.5rem;
}

.field-label {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 750;
}

.field-meta,
.field-hint {
  display: flex;
  margin: 0.28rem 0 0;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.66rem;
}

.field-error {
  min-height: 1.1rem;
  margin: 0.35rem 0 0;
  color: var(--danger);
  font-size: 0.72rem;
  font-weight: 670;
}

.dialog-actions {
  display: flex;
  margin-top: 1rem;
  justify-content: flex-end;
  gap: 0.55rem;
}

.bottom-sheet {
  position: fixed;
  inset: auto 0 0;
  width: min(100%, 34rem);
  max-height: min(82svh, 42rem);
  margin: 0 auto;
  padding: 0.55rem 1rem calc(1rem + env(safe-area-inset-bottom));
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-bottom: 0;
  border-radius: 1.55rem 1.55rem 0 0;
  background: rgba(255, 253, 248, 0.98);
  box-shadow: var(--shadow-float);
  opacity: 0;
  transform: translateY(100%);
  transition: opacity 180ms ease, transform 310ms cubic-bezier(0.2, 0.82, 0.2, 1), overlay 310ms allow-discrete, display 310ms allow-discrete;
}

.bottom-sheet[open] {
  opacity: 1;
  transform: translateY(0);
}

@starting-style {
  .bottom-sheet[open] {
    opacity: 0;
    transform: translateY(100%);
  }
}

.bottom-sheet .dialog-header {
  margin-top: 0.25rem;
}

.sticky-actions {
  position: sticky;
  bottom: calc(-1rem - env(safe-area-inset-bottom));
  margin-right: -1rem;
  margin-left: -1rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: blur(1rem);
  -webkit-backdrop-filter: blur(1rem);
}

.viewer {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: #171614;
  color: white;
}

.viewer::backdrop {
  background: #171614;
}

.viewer-shell {
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.viewer-header,
.viewer-footer {
  position: relative;
  z-index: 5;
  display: flex;
  width: 100%;
  padding-right: max(0.75rem, env(safe-area-inset-right));
  padding-left: max(0.75rem, env(safe-area-inset-left));
  align-items: center;
  background: rgba(23, 22, 20, 0.82);
  backdrop-filter: blur(1.2rem) saturate(120%);
  -webkit-backdrop-filter: blur(1.2rem) saturate(120%);
}

.viewer-header {
  min-height: calc(4.3rem + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  justify-content: space-between;
}

.viewer-footer {
  min-height: calc(4.1rem + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  justify-content: center;
}

.viewer-close,
.viewer-action,
.viewer-delete {
  display: inline-flex;
  min-height: 2.9rem;
  padding: 0.55rem 0.68rem;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 0;
  border-radius: 0.8rem;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 0.78rem;
  font-weight: 720;
  cursor: pointer;
}

.viewer-close svg,
.viewer-action svg,
.viewer-delete svg {
  width: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.viewer-action {
  width: 2.9rem;
  padding: 0;
}

.viewer-heading {
  display: flex;
  min-width: 0;
  padding: 0 0.5rem;
  flex-direction: column;
  text-align: center;
}

.viewer-heading strong {
  max-width: min(44vw, 18rem);
  overflow: hidden;
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-heading span {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.67rem;
}

.viewer-stage {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  place-items: center;
  touch-action: none;
  user-select: none;
}

.viewer-image-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  will-change: transform;
}

.viewer-image-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  opacity: 0;
  transform-origin: center;
  will-change: transform;
  transition: opacity 180ms ease;
}

.viewer-image-wrap img.is-loaded {
  opacity: 1;
}

.viewer-loading {
  position: absolute;
  display: grid;
  width: 2.4rem;
  height: 2.4rem;
  place-items: center;
}

.viewer-loading span:first-child {
  width: 1.65rem;
  height: 1.65rem;
  border: 2px solid rgba(255, 255, 255, 0.23);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.viewer-nav {
  position: absolute;
  z-index: 4;
  top: 50%;
  display: grid;
  width: 3rem;
  height: 4rem;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 0.9rem;
  background: rgba(10, 10, 10, 0.44);
  color: white;
  cursor: pointer;
  transform: translateY(-50%);
}

.viewer-nav:active:not(:disabled) {
  transform: translateY(-50%) scale(0.94);
}

.viewer-nav svg {
  width: 1.65rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.viewer-prev { left: max(0.55rem, env(safe-area-inset-left)); }
.viewer-next { right: max(0.55rem, env(safe-area-inset-right)); }

.viewer-footer p {
  margin: 0;
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.68rem;
  text-align: center;
}

.viewer-delete {
  position: absolute;
  right: max(0.75rem, env(safe-area-inset-right));
  color: #ffb7b4;
}

.danger-icon {
  display: grid;
  width: 3.25rem;
  height: 3.25rem;
  margin: 0 auto 0.7rem;
  place-items: center;
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
}

.danger-icon svg {
  width: 1.55rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.confirm-dialog h2,
.confirm-dialog p {
  text-align: center;
}

.confirm-dialog h2 {
  margin: 0;
  font-size: 1.18rem;
  letter-spacing: -0.025em;
}

.confirm-dialog > form > p:not(.field-error) {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.confirm-dialog .dialog-actions .secondary-button {
  flex-shrink: 0;
  white-space: nowrap;
}

.toast-region {
  position: fixed;
  z-index: 200;
  top: calc(var(--app-header-height) + 0.65rem);
  left: 50%;
  max-width: calc(100% - 1.4rem);
  padding: 0.66rem 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(42, 37, 31, 0.93);
  box-shadow: 0 8px 24px rgba(32, 26, 19, 0.18);
  color: white;
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -0.7rem);
  transition: opacity 160ms ease, transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

.toast-region.is-error {
  background: rgba(126, 29, 34, 0.96);
}

@media (min-width: 42rem) {
  :root {
    --gallery-row-height: clamp(9.5rem, 19vw, 13rem);
    --header-height: 4.75rem;
  }

  .header-inner {
    padding-block: 0.7rem;
  }

  .brand-kicker { font-size: 0.68rem; }
  .brand-title { font-size: 1.28rem; }
  .identity-name { font-size: 0.84rem; }

  .loading-state {
    grid-template-columns: 1.3fr 0.8fr 1fr;
    grid-auto-rows: 10rem;
  }

  .skeleton-wide { grid-column: span 1; }

  .person-section { min-width: 0; }

  .photo-card { min-width: 6.5rem; }

  .upload-fab {
    right: max(1.5rem, env(safe-area-inset-right));
    bottom: max(1.5rem, env(safe-area-inset-bottom));
  }
}

@media (min-width: 75rem) {
  .upload-fab {
    right: max(calc((100vw - 88rem) / 2 + 2rem), 2rem);
  }

  .upload-panel {
    right: max(calc((100vw - 88rem) / 2 + 2rem), 2rem);
  }
}

@media (max-width: 27rem) {
  .brand-kicker { display: none; }
  .brand-title { font-size: 1.05rem; }
  .identity-button { max-width: 13.5rem; }
  .identity-edit-icon { display: none; }
  .gallery-heading { align-items: center; }
  .organize-button { padding-inline: 0.6rem; }
  .organize-button svg { display: none; }

  .name-dialog {
    padding: 1rem;
  }

  .handoff-qr {
    width: min(10.5rem, 55vw);
  }

  .handoff-actions .primary-button,
  .handoff-actions .secondary-button {
    flex: 1;
    padding-inline: 0.65rem;
  }

  .upload-panel {
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 88svh;
    padding-bottom: calc(0.85rem + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 1.45rem 1.45rem 0 0;
  }

  .selection-bar {
    right: 0;
    bottom: 0;
    width: 100%;
    padding: 0.65rem 0.65rem calc(0.65rem + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 1.1rem 1.1rem 0 0;
    transform: none;
  }

  @keyframes selection-in {
    from { opacity: 0; transform: translateY(1.2rem); }
  }

  .selection-bar .secondary-button,
  .selection-bar .primary-button {
    padding-inline: 0.7rem;
    font-size: 0.76rem;
  }

  .viewer-nav {
    top: auto;
    bottom: 0.8rem;
    width: 3.25rem;
    height: 3.25rem;
    transform: none;
  }

  .viewer-nav:active:not(:disabled) {
    transform: scale(0.94);
  }

  .viewer-footer p { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .pressable:active:not(:disabled) {
    transform: none;
  }

  .viewer-nav:active:not(:disabled) {
    transform: translateY(-50%);
  }
}

@media (prefers-reduced-transparency: reduce) {
  .app-header,
  .upload-panel,
  .selection-bar,
  .viewer-header,
  .viewer-footer,
  .sticky-actions {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .app-header { background: #f8f5ee; }
  .upload-panel,
  .selection-bar,
  .sticky-actions { background: #fffdf8; }
  .viewer-header,
  .viewer-footer { background: #171614; }
}

@media (prefers-contrast: more) {
  :root { --line: rgba(41, 37, 31, 0.48); }

  .app-header,
  .upload-panel,
  .selection-bar {
    border-color: var(--ink);
    background: var(--surface);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .identity-button,
  .organize-button,
  .secondary-button,
  input,
  select {
    border-color: var(--ink) !important;
  }
}
