@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,700;1,9..40,400&family=Playfair+Display:wght@700;900&display=swap');

:root {
  --ink: #1e1c18;
  --muted: #6b6555;
  --bg: #f0ece2;
  --paper: #faf8f3;
  --line: #ddd8cc;
  --green: #2d6a4f;
  --mint: #d8ede3;
  --pine: #1b4332;
  --stone: #8d8375;
  --rock: #c9c2b4;
  --rust: #7a4419;
  --err: #a3363a;
  --peak: #4a5568;
  --snow: #f5f3ee;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

body::before {
  content: '';
  display: block;
  width: 100%;
  height: 6px;
  background: linear-gradient(90deg, var(--pine) 0%, var(--green) 40%, #52b788 70%, var(--rock) 100%);
}

.wrap { max-width: 960px; margin: 0 auto; padding: 28px 16px 80px; }

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: var(--bg);
  background-image: radial-gradient(ellipse 80% 40% at 50% 110%, rgba(45,106,79,.12) 0%, transparent 60%);
}
.auth-wrap { max-width: 420px; width: 100%; }

.auth-brand {
  text-align: center;
  margin-bottom: 24px;
}
.auth-brand h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(2.6rem, 8vw, 3.6rem);
  font-weight: 900;
  margin: 10px 0 4px;
  color: var(--pine);
  letter-spacing: -.02em;
}

.auth-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px 22px 18px;
  margin-top: 16px;
  box-shadow: 0 4px 24px rgba(30,28,24,.07), 0 1px 3px rgba(30,28,24,.04);
}
.auth-form { display: grid; gap: 10px; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}

h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 900;
  font-size: clamp(2rem, 5.5vw, 3rem);
  margin: 6px 0;
  color: var(--pine);
  letter-spacing: -.02em;
}
h2 { margin: 0; font-size: 1.2rem; font-weight: 700; color: var(--ink); }
p { margin: 4px 0 0; }

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--mint);
  color: var(--pine);
  font-weight: 700;
  font-size: .72rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 5px 11px;
  border-radius: 99px;
  border: 1px solid rgba(45,106,79,.18);
}
.pill::before {
  content: '▲';
  font-size: .5rem;
  opacity: .7;
}

.account { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  margin-top: 20px;
  box-shadow: 0 2px 12px rgba(30,28,24,.05), 0 1px 2px rgba(30,28,24,.03);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--green) 0%, var(--mint) 50%, transparent 100%);
  opacity: .5;
  border-radius: 22px 22px 0 0;
}

.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }

label {
  display: block;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin: 14px 0 5px;
}
input, textarea {
  width: 100%;
  font: inherit;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(45,106,79,.12);
}
textarea { min-height: 80px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; }

.score-input { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.score-input input[type=range] {
  flex: 1;
  accent-color: var(--green);
  height: 4px;
}
.scoreOut {
  min-width: 2ch;
  text-align: right;
  font-weight: 900;
  font-family: 'Playfair Display', serif;
  font-size: 1.25rem;
  color: var(--green);
}

button {
  border: 0;
  border-radius: 11px;
  padding: 11px 18px;
  background: var(--pine);
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  cursor: pointer;
  margin-top: 16px;
  letter-spacing: .01em;
  transition: background .15s, box-shadow .15s, transform .1s;
  box-shadow: 0 2px 8px rgba(27,67,50,.25);
}
button:hover { background: var(--green); box-shadow: 0 4px 16px rgba(27,67,50,.3); }
button:active { transform: translateY(1px); }
button.secondary {
  background: var(--snow);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(30,28,24,.08);
  border: 1px solid var(--line);
}
button.secondary:hover { background: var(--rock); }
button.small { padding: 7px 11px; margin-top: 0; font-size: .83rem; }

.flash { padding: 11px 15px; border-radius: 11px; margin: 14px 0 0; font-weight: 600; font-size: .93rem; }
.flash.ok { background: var(--mint); color: var(--pine); border: 1px solid rgba(45,106,79,.2); }
.flash.err { background: #f6e1e2; color: var(--err); border: 1px solid rgba(163,54,58,.2); }

.rank-list { display: grid; gap: 12px; margin-top: 16px; }

.rank-item {
  display: flex;
  gap: 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 11px 13px;
  align-items: center;
  background: var(--paper);
  transition: box-shadow .15s, transform .1s;
}
.rank-item:hover { box-shadow: 0 4px 16px rgba(30,28,24,.08); transform: translateY(-1px); }

.thumb {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 11px;
  background: var(--rock);
  flex-shrink: 0;
  border: 1.5px solid var(--line);
}

.rank-body { flex: 1; min-width: 0; }
.rank-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

.score {
  font-family: 'Playfair Display', serif;
  font-weight: 900;
  font-size: 1.35rem;
  color: var(--green);
  flex-shrink: 0;
}
.score.small {
  font-size: .98rem;
  padding: 4px 10px;
  background: var(--mint);
  border-radius: 8px;
  align-self: flex-start;
  white-space: nowrap;
  border: 1px solid rgba(45,106,79,.15);
}

.entries { display: grid; gap: 10px; margin-top: 14px; }

.entry {
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 13px 15px;
  background: var(--paper);
}
.entry-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.entry-items { display: grid; gap: 5px; margin-top: 10px; }
.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.entry-item:last-child { border-bottom: none; }
.entry-dish { flex: 1; min-width: 0; overflow-wrap: break-word; }
.entry-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  flex-shrink: 0;
}
.entry-item-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.photo-upload-form { margin: 0; }
.photo-upload-label {
  display: inline-block;
  cursor: pointer;
  font-size: .78rem;
  font-weight: 700;
  color: var(--green);
  border: 1px solid var(--mint);
  border-radius: 8px;
  padding: 4px 9px;
  white-space: nowrap;
  transition: background .14s;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
}
.photo-upload-label:hover { background: var(--mint); }
.photo-upload-label input[type=file] { display: none; }

.visit-form { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.visit-form label { margin: 0; }
.visit-form input { width: auto; }

.autocomplete-wrap { position: relative; }
.suggestions {
  display: none;
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  margin-top: 5px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 8px 28px rgba(30,28,24,.1);
}
.suggestions.open { display: block; }
.suggestion { padding: 10px 13px; cursor: pointer; font-size: .92rem; border-bottom: 1px solid var(--line); }
.suggestion:last-child { border-bottom: none; }
.suggestion:hover { background: var(--mint); }

.dish-row {
  border: 1.5px solid var(--line);
  border-radius: 15px;
  padding: 16px;
  margin-top: 14px;
  background: var(--snow);
}

.rate-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.rate-actions button { margin-top: 0; }
#addDishRow { margin-right: 10px; }

@media (max-width: 680px) {
  .grid2 { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr; }
  .top { flex-direction: column; padding-bottom: 12px; }
  .account { width: 100%; justify-content: space-between; }
  .head { flex-direction: row; align-items: center; }
  .dish-row { padding: 11px; }
  .dish-row .field { margin-bottom: 4px; }
  .score-input { flex-wrap: nowrap; gap: 8px; }
  .score-input input[type=range] { flex: 1; }
  .rank-item { padding: 9px; gap: 9px; }
  .thumb { width: 58px; height: 58px; }
  .rank-head { flex-wrap: wrap; gap: 6px; }
  .score { font-size: 1.1rem; }
  .entry-item { gap: 10px; }
  .score.small { font-size: .88rem; padding: 3px 8px; }
  .visit-form { flex-direction: column; align-items: flex-start; }
  .visit-form input { width: 100%; }
  .rate-actions { flex-direction: column; }
  .rate-actions button { width: 100%; }
  #addDishRow { width: 100%; margin-right: 0; }
}

.admin-link {
  display: inline-block;
  color: var(--green);
  font-weight: 700;
  text-decoration: none;
  padding: 6px 11px;
  border-radius: 9px;
  border: 1px solid var(--mint);
  font-size: .88rem;
  transition: background .14s;
}
.admin-link:hover { background: var(--mint); }

.table-wrap { overflow-x: auto; margin-top: 8px; }
.token-table { width: 100%; border-collapse: collapse; font-size: .91rem; }
.token-table th, .token-table td {
  text-align: left;
  padding: 10px 13px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.token-table th {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.token-table code {
  background: var(--snow);
  padding: 3px 7px;
  border-radius: 6px;
  font-size: .87rem;
  word-break: break-all;
  border: 1px solid var(--line);
}

.rank-item {
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 18px;
  background: rgba(255,255,255,.04);
  overflow: hidden;
  margin-bottom: 14px;
}

.rank-summary {
  list-style: none;
  cursor: pointer;
  padding: 16px 18px;
}

.rank-summary::-webkit-details-marker {
  display: none;
}

.rank-summary::after {
  content: "+";
  float: right;
  font-size: 1.2rem;
  opacity: .7;
}

.rank-item[open] .rank-summary::after {
  content: "−";
}

.rank-expand {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  padding: 0 18px 18px;
  align-items: start;
}

.rank-media {
  width: 100%;
}

.thumb-button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.thumb-large {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: 14px;
}

.thumb-placeholder {
  display: grid;
  place-items: center;
  min-height: 180px;
  border-radius: 14px;
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.65);
}

.rank-meta p {
  margin: 0 0 10px;
}

.image-modal[hidden] {
  display: none;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 20, .82);
  backdrop-filter: blur(6px);
}

.image-modal-content {
  position: relative;
  z-index: 2;
  width: min(92vw, 1100px);
  max-height: 90vh;
  margin: 4vh auto 0;
  display: grid;
  gap: 12px;
  justify-items: center;
}

.image-modal-content img {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 18px;
  object-fit: contain;
}

.image-modal-caption {
  color: #fff;
}

.image-modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 3;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 0;
  cursor: pointer;
  background: rgba(255,255,255,.14);
  color: #fff;
  font-size: 28px;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 700px) {
  .rank-expand {
    grid-template-columns: 1fr;
  }

  .thumb-large,
  .thumb-placeholder {
    height: 220px;
  }

  .rank-summary {
    padding: 14px;
  }
}

.rank-thumbs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.thumb-mini {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}