:root {
  --bg: #f5f3ea;
  --surface: #ffffff;
  --ink: #2e3423;
  --muted: #6b7360;
  --accent: #6d7c3d;
  --accent-ink: #fff;
  --border: #dde1cf;
  --danger: #b44a4a;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(40, 50, 25, 0.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

header {
  padding: 3.25rem 1.25rem 1rem;
  text-align: center;
  position: relative;
}

header h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  margin: 0 0 0.25rem;
  font-size: 1.85rem;
  letter-spacing: 0.01em;
}

.event-date {
  margin: 0.1rem 0 0.4rem;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  color: var(--muted);
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}

.lead { margin: 0; color: var(--muted); }

.lang-toggle {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: inline-flex;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  font-size: 0.75rem;
  z-index: 10;
}
.lang-toggle button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.lang-toggle button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

main { padding: 0 1.25rem 4rem; max-width: 960px; margin: 0 auto; }

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

/* ---------- Upload page ---------- */

.upload-page #name-section { margin-top: 1rem; }

.upload-page label[for="name"] {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.upload-page input[type="text"] {
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.upload-page input.invalid { border-color: var(--danger); animation: shake 0.2s; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

#table-line { margin: 0.5rem 0 0; }

#pickers {
  display: grid;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.pick-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  text-align: center;
  box-shadow: var(--shadow);
}
.pick-btn svg { flex: 0 0 auto; }

.pick-btn:disabled { opacity: 0.5; }

.hint {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}

.note-field summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  box-shadow: var(--shadow);
  list-style: none;
}
.note-field summary::-webkit-details-marker { display: none; }
.note-field summary .icon { color: var(--accent-ink); }
.note-field[open] summary { margin-bottom: 0.5rem; }
.note-field textarea {
  width: 100%;
  padding: 0.75rem;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  resize: vertical;
}
.note-field button {
  margin-top: 0.5rem;
  padding: 0.7rem 1rem;
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---------- Recorder dialog ---------- */

#rec-dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 360px;
  width: calc(100% - 2rem);
}
#rec-dialog::backdrop { background: rgba(46, 52, 35, 0.55); }
.rec-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem 1.25rem;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.rec-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(180, 74, 74, 0.12);
  color: var(--danger);
  margin-bottom: 0.75rem;
  position: relative;
}
.rec-icon-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--danger);
  animation: pulse-ring 1.4s infinite ease-out;
}
@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}
.rec-time {
  font-family: Georgia, serif;
  font-size: 1.8rem;
  color: var(--ink);
  letter-spacing: 0.05em;
  margin: 0.25rem 0 1rem;
}
.rec-time small { color: var(--muted); font-size: 0.95rem; }
.rec-actions {
  display: flex;
  gap: 0.5rem;
}
.rec-actions button {
  flex: 1;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
}
.rec-actions .primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.rec-actions .secondary {
  background: var(--surface);
  color: var(--ink);
}

/* ---------- Queue ---------- */

#queue {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.q-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  align-items: center;
  flex-wrap: wrap;
}
.q-item[data-status="done"] { border-color: #c4d4a4; }
.q-item[data-status="failed"] { border-color: var(--danger); color: var(--danger); }
.q-item[data-status="uploading"],
.q-item[data-status="retrying"] { border-color: var(--accent); }
.q-item[data-status="reverted"] { opacity: 0.55; text-decoration: line-through; }
.q-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}
.q-label svg { flex: 0 0 auto; color: var(--muted); }
.q-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--border);
  flex: 0 0 auto;
}
.q-thumb-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: var(--border);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.q-status { flex-shrink: 0; color: var(--muted); }
.undo-btn {
  margin-left: 0.5rem;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}
.undo-btn[disabled] { opacity: 0.4; cursor: default; }

.q-dismiss-btn {
  margin-left: 0.4rem;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.gallery-link {
  text-align: center;
  margin-top: 2rem;
}
.gallery-link a { color: var(--accent); text-decoration: none; font-weight: 600; }

/* ---------- Install banner (Android-only) ---------- */

.install-banner {
  display: none;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0 0;
  padding: 0.7rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.install-banner.show { display: flex; }
.install-banner .msg { flex: 1; color: var(--ink); }
.install-banner .install {
  padding: 0.4rem 0.9rem;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}
.install-banner .dismiss {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.25rem;
}

/* ---------- Thank-you overlay ---------- */

.thankyou {
  position: fixed;
  inset: 0;
  background: rgba(46, 52, 35, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 1rem;
  animation: fade-in 0.2s;
}
.thankyou[hidden] { display: none; }
.thankyou-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem 1.5rem 1.5rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.thankyou-card h2 {
  font-family: Georgia, serif;
  font-weight: 500;
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  color: var(--accent);
}
.thankyou-card p { margin: 0 0 1.25rem; color: var(--ink); }
.thankyou-card button {
  padding: 0.7rem 1.4rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}

/* ---------- Gallery ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin: 0.5rem 0 0.5rem;
}
.chip {
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.85rem;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.card {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 220px;
}
.card.new { animation: fade-in 0.5s; box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
@keyframes fade-in { from { opacity: 0; transform: translateY(-6px); } }

.card > figcaption { margin-top: auto; }

.card img {
  width: 100%;
  display: block;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #eee;
  cursor: zoom-in;
}
.card.kind-video img { cursor: pointer; }

.card.kind-audio { padding: 0; }
.audio-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 1rem;
  color: var(--accent);
}
.audio-play-badge {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.1s;
}
.audio-play-badge:active { transform: scale(0.95); }
.audio-play-badge svg { margin-left: 4px; }
.audio-play-badge.playing svg { margin-left: 0; }
.audio-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.card.kind-message blockquote {
  margin: 0;
  padding: 1rem;
  font-family: Georgia, serif;
  font-style: italic;
  color: var(--ink);
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.play-badge {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(30, 35, 20, 0.6);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  pointer-events: none;
}

figcaption {
  padding: 0.55rem 0.75rem 0.7rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  align-items: center;
  font-size: 0.85rem;
}
figcaption strong { font-weight: 600; }
.table-tag {
  background: var(--border);
  color: var(--ink);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
}
.card-note {
  flex-basis: 100%;
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.lightbox[hidden] { display: none; }
.lightbox-body {
  max-width: 100%;
  max-height: 100%;
  width: min(1200px, 100%);
  aspect-ratio: 16/10;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-body img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.lightbox-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.video-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.video-wrap video {
  flex: 1;
  width: 100%;
  max-height: 100%;
  background: #000;
  border-radius: 6px;
}
.drive-fallback {
  color: #fff;
  text-decoration: underline;
  font-size: 0.9rem;
  padding: 0.4rem 0.8rem;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
}
.drive-fallback.prominent {
  background: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.video-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--border);
  color: var(--muted);
  cursor: pointer;
}
.lightbox-close {
  position: absolute;
  top: 1rem; right: 1rem;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
  z-index: 2;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-size: 2.4rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 2;
}
.lightbox-nav:hover { background: rgba(255,255,255,0.28); }
.lightbox-nav.prev { left: 0.75rem; }
.lightbox-nav.next { right: 0.75rem; }

.message-wrap {
  max-width: min(800px, 92vw);
  padding: 1.5rem;
  color: #fff;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.lightbox-quote {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: clamp(1.25rem, 5vw, 2rem);
  line-height: 1.45;
  letter-spacing: 0.01em;
}
.lightbox-attrib {
  margin: 0;
  color: rgba(255,255,255,0.75);
  font-size: 1rem;
}

@media (max-width: 480px) {
  .lightbox-nav { width: 40px; height: 40px; font-size: 2rem; background: rgba(255,255,255,0.28); }
}

/* ---------- Admin ---------- */

.admin-grid .card { border-style: solid; }
.admin-grid .card.hidden-entry { opacity: 0.45; border-style: dashed; }
.actions {
  flex-basis: 100%;
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
}
.actions button {
  flex: 1;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
}
.actions button.danger { color: var(--danger); border-color: var(--danger); }

/* ---------- small screens ---------- */

@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  header h1 { font-size: 1.55rem; }
  .lang-toggle { top: 0.5rem; right: 0.5rem; }
}
