/* ===== 點記 DianJi — Design Tokens ===== */

:root,
[data-theme='light'] {
  /* Surfaces — cool paper / blueprint-adjacent neutrals */
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-surface-2: #fafbfc;
  --color-surface-offset: #ececf0;
  --color-surface-dynamic: #e2e5ea;
  --color-divider: #e6e9ed;
  --color-border: #dbdfe5;

  /* Text */
  --color-text: #171b24;
  --color-text-muted: #5c6470;
  --color-text-faint: #98a1ad;
  --color-text-inverse: #f7f8fa;

  /* Primary accent — blueprint blue */
  --color-primary: #2454c7;
  --color-primary-hover: #1b3f9e;
  --color-primary-active: #142f79;
  --color-primary-highlight: #dce5f8;

  /* Pin accent — amber field marker (distinct from UI chrome) */
  --color-pin: #e8830f;
  --color-pin-hover: #c76c09;
  --color-pin-highlight: #fbe6cb;

  /* Status */
  --color-success: #2e8b57;
  --color-success-highlight: #d7ecdf;
  --color-warning: #c9820b;
  --color-warning-highlight: #f6e6c8;
  --color-error: #d1425b;
  --color-error-highlight: #f7dbe1;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 1rem;
  --radius-xl: 1.375rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-interactive: 160ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Shadows */
  --shadow-sm: 0 1px 2px oklch(0.2 0.02 250 / 0.08);
  --shadow-md: 0 6px 16px oklch(0.2 0.02 250 / 0.12);
  --shadow-lg: 0 16px 36px oklch(0.2 0.02 250 / 0.18);

  --font-display: 'General Sans', 'Satoshi', system-ui, sans-serif;
  --font-body: 'Satoshi', 'Inter', system-ui, sans-serif;
}

[data-theme='dark'] {
  --color-bg: #0f1420;
  --color-surface: #161c2b;
  --color-surface-2: #1b2233;
  --color-surface-offset: #202840;
  --color-surface-dynamic: #263050;
  --color-divider: #232b42;
  --color-border: #2c3550;

  --color-text: #e7eaf0;
  --color-text-muted: #9aa3b8;
  --color-text-faint: #64708a;
  --color-text-inverse: #10141f;

  --color-primary: #7ea0ef;
  --color-primary-hover: #97b3f2;
  --color-primary-active: #5f86e3;
  --color-primary-highlight: #23335e;

  --color-pin: #f5a85e;
  --color-pin-hover: #f8bd80;
  --color-pin-highlight: #3d3320;

  --color-success: #5fb989;
  --color-success-highlight: #1f3a2c;
  --color-warning: #e0a63a;
  --color-warning-highlight: #3d3320;
  --color-error: #e86b85;
  --color-error-highlight: #3d2430;

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-md: 0 6px 16px oklch(0 0 0 / 0.4);
  --shadow-lg: 0 16px 36px oklch(0 0 0 / 0.55);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #0f1420;
    --color-surface: #161c2b;
    --color-surface-2: #1b2233;
    --color-surface-offset: #202840;
    --color-surface-dynamic: #263050;
    --color-divider: #232b42;
    --color-border: #2c3550;
    --color-text: #e7eaf0;
    --color-text-muted: #9aa3b8;
    --color-text-faint: #64708a;
    --color-text-inverse: #10141f;
    --color-primary: #7ea0ef;
    --color-primary-hover: #97b3f2;
    --color-primary-active: #5f86e3;
    --color-primary-highlight: #23335e;
    --color-pin: #f5a85e;
    --color-pin-hover: #f8bd80;
    --color-pin-highlight: #3d3320;
    --color-success: #5fb989;
    --color-success-highlight: #1f3a2c;
    --color-warning: #e0a63a;
    --color-warning-highlight: #3d3320;
    --color-error: #e86b85;
    --color-error-highlight: #3d2430;
    --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
    --shadow-md: 0 6px 16px oklch(0 0 0 / 0.4);
    --shadow-lg: 0 16px 36px oklch(0 0 0 / 0.55);
  }
}

:root {
  --text-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.83rem + 0.2vw, 0.9375rem);
  --text-base: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1.05rem + 0.4vw, 1.3125rem);
  --text-xl: clamp(1.375rem, 1.2rem + 0.9vw, 1.75rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
}

/* ===== App Shell ===== */

html,
body {
  height: 100%;
  width: 100%;
}

body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--color-bg);
}
.screen.is-active {
  display: flex;
}

/* ===== Top bar ===== */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: max(var(--space-3), env(safe-area-inset-top)) var(--space-4) var(--space-3);
  padding-top: calc(env(safe-area-inset-top) + var(--space-3));
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
  z-index: 20;
}

.topbar__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-base);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  color: var(--color-text);
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--color-surface-offset);
}
.icon-btn:active {
  transform: scale(0.94);
}
.icon-btn svg {
  width: 22px;
  height: 22px;
}

/* ===== Home screen ===== */

.home-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-4) var(--space-12);
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--space-12));
}

.brand-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-4) var(--space-8);
  text-align: center;
}

.brand-hero .logo-mark {
  width: 64px;
  height: 64px;
  color: var(--color-primary);
}

.brand-hero h1 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-hero p {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  max-width: 32ch;
}

.primary-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-4) var(--space-5);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-radius: var(--radius-lg);
  font-weight: 600;
  font-size: var(--text-base);
  box-shadow: var(--shadow-sm);
}
.primary-cta:hover {
  background: var(--color-primary-hover);
}
.primary-cta:active {
  transform: scale(0.98);
  background: var(--color-primary-active);
}
.primary-cta svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: var(--space-8) 0 var(--space-3);
}

/* ===== Home — folders & breadcrumb ===== */

.home-toolbar {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.breadcrumb-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-4) 0 var(--space-1);
}
.breadcrumb-back {
  width: 34px;
  height: 34px;
}
.breadcrumb-back svg {
  width: 18px;
  height: 18px;
}
.breadcrumb-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-base);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.folder-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  text-align: left;
}
.folder-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}
.folder-card:active {
  transform: scale(0.98);
}

.folder-card__icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--color-primary-highlight);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.folder-card__icon svg {
  width: 20px;
  height: 20px;
}

.folder-card__name {
  font-size: var(--text-sm);
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-card__meta {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.folder-card__actions {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  display: flex;
  gap: 1px;
}
.folder-card__action {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-faint);
  flex-shrink: 0;
}
.folder-card__action:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}
.folder-card__action[data-action='delete']:hover {
  background: var(--color-error-highlight);
  color: var(--color-error);
}
.folder-card__action svg {
  width: 15px;
  height: 15px;
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.doc-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  text-align: left;
}
.doc-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}
.doc-card:active {
  transform: scale(0.99);
}

.doc-card__thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--color-surface-offset);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-faint);
  flex-shrink: 0;
  overflow: hidden;
}
.doc-card__thumb svg {
  width: 22px;
  height: 22px;
}

.doc-card__info {
  flex: 1;
  min-width: 0;
}
.doc-card__name {
  font-size: var(--text-sm);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-card__meta {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.doc-card__delete {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  color: var(--color-text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.doc-card__delete:hover {
  background: var(--color-error-highlight);
  color: var(--color-error);
}
.doc-card__delete svg {
  width: 18px;
  height: 18px;
}

.doc-card__move {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  color: var(--color-text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.doc-card__move:hover {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
}
.doc-card__move svg {
  width: 18px;
  height: 18px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-10) var(--space-4);
  color: var(--color-text-faint);
  text-align: center;
}
.empty-state svg {
  width: 36px;
  height: 36px;
  opacity: 0.6;
}
.empty-state span {
  font-size: var(--text-sm);
}

/* ===== Viewer screen ===== */

.viewer-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: repeating-conic-gradient(
      var(--color-surface-offset) 0% 25%,
      var(--color-surface-2) 0% 50%
    )
    50% / 24px 24px;
  touch-action: none;
}

.viewer-canvas-wrap {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.viewer-canvas-wrap canvas,
.viewer-canvas-wrap img {
  display: block;
  box-shadow: var(--shadow-lg);
  background: #fff;
}

.pin {
  position: absolute;
  /* Anchor exactly at the pointed tip of the rotated .pin__dot, not the
     bottom of the whole dot+label stack. The dot is a 30px square rotated
     45deg, so its sharp corner sits 15px (half side) + 15*sqrt(2)px (half
     diagonal) ≈ 36.21px below the box top — not 30px. transform-origin
     matches the same point so the counter-zoom scale() applied in JS never
     shifts the anchor, at any zoom level. */
  transform-origin: 50% 36.21px;
  transform: translate(-50%, -36.21px);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 5;
  touch-action: none;
  cursor: grab;
}
.pin.is-dragging {
  z-index: 20;
  cursor: grabbing;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.25));
}
.pin.is-dragging .pin__dot {
  box-shadow: var(--shadow-lg);
}
/* When the drag-to-move setting is off (default), pins are fixed —
   show a normal pointer cursor instead of the "grab" affordance. */
.pin-drag-disabled .pin {
  cursor: pointer;
}

/* Read-only collaboration mode — disables every editing affordance for a
   shared document the current collaborator can't write to. Covers
   dynamically-created elements (photo tiles, delete buttons) too, since
   it only needs this one body-level rule instead of per-element wiring. */
.read-only-doc #btn-add-mark,
.read-only-doc #btn-save-pin,
.read-only-doc #btn-delete-pin,
.read-only-doc .photo-thumb--add,
.read-only-doc .photo-thumb__delete {
  pointer-events: none;
  opacity: 0.4;
}
.read-only-doc .pin {
  cursor: pointer;
}

.pin__dot {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full) var(--radius-full) var(--radius-full) 3px;
  background: var(--color-pin);
  transform: rotate(45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  border: 2px solid var(--color-surface);
}
.pin__dot svg {
  width: 14px;
  height: 14px;
  color: #fff;
  transform: rotate(-45deg);
}
.pin.has-photo .pin__dot {
  background: var(--color-primary);
}
.pin__badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  border: 2px solid var(--color-surface);
}
.pin__badge.status-uploading {
  background: var(--color-warning);
}
.pin__badge.status-uploaded {
  background: var(--color-success);
}
.pin__badge.status-failed {
  background: var(--color-error);
}
.pin__label {
  margin-top: var(--space-1);
  max-width: 120px;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}

.pin-ghost {
  position: absolute;
  transform-origin: 50% 36.21px;
  transform: translate(-50%, -36.21px);
  width: 30px;
  height: 30px;
  z-index: 6;
  pointer-events: none;
}
.pin-ghost__dot {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full) var(--radius-full) var(--radius-full) 3px;
  background: var(--color-pin);
  opacity: 0.55;
  transform: rotate(45deg);
  border: 2px dashed var(--color-surface);
}

/* Viewer toolbar (bottom, floating) */

.viewer-toolbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  row-gap: var(--space-2);
  padding: var(--space-3) var(--space-3);
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--space-3));
  z-index: 15;
  max-width: 100%;
  box-sizing: border-box;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-1);
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
}

.toolbar-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  flex-shrink: 0;
}
.toolbar-btn:hover {
  background: var(--color-surface-offset);
}
.toolbar-btn:active {
  transform: scale(0.92);
}
.toolbar-btn svg {
  width: 19px;
  height: 19px;
}
.toolbar-btn.is-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.zoom-readout {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  min-width: 36px;
  text-align: center;
  flex-shrink: 0;
}

.fab-mark {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 48px;
  min-width: 48px;
  padding: 0 var(--space-5) 0 var(--space-4);
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-weight: 600;
  font-size: var(--text-sm);
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
  white-space: nowrap;
}
.fab-mark svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.fab-mark.is-armed {
  background: var(--color-pin);
}
.fab-mark:active {
  transform: scale(0.96);
}

/* Narrow viewports (small phones, or larger OS font-size settings inflating
   the toolbar's rem-based text/gaps): drop the text label and collapse the
   "add mark" button down to a plain icon button so the whole toolbar reliably
   fits on one row without pushing anything past the screen edge. */
@media (max-width: 400px) {
  .fab-mark {
    padding: 0;
    width: 48px;
    justify-content: center;
  }
  .fab-mark__label {
    display: none;
  }
}

.page-nav {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 64px);
  right: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-1);
  box-shadow: var(--shadow-md);
  z-index: 15;
  font-size: var(--text-xs);
  font-weight: 600;
}
.page-nav button {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-nav button:hover {
  background: var(--color-surface-offset);
}
.page-nav button svg {
  width: 15px;
  height: 15px;
}
.page-nav span {
  padding: 0 var(--space-1);
}

.hint-banner {
  position: absolute;
  top: calc(env(safe-area-inset-top) + var(--space-3) + 56px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-pin-highlight);
  color: var(--color-pin-hover);
  border: 1px solid var(--color-pin);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
  z-index: 16;
  box-shadow: var(--shadow-sm);
}

/* readonly collaboration banner — shares hint-banner layout, warning tone */
.readonly-banner {
  background: var(--color-warning-highlight);
  color: var(--color-warning);
  border-color: var(--color-warning);
}

/* collaborator list (share management sheet) */
.collab-list {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.collab-list:empty::before {
  content: '尚未新增協作者';
  display: block;
  padding: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
.collab-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
}
.collab-row:last-child {
  border-bottom: none;
}
.collab-row__email {
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.collab-row__role {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
  flex-shrink: 0;
}
.collab-row__role.is-writer {
  background: var(--color-success-highlight);
  color: var(--color-success);
}
.collab-row__remove {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-faint);
  border-radius: var(--radius-full);
}
.collab-row__remove:hover {
  background: var(--color-error-highlight);
  color: var(--color-error);
}
.collab-row__remove svg {
  width: 15px;
  height: 15px;
}

/* ===== Sheets / modals ===== */

.overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in oklab, black 45%, transparent);
  z-index: 50;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.overlay.is-active {
  display: flex;
}
.overlay.is-center {
  align-items: center;
}

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-5) var(--space-5) calc(env(safe-area-inset-bottom) + var(--space-6));
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: sheet-up 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.overlay.is-center .sheet {
  border-radius: var(--radius-xl);
  margin: var(--space-4);
}

@keyframes sheet-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.sheet__handle {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  margin: 0 auto var(--space-4);
}

.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.sheet__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-lg);
}

.field {
  margin-bottom: var(--space-4);
}
.field label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}
.field textarea,
.field input[type='text'],
.field input[type='email'] {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: var(--text-base);
  background: var(--color-surface-2);
  color: var(--color-text);
  resize: vertical;
  min-height: 44px;
}
.field textarea {
  min-height: 84px;
  line-height: 1.5;
}
.field textarea:focus,
.field input[type='text']:focus,
.field input[type='email']:focus {
  border-color: var(--color-primary);
  outline: none;
}

.photo-preview {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface-offset);
  margin-bottom: var(--space-4);
  position: relative;
  aspect-ratio: 4/3;
}
.photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-preview__status {
  position: absolute;
  bottom: var(--space-2);
  left: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  background: color-mix(in oklab, black 55%, transparent);
  color: #fff;
}
.photo-preview__status svg {
  width: 13px;
  height: 13px;
}

.photo-gallery {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-1);
  -webkit-overflow-scrolling: touch;
}

.photo-thumb {
  position: relative;
  flex-shrink: 0;
  width: 92px;
  height: 92px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Shown while a collaborator's photo (referenced via manifest.json but not
   yet downloaded locally) is being lazily fetched from Google Drive. */
.photo-thumb.is-loading-remote img {
  opacity: 0.25;
}
.photo-thumb.is-loading-remote::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  animation: spin 0.8s linear infinite;
}
.photo-thumb__status {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  border: 2px solid rgba(255, 255, 255, 0.9);
}
.photo-thumb__status.status-uploading {
  background: var(--color-warning);
}
.photo-thumb__status.status-uploaded {
  background: var(--color-success);
}
.photo-thumb__status.status-failed {
  background: var(--color-error);
}
.photo-thumb__status.status-none {
  display: none;
}
.photo-thumb__delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: color-mix(in oklab, black 55%, transparent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-thumb__delete svg {
  width: 12px;
  height: 12px;
}
.photo-thumb--add {
  flex-shrink: 0;
  width: 92px;
  height: 92px;
  border-radius: var(--radius-md);
  border: 1.5px dashed var(--color-border);
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
}
.photo-thumb--add svg {
  width: 20px;
  height: 20px;
}
.photo-thumb--add:active {
  transform: scale(0.97);
}

.btn-row {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  flex: 1;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--text-sm);
  border: 1px solid transparent;
}
.btn svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}
.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}
.btn-primary:hover {
  background: var(--color-primary-hover);
}
.btn-secondary {
  background: var(--color-surface-offset);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-surface-dynamic);
}
.btn-danger {
  background: var(--color-error-highlight);
  color: var(--color-error);
}
.btn-danger:hover {
  filter: brightness(0.96);
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  margin-bottom: var(--space-4);
}
.status-pill svg {
  width: 13px;
  height: 13px;
}
.status-pill.status-none {
  background: var(--color-surface-offset);
  color: var(--color-text-faint);
}
.status-pill.status-uploading {
  background: var(--color-warning-highlight);
  color: var(--color-warning);
}
.status-pill.status-uploaded {
  background: var(--color-success-highlight);
  color: var(--color-success);
}
.status-pill.status-failed {
  background: var(--color-error-highlight);
  color: var(--color-error);
}

/* Fullscreen photo viewer */
.photo-full {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
}
.photo-full.is-active {
  display: flex;
}
.photo-full img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.photo-full__close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + var(--space-3));
  right: var(--space-4);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: color-mix(in oklab, black 40%, transparent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 61;
}
.photo-full__close svg {
  width: 20px;
  height: 20px;
}
.photo-full__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: color-mix(in oklab, black 40%, transparent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 61;
}
.photo-full__nav svg {
  width: 22px;
  height: 22px;
}
.photo-full__nav--prev {
  left: var(--space-4);
}
.photo-full__nav--next {
  right: var(--space-4);
}
.photo-full__nav[hidden] {
  display: none;
}
.photo-full__caption {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + var(--space-5));
  left: var(--space-4);
  right: var(--space-4);
  text-align: center;
  color: #fff;
  font-size: var(--text-sm);
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

/* ===== Settings screen ===== */

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-4) var(--space-12);
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--space-12));
}

.settings-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
}
.settings-card h2 {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  margin-bottom: var(--space-1);
}
.settings-card__desc {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
  line-height: 1.5;
}

.settings-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}
.settings-row__text {
  flex: 1;
  min-width: 0;
}
.settings-row__title {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-1);
}
.settings-row .settings-card__desc {
  margin-bottom: 0;
}

.switch {
  flex-shrink: 0;
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--color-border);
  padding: 3px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  margin-top: 2px;
}
.switch__knob {
  display: block;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: #fff;
  box-shadow: var(--shadow-sm);
  transform: translateX(0);
  transition: transform 0.2s ease;
}
.switch[aria-checked="true"] {
  background: var(--color-primary);
}
.switch[aria-checked="true"] .switch__knob {
  transform: translateX(20px);
}

.account-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}
.account-row__avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-primary-highlight);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.account-row__email {
  font-size: var(--text-sm);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-crumbs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}
.folder-crumbs button {
  color: var(--color-primary);
  font-weight: 600;
}

.folder-list {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  max-height: 260px;
  overflow-y: auto;
  margin-bottom: var(--space-3);
}
.folder-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  font-size: var(--text-sm);
  text-align: left;
}
.folder-row:last-child {
  border-bottom: none;
}
.folder-row:hover {
  background: var(--color-surface-2);
}
.folder-row svg {
  width: 18px;
  height: 18px;
  color: var(--color-text-faint);
  flex-shrink: 0;
}

.selected-folder {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--color-success-highlight);
  color: var(--color-success);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-3);
}
.selected-folder svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.setup-steps {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.7;
  padding-left: var(--space-4);
}
.setup-steps li {
  margin-bottom: var(--space-2);
}
.setup-steps a {
  color: var(--color-primary);
  font-weight: 600;
}
.setup-steps code {
  background: var(--color-surface-offset);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.toggle-details {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-3);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* toast */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + var(--space-6));
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--color-text);
  color: var(--color-text-inverse);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  text-align: center;
}
.toast.is-active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* loading spinner */
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid color-mix(in oklab, currentColor 25%, transparent);
  border-top-color: currentColor;
  animation: spin 700ms linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.upload-drop {
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  text-align: center;
  margin-bottom: var(--space-2);
}
.upload-drop svg {
  width: 30px;
  height: 30px;
  color: var(--color-text-faint);
}
.upload-drop span {
  font-size: var(--text-sm);
}
.upload-drop small {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

@media (min-width: 640px) {
  .home-content,
  .settings-content {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
  }
  .topbar {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
  }
}
