:root {
  --primary: #1c1c1e;
  --primary-2: #232326;
  --gold: #d4af37;
  --gold-soft: #b3922c;
  --accent: #c0392b;
  --ivory: #f5eeda;
  --ivory-2: #efe5c8;
  --ink: #2b2b2e;
  --muted: #8b8b90;
  --line: #3a3a3e;
  --silver: #b8b8bd;
  --caddy: #141416;
  --ring-gold: #c9a227;
  --ring-silver: #a9a9ae;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255,255,255,0.02), transparent 55%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.006) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.004) 0 2px, transparent 2px 5px),
    var(--primary);
  color: var(--ivory);
  font-family: "Avenir Next", "Segoe UI", -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  overflow: hidden;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Views ---------- */
.view {
  flex: 1;
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 18px calc(env(safe-area-inset-bottom, 0px) + 96px);
  display: none;
}
.view.active { display: block; -webkit-overflow-scrolling: touch; }

.view::-webkit-scrollbar { width: 0; }

/* ---------- Typography helpers ---------- */
.serif { font-family: Georgia, "Times New Roman", serif; }

/* ---------- Search bar ---------- */
.searchbar { position: sticky; top: 0; z-index: 5; padding-bottom: 10px; }
.searchbar input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0,0,0,0.28);
  color: var(--ivory);
  font-size: 15px;
  outline: none;
}
.searchbar input:focus { border-color: var(--gold); }
.searchbar input::placeholder { color: var(--muted); }

/* ---------- List & place cards ---------- */
.list { display: flex; flex-direction: column; gap: 18px; padding-top: 4px; }

.plate {
  position: relative;
  background: radial-gradient(circle at 50% 35%, #e8e3d2, #c9c3ae 65%, #ada68f 100%);
  border-radius: 50%;
  padding: 26px 20px 30px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.45), inset 0 2px 4px rgba(255,255,255,0.35), inset 0 -3px 6px rgba(0,0,0,0.25);
}
.plate::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.12);
  pointer-events: none;
}

.card {
  background: linear-gradient(180deg, var(--ivory), var(--ivory-2));
  color: var(--ink);
  border-radius: 6px 6px 10px 10px;
  padding: 14px 14px 12px;
  position: relative;
  transform: perspective(600px) rotateX(-3deg);
  box-shadow: 0 8px 20px rgba(0,0,0,0.45), inset 0 0 0 1px rgba(255,255,255,0.4);
  transition: transform 0.15s ease;
}
.card:active { transform: perspective(600px) rotateX(-2deg) translateY(1px); }

.card .title {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 21px;
  line-height: 1.15;
  background: linear-gradient(160deg, #8a6d1f, var(--gold) 60%, #6e5515);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 0 0 4px;
  word-break: break-word;
}

.card .stamp {
  display: inline-block;
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 1px 5px;
  margin-bottom: 8px;
}

.card .guests {
  color: var(--ink);
  font-size: 13px;
}

/* Edit form (inline) */
.inline-edit {
  margin-top: 10px;
  border-top: 1px dashed rgba(0,0,0,0.2);
  padding-top: 10px;
  display: none;
  flex-direction: column;
  gap: 8px;
}
.inline-edit.open { display: flex; }
.inline-edit input, .inline-edit textarea {
  width: 100%;
  border: 1px solid rgba(0,0,0,0.25);
  border-radius: 6px;
  padding: 8px 9px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
.inline-edit label { font-size: 12px; color: rgba(0,0,0,0.6); display: flex; flex-direction: column; gap: 3px; }
.inline-actions { display: flex; gap: 8px; }
.inline-actions button { flex: 1; padding: 8px; border: none; border-radius: 6px; font-weight: 600; font-size: 13px; cursor: pointer; }
.btn-save-inline { background: var(--gold); color: #1c1c1e; }
.btn-cancel-inline { background: #d9d2c0; color: var(--ink); }

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: flex-end;
}
.card-actions .edit { flex: 1; }
.card-actions button {
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.card-actions .btn-edit { background: #e7dfc8; color: #4a3c10; }
.card-actions .btn-del { background: transparent; border: 1px solid rgba(192,57,43,0.5); color: var(--accent); }

/* Past muted style */
.card.past { opacity: 0.62; filter: grayscale(0.6) sepia(0.2); }
.card.past::before {
  content: "PAST";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-14deg);
  font-family: Georgia, serif;
  font-size: 46px;
  letter-spacing: 0.12em;
  color: rgba(0,0,0,0.08);
  pointer-events: none;
  white-space: nowrap;
}

/* Empty state */
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty .fold {
  width: 110px;
  height: 72px;
  margin: 0 auto 16px;
  background: linear-gradient(160deg, #f0e9d0, #dcd2b0);
  border-radius: 4px 4px 8px 8px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.4), inset 0 0 0 1px rgba(255,255,255,0.4);
  transform: perspective(500px) rotateX(-6deg);
}
.empty p { margin: 4px 0; font-size: 14px; line-height: 1.5; }

/* ---------- Dashboard ---------- */
.dash-wrap { display: flex; flex-direction: column; gap: 24px; }

.counters { display: flex; gap: 16px; }
.counter { flex: 1; text-align: center; }
.charger {
  background: radial-gradient(circle at 50% 40%, #e6e0cf, #cfc9b2 70%, #b6af98 100%);
  border-radius: 50%;
  padding: 18px 12px 26px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.5), inset 0 2px 5px rgba(255,255,255,0.35), inset 0 -4px 8px rgba(0,0,0,0.2);
}
.ring {
  position: relative;
  width: 74px;
  height: 38px;
  margin: 6px auto 10px;
  border-radius: 50%;
  background: var(--ring-gold);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.3), 0 4px 10px rgba(0,0,0,0.4);
}
.ring.silver { background: var(--ring-silver); }
.ring .digit {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, serif;
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.counter .label { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-top: 2px; }

.next-block { text-align: center; }
.next-block .head { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.next-block .plate { max-width: 320px; margin: 0 auto; }
.next-block .card { text-align: left; }
.next-block .sub { color: rgba(0,0,0,0.6); font-size: 12px; margin-top: 8px; }

/* ---------- Create form ---------- */
#form-create { display: flex; flex-direction: column; gap: 14px; max-width: 420px; margin: 0 auto; }
#form-create h1 { font-family: Georgia, serif; font-style: italic; color: var(--gold); margin: 0 0 6px; font-size: 26px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; color: var(--muted); }
.field > span em { font-style: normal; color: var(--muted); opacity: 0.8; }
.field input, .field textarea {
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ivory);
  padding: 12px 13px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--gold); }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); }
.err { color: #e07b6b; font-size: 12px; min-height: 0; }
.err.show { color: #e07b6b; }
.field input.invalid, .field textarea.invalid { border-color: var(--accent); }

.btn-seal {
  margin-top: 6px;
  padding: 14px;
  border: none;
  border-radius: 100px;
  background: radial-gradient(circle at 35% 30%, var(--gold), var(--gold-soft));
  color: #1c1c1e;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(212,175,55,0.3);
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: calc(env(safe-area-inset-right, 0px) + 18px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 92px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 35% 30%, var(--gold), var(--gold-soft));
  color: #1c1c1e;
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(212,175,55,0.45);
  z-index: 30;
  display: none;
}
.fab.show { display: block; }

/* ---------- Bottom caddy ---------- */
.caddy {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding: 0 22px env(safe-area-inset-bottom, 0px);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  background: linear-gradient(180deg, var(--caddy), #0c0c0d);
  box-shadow: 0 -4px 14px rgba(0,0,0,0.5);
  z-index: 40;
}
.piece {
  position: relative;
  width: 60px;
  border: none;
  background: transparent;
  color: #6f6f74;
  cursor: pointer;
  padding: 0;
  transition: transform 0.18s ease, color 0.18s ease, filter 0.18s ease;
  filter: grayscale(0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 14px;
}
.piece svg { width: 26px; height: 26px; fill: currentColor; }
.piece:active { transform: translateY(-2px); }
.piece.active {
  color: var(--gold);
  filter: drop-shadow(0 -2px 5px rgba(212,175,55,0.45));
  transform: translateY(-7px);
}
.piece.active::after {
  content: "";
  position: absolute;
  bottom: 8px;
  width: 34px;
  height: 5px;
  border-radius: 50%;
  background: rgba(0,0,0,0.4);
  filter: blur(2px);
}

/* ---------- Modal ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 24px;
}
.modal-mask[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 320px;
  background: var(--ivory);
  color: var(--ink);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.5);
}
.modal h3, .modal p { margin: 0 0 10px; }
.modal .modal-title { font-family: Georgia, serif; font-size: 19px; }
.modal .modal-msg { color: rgba(0,0,0,0.6); font-size: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions button { flex: 1; padding: 11px; border-radius: 8px; border: none; font-weight: 600; font-size: 14px; cursor: pointer; }
.btn.ghost { background: #e0d9c6; color: var(--ink); }
.btn.danger { background: var(--accent); color: #fff; }

@media (min-width: 700px) {
  .view { padding-left: 8vw; padding-right: 8vw; }
  .caddy { max-width: 480px; left: 50%; transform: translateX(-50%); border-radius: 0; }
  .fab { right: calc((100vw - 480px)/2 + 18px); }
}