/* ORDINAL CARDS — black neon gaming theme.
   teal = you / primary action · pink = opponent / destructive · gold = the called stat */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #07070b;
  --panel: #0f0f14;
  --panel2: #15151c;
  --line: #22222b;
  --line2: #31313d;
  --text: #f2f2f7;
  --dim: #7c7c92;
  --ink: #06060a;
  --teal: #2ee6c5;
  --pink: #ff5fa8;
  --gold: #ffcf5a;
  --green: #3ee38a;
  --red: #ff5470;
  --orange: #ff9a52;
  --glow-teal: 0 0 22px rgba(46, 230, 197, .35);
  --glow-pink: 0 0 22px rgba(255, 95, 168, .35);
  --glow-gold: 0 0 22px rgba(255, 207, 90, .35);
}

html, body { height: 100%; }
body {
  background: var(--bg);
  background:
    radial-gradient(900px 560px at 50% -12%, rgba(46, 230, 197, .13), transparent 62%),
    radial-gradient(700px 500px at 110% 105%, rgba(255, 95, 168, .10), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 500 14px/1.3 "Chakra Petch", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  user-select: none;
}
#app { max-width: 430px; height: 100vh; height: 100dvh; margin: 0 auto; display: flex; flex-direction: column; overflow: hidden; }

/* ---- scrollbars that belong to the theme (scoped: a universal
   scrollbar-width/color would switch off ::-webkit-scrollbar in Chromium) ---- */
.grid::-webkit-scrollbar, .stage::-webkit-scrollbar, .sheet::-webkit-scrollbar { width: 6px; height: 6px; }
.grid::-webkit-scrollbar-track, .stage::-webkit-scrollbar-track, .sheet::-webkit-scrollbar-track { background: transparent; }
.grid::-webkit-scrollbar-thumb, .stage::-webkit-scrollbar-thumb, .sheet::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 6px; }
.grid::-webkit-scrollbar-thumb:hover, .stage::-webkit-scrollbar-thumb:hover, .sheet::-webkit-scrollbar-thumb:hover { background: var(--teal); }
@supports not selector(::-webkit-scrollbar) {
  .grid, .stage, .sheet { scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
}

/* ---- controls ---- */
button, a.btn {
  display: inline-block; text-align: center; text-decoration: none;
  background: linear-gradient(180deg, #17171f, #0f0f14);
  color: var(--text); border: 1px solid var(--line2); border-radius: 12px;
  font: inherit; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  padding: 13px 18px; cursor: pointer;
  transition: transform .12s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease;
}
button:active, a.btn:active { transform: scale(.97); }
button:disabled { border-color: var(--line); color: #62627a; background: transparent; cursor: default; box-shadow: none; }
button:disabled:active { transform: none; }
.primary, .bar button.play, .rowbtns .again, a.btn.wx {
  background: linear-gradient(180deg, #3cf2d2, #1fcfae); color: var(--ink); border-color: transparent;
  box-shadow: 0 8px 22px rgba(46, 230, 197, .28);
}
.danger, .obtn, .rowbtns .exit, .retry { border-color: rgba(255, 95, 168, .55); color: var(--pink); }
input {
  background: var(--panel); color: var(--text); border: 1px solid var(--line2); border-radius: 12px;
  font: inherit; padding: 13px; width: 100%; outline: none; text-align: center; letter-spacing: .06em;
  transition: border-color .18s, box-shadow .18s;
}
input:focus { border-color: var(--teal); box-shadow: var(--glow-teal); }

.dim { color: var(--dim); }
.pulse { animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
@keyframes pop { from { transform: scale(.86); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes winpulse { 0%, 100% { box-shadow: 0 0 0 1px var(--green), 0 0 18px rgba(62, 227, 138, .35); } 50% { box-shadow: 0 0 0 1px var(--green), 0 0 34px rgba(62, 227, 138, .7); } }

/* ---- centered screens (connect / queue / over) ---- */
/* centered via auto margins, not justify-content: a centered scroll container
   clips its top half when content overflows and it can never scroll there */
.center { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 14px; padding: 24px; }
.center::before, .stage::before { content: ""; margin-bottom: auto; }
.center::after, .stage::after { content: ""; margin-top: auto; }
.center .logo {
  font-size: clamp(19px, 6vw, 26px); font-weight: 700; letter-spacing: .3em; white-space: nowrap; margin-bottom: 28px;
  background: linear-gradient(90deg, var(--teal) 0%, var(--gold) 55%, var(--pink) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 12px rgba(46, 230, 197, .3));
}
.center button, .center a.btn { width: min(240px, 82vw); }
.wu { border-color: rgba(255, 154, 82, .6); color: var(--orange); }
.wa { border-color: var(--line2); }
.big { font-size: clamp(34px, 13vw, 52px); font-weight: 700; letter-spacing: .24em; animation: pop .35s cubic-bezier(.2, .9, .3, 1.3); }
.big.w { color: var(--green); text-shadow: 0 0 28px rgba(62, 227, 138, .6); }
.big.l { color: var(--red); text-shadow: 0 0 28px rgba(255, 84, 112, .55); }
.big.d { color: var(--gold); text-shadow: 0 0 28px rgba(255, 207, 90, .55); }

/* ---- deck builder ---- */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px;
  background: rgba(9, 9, 13, .82); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.bar .count { letter-spacing: .22em; color: var(--gold); font-weight: 700; text-shadow: 0 0 14px rgba(255, 207, 90, .35); }
.bar button.play { padding: 10px 22px; }
.bar button.play:disabled { background: transparent; box-shadow: none; color: #62627a; border-color: var(--line); }
.bar .who { color: var(--dim); font-size: 13px; }
.obtn { font-size: 10px; padding: 10px 12px; min-height: 36px; border-radius: 8px; letter-spacing: .18em; }

.tabs { display: flex; border-bottom: 1px solid var(--line); background: rgba(9, 9, 13, .6); }
.tab { flex: 1; text-align: center; padding: 11px 0; font-size: 12px; font-weight: 700; letter-spacing: .28em; color: var(--dim); cursor: pointer; text-transform: uppercase; transition: color .18s; }
.tab.on { color: var(--teal); box-shadow: inset 0 -2px 0 var(--teal); text-shadow: 0 0 12px rgba(46, 230, 197, .5); }
.tab.clear { flex: 0 0 auto; padding: 11px 16px; color: var(--pink); }

.grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; padding: 12px 10px 20px; align-content: start; }
.grid:empty::after { content: "···"; color: var(--dim); grid-column: 1/-1; text-align: center; padding: 40px 0; }
.retry { grid-column: 1/-1; justify-self: center; margin-top: 30px; }

/* ---- a card: number, art, stat block ---- */
/* no overflow:hidden here — it lets the grid row collapse the aspect-ratio thumb */
.card {
  position: relative; border: 1px solid var(--line); border-radius: 14px;
  background: linear-gradient(180deg, #14141b, #0d0d12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04), 0 4px 14px rgba(0, 0, 0, .45);
  display: flex; flex-direction: column; cursor: pointer;
  transition: transform .15s ease, box-shadow .18s ease, border-color .18s ease;
}
.card:active { transform: scale(.98); }
.card.on, .card.pick { border-color: var(--teal); box-shadow: 0 0 0 1px var(--teal), 0 10px 28px rgba(46, 230, 197, .22); }
.card .ord {
  position: absolute; top: 6px; right: 6px; z-index: 1; font-size: 11px; font-weight: 700;
  background: linear-gradient(180deg, #ffd978, #f5b93a); color: var(--ink); padding: 1px 7px; border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}
.chead { font-size: 10px; font-weight: 700; color: var(--dim); letter-spacing: .1em; padding: 5px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; border-radius: 13px 13px 0 0; }
.stats { border-top: 1px solid var(--line); padding: 4px 8px 7px; }
.srow { display: flex; justify-content: space-between; gap: 4px; font-size: 10px; line-height: 1.6; }
.srow span { color: var(--dim); letter-spacing: .08em; }
.srow b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.srow.hi { background: var(--gold); margin: 0 -8px; padding: 0 8px; box-shadow: var(--glow-gold); }
.srow.hi span, .srow.hi b { color: var(--ink); }
.sdiv { border-top: 1px solid var(--line2); margin: 4px -8px 3px; opacity: .8; }
.fdiv { border-top: 1px solid var(--line2); margin: 3px 0; }

.thumb { position: relative; width: 100%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; background: #0a0a0f; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
/* absolute — as a flex item the 200% iframe gets shrunk and lands top-left */
.thumb iframe { position: absolute; top: 0; left: 0; width: 200%; height: 200%; transform: scale(.5); transform-origin: 0 0; border: 0; pointer-events: none; background: #fff; }
.thumb .txt { font-size: 10px; color: #d9d9e6; padding: 6px; text-align: center; word-break: break-all; max-height: 100%; overflow: hidden; }
.thumb .mime { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .1em; }

/* ---- game ---- */
.gtop {
  display: flex; align-items: baseline; justify-content: space-between; padding: 12px 16px;
  background: rgba(9, 9, 13, .82); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.gtop .score { font-size: 24px; font-weight: 700; }
.gtop > span:first-child .score { color: var(--pink); text-shadow: 0 0 14px rgba(255, 95, 168, .6); }
.gtop > span:last-child .score { color: var(--teal); text-shadow: 0 0 14px rgba(46, 230, 197, .6); }
.gtop .rnd { color: var(--dim); letter-spacing: .22em; font-weight: 700; }
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 12px; padding: 12px; overflow-y: auto; }
.stage .wait { color: var(--dim); font-size: 30px; }
.callout { font-size: clamp(24px, 8vw, 36px); font-weight: 700; letter-spacing: .28em; color: var(--gold); text-shadow: 0 0 24px rgba(255, 207, 90, .5); animation: pop .3s cubic-bezier(.2, .9, .3, 1.3); }
.callout .arrow { font-size: clamp(18px, 6vw, 26px); }

.minicard { width: 72px; flex: 0 0 auto; border: 1px solid var(--line2); border-radius: 10px; background: var(--panel); box-shadow: 0 6px 18px rgba(0, 0, 0, .5); }
.minicard .thumb { border-radius: 9px; }
.frows { display: flex; flex-direction: column; gap: 4px; width: min(260px, 94vw); }
.frow { display: flex; align-items: center; gap: 6px; }
.frow .fl { width: 50px; color: var(--dim); font-size: 11px; letter-spacing: .1em; }
.frow .fv { flex: 1; text-align: right; font-size: 13px; font-weight: 700; }
.frow button { padding: 0 12px; min-width: 48px; min-height: 40px; font-size: 14px; line-height: 1.3; border-radius: 10px; }

.duel { display: flex; gap: 14px; align-items: flex-start; }
.duel .side { width: 132px; display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.duel .side .card { cursor: default; }
.duel .side.win .card { border-color: var(--green); animation: winpulse 1.4s ease-in-out infinite; }
.duel .side.lose { opacity: .6; filter: grayscale(.5); }
.duel .val { font-size: 22px; font-weight: 700; text-align: center; color: var(--gold); text-shadow: 0 0 16px rgba(255, 207, 90, .45); }
.duel .tag { font-size: 11px; color: var(--dim); letter-spacing: .22em; text-align: center; }

.timer { height: 3px; background: var(--line); margin: 0 14px; border-radius: 3px; }
.timer i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--pink)); border-radius: 3px; box-shadow: 0 0 10px rgba(46, 230, 197, .6); transition: width .25s linear; }

.handwrap { padding: 10px 14px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(9, 9, 13, .6); }
.hand { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hint { text-align: center; color: var(--dim); font-size: 11px; letter-spacing: .34em; padding-top: 8px; min-height: 22px; }

/* ---- over ---- */
.result-score { font-size: 22px; color: var(--dim); letter-spacing: .32em; font-weight: 700; }
.rowbtns { display: flex; gap: 10px; width: min(300px, 86vw); }
.rowbtns button { flex: 1; width: auto; padding: 14px 0; }

.flash { position: fixed; top: 18px; left: 0; right: 0; width: fit-content; margin: 0 auto; background: var(--gold); color: var(--ink); padding: 8px 16px; font-size: 12px; font-weight: 700; letter-spacing: .22em; border-radius: 10px; z-index: 9; box-shadow: var(--glow-gold); animation: pop .2s ease-out; }

#ver { position: fixed; right: 8px; bottom: calc(6px + env(safe-area-inset-bottom)); font-size: 10px; color: #3a3a48; letter-spacing: .14em; pointer-events: none; z-index: 5; }

/* ---- info ---- */
.ibtn { position: relative; width: 30px; height: 30px; padding: 0; border: 1px solid rgba(255, 207, 90, .55); color: var(--gold); background: transparent; font-size: 14px; letter-spacing: 0; flex: 0 0 auto; border-radius: 50%; font-style: italic; font-family: Georgia, serif; font-weight: 400; text-transform: none; }
.ibtn::before { content: ""; position: absolute; inset: -7px; }   /* 44px hit area, small visual */
.mid { display: inline-flex; align-items: center; gap: 8px; }
.overlay { position: fixed; inset: 0; background: rgba(4, 4, 8, .86); backdrop-filter: blur(6px); display: flex; padding: 20px; z-index: 20; overflow-y: auto; overscroll-behavior: contain; }
.sheet {
  margin: auto; max-height: 100%; overflow-y: auto;
  border: 1px solid var(--line2); border-radius: 18px; padding: 22px 20px; width: min(340px, 100%);
  background: linear-gradient(180deg, #15151d, #0c0c11);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .7), 0 0 0 1px rgba(46, 230, 197, .12), var(--glow-teal);
  animation: pop .25s cubic-bezier(.2, .9, .3, 1.2);
}
.ihead { font-size: 10px; font-weight: 700; color: var(--teal); letter-spacing: .34em; padding: 14px 0 4px; }
.ihead:first-child { padding-top: 0; }
.irow { display: flex; gap: 12px; font-size: 12px; line-height: 1.5; padding: 7px 0; border-bottom: 1px solid var(--line); }
.irow b { width: 56px; flex: 0 0 auto; font-weight: 700; color: var(--gold); }
.irow span { color: var(--dim); letter-spacing: .04em; }
.dirs { padding-top: 14px; font-size: 12px; font-weight: 700; letter-spacing: .18em; text-align: center; color: var(--pink); }

/* ---- mode switch (deck builder) ---- */
.modes { display: flex; border-bottom: 1px solid var(--line); background: rgba(9, 9, 13, .5); }
.mode { flex: 1; text-align: center; padding: 9px 0; font-size: 11px; font-weight: 700; letter-spacing: .32em; color: var(--dim); cursor: pointer; transition: color .18s; }
.mode.on { color: var(--gold); box-shadow: inset 0 -2px 0 var(--gold); text-shadow: 0 0 12px rgba(255, 207, 90, .5); }

/* ---- battle card face ---- */
.chead { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.type { font-style: normal; font-size: 8px; font-weight: 700; letter-spacing: .1em; padding: 1px 5px; border-radius: 6px; color: var(--ink); }
.type.IMAGE { background: var(--pink); }
.type.TEXT { background: var(--gold); }
.type.CODE { background: var(--teal); }
.stats.battle .srow { align-items: center; gap: 6px; }
.stats.battle .srow span { width: 24px; }
.stats.battle .srow > b { min-width: 26px; text-align: right; }
.sbar { flex: 1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.sbar b { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--pink)); border-radius: 2px; transition: width .4s ease; }
.srow.hp .sbar b { background: var(--green); }
.tier { font-size: 9px; font-weight: 700; letter-spacing: .24em; text-align: center; padding-top: 4px; color: var(--dim); }
.tier.RARE { color: var(--text); }
.tier.EPIC { color: var(--teal); text-shadow: 0 0 10px rgba(46, 230, 197, .5); }
.tier.LEGENDARY { color: var(--pink); text-shadow: 0 0 10px rgba(255, 95, 168, .6); }
.tier.GOD { color: var(--gold); text-shadow: var(--glow-gold); }
.raw { font-size: 8px; color: var(--dim); text-align: center; letter-spacing: .06em; padding-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- battle arena: opponent | effects | you, side by side so both actives
   fit above the bench without scrolling on a phone ---- */
.stage.arena { flex-direction: row; align-items: center; justify-content: center; gap: 6px; }
.stage.arena::before, .stage.arena::after { display: none; }
.zone { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 132px; flex: 0 0 auto; }
.zone .card { width: 100%; cursor: default; }
.zone.opp .card { border-color: rgba(255, 95, 168, .5); }
.zone.you .card { border-color: rgba(46, 230, 197, .5); }
.zinfo { font-size: 10px; color: var(--dim); letter-spacing: .2em; }
.hpwrap { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.hpbar { width: 100%; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.hpbar b { display: block; height: 100%; background: var(--green); border-radius: 4px; transition: width .5s ease; box-shadow: 0 0 10px rgba(62, 227, 138, .5); }
.hpbar b.low { background: var(--red); box-shadow: 0 0 10px rgba(255, 84, 112, .6); }
.hpnum { font-size: 11px; font-weight: 700; color: var(--dim); letter-spacing: .1em; }
.fx { flex: 1 1 60px; min-width: 60px; min-height: 34px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.dmg { font-size: 28px; font-weight: 700; color: var(--gold); text-shadow: 0 0 18px rgba(255, 207, 90, .6); animation: floatUp 1s ease-out both; }
.dmg i { font-style: normal; font-size: 13px; color: var(--pink); margin-left: 4px; }
.dmg.opp { color: var(--red); text-shadow: 0 0 18px rgba(255, 84, 112, .6); }
.ko { font-size: 22px; font-weight: 700; letter-spacing: .3em; color: var(--red); text-shadow: 0 0 20px rgba(255, 84, 112, .7); animation: pop .4s cubic-bezier(.2, .9, .3, 1.4) both; }
.note { font-size: 12px; font-weight: 700; letter-spacing: .3em; color: var(--dim); animation: pop .3s ease-out both; }
@keyframes floatUp { from { transform: translateY(10px); opacity: 0; } 25% { opacity: 1; } 70% { opacity: 1; } to { transform: translateY(-14px); opacity: 0; } }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.shake { animation: shake .35s ease-in-out; }
.actions { display: flex; gap: 10px; padding: 8px 14px 0; }
.actions button { flex: 1; min-height: 48px; padding: 0; }
.actions .swp.on { border-color: var(--gold); color: var(--gold); box-shadow: var(--glow-gold); }
.pips { letter-spacing: .12em; font-size: 15px; }
.pips.opp { color: var(--pink); text-shadow: 0 0 10px rgba(255, 95, 168, .5); }
.pips.you { color: var(--teal); text-shadow: 0 0 10px rgba(46, 230, 197, .5); }
.foot { padding-top: 12px; font-size: 9px; color: var(--dim); letter-spacing: .2em; text-align: center; }

/* ---- small / short screens ---- */
@media (max-height: 720px) {
  .gtop { padding: 8px 14px; }
  .stage { gap: 8px; padding: 8px; }
  .handwrap { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
  .hand { gap: 6px; }
  .hand .thumb { aspect-ratio: 16/10; }
  .duel .side { width: 112px; }
}
@media (max-height: 720px) {
  .zone { width: 112px; }
}
@media (max-height: 560px) {
  .hand .thumb { display: none; }   /* landscape phones: stats-only hand */
  .minicard { display: none; }
  .gtop .score { font-size: 18px; }
  .zone { width: 96px; }
  .zone .thumb { display: none; }
  .zone .raw, .zone .tier { display: none; }
}
@media (max-width: 350px) {
  .srow { font-size: 9px; }
  .bar { padding: 10px; gap: 6px; }
  .bar button.play { padding: 10px 14px; }
  .bar .who { display: none; }
}
/* hover only where a real pointer exists — on touch, :hover sticks after a tap */
@media (hover: hover) {
  button:hover, a.btn:hover { border-color: var(--teal); }
  .primary:hover, .bar button.play:hover, .rowbtns .again:hover, a.btn.wx:hover { box-shadow: 0 10px 28px rgba(46, 230, 197, .42); border-color: transparent; }
  .danger:hover, .obtn:hover, .rowbtns .exit:hover, .retry:hover { border-color: var(--pink); box-shadow: var(--glow-pink); }
  .wu:hover { border-color: var(--orange); box-shadow: 0 0 22px rgba(255, 154, 82, .3); }
  .tab:hover { color: var(--text); }
  .card:hover { border-color: var(--line2); transform: translateY(-2px); }
  .card.on:hover, .card.pick:hover { border-color: var(--teal); }
  .duel .side .card:hover { transform: none; }
  .frow button:first-of-type:hover { border-color: var(--teal); color: var(--teal); }
  .frow button:last-of-type:hover { border-color: var(--pink); color: var(--pink); }
  .ibtn:hover { border-color: var(--gold); box-shadow: var(--glow-gold); }
}
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { animation: none !important; transition: none !important; }
}
