* {
  box-sizing: border-box;
  margin: 0;
}

:root {
  --accent: #fa734d;
  --accent2: #ed4282;
  --gradient: linear-gradient(135deg, var(--accent), var(--accent2));
  --bg: #f4f4f6;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #75757c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #98989f;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Join screen */
.join {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  z-index: 20;
}

.joinCard {
  width: 100%;
  max-width: 380px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.logo {
  width: 84px;
  height: 84px;
  margin: 0 auto 6px;
  border-radius: 24px;
  background: var(--gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(237, 66, 130, 0.35);
}

.joinCard h1 {
  font-size: 28px;
}

.joinCard > p {
  color: var(--muted);
  margin-bottom: 10px;
}

.joinCard input {
  font-size: 17px;
  padding: 15px 16px;
  border-radius: 14px;
  border: none;
  background: var(--card);
  color: var(--text);
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(120, 120, 128, 0.2);
}

.joinCard input:focus {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.joinCard button {
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  padding: 16px;
  border: none;
  border-radius: 16px;
  background: var(--gradient);
  cursor: pointer;
}

.error {
  color: #d43c31;
  font-size: 14px;
}

/* App */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 0 110px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 14px;
}

header h1 {
  font-size: 32px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--gradient);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

/* On the TV card */
.onTv {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: 18px;
  padding: 12px;
  margin: 0 16px 16px;
}

.thumbs {
  position: relative;
  width: 86px;
  height: 70px;
  flex: none;
}

.thumbs img {
  position: absolute;
  width: 62px;
  height: 62px;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid var(--card);
}

.thumbs img:nth-child(1) { left: 0; top: 4px; transform: rotate(-5deg); z-index: 1; }
.thumbs img:nth-child(2) { left: 10px; top: 2px; transform: rotate(1deg); z-index: 2; }
.thumbs img:nth-child(3) { left: 20px; top: 0; transform: rotate(6deg); z-index: 3; }
.thumbs img:only-child { left: 10px; top: 2px; transform: none; }

.onTvText {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.onTvLabel {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.onTvLabel svg {
  width: 16px;
  height: 16px;
}

#onTvTitle {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Photo grid */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}

@media (min-width: 480px) {
  .grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.grid .cell {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: rgba(120, 120, 128, 0.14);
}

.grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.grid .onTvBadge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid .onTvBadge svg {
  width: 12px;
  height: 12px;
  fill: #fff;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 30px;
}

/* Upload button */
.uploadFab {
  position: fixed;
  right: 20px;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(237, 66, 130, 0.45);
  cursor: pointer;
  z-index: 10;
}

.uploadFab svg {
  width: 26px;
  height: 26px;
}

.uploadFab input {
  display: none;
}

.uploadFab.busy {
  opacity: 0.6;
  pointer-events: none;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(100px, calc(env(safe-area-inset-bottom) + 84px));
  transform: translateX(-50%);
  background: var(--card);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  max-width: calc(100vw - 48px);
  text-align: center;
  z-index: 30;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.94);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}

.lightboxClose {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  z-index: 41;
}

.lightboxInfo {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(28, 28, 30, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-radius: 16px;
  padding: 12px 14px;
  color: #fff;
}

.lightboxAvatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.lightboxName {
  font-weight: 600;
  font-size: 15px;
}

.lightboxDate {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}

.lightboxOnTv {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 6px 12px;
}

.lightboxOnTv svg {
  width: 14px;
  height: 14px;
  fill: #fff;
}

/* Header buttons */
.headerButtons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.iconBtn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--card);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.iconBtn svg {
  width: 22px;
  height: 22px;
}

/* Collage shelf */
.collagesSection {
  margin: 0 0 14px;
}

.collagesSection h2 {
  font-size: 18px;
  padding: 0 16px 8px;
}

.collageRow {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 0 16px 4px;
  -webkit-overflow-scrolling: touch;
}

.collageCard {
  flex: none;
  background: var(--card);
  border-radius: 14px;
  padding: 10px;
  cursor: pointer;
}

.collageThumbs {
  width: 116px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
}

.collageThumbs img {
  width: 100%;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
}

.collageMeta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.collageMeta svg {
  width: 14px;
  height: 14px;
  fill: var(--accent);
}

/* Lightbox actions */
.lightboxPanel {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(28, 28, 30, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-radius: 18px;
  padding: 12px 14px;
  color: #fff;
}

.lightboxPanel .lightboxInfo {
  position: static;
  background: none;
  padding: 0;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-radius: 0;
}

.lightboxActions {
  display: flex;
  gap: 10px;
}

.btnGradient {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  background: var(--gradient);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 16px;
  cursor: pointer;
}

.btnGradient:disabled {
  opacity: 0.45;
}

.btnGradient svg {
  width: 18px;
  height: 18px;
}

.btnDanger {
  border: none;
  border-radius: 999px;
  background: rgba(255, 59, 48, 0.9);
  padding: 12px 18px;
  cursor: pointer;
}

.btnDanger svg {
  width: 18px;
  height: 18px;
}

.btnDangerSoft {
  flex: 1;
  border: none;
  border-radius: 999px;
  background: rgba(255, 59, 48, 0.14);
  color: #ff3b30;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 16px;
  cursor: pointer;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 540px) {
  .modal {
    align-items: center;
  }
}

.modalCard {
  width: 100%;
  max-width: 540px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 16px 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (min-width: 540px) {
  .modalCard {
    border-radius: 22px;
  }
}

.modalBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modalPlain {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 16px;
  cursor: pointer;
}

.modalPlain.small {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

.modalBold {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.modalBold:disabled {
  opacity: 0.4;
}

.modalHint {
  font-size: 13px;
  color: var(--muted);
}

.composerGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.composerCell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
}

.composerCell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.composerCell .pick {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid #fff;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.composerCell .pick.picked {
  background: var(--accent);
  border-color: var(--accent);
}

.composerActions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fieldLabel {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 6px;
}

.modalCard select,
.modalCard input {
  font-size: 16px;
  padding: 13px 14px;
  border-radius: 12px;
  border: none;
  background: var(--card);
  color: var(--text);
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(120, 120, 128, 0.2);
  width: 100%;
  -webkit-appearance: none;
}

/* Crop editor */
.cropFrame {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 12px;
  background: #000;
  touch-action: none;
  cursor: grab;
}

.cropFrame img {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

#cropZoom {
  width: 100%;
  accent-color: var(--accent);
  padding: 0;
  box-shadow: none;
  background: none;
  -webkit-appearance: auto;
}
