:root {
  --wine: #722f37;
  --wine-dark: #561f27;
  --brown: #a0714f;
  --brown-soft: #f3e8dc;
  --cream: #fbf6ef;
  --ink: #2b1d1f;
  --muted: #7b6a6c;
  --line: #eadfd6;
  --ok: #4f7a4a;
  --ok-soft: #e7efe1;
  --bad: #c0392b;
  --bad-soft: #fbe5e2;
  --warn-soft: #fff4cc;
  --card: #ffffff;
  --radius: 18px;
  --shadow: 0 6px 22px rgba(86, 31, 39, 0.09);
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -10%, rgba(160, 113, 79, 0.18), transparent 45%),
    radial-gradient(circle at 110% 10%, rgba(114, 47, 55, 0.12), transparent 40%),
    var(--cream);
  background-attachment: fixed;
  min-height: 100vh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
body.page-auth, body.admin { padding-bottom: 32px; }
a { color: var(--wine); }
img { max-width: 100%; }
[hidden] { display: none !important; }

.page, .auth { max-width: 640px; margin: 0 auto; padding: 16px; }
.auth { padding-top: 24px; }
.page-title { font-family: var(--serif); color: var(--wine); font-size: 1.8rem; margin: 8px 0 4px; }
.section-title { font-family: var(--serif); color: var(--wine); font-size: 1.25rem; margin: 22px 4px 10px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin: 14px 0;
  border: 1px solid rgba(160, 113, 79, 0.18);
}
.card-title { font-family: var(--serif); margin: 0 0 10px; font-size: 1.5rem; color: var(--wine); }
.card-title.small { font-size: 1.15rem; }
.center { text-align: center; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.88rem; margin: 12px 0 0; }
.back { display: inline-block; margin: 4px 0 6px; text-decoration: none; font-weight: 600; }
.topline { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 0; }

/* Hero / rich text written by Chiara */
.hero {
  background: linear-gradient(160deg, #fff 0%, #fff 55%, var(--brown-soft) 100%);
  border-top: 5px solid var(--brown);
}
.rich { overflow-wrap: anywhere; }
.rich > :first-child { margin-top: 0; }
.rich > :last-child { margin-bottom: 0; }
.rich h1, .rich h2, .rich h3 { font-family: var(--serif); line-height: 1.2; margin: 0.4em 0; }
.rich h1 { font-size: 2rem; }
.rich h2 { font-size: 1.5rem; }
.rich p { margin: 0.5em 0; }
.rich img { display: block; margin: 8px auto; border-radius: 12px; height: auto; }
.rich ul, .rich ol { padding-left: 1.4em; }
.rich .ql-size-small { font-size: 0.75em; }
.rich .ql-size-large { font-size: 1.5em; }
.rich .ql-size-huge { font-size: 2.4em; line-height: 1.15; }
.rich .ql-align-center { text-align: center; }
.rich .ql-align-right { text-align: right; }
.rich .ql-align-justify { text-align: justify; }

/* Forms */
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-weight: 600; font-size: 0.95rem; }
input, textarea, select {
  font: inherit;
  font-size: 17px; /* >=16px: no zoom on iPhone */
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: #fffdfb;
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"] { min-height: 52px; }
input:focus, textarea:focus { outline: none; border-color: var(--brown); box-shadow: 0 0 0 4px rgba(160, 113, 79, 0.2); }
.search { margin: 6px 0 4px; border-radius: 999px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  color: var(--wine);
  background: var(--brown-soft);
  transition: transform 0.08s ease, filter 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn-block { display: flex; width: 100%; margin: 12px 0; }
.btn-xl { min-height: 64px; font-size: 1.15rem; border-radius: 18px; }
.btn-primary { background: linear-gradient(135deg, var(--wine), var(--wine-dark)); color: #fff; box-shadow: 0 6px 16px rgba(114, 47, 55, 0.3); }
.btn-gold { background: linear-gradient(135deg, #b88660, var(--brown)); color: #fff; box-shadow: 0 6px 16px rgba(160, 113, 79, 0.35); }
.btn-ghost { background: #fff; border: 1.5px solid var(--line); color: var(--wine); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-bad { background: var(--bad); color: #fff; }
.btn-small { min-height: 40px; padding: 8px 14px; font-size: 0.9rem; border-radius: 12px; }
.btn.disabled { opacity: 0.5; pointer-events: none; }
.link-btn { background: none; border: 0; font: inherit; color: var(--wine); text-decoration: underline; cursor: pointer; padding: 6px; }
.icon-btn { background: #fff; border: 1px solid var(--line); border-radius: 10px; font-size: 1.1rem; min-width: 40px; min-height: 40px; cursor: pointer; }
.icon-btn:disabled { opacity: 0.3; }
.danger-text { color: var(--bad) !important; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Messages */
.alert { background: var(--bad-soft); color: #8a2318; padding: 12px 14px; border-radius: 12px; font-size: 0.95rem; }
.flash {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translateX(-50%);
  z-index: 50; width: min(92vw, 520px); padding: 14px 18px; border-radius: 14px;
  font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15); transition: opacity 0.4s, transform 0.4s;
}
.flash-ok { background: var(--ok); color: #fff; }
.flash-error { background: var(--bad); color: #fff; }
.flash.hide { opacity: 0; transform: translate(-50%, -20px); pointer-events: none; }
.closed-banner { background: var(--ink); color: #fff; text-align: center; padding: 10px 16px; font-weight: 600; font-size: 0.95rem; }

/* Welcome */
.big-emoji { font-size: 3.5rem; }
.creds { display: grid; gap: 10px; margin: 16px 0; }
.creds div { background: var(--brown-soft); border-radius: 14px; padding: 12px; display: grid; }
.creds span { font-size: 0.85rem; color: var(--muted); }
.creds strong { font-size: 1.5rem; font-family: ui-monospace, Menlo, monospace; color: var(--wine); word-break: break-all; user-select: all; }

/* Progress */
.progress { height: 14px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--brown), var(--wine)); border-radius: inherit; transition: width 0.3s; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.progress-head strong { font-size: 1.4rem; color: var(--wine); }
.upload-progress { margin-top: 8px; }

/* Goal list */
.goal-list, .rank-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 10px; }
.goal-item, .rank-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; min-height: 72px;
  background: #fff; border-radius: 16px; box-shadow: var(--shadow); text-decoration: none; color: var(--ink);
  border: 1.5px solid transparent;
}
.goal-item.done { border-color: rgba(79, 122, 74, 0.35); background: linear-gradient(90deg, var(--ok-soft), #fff 60%); }
.goal-num {
  flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brown-soft); color: var(--wine); font-weight: 800;
}
.goal-item.done .goal-num { background: var(--ok); color: #fff; }
.goal-text { flex: 1; display: grid; min-width: 0; }
.goal-text small { color: var(--muted); }
.goal-item.done .goal-text small { color: var(--ok); font-weight: 600; }
.goal-thumb { width: 52px; height: 52px; border-radius: 12px; object-fit: cover; flex: none; }
.goal-arrow { font-size: 1.4rem; opacity: 0.6; }

/* Goal detail */
.goal-badge { display: inline-block; background: var(--brown-soft); color: var(--wine); font-weight: 700; font-size: 0.8rem; padding: 4px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.04em; }
.goal-head .card-title { margin-top: 10px; }
.goal-desc { white-space: pre-line; }
.status { font-weight: 700; color: var(--muted); margin: 10px 0 0; }
.status-done { color: var(--ok); }
.goal-head.done { border-top: 5px solid var(--ok); }
.upload-card { padding: 14px 18px; }
.upload-btn { cursor: pointer; }

.photo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 10px 0; }
.photo { margin: 0; background: #fff; border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.photo img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--line); }
.photo figcaption { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 8px 10px; font-size: 0.8rem; color: var(--muted); }
.photo-deleted img { filter: grayscale(1); opacity: 0.6; }
.photo-deleted figcaption { flex-direction: column; align-items: stretch; }
.deleted-box summary { cursor: pointer; font-weight: 700; padding: 4px 0; }

/* Foto della serata */
.party-card { border-top: 5px solid var(--ok); background: linear-gradient(160deg, #fff 55%, var(--ok-soft)); }
.party-card .card-title { color: var(--ok); }
.photo-owner { font-weight: 700; color: var(--ink); }

/* Rules */
.rules-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.rules-list li { display: flex; gap: 12px; align-items: flex-start; }
.rule-icon { font-size: 1.5rem; line-height: 1.2; }

/* Footer */
.credits { text-align: center; color: var(--muted); font-size: 0.78rem; letter-spacing: 0.04em; padding: 18px 16px 8px; opacity: 0.85; }
.credits strong { color: var(--wine); }

/* Bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a { flex: 1; display: grid; justify-items: center; gap: 2px; padding: 6px; font-size: 0.78rem; font-weight: 600; color: var(--muted); text-decoration: none; border-radius: 12px; }
.tabbar a span { font-size: 1.4rem; }
.tabbar a.active { color: var(--wine); background: var(--brown-soft); }

/* Admin */
.admin-header { position: sticky; top: 0; z-index: 30; background: var(--wine); color: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); }
.admin-top { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px 0; max-width: 900px; margin: 0 auto; }
.admin-top .link-btn { color: #fff; }
.admin-tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; padding: 8px 6px 10px; max-width: 900px; margin: 0 auto; }
.admin-tabs a { display: grid; justify-items: center; color: #f1dfe1; text-decoration: none; font-weight: 600; font-size: 0.74rem; padding: 6px 2px; border-radius: 12px; }
.admin-tabs a span { font-size: 1.25rem; line-height: 1.2; }
.admin-tabs a.active { background: #fff; color: var(--wine); }
.admin .page { max-width: 900px; }

.legend summary { font-weight: 700; cursor: pointer; }
.legend ul { margin: 10px 0 0; padding-left: 1.2em; display: grid; gap: 6px; font-size: 0.95rem; }

.rank-item.podium { border-color: var(--brown); background: linear-gradient(90deg, var(--brown-soft), #fff 70%); }
.rank-item.tied { box-shadow: var(--shadow), inset 4px 0 0 #e0b400; }
.rank-pos { flex: none; width: 38px; text-align: center; font-weight: 800; font-size: 1.25rem; color: var(--wine); }
.rank-name { flex: 1; display: grid; min-width: 0; }
.rank-name small { color: var(--muted); font-size: 0.82rem; }
.rank-score { text-align: right; display: grid; }
.rank-score strong { font-size: 1.6rem; line-height: 1; color: var(--wine); }
.rank-score small { color: var(--muted); font-size: 0.8rem; }
.tag { display: inline-block; background: var(--brown-soft); color: #6b4a30; border-radius: 999px; padding: 1px 8px; font-size: 0.78rem; font-weight: 700; }
.tag-tie { background: var(--warn-soft); color: #7a5b00; }
.tag-bad { background: var(--bad-soft); color: var(--bad); }

.profile-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 8px 0; }
.profile-stats div { background: var(--cream); border-radius: 12px; padding: 10px; display: grid; text-align: center; }
.profile-stats span { font-size: 0.75rem; color: var(--muted); }
.profile-stats strong { font-size: 1.05rem; color: var(--wine); }

.review-card { border-left: 6px solid var(--line); }
.review-card.is-valid { border-left-color: var(--ok); }
.review-card.is-invalid { border-left-color: var(--bad); background: #fffafa; }
.review-card.is-pending { border-left-color: var(--brown); }
.review-card.is-empty { opacity: 0.65; }
.review-head { display: flex; gap: 12px; align-items: center; }
.review-head div { display: grid; }
.review-head small { color: var(--muted); }
.review-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }

.goal-edit-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.goal-edit-head .move { margin-left: auto; display: flex; gap: 6px; }
.goal-edit .form { gap: 8px; }

.editor { min-height: 160px; background: #fff; font-size: 16px; }
.ql-toolbar.ql-snow { border-radius: 12px 12px 0 0; border-color: var(--line); flex-wrap: wrap; }
.ql-container.ql-snow { border-radius: 0 0 12px 12px; border-color: var(--line); }
.sticky-save { position: sticky; bottom: 0; padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--cream) 30%); }

@media (min-width: 560px) {
  .photo-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Photo viewer */
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(20, 10, 12, 0.94);
  display: grid; place-items: center; padding: calc(16px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; touch-action: pinch-zoom; }
.lightbox-close {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 48px; height: 48px;
  border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.9); color: var(--wine); font-size: 1.4rem; cursor: pointer;
}
body.no-scroll { overflow: hidden; }
