:root {
  --bg: #14151a;
  --panel-bg: #1d1f26;
  --text: #f2f2f4;
  --text-dim: #9a9ca6;
  --accent: #e8608a;
  --accent-dim: #6b4a55;
  --border: #2c2e37;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

#app-header h1 {
  font-size: 1.1rem;
  margin: 0;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.whoami {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-right: 0.5rem;
}

.btn {
  background: var(--accent);
  color: #1a1013;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.privacy-link {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-decoration: none;
}

.privacy-link:hover {
  text-decoration: underline;
}

.sync-status {
  padding: 0 1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  min-height: 1.2em;
}

#app-main {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.view {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* Viewer mode */
#viewer-view {
  position: relative;
}

.viewer-stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-width: 0;
}

.viewer-image-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#viewer-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
}

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border: none;
  width: 3rem;
  height: 4rem;
  font-size: 1.8rem;
  cursor: pointer;
  border-radius: 6px;
}

.nav-btn:hover {
  background: rgba(0, 0, 0, 0.7);
}

.nav-prev {
  left: 0.75rem;
}

.nav-next {
  right: 0.75rem;
}

.viewer-counter {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  z-index: 5;
}

.side-panel {
  width: 320px;
  flex-shrink: 0;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 1rem;
}

.panel-toggle {
  display: none;
}

.pin-title {
  font-size: 1rem;
  margin: 0 0 0.4rem;
}

.pin-description {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
  white-space: pre-wrap;
}

.pin-link {
  display: inline-block;
  color: var(--accent);
  font-size: 0.8rem;
  text-decoration: none;
  margin-bottom: 1rem;
}

.feedback-section {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.stars-row, .rating-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.person-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.person-name {
  width: 60px;
  flex-shrink: 0;
  color: var(--text-dim);
}

.star-toggle {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-dim);
  line-height: 1;
}

.star-toggle.active {
  color: var(--accent);
}

.star-toggle:disabled, .rating-star:disabled {
  cursor: default;
}

.rating-stars {
  display: flex;
  gap: 0.15rem;
}

.rating-star {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-dim);
  line-height: 1;
  padding: 0;
}

.rating-star.filled {
  color: var(--accent);
}

.comments-section h3 {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0.75rem 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.comments-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.comment {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
}

.comment-meta {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.15rem;
}

.comment-author {
  font-weight: 600;
  color: var(--text);
}

.comment-delete {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
}

.comment-body {
  font-size: 0.85rem;
  white-space: pre-wrap;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.comment-form textarea {
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
}

.comment-form .btn {
  align-self: flex-end;
}

/* Grid mode */
.grid-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  align-content: start;
}

.grid-item {
  position: relative;
  border: none;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--panel-bg);
  aspect-ratio: 1;
}

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

.grid-item-badges {
  position: absolute;
  bottom: 0.3rem;
  left: 0.3rem;
  right: 0.3rem;
  display: flex;
  gap: 0.3rem;
}

.badge {
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
}

.badge:empty {
  display: none;
}

/* Responsive: bottom sheet panel on narrow screens */
@media (max-width: 720px) {
  .side-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 45vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    transform: translateY(calc(100% - 2.6rem));
    transition: transform 0.2s ease;
    z-index: 10;
  }

  .side-panel.expanded {
    transform: translateY(0);
  }

  .panel-toggle {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.85rem;
    padding: 0.6rem 0;
    cursor: pointer;
  }

  .side-panel-content {
    overflow-y: auto;
    max-height: calc(45vh - 2.6rem);
  }

  .nav-btn {
    width: 2.5rem;
    height: 3.2rem;
    font-size: 1.4rem;
  }
}
