:root {
  --garnet: #8e1d4a;
  --wine: #5a0f35;
  --gamay: #2e0b3d;
  --pink: #ff4f9a;
  --pink-dark: #b02a68;
  --yellow: #ffcf3a;
  --mint: #5ee0c0;
  --glass: rgba(255, 255, 255, 0.12);
  --glass-strong: rgba(255, 255, 255, 0.2);
  --text: #fff;
  --muted: rgba(255, 255, 255, 0.7);
  --radius: 22px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Fredoka', system-ui, sans-serif;
  color: var(--text);
  background: var(--gamay) radial-gradient(circle at 20% 0%, var(--garnet) 0%, var(--wine) 40%, var(--gamay) 100%) fixed;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
a { color: inherit; }

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px 24px;
}
.loading { font-size: 64px; text-align: center; padding-top: 30vh; animation: bounce 1s infinite; }

h1, h2 { margin: 0 0 14px; font-weight: 700; line-height: 1.1; }
h1 { font-size: 30px; }
h2 { font-size: 24px; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- Buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 13px 26px;
  background: var(--pink); color: #fff; font-weight: 700; font-size: 17px;
  box-shadow: 0 5px 0 var(--pink-dark); transition: transform .1s, box-shadow .1s, opacity .2s;
  text-decoration: none;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--pink-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.block { display: flex; width: 100%; }
.btn.yellow { background: var(--yellow); color: var(--wine); box-shadow: 0 5px 0 #c99a12; }
.btn.ghost { background: var(--glass); box-shadow: none; }
.btn.danger { background: #e5334b; box-shadow: 0 5px 0 #92202f; }
.btn.small { padding: 8px 16px; font-size: 14px; }

.field {
  width: 100%; border: 2px solid transparent; border-radius: 16px;
  background: var(--glass); padding: 14px 16px; font-size: 17px; outline: none;
  transition: border-color .2s, background .2s;
}
.field:focus { border-color: var(--yellow); background: var(--glass-strong); }
.field::placeholder { color: var(--muted); }
textarea.field { resize: vertical; min-height: 84px; }
label.lbl { display: block; font-weight: 600; margin: 18px 0 8px; }

/* ---------- Welcome & countdown ---------- */
.hero { text-align: center; padding-top: 6vh; }
.hero .logo { font-size: 72px; display: inline-block; animation: wobble 3s ease-in-out infinite; }
.hero h1 { font-size: 46px; margin: 8px 0 4px; letter-spacing: -0.5px; }
.hero h1 span { color: var(--yellow); }
.hero p { color: var(--muted); margin: 0 0 30px; font-size: 18px; }
.hero form { display: grid; gap: 16px; max-width: 360px; margin: 0 auto; }

.countdown { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-width: 420px; margin: 26px auto 18px; }
.countdown div {
  background: var(--glass); border-radius: 18px; padding: 14px 4px 10px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .25);
}
.countdown div:nth-child(odd) { transform: rotate(-2deg); }
.countdown div:nth-child(even) { transform: rotate(2deg); }
.countdown b { display: block; font-size: 38px; line-height: 1; color: var(--yellow); font-variant-numeric: tabular-nums; }
.countdown small { color: var(--muted); font-size: 13px; }
.opening-date { font-size: 18px; font-weight: 600; }
.floaters { font-size: 34px; margin-top: 34px; display: flex; justify-content: center; gap: 22px; }
.floaters span { animation: bounce 1.6s ease-in-out infinite; }
.floaters span:nth-child(2) { animation-delay: .2s; }
.floaters span:nth-child(3) { animation-delay: .4s; }
.floaters span:nth-child(4) { animation-delay: .6s; }

/* ---------- Wine grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; }
.card {
  display: block; text-decoration: none; background: var(--glass); border-radius: var(--radius);
  overflow: hidden; box-shadow: 0 10px 24px rgba(0, 0, 0, .3); transition: transform .2s;
  position: relative;
}
.card:nth-child(3n+1) { transform: rotate(-1.5deg); }
.card:nth-child(3n+2) { transform: rotate(1deg); }
.card:nth-child(3n) { transform: rotate(-.5deg); }
.card:active { transform: scale(.97); }
.card img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: var(--glass); }
.card .info { padding: 10px 12px 12px; }
.card .name { font-weight: 600; font-size: 16px; line-height: 1.2; overflow-wrap: anywhere; }
.card .by { color: var(--muted); font-size: 13px; }
.badge {
  position: absolute; top: 10px; right: 10px; border-radius: 999px; padding: 4px 10px;
  font-size: 12px; font-weight: 700; background: var(--yellow); color: var(--wine);
}
.badge.done { background: var(--mint); }
.empty { text-align: center; padding: 40px 10px; }
.empty .big { font-size: 64px; }
.list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }

/* ---------- Wine sheet ---------- */
.back { display: inline-block; text-decoration: none; color: var(--muted); margin-bottom: 12px; }
.sheet-photo {
  width: 100%; max-height: 52vh; object-fit: cover; border-radius: var(--radius);
  transform: rotate(-1.5deg); box-shadow: 0 12px 30px rgba(0, 0, 0, .35); margin: 4px 0 18px;
  background: var(--glass);
}
.sheet-title { overflow-wrap: anywhere; }
.admin-bar { display: flex; gap: 10px; margin: 0 0 16px; flex-wrap: wrap; }
.crit { margin: 16px 0; }
.crit .crit-name { font-weight: 600; font-size: 17px; }
.crit .crit-hint { color: var(--muted); font-size: 13px; margin-left: 4px; }
.pills { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; margin-top: 8px; }
.pills button {
  aspect-ratio: 1; border: 0; border-radius: 50%; background: var(--glass); font-weight: 600;
  font-size: clamp(11px, 3.4vw, 16px); padding: 0; transition: transform .15s, background .15s;
}
.pills button.on { background: var(--yellow); color: var(--wine); transform: scale(1.2); }
.crit.bonbon .pills button.on { background: var(--pink); color: #fff; }
.save-row { margin: 22px 0 8px; }

.others { margin-top: 30px; }
.other { background: var(--glass); border-radius: 18px; padding: 12px 14px; margin-bottom: 10px; }
.other .who { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.other .scores { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 14px; color: var(--muted); margin-top: 4px; }
.other .remark { margin-top: 6px; font-style: italic; overflow-wrap: anywhere; }

/* ---------- Ranking ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; margin: 0 -16px; padding-left: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips a {
  flex: none; text-decoration: none; padding: 8px 14px; border-radius: 999px;
  background: var(--glass); font-weight: 500; white-space: nowrap;
}
.chips a.on { background: var(--yellow); color: var(--wine); font-weight: 700; }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 26px 0 18px; }
.podium a { flex: 1; max-width: 140px; text-align: center; text-decoration: none; }
.podium img {
  width: 76px; height: 76px; margin: 0 auto 6px; border-radius: 50%; object-fit: cover;
  border: 4px solid #fff; box-shadow: 0 6px 16px rgba(0, 0, 0, .35); background: var(--glass);
}
.podium .p1 img { width: 96px; height: 96px; border-color: var(--yellow); }
.podium .pname { font-weight: 600; font-size: 14px; line-height: 1.15; overflow-wrap: anywhere; min-height: 2.3em; }
.podium .pscore { color: var(--yellow); font-weight: 700; }
.podium .step {
  margin-top: 6px; border-radius: 16px 16px 0 0; background: var(--glass-strong);
  display: flex; justify-content: center; padding-top: 8px; font-size: 28px;
}
.podium .p1 .step { height: 104px; background: linear-gradient(var(--yellow), rgba(255, 207, 58, .25)); }
.podium .p2 .step { height: 76px; }
.podium .p3 .step { height: 54px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--glass); border-radius: 16px; text-decoration: none;
}
.row img { width: 44px; height: 44px; border-radius: 12px; object-fit: cover; flex: none; background: var(--glass); }
.row .rank { width: 24px; font-weight: 700; text-align: center; flex: none; }
.row .rname { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.row .rvotes { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.row .rscore { font-weight: 700; color: var(--yellow); font-size: 18px; }
.section-title { margin: 26px 0 10px; font-size: 18px; color: var(--muted); font-weight: 600; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--mint); font-weight: 600; }
.live::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--mint); animation: pulse 1.5s infinite; }

/* ---------- Add wine ---------- */
.photo-pick {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 220px; border: 3px dashed var(--glass-strong); border-radius: var(--radius);
  background: var(--glass); cursor: pointer; text-align: center; overflow: hidden; position: relative;
}
.photo-pick .big { font-size: 54px; }
.photo-pick img { width: 100%; max-height: 50vh; object-fit: cover; }
.photo-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.add-form { display: grid; gap: 4px; }
.add-form .btn { margin-top: 22px; }

/* ---------- Tab bar & footer ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(30, 6, 30, .55); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid rgba(255, 255, 255, .08);
}
#tabbar[hidden] { display: none; }
#tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; font-size: 12px; color: var(--muted); font-weight: 500;
}
#tabbar a span { font-size: 22px; transition: transform .2s; }
#tabbar a.on { color: var(--yellow); }
#tabbar a.on span { transform: scale(1.2) translateY(-2px); }
#footer {
  max-width: 720px; margin: 0 auto; padding: 0 16px calc(var(--tabbar-h) + 24px);
  text-align: center; font-size: 13px; color: var(--muted);
}
#footer button { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 4px; }

/* ---------- Modal & toast ---------- */
#modal {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(20, 0, 20, .6); backdrop-filter: blur(4px);
}
#modal[hidden] { display: none; }
#modal form {
  width: 100%; max-width: 380px; background: linear-gradient(160deg, var(--garnet), var(--gamay));
  border-radius: 26px; padding: 22px; box-shadow: 0 20px 50px rgba(0, 0, 0, .5); animation: pop .25s;
}
#modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
#modal .error { color: var(--yellow); min-height: 1.2em; margin-top: 8px; font-size: 14px; }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); z-index: 40;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--yellow); color: var(--wine); font-weight: 600; padding: 12px 20px; border-radius: 999px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .35); animation: toastIn .25s;
}
#toast[hidden] { display: none; }

/* ---------- Confetti ---------- */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
#confetti i {
  position: absolute; top: -20px; width: 9px; height: 15px; border-radius: 3px;
  animation: fall 1.4s cubic-bezier(.25, .6, .4, 1) forwards;
}

@keyframes fall {
  to { transform: translate(var(--dx), 105vh) rotate(var(--rot)); opacity: .8; }
}
@keyframes toastIn { from { transform: translateX(-50%) scale(.8); opacity: 0; } }
@keyframes pop { 0% { transform: scale(.8); } 60% { transform: scale(1.08); } }
.pills button.on { animation: popOn .3s; }
@keyframes popOn { 0% { transform: scale(.9); } 60% { transform: scale(1.35); } 100% { transform: scale(1.2); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes wobble { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
