:root {
  --bg: #0F1923;
  --bg-grad: #182B3C;
  --surface: #1B2838;
  --surface-2: #22344A;
  --card: #1E2D3D;
  --card-hover: #28405A;
  --card-dead: #111921;
  --line: rgba(236, 232, 225, .10);
  --line-2: rgba(236, 232, 225, .20);
  --text: #ECE8E1;
  --dim: #8A9C95;
  --accent: #FF4655;
  --accent-2: #E63E4C;
  --gold: #FFD24A;
  --gold-gl: rgba(255, 210, 74, .35);
  --duelist: #FF4655;
  --init: #48E5A5;
  --ctrl: #A568E6;
  --sent: #F0D264;
  --r: 4px;
  --cut: 10px;
  --g: 10px;
  --ff: 'Teko', 'Arial Narrow', sans-serif;
  --fb: 'Nunito Sans', system-ui, sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0 }
html { background: var(--bg) }
body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-grad), transparent 70%),
    linear-gradient(180deg, transparent, rgba(255, 70, 85, .04)),
    var(--bg);
  color: var(--text);
  font-family: var(--fb);
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-tap-highlight-color: transparent;
}
body > * { width: 100%; max-width: 1040px; margin-inline: auto }
svg { width: 1em; height: 1em; flex-shrink: 0 }

/* ---------- buttons ---------- */
button {
  font: 600 .8rem/1 var(--fb);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .2s, border-color .2s, color .2s, transform .15s var(--spring), box-shadow .2s;
}
button:hover { background: var(--surface-2); border-color: rgba(236, 232, 225, .32) }
button:active { transform: scale(.95) }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }
button.ac {
  background: var(--accent); border-color: var(--accent); color: #fff;
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
}
button.ac:hover { background: var(--accent-2); box-shadow: 0 0 18px rgba(255, 70, 85, .35) }
button.pm { background: rgba(255, 210, 74, .14); border-color: var(--gold); color: var(--gold); animation: breathe 1.6s ease-in-out infinite }
button.ghost { background: transparent; border-color: var(--line) }
button.ghost:hover { background: var(--surface) }
button.round { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 1rem }

/* ---------- header ---------- */
.top { position: relative; z-index: 50; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; animation: drop .6s var(--ease) both }
.brand h1 {
  font: 700 clamp(2rem, 6vw, 3.2rem)/.9 var(--ff);
  letter-spacing: .06em; color: var(--accent);
  text-shadow: 0 0 24px rgba(255, 70, 85, .25);
}
.tag { color: var(--dim); font-size: .82rem; margin-top: 4px; max-width: 52ch; text-wrap: pretty }
.top-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0 }

.lang { position: relative }
.lang svg { font-size: 1rem }
.menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 60;
  list-style: none; min-width: 200px; max-height: min(70vh, 460px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
  opacity: 0; transform: translateY(-6px) scale(.98); transform-origin: top right; pointer-events: none;
  transition: opacity .2s, transform .25s var(--ease);
  scrollbar-width: thin; scrollbar-color: var(--surface-2) transparent;
}
.menu.open { opacity: 1; transform: none; pointer-events: auto }
.menu li {
  padding: 8px 10px; border-radius: 5px; cursor: pointer; font-size: .85rem;
  display: flex; justify-content: space-between; gap: 12px; transition: background .15s;
}
.menu li small { color: var(--dim); text-transform: uppercase; font-size: .68rem; letter-spacing: .08em }
.menu li:hover, .menu li:focus-visible { background: var(--surface-2); outline: none }
.menu li[aria-selected="true"] { color: var(--accent); background: rgba(255, 70, 85, .08) }

/* ---------- card of the day ---------- */
.daily {
  display: flex; gap: 18px; align-items: center;
  background: linear-gradient(110deg, rgba(255, 70, 85, .10), var(--surface) 45%);
  border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
  position: relative; overflow: hidden;
  animation: rise .7s .08s var(--ease) both;
}
.daily::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, .05) 50%, transparent 60%);
  transform: translateX(-100%); animation: sheen 6s 1.2s ease-in-out infinite;
}
.dcard {
  position: relative; width: 104px; height: 136px; flex-shrink: 0; padding: 0;
  background: none; border: 0; perspective: 800px; transform-style: preserve-3d;
}
.dcard:hover { background: none }
.dface {
  position: absolute; inset: 0; border-radius: 8px; backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  transition: transform .8s var(--ease);
  clip-path: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut)));
}
.dback {
  background: repeating-linear-gradient(135deg, #1f2f40 0 6px, #1a2836 6px 12px);
  border: 1px solid var(--line-2);
}
.dq { font: 700 3.4rem/1 var(--ff); color: var(--accent); animation: pulse 2.2s ease-in-out infinite }
.dhint { white-space: normal; line-height: 1.25; font-size: .62rem; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; text-align: center; padding: 0 6px }
.dfront {
  transform: rotateY(180deg);
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--rc, var(--accent)) 35%, transparent), var(--card) 70%);
  border: 1px solid var(--rc, var(--accent));
  box-shadow: inset 0 0 24px color-mix(in srgb, var(--rc, var(--accent)) 25%, transparent);
}
.dfront img, .dfront svg { width: 58px; height: 58px; object-fit: contain; color: var(--rc); filter: drop-shadow(0 0 8px rgba(0, 0, 0, .6)) }
.dfront .dslot { font: 600 1.1rem/1 var(--ff); color: var(--text); opacity: .8 }
.dcard.open .dback { transform: rotateY(-180deg) }
.dcard.open .dfront { transform: rotateY(0) }
.dcard:not(.open):hover .dback { transform: rotateY(-12deg) }

.dinfo { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px }
.dtitle { display: flex; align-items: center; gap: 8px; font-size: .7rem; text-transform: uppercase; letter-spacing: .14em; color: var(--accent); font-weight: 700 }
.spark { width: 8px; height: 8px; background: var(--accent); transform: rotate(45deg); animation: spin 4s linear infinite }
.dname { font: 600 clamp(1.6rem, 4vw, 2.2rem)/1 var(--ff); letter-spacing: .03em; transition: filter .5s, opacity .5s }
.daily:not(.revealed) .dname, .daily:not(.revealed) .dmeta, .daily:not(.revealed) .ddesc { filter: blur(7px); opacity: .5; user-select: none }
.dmeta { font-size: .78rem; color: var(--dim); display: flex; gap: 10px; flex-wrap: wrap; transition: filter .5s, opacity .5s }
.dmeta b { color: var(--rc); font-weight: 700 }
.ddesc { font-size: .78rem; color: var(--dim); line-height: 1.45; max-width: 70ch; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; transition: filter .5s, opacity .5s }
.drow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 6px }
.dnext { font-size: .75rem; color: var(--dim); font-variant-numeric: tabular-nums }

/* ---------- toolbar ---------- */
.bar {
  position: sticky; top: 8px; z-index: 30;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: rgba(20, 32, 45, .82); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px;
  animation: rise .7s .16s var(--ease) both;
}
.seed { font-family: var(--ff); font-size: 1.25rem; letter-spacing: .14em; padding: 5px 12px; gap: 8px }
.seed small { font: 700 .62rem var(--fb); color: var(--dim); text-transform: uppercase; letter-spacing: .1em }
.seed svg { font-size: .9rem; color: var(--dim); transition: color .2s }
.seed:hover svg { color: var(--text) }
.count { margin-inline-start: auto; display: flex; flex-direction: column; gap: 5px; min-width: 120px; font-size: .78rem; color: var(--dim); font-variant-numeric: tabular-nums; padding: 0 6px }
.count strong { color: var(--text); display: inline-block }
.count strong.bump { animation: bump .35s var(--spring) }
.meter { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden }
.meter span { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width .45s var(--ease); transform-origin: left }

.legend { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; animation: rise .7s .22s var(--ease) both }
.legend i { display: flex; align-items: center; gap: 6px; font-size: .72rem; font-style: normal; color: var(--dim) }
.legend b { width: 9px; height: 9px; transform: rotate(45deg); display: inline-block }

  display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows .35s var(--ease), opacity .3s;
  text-align: center; font-size: .85rem; color: var(--gold);
}

/* ---------- board ---------- */
.gc { flex: 1 }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--g); perspective: 1200px }

.card {
  position: relative; aspect-ratio: 4 / 4.6; cursor: pointer; user-select: none; -webkit-user-select: none;
  animation: deal .55s var(--ease) both; animation-delay: calc(var(--i) * 22ms);
  border-radius: 6px;
}
.card .in {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform .6s var(--ease);
}
.card .face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 6px; overflow: hidden; padding: 8px 9px;
  display: flex; flex-direction: column;
  clip-path: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut)));
}
.card .front {
  background: linear-gradient(170deg, color-mix(in srgb, var(--rc) 12%, var(--card)), var(--card) 55%);
  border: 1px solid var(--line);
  transition: background .25s, box-shadow .25s, border-color .25s;
}
.card .front::before { content: ''; position: absolute; inset: 0 0 auto; height: 3px; background: var(--rc) }
.card .back {
  transform: rotateY(180deg);
  background: repeating-linear-gradient(135deg, #16212c 0 5px, #121b24 5px 10px);
  border: 1px solid var(--line);
  align-items: center; justify-content: center; gap: 4px; text-align: center;
}
.card .back .x { font: 600 2rem/1 var(--ff); color: color-mix(in srgb, var(--rc) 60%, #444) }
.card .back .bn { font-size: .62rem; color: #5d6d78; line-height: 1.2 }

.card:hover:not(.elim) .in { transform: translateY(-4px) rotateX(4deg) }
.card:hover:not(.elim) .front { border-color: color-mix(in srgb, var(--rc) 60%, transparent); box-shadow: 0 10px 24px rgba(0, 0, 0, .35), 0 0 0 1px color-mix(in srgb, var(--rc) 35%, transparent) }
.card:active:not(.elim) .in { transform: scale(.96) }
.card.elim .in { transform: rotateY(180deg) }
.card.elim:hover .in { transform: rotateY(180deg) translateY(-2px) }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px }

.card .hd { display: flex; align-items: center; gap: 6px; min-width: 0 }
.card .sl {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 22px; height: 22px; border-radius: 4px; background: rgba(236, 232, 225, .1);
  font: 600 .95rem/1 var(--ff); padding-top: 2px;
}
.card .sl.u { background: rgba(255, 184, 77, .2); color: #FFB84D }
.card .ag { font-size: .68rem; color: var(--dim); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.card .ic { flex: 1; display: flex; justify-content: center; align-items: center; min-height: 0 }
.card .ic img, .card .ic svg { width: clamp(30px, 5.4vw, 46px); height: clamp(30px, 5.4vw, 46px); object-fit: contain; color: var(--rc); filter: drop-shadow(0 0 5px rgba(0, 0, 0, .6)); transition: transform .35s var(--spring) }
.card .ic img { animation: fadein .4s ease both }
.card:hover:not(.elim) .ic img, .card:hover:not(.elim) .ic svg { transform: scale(1.1) }
.card .nm { font: 600 clamp(.95rem, 1.8vw, 1.12rem)/1 var(--ff); letter-spacing: .02em; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-top: 2px }

/* My pick: only the outline changes, so nothing on the page moves.
   The face is clipped, so the second pixel of the outline is an inset shadow. */
.card.pick .front, .card.pick:hover .front, body.pm-on .card.pick:not(.elim) .front { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold) }
body.pm-on .card:not(.elim) { cursor: crosshair }
body.pm-on .card:not(.elim) .front { border-color: rgba(255, 210, 74, .35) }
body.pm-on .card:not(.elim):hover .front { border-color: var(--gold); box-shadow: 0 0 16px var(--gold-gl) }
.card.last .front { animation: glow 1.2s ease-in-out 3 }

/* ---------- footer ---------- */
.foot { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: .68rem; color: #5f7179; padding-top: 8px }

/* ---------- overlays ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100; max-width: none; margin: 0;
  background: rgba(5, 10, 15, .66); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.modal.open { opacity: 1; pointer-events: auto }
.modal-c {
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; padding: 24px;
  width: min(360px, 90vw); text-align: center; box-shadow: 0 30px 60px rgba(0, 0, 0, .5);
  transform: translateY(16px) scale(.96); transition: transform .35s var(--spring);
}
.modal.open .modal-c { transform: none }
.modal-c h2 { font: 600 1.7rem/1 var(--ff); margin-bottom: 14px; letter-spacing: .04em }
.modal-c input {
  width: 100%; padding: 10px; border-radius: var(--r); border: 1px solid var(--line-2); background: var(--card);
  color: var(--text); font: 500 1.5rem var(--ff); letter-spacing: .18em; text-align: center; outline: none;
  text-transform: uppercase; transition: border-color .2s, box-shadow .2s;
}
.modal-c input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 70, 85, .18) }
.modal-c .mb { display: flex; gap: 8px; margin-top: 16px; justify-content: center }

.help {
  position: fixed; top: 60px; inset-inline-end: 16px; width: 320px; max-width: calc(100vw - 32px); margin: 0;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; padding: 16px 18px; z-index: 70;
  font-size: .8rem; color: var(--dim); line-height: 1.6; box-shadow: 0 24px 50px rgba(0, 0, 0, .5);
  opacity: 0; transform: translateY(-8px) scale(.98); transform-origin: top right; pointer-events: none;
  transition: opacity .22s, transform .3s var(--ease);
}
.help.open { opacity: 1; transform: none; pointer-events: auto }
.help h3 { font: 600 1.3rem/1 var(--ff); color: var(--text); margin: 4px 0 6px; letter-spacing: .03em }
.help h3 + ol, .help h3 + ul { margin-bottom: 8px }
.help ol, .help ul { padding-inline-start: 18px }

.toast {
  position: fixed; bottom: 22px; left: 50%; z-index: 120; width: auto; max-width: calc(100vw - 32px); margin: 0;
  transform: translate(-50%, 90px) scale(.9); opacity: 0; pointer-events: none;
  background: var(--surface-2); border: 1px solid var(--line-2); border-inline-start: 3px solid var(--accent);
  border-radius: 8px; padding: 11px 18px; font-size: .85rem; box-shadow: 0 16px 32px rgba(0, 0, 0, .4);
  transition: transform .45s var(--spring), opacity .25s;
}
.toast.vis { opacity: 1; transform: translate(-50%, 0) scale(1) }

/* ---------- keyframes ---------- */
@keyframes deal { from { opacity: 0; transform: translateY(18px) rotate(-3deg) scale(.92) } to { opacity: 1; transform: none } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }
@keyframes drop { from { opacity: 0; transform: translateY(-12px) } to { opacity: 1; transform: none } }
@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: scale(0) rotate(-90deg) } to { transform: none } }
@keyframes bump { 40% { transform: scale(1.35); color: var(--accent) } }
@keyframes glow { 50% { box-shadow: 0 0 22px var(--gold-gl), inset 0 0 14px var(--gold-gl) } }
@keyframes breathe { 50% { box-shadow: 0 0 14px var(--gold-gl) } }
@keyframes pulse { 50% { transform: scale(1.08); text-shadow: 0 0 18px rgba(255, 70, 85, .55) } }
@keyframes spin { to { transform: rotate(405deg) } }
@keyframes sheen { 0%, 70% { transform: translateX(-100%) } 100% { transform: translateX(100%) } }

/* ---------- layout ---------- */
@media (max-width: 860px) { .grid { grid-template-columns: repeat(5, 1fr) } }
@media (max-width: 700px) {
  .grid { grid-template-columns: repeat(3, 1fr) }
  .count { margin-inline-start: 0; flex-basis: 100% }
  .bar { position: static }
  .tag { display: none }
}
@media (max-width: 460px) {
  body { padding: 10px 10px 20px }
  .grid { grid-template-columns: repeat(3, 1fr); gap: 7px }
  .card .face { padding: 6px }
  .card .ag { font-size: .6rem }
  .daily { gap: 12px; padding: 12px }
  .dcard { width: 84px; height: 112px }
  .bar button { padding: 8px 10px; font-size: .74rem }
  .seed { font-size: 1.1rem }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important }
}
