:root {
  --paper: #f4ecdf;
  --paper-2: #ece0cd;
  --ink: #3b3128;
  --ink-soft: #7a6c5d;
  --felt-1: #2e4a43;
  --felt-2: #1f3531;
  --amber: #d9a441;
  --amber-deep: #b07f24;
  --card-back-1: #3d5a52;
  --card-back-2: #2a423b;
  --card-w: 168px;
  --card-h: 251px;
  --radius: 13px;
  --shadow: 0 6px 18px rgba(20, 18, 12, 0.35);
  --font-serif: "Lora", Georgia, "Times New Roman", serif;
  --font-sans: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--paper);
  background-image:
    radial-gradient(circle at 18% 12%, rgba(217, 164, 65, 0.10), transparent 42%),
    radial-gradient(circle at 85% 92%, rgba(46, 74, 67, 0.08), transparent 50%);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- header ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.4rem;
  padding: 1.3rem 2rem 0.7rem;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.85rem; }

.brand-mark {
  flex: none;
  width: 52px;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  line-height: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #3d5a52, #243b35);
  box-shadow: inset 0 0 0 1.5px rgba(244, 236, 223, 0.25), 0 3px 8px rgba(31, 53, 49, 0.3);
}

h1 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: clamp(1.55rem, 3.2vw, 2.2rem);
  line-height: 1.05;
  margin: 0;
  letter-spacing: 0.005em;
  color: var(--ink);
}

.tagline {
  margin: 0.25rem 0 0;
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 0.9rem;
  letter-spacing: 0.005em;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- buttons ---------- */

.ghost-btn, .solid-btn {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: 999px;
  padding: 0.5rem 1.05rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.ghost-btn {
  background: transparent;
  border: 1.5px solid rgba(59, 49, 40, 0.3);
  color: var(--ink);
}
.ghost-btn:hover { background: rgba(59, 49, 40, 0.07); }

.solid-btn {
  background: var(--felt-1);
  border: 1.5px solid var(--felt-1);
  color: #f6efe2;
  box-shadow: 0 4px 12px rgba(46, 74, 67, 0.3);
}
.solid-btn:hover { transform: translateY(-1px); background: var(--felt-2); }

.ghost-btn.small, .solid-btn.small { font-size: 0.78rem; padding: 0.36rem 0.82rem; }

.solid-btn.is-disabled, .ghost-btn.is-disabled { opacity: 0.5; pointer-events: none; }

/* ---------- intro + intention ---------- */

.intro {
  max-width: 760px;
  margin: 0;
  padding: 0.2rem 2rem 0.4rem;
  color: var(--ink-soft);
  font-size: 0.96rem;
  line-height: 1.55;
}

.intention {
  padding: 0.7rem 2rem 1rem;
  max-width: 760px;
}

.intention label {
  display: block;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}

.intention .optional { font-weight: 500; text-transform: none; letter-spacing: 0; }

#intention-input {
  width: 100%;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.5);
  border: none;
  border-bottom: 2px solid rgba(59, 49, 40, 0.28);
  border-radius: 7px 7px 0 0;
  padding: 0.55rem 0.7rem;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
#intention-input:focus { border-bottom-color: var(--amber-deep); background: rgba(255, 255, 255, 0.72); }
#intention-input::placeholder { color: var(--ink-soft); opacity: 0.7; }

/* ---------- shared banner ---------- */

.shared-banner {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin: 0 2rem 0.4rem;
  padding: 0.55rem 1rem;
  background: rgba(217, 164, 65, 0.16);
  border: 1px solid rgba(176, 127, 36, 0.35);
  border-radius: 10px;
  font-size: 0.9rem;
  color: var(--ink);
}

/* ---------- table ---------- */

.table {
  position: relative;
  flex: 1;
  margin: 0.4rem 1.4rem 1rem;
  min-height: 480px;
  border-radius: 22px;
  background: radial-gradient(ellipse at 50% 28%, var(--felt-1), var(--felt-2) 85%);
  box-shadow:
    inset 0 0 60px rgba(0, 0, 0, 0.35),
    inset 0 0 4px rgba(255, 255, 255, 0.12),
    0 10px 30px rgba(31, 53, 49, 0.35);
  overflow: hidden;
  touch-action: none;
}

.table::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px dashed rgba(244, 236, 223, 0.16);
  border-radius: 16px;
  pointer-events: none;
}

/* ---------- deck ---------- */

.deck-col {
  position: absolute;
  left: 34px;
  top: 32px;
  width: var(--card-w);
  display: flex;
  flex-direction: column;
  gap: 9px;
  z-index: 5;
}

.deck {
  position: relative;
  width: 100%;
  height: var(--card-h);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}

.deck-card {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 50% 42%, rgba(244, 236, 223, 0.14) 0 18%, transparent 19%),
    repeating-linear-gradient(45deg, rgba(244, 236, 223, 0.06) 0 8px, transparent 8px 16px),
    linear-gradient(160deg, var(--card-back-1), var(--card-back-2));
  border: 2px solid rgba(244, 236, 223, 0.5);
  box-shadow: var(--shadow);
}

.deck-card::after {
  content: "🦝";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2.6rem;
  opacity: 0.92;
  filter: grayscale(0.2);
}

.deck-card:nth-child(1) { transform: translate(7px, 7px) rotate(2.5deg); }
.deck-card:nth-child(2) { transform: translate(3px, 3px) rotate(-1.5deg); }
.deck-card:nth-child(3) { transform: translate(0, 0); transition: transform 0.18s ease; }

.deck:hover .deck-card:nth-child(3),
.deck:focus-visible .deck-card:nth-child(3) { transform: translate(-3px, -5px) rotate(-2deg); }

.deck-label {
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(244, 236, 223, 0.78);
  margin-top: 2px;
}

.deck.empty { cursor: default; }
.deck.empty .deck-card:nth-child(1),
.deck.empty .deck-card:nth-child(2) { opacity: 0.4; }
.deck.empty .deck-card:nth-child(3) { opacity: 0.4; }

.deck-count {
  color: rgba(244, 236, 223, 0.82);
  line-height: 1.4;
  margin-top: 2px;
}
.deck-count strong { display: block; font-family: var(--font-serif); font-size: 1rem; font-weight: 600; }
.deck-count span { font-size: 0.78rem; color: rgba(244, 236, 223, 0.6); }

.deck-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 3px; }
.felt-btn {
  flex: 1 1 auto;
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.42rem 0.5rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  color: #f3ece0;
  background: rgba(244, 236, 223, 0.12);
  border: 1px solid rgba(244, 236, 223, 0.32);
  transition: background 0.15s ease, transform 0.12s ease;
}
.felt-btn:hover { background: rgba(244, 236, 223, 0.22); transform: translateY(-1px); }

/* ---------- cards on the table ---------- */

.card {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  perspective: 1000px;
  cursor: grab;
  z-index: 10;
  touch-action: none;
}
.card.dragging { cursor: grabbing; }
.card.dragging .card-inner { box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5); }

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.4, 0.1, 0.2, 1), box-shadow 0.2s ease;
  box-shadow: var(--shadow);
}
.card.face-down .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

.card-front { background: var(--paper); border: 4px solid #fdf8ee; }
.card-front img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }

.card-back {
  transform: rotateY(180deg);
  background:
    radial-gradient(circle at 50% 42%, rgba(244, 236, 223, 0.14) 0 18%, transparent 19%),
    repeating-linear-gradient(45deg, rgba(244, 236, 223, 0.06) 0 8px, transparent 8px 16px),
    linear-gradient(160deg, var(--card-back-1), var(--card-back-2));
  border: 2px solid rgba(244, 236, 223, 0.5);
}
.card-back::after {
  content: "🦝";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2.6rem;
  opacity: 0.92;
  filter: grayscale(0.2);
}

@keyframes deal {
  from { transform: translate(var(--deal-dx, -200px), var(--deal-dy, 0)) rotate(0deg) scale(0.95); }
  to   { transform: translate(0, 0) rotate(var(--tilt, 0deg)) scale(1); }
}
.card { transform: rotate(var(--tilt, 0deg)); }
.card.dealing { animation: deal 0.55s cubic-bezier(0.3, 0.8, 0.3, 1); }

/* ---------- zoom lightbox ---------- */

.zoom {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: rgba(20, 24, 21, 0.86);
  backdrop-filter: blur(3px);
  padding: 4vh 4vw;
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.zoom img {
  max-width: min(92vw, 560px);
  max-height: 90vh;
  border-radius: 16px;
  border: 6px solid #fdf8ee;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

.zoom-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 16px;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1.5px solid rgba(246, 239, 226, 0.6);
  background: rgba(0, 0, 0, 0.25);
  color: #f6efe2;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

/* ---------- modals ---------- */

.modal {
  max-width: 470px;
  width: calc(100% - 2rem);
  border: none;
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  padding: 1.6rem 1.7rem;
  box-shadow: 0 24px 70px rgba(20, 18, 12, 0.5);
}
.modal::backdrop { background: rgba(26, 30, 26, 0.55); backdrop-filter: blur(2px); }
.modal h2 { font-family: var(--font-serif); font-weight: 600; margin: 0 0 0.6rem; font-size: 1.4rem; }
.modal p, .modal li { font-size: 0.95rem; line-height: 1.55; }
.modal ol { padding-left: 1.2rem; }
.modal li { margin-bottom: 0.35rem; }
.modal .fine { color: var(--ink-soft); font-size: 0.82rem; }
.modal form { text-align: right; margin-top: 0.7rem; }
.modal-close-row { text-align: center; }

/* share modal */
.share-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0.6rem 0 0.3rem;
}
.share-message {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--ink);
  border: 1px solid rgba(59, 49, 40, 0.25);
  border-radius: 9px;
  padding: 0.55rem 0.65rem;
  background: rgba(255, 255, 255, 0.6);
  resize: none;
}
.share-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.7rem; }
.share-actions .solid-btn, .share-actions .ghost-btn { flex: 1 1 auto; justify-content: center; }
.share-contacts {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgba(59, 49, 40, 0.15);
  font-size: 0.85rem;
}
.share-contacts a { color: var(--amber-deep); text-decoration: none; font-weight: 600; }
.share-contacts a:hover { text-decoration: underline; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 300;
  background: rgba(31, 53, 49, 0.96);
  color: #f6efe2;
  font-size: 0.88rem;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  max-width: calc(100% - 2rem);
  text-align: center;
}

/* ---------- footer ---------- */

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1.2rem;
  flex-wrap: wrap;
  padding: 0.6rem 2rem 1.3rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}
.footer-brand strong { font-family: var(--font-serif); font-weight: 600; color: var(--ink); margin-right: 0.5rem; }
.footer-links { display: flex; gap: 1.1rem; }
.footer-links a { color: var(--amber-deep); text-decoration: none; font-weight: 600; }
.footer-links a:hover { text-decoration: underline; }

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  :root { --card-w: 116px; --card-h: 173px; }
  .site-header { padding: 1rem 1.1rem 0.5rem; gap: 0.7rem; }
  .brand-mark { width: 40px; height: 40px; }
  .header-actions { width: 100%; }
  .header-actions .ghost-btn, .header-actions .solid-btn { flex: 1 1 auto; justify-content: center; }
  #discuss-btn { flex-basis: 100%; }
  .intro { padding: 0.2rem 1.1rem 0.3rem; font-size: 0.92rem; }
  .intention { padding: 0.5rem 1.1rem 0.8rem; }
  .shared-banner { margin: 0 1.1rem 0.4rem; }
  .table { margin: 0.3rem 0.7rem 0.8rem; min-height: 460px; }
  .deck-col { left: 16px; top: 16px; }
  .deck-count strong { font-size: 0.9rem; }
  .site-footer { padding: 0.5rem 1.1rem 1.1rem; }
}

@media (max-width: 420px) {
  :root { --card-w: 102px; --card-h: 152px; }
}
