:root {
  --gold: #e9c46a;
  --gold-deep: #b8892f;
  --ink: #2b1d0e;
  --panel: rgba(20, 12, 6, .62);
  --panel-line: rgba(233, 196, 106, .45);
  --text: #f6ead2;
  --card-w: clamp(56px, min(11vw, (100vh - 210px) / 6.3), 150px);
  --gap: clamp(8px, 1.4vw, 18px);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Philosopher", Georgia, serif;
  color: var(--text);
  background: #1b120a center / cover no-repeat fixed;
  background-image: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,.65) 100%), var(--table-img);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}
body[data-table="felt"]      { --table-img: url("../img/tables/felt.webp"); }
body[data-table="oak"]       { --table-img: url("../img/tables/oak.webp"); }
body[data-table="night"]     { --table-img: url("../img/tables/night.webp"); }
body[data-table="parchment"] { --table-img: url("../img/tables/parchment.webp"); }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding: 12px clamp(16px, 3vw, 36px);
  background: linear-gradient(to bottom, rgba(10,6,2,.85), rgba(10,6,2,.35));
  border-bottom: 1px solid var(--panel-line);
  position: relative;
  z-index: 5;
}

.logo {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-weight: 700;
  font-size: clamp(22px, 2.6vw, 34px);
  letter-spacing: .5px;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(233,196,106,.45), 0 2px 2px #000;
}
.logo span { color: #fff3d6; }

.stats { display: flex; gap: 10px; }
.stat {
  min-width: 74px;
  text-align: center;
  padding: 4px 12px;
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  background: var(--panel);
}
.stat small { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; opacity: .75; }
.stat b { font-size: 20px; color: var(--gold); font-variant-numeric: tabular-nums; }

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

.tables { display: flex; gap: 6px; }
.table-pick {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25);
  background: center / cover;
  padding: 0;
  transition: transform .2s, border-color .2s, box-shadow .2s;
}
.table-pick:hover { transform: scale(1.08); }
.table-pick[aria-checked="true"] { border-color: var(--gold); box-shadow: 0 0 12px rgba(233,196,106,.7); }

.btn {
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(180deg, #f5d98b, var(--gold-deep));
  border: 1px solid #f9e7b3;
  border-radius: 999px;
  padding: 9px 18px;
  white-space: nowrap;
  box-shadow: 0 3px 0 #6e4f17, 0 6px 14px rgba(0,0,0,.4);
  transition: transform .12s, box-shadow .12s, filter .2s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #6e4f17, 0 3px 8px rgba(0,0,0,.4); }
.btn.icon { padding: 7px 11px; }
.btn.icon.off { filter: grayscale(1) brightness(.8); opacity: .7; }
.btn.icon.off::after { content: ""; position: absolute; left: 8px; right: 8px; top: 50%; height: 2px; background: #6e2a1a; transform: rotate(-35deg); }
.btn.icon { position: relative; }
.btn.big { font-size: 18px; padding: 12px 28px; }

/* ---------- play area ---------- */
.play {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 4vw, 60px);
  padding: clamp(14px, 2.5vh, 32px) 16px;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, var(--card-w));
  gap: var(--gap);
  padding: clamp(14px, 2vw, 26px);
  border-radius: 22px;
  background: rgba(0,0,0,.18);
  box-shadow: inset 0 0 40px rgba(0,0,0,.35), 0 0 0 1px rgba(233,196,106,.25);
}

/* ---------- cards ---------- */
.card {
  width: var(--card-w);
  aspect-ratio: 7 / 10;
  perspective: 900px;
  border: 0; padding: 0; background: none;
  animation: deal .55s cubic-bezier(.2,.8,.3,1.2) backwards;
}
.card:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; border-radius: var(--radius); }
.card.gone { visibility: hidden; pointer-events: none; }

.card-inner {
  display: block;
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.4,.2,.2,1);
}
.card.open .card-inner,
.card.matched .card-inner { transform: rotateY(180deg); }
@media (hover: hover) {
  .card:not(.open):hover .card-inner { transform: translateY(-4px) rotateZ(-1deg); }
}

.face {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  box-shadow: 0 6px 14px rgba(0,0,0,.45), 0 1px 0 rgba(255,255,255,.15) inset;
}
.face.back {
  background: #5a1420 url("../img/back.webp") center / cover;
  border: 2px solid #d9b25a;
}
.face.front {
  transform: rotateY(180deg);
  background: #f3e3c0;
  border: 3px solid #d9b25a;
  display: flex;
  flex-direction: column;
}
.face.front img {
  width: 100%;
  flex: 1;
  min-height: 0;
  object-fit: cover;
  display: block;
}
.face.front .name {
  font-family: "Cormorant Garamond", serif;
  font-weight: 700;
  font-size: clamp(10px, calc(var(--card-w) * .12), 17px);
  color: var(--ink);
  text-align: center;
  padding: 3px 2px 4px;
  background: linear-gradient(#f6e7c4, #e6cf9b);
  border-top: 1px solid #c9a24f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card.wrong .card-inner { animation: shake .45s; }
.card.matched .face.front { box-shadow: 0 0 22px 4px rgba(255,222,120,.85); }

@keyframes deal {
  from { opacity: 0; transform: translateY(-40px) rotate(-8deg) scale(.8); }
}
@keyframes shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  25% { transform: rotateY(180deg) translateX(-6px); }
  75% { transform: rotateY(180deg) translateX(6px); }
}

/* ---------- deck ---------- */
.deck-area { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.deck {
  position: relative;
  width: calc(var(--card-w) * 1.05);
  aspect-ratio: 7 / 10;
}
.deck-slot {
  position: absolute; inset: 0;
  border: 2px dashed rgba(233,196,106,.55);
  border-radius: var(--radius);
  display: grid; place-items: center;
  font-family: "Cormorant Garamond", serif;
  font-size: 18px;
  color: rgba(246,234,210,.7);
  background: rgba(0,0,0,.2);
}
.stacked {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 3px solid #d9b25a;
  background: #f3e3c0;
  box-shadow: 0 4px 10px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
}
.stacked img { width: 100%; flex: 1; min-height: 0; object-fit: cover; }
.stacked .name {
  font-family: "Cormorant Garamond", serif; font-weight: 700;
  color: var(--ink); text-align: center; font-size: 15px; padding: 3px;
  background: linear-gradient(#f6e7c4, #e6cf9b);
}
.deck-caption {
  margin: 0;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
}
.deck-caption b { color: var(--gold); }

.stacked.flyer {
  position: fixed;
  inset: auto;
  z-index: 50;
  pointer-events: none;
  transform-origin: 0 0;
  will-change: transform;
}

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0;
  z-index: 100;
  display: grid; place-items: center;
  background: rgba(5,3,1,.6);
  backdrop-filter: blur(3px);
  padding: 16px;
}
.modal[hidden] { display: none; }
.scroll {
  max-width: 420px;
  width: 100%;
  text-align: center;
  color: var(--ink);
  padding: 30px 28px 34px;
  border-radius: 16px;
  background:
    radial-gradient(ellipse at center, #fbefd2 0%, #ecd6a4 70%, #d7b878 100%);
  border: 3px solid #b8892f;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  animation: pop .45s cubic-bezier(.2,.9,.3,1.3);
}
.scroll h2 { font-family: "Cormorant Garamond", serif; font-size: 32px; margin: 0 0 6px; }
.stars { font-size: 38px; letter-spacing: 6px; margin: 6px 0; }
.stars .off { filter: grayscale(1); opacity: .35; }
.best { font-size: 14px; opacity: .8; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }

/* ---------- ambient sparkles ---------- */
.sparkles { position: fixed; inset: 0; pointer-events: none; z-index: 1; overflow: hidden; }
.sparkles i {
  position: absolute;
  width: 4px; height: 4px; border-radius: 50%;
  background: #ffeeb0;
  box-shadow: 0 0 8px 2px rgba(255,230,150,.8);
  animation: float linear infinite;
  opacity: 0;
  will-change: transform, opacity;
}
@keyframes float {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: .9; }
  100% { transform: translateY(-110vh); opacity: 0; }
}
.burst {
  position: fixed; z-index: 60; pointer-events: none;
  width: 6px; height: 6px; border-radius: 50%;
  background: #fff2b8; box-shadow: 0 0 10px 3px rgba(255,215,110,.9);
}

/* ---------- account / about modals ---------- */
.btn.ghost {
  color: var(--gold);
  background: rgba(20,12,6,.55);
  border-color: var(--panel-line);
  box-shadow: none;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn.ghost:active { transform: translateY(1px); box-shadow: none; }
.btn.ghost-dark {
  color: #5a3b12;
  background: transparent;
  border: 1px solid #b8892f;
  box-shadow: none;
}
.btn.ghost-dark:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: .6; }

.modal-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.save-note { font-size: 14px; min-height: 1.2em; color: #5a3b12; }

.scroll { position: relative; max-height: calc(100vh - 32px); overflow-y: auto; }
.scroll.profile, .scroll.about { max-width: 640px; text-align: left; }
.scroll h3 {
  font-family: "Cormorant Garamond", serif;
  font-size: 22px;
  margin: 18px 0 8px;
  color: #5a3b12;
}
.scroll a { color: #8a4a12; }
.close {
  position: absolute; top: 8px; right: 12px;
  width: 36px; height: 36px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: #5a3b12;
  font-size: 28px; line-height: 1;
}
.close:hover { background: rgba(90,59,18,.12); }

.tabs { display: flex; margin: 10px 0 16px; border-bottom: 1px solid #c9a24f; }
.tabs button {
  flex: 1;
  font: inherit; font-weight: 700;
  color: #7a5a2a;
  background: none; border: 0;
  padding: 8px;
  border-bottom: 3px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: #b8892f; }

#authForm { display: flex; flex-direction: column; gap: 12px; text-align: left; }
#authForm label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 700; color: #5a3b12; }
#authForm input {
  font: inherit; font-size: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #b8892f;
  background: #fffaf0;
  color: var(--ink);
}
#authForm input:focus { outline: 2px solid #b8892f; outline-offset: 1px; }
#authForm .btn { align-self: center; margin-top: 4px; }
.only-register { display: none !important; }
.register .only-register { display: flex !important; }
.form-error { margin: 0; min-height: 1.2em; color: #a3271b; font-size: 14px; font-weight: 700; }
.form-hint { margin: 0; font-size: 13px; color: #6d5530; }

.profile-sub { margin: 0 0 12px; color: #6d5530; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile {
  text-align: center;
  padding: 10px 6px;
  border-radius: 12px;
  background: rgba(255,250,235,.6);
  border: 1px solid #d2b06a;
}
.tile b { display: block; font-size: 22px; color: var(--ink); }
.tile small { font-size: 12px; color: #6d5530; }

.collection { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.collection figure {
  margin: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid #d9b25a;
  background: #f3e3c0;
}
.collection img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.collection figcaption {
  display: flex; justify-content: space-between; gap: 4px;
  padding: 3px 6px;
  font-size: 12px; font-weight: 700;
  color: var(--ink);
}
.collection figcaption span { color: #8a6a2a; }
.collection figcaption b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collection .locked img { filter: grayscale(1) brightness(.35) blur(2px); }
.collection .locked { border-color: #b9a27a; }
.collection-note { grid-column: 1 / -1; margin: 2px 0 0; font-size: 13px; color: #6d5530; }

.recent { list-style: none; margin: 0 0 18px; padding: 0; }
.recent li {
  display: grid;
  grid-template-columns: 92px 1fr auto auto;
  gap: 10px;
  padding: 6px 4px;
  border-bottom: 1px dashed #d2b06a;
  font-size: 14px;
}
.muted { color: #8a744c; }

.about ol, .about ul { padding-left: 20px; margin: 0 0 8px; }
.about li { margin-bottom: 6px; }
.about section p { margin: 6px 0; }
.dev { font-size: 18px; }

@media (max-width: 520px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .recent li { grid-template-columns: 1fr auto; }
  .recent li .muted { display: none; }
}

/* ---------- magic wand cursors ---------- */
html { cursor: url("../img/cursors/wand.svg") 5 5, auto; }
a, button, summary, [role="tab"], .card, .table-pick, .close {
  cursor: url("../img/cursors/wand-glow.svg") 5 5, pointer;
}
input { cursor: text; }
.btn:disabled { cursor: wait; }
.wand-spark {
  position: fixed; z-index: 1000; pointer-events: none;
  width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: #fff3c4;
  box-shadow: 0 0 6px 2px rgba(255, 210, 110, .85);
}

/* ---------- responsive ---------- */
@media (max-width: 600px), (max-aspect-ratio: 4/5) {
  :root { --card-w: max(54px, min(20vw, (100vh - 330px) / 6.4)); }
  .topbar { justify-content: center; text-align: center; }
  .play { flex-direction: column; gap: 14px; }
  .deck-area { flex-direction: row; }
  .deck { width: calc(var(--card-w) * .8); }
  .stacked .name { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
