:root {
  --green: #7bc043;
  --green-dark: #5a9c2c;
  --sky: #cfe9ff;
  --sun: #ffd93d;
  --pink: #ff7eb6;
  --bg: #fff8e7;
  --text: #2b2b2b;
  --muted: #6a6a6a;
  --danger: #e44d4d;
  --shadow: 0 4px 14px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Comic Sans MS", "Comic Sans", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.topbar {
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: white;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.5px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.user-badge {
  font-size: 0.85rem;
  background: rgba(255,255,255,0.25);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  color: white;
}
.user-badge:empty { display: none; }

.logout {
  color: white;
  text-decoration: underline;
  font-size: 0.85rem;
  opacity: 0.85;
}
.logout:hover { opacity: 1; }

button {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  border: 0;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.15s ease;
  font-weight: 600;
}

button:active { transform: scale(0.97); }

button.primary {
  background: var(--sun);
  color: #5a4a00;
  box-shadow: var(--shadow);
}
button.primary:hover { background: #ffe066; }

button.ghost {
  background: transparent;
  color: var(--text);
  border: 2px solid #ddd;
}

button.danger {
  background: var(--danger);
  color: white;
  box-shadow: var(--shadow);
}

button.big { font-size: 1.05rem; padding: 0.8rem 1.2rem; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  padding: 0 1rem 1rem;
  max-width: 1100px;
  margin: 0 auto;
}

.main {
  max-width: 1100px;
  margin: 0 auto;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1rem 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar input[type="search"] {
  flex: 1 1 200px;
  min-width: 0;
  font-family: inherit;
  font-size: 1rem;
  padding: 0.55rem 0.9rem;
  border: 2px solid #e1e1e1;
  border-radius: 999px;
  background: white;
}
.toolbar input[type="search"]:focus {
  outline: none;
  border-color: var(--green);
}

.toolbar select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 0.7rem;
  border: 2px solid #e1e1e1;
  border-radius: 999px;
  background: white;
  cursor: pointer;
}
.toolbar select:focus {
  outline: none;
  border-color: var(--green);
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 3rem 1rem;
}

.friend-card {
  background: white;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease;
  display: flex;
  flex-direction: column;
}
.friend-card:hover { transform: translateY(-3px); }

.friend-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--sky);
  display: block;
}

.friend-card .info {
  padding: 0.6rem 0.8rem 0.8rem;
}

.friend-card h3 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
  color: var(--green-dark);
}

.friend-card .sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding:
    calc(env(safe-area-inset-top) + 1rem)
    1rem
    calc(env(safe-area-inset-bottom) + 1rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal.hidden { display: none; }

.card {
  background: white;
  border-radius: 20px;
  padding: 1.2rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin: auto 0;
}

.card h2 {
  margin: 0;
  color: var(--green-dark);
}

.card label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 0.95rem;
}

.card input[type="text"],
.card textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.6rem 0.8rem;
  border: 2px solid #e1e1e1;
  border-radius: 12px;
  background: #fafafa;
}
.card input[type="text"]:focus,
.card textarea:focus {
  outline: none;
  border-color: var(--green);
  background: white;
}

.card textarea {
  min-height: 7rem;
  resize: vertical;
  line-height: 1.4;
  font-family: inherit;
  overflow-y: auto;
}

.photo-label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sky);
  border-radius: 16px;
  min-height: 200px;
  border: 3px dashed #88c1ff;
  cursor: pointer;
  overflow: hidden;
  font-weight: 700;
  color: #2a6bb3;
}
.photo-label input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.photo-label img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-label img:not([src]),
.photo-label img[src=""] { display: none; }

.row {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.msg {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.2em;
}
.msg.error { color: var(--danger); }

.hidden { display: none !important; }

#viewer .card img {
  width: 100%;
  border-radius: 12px;
  background: var(--sky);
  max-height: 60vh;
  object-fit: contain;
}

.meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

.details {
  margin: 0.4rem 0 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 0.8rem;
  align-items: baseline;
}
.details dt {
  font-weight: 700;
  color: var(--green-dark);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.details dd {
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
