/* ---------- Terminus webfont (paths are relative to this css file) ---------- */
@font-face {
  font-family: "Terminus";
  src: url("../fonts/TerminusTTF-4.49.3.ttf") format("truetype");
  font-weight: normal; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Terminus";
  src: url("../fonts/TerminusTTF-Bold-4.49.3.ttf") format("truetype");
  font-weight: bold; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Terminus";
  src: url("../fonts/TerminusTTF-Italic-4.49.3.ttf") format("truetype");
  font-weight: normal; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "Terminus";
  src: url("../fonts/TerminusTTF-Bold-Italic-4.49.3.ttf") format("truetype");
  font-weight: bold; font-style: italic; font-display: swap;
}

:root {
  --bg: #060606;
  --line: #ffffff;
  --ink: #ffffff;
  --accent: #fff371;
  --danger: #ff6b6b;
  --ok: #7dff9b;
  /* Everything uses Terminus now (both former "display" and "mono" roles). */
  --display: "Terminus", "Michroma", "Arial Narrow", sans-serif;
  --mono: "Terminus", "Share Tech Mono", ui-monospace, monospace;
  /* Logo keeps its original display face. */
  --logo: "Michroma", "Arial Narrow", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--ink); text-decoration: none; }
a:hover { color: var(--accent); }

/* ---------- top nav ---------- */
.nav {
  height: 70px;
  border-bottom: 2px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 32px;
  gap: 24px;
  position: relative; /* anchor for the mobile nav-links dropdown */
}
.brand {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--logo); font-size: 20px; letter-spacing: 1px; white-space: nowrap;
}
.brand-dots { display: flex; gap: 4px; }
.brand-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink); display: block; }
/* logo image (top-left), with a color swap on hover */
.brand .logo-img { height: 32px; width: auto; display: block; }
.brand .logo-hover { display: none; }
.brand:hover .logo-img { display: none; }
.brand:hover .logo-hover { display: block; }
.nav-links { display: flex; gap: 48px; margin-inline: auto; font-size: 18px; }
.nav-links a.active { color: var(--accent); }
.connect {
  font-size: 18px; white-space: nowrap; background: none; border: none;
  color: var(--ink); font-family: var(--mono); cursor: pointer;
}
.connect:hover { color: var(--accent); }
/* loyalty points pill, injected into the nav next to the wallet button when connected */
.points-pill {
  display: inline-flex; align-items: center; white-space: nowrap;
  border: 1px solid var(--accent); color: var(--accent);
  font-size: 13px; padding: 5px 11px; line-height: 1; letter-spacing: .5px;
}
.points-pill:hover { background: rgba(255, 243, 113, .12); color: var(--accent); }
/* logout/disconnect icon, injected to the left of the wallet button when connected */
.disconnect {
  align-items: center; justify-content: center;
  background: none; border: none; color: var(--ink); cursor: pointer;
  padding: 4px; line-height: 0;
}
.disconnect:hover { color: var(--danger); }
.disconnect svg { width: 20px; height: 20px; display: block; }
/* mobile hamburger menu toggle (hidden on desktop) */
.nav-toggle { display: none; background: none; border: none; color: var(--ink); cursor: pointer; padding: 6px; line-height: 0; }
.nav-toggle:hover { color: var(--accent); }
.nav-toggle svg { width: 26px; height: 26px; display: block; }

.layout { display: flex; align-items: stretch; gap: 36px; padding: 36px 32px; max-width: 1920px; margin: 0 auto; }
.page { padding: 36px 32px; max-width: 1400px; margin: 0 auto; }

/* ---------- buttons / inputs ---------- */
.btn {
  background: #fff; color: #000; border: none;
  font-family: var(--mono); font-size: 18px; letter-spacing: 1px;
  padding: 14px 28px; cursor: pointer;
  transition: filter .15s ease, transform .15s ease;
}
.btn:hover:not(:disabled) { filter: drop-shadow(0 0 10px var(--accent)); transform: scale(1.01); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.ghost { background: none; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); filter: none; }
.btn.accent { background: var(--accent); }
.btn.black { background: #000; color: var(--ink); border: 1px solid var(--line); }
.btn.black:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); filter: none; }

input[type="text"], input[type="number"] {
  background: var(--bg); border: 1px solid var(--line); color: var(--ink);
  font-family: var(--mono); font-size: 18px; padding: 12px 14px; width: 100%;
}
input:focus { outline: 1px solid var(--accent); }

/* USDC vault deposit/withdraw rows: equal width + an in-field suffix label */
.vault-row { display: flex; gap: 16px; align-items: center; }
.vault-row > input, .vault-row .input-wrap { flex: 1 1 auto; min-width: 0; }
.input-wrap { position: relative; }
.input-wrap input { width: 100%; padding-right: 150px; }
.input-suffix {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  pointer-events: none; white-space: nowrap; font-size: 14px;
}

/* ---------- card grid ---------- */
.pool { flex: 1 1 auto; min-width: 0; }
.pool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 36px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px; }

.card {
  border: 1px solid var(--line); background: var(--bg); min-height: 300px; min-width: 0;
  padding: 14px 14px 16px; display: flex; flex-direction: column; align-items: center;
  transition: border-color .15s ease, transform .15s ease;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card.selected { border: 2px solid var(--accent); }
/* Fixed image box: the picture is forced to fit this box (object-fit), the box
   never grows to the picture. width:100% + .card min-width:0 stop an odd-aspect
   image's intrinsic width from blowing out its 1fr grid column and shifting the
   whole row. object-fit:contain shows the whole card (letterboxed); swap to
   `cover` to fill the box edge-to-edge (crops overflow instead). */
.card-img {
  width: 100%; height: 178px; display: block; margin: 6px 0 0;
  object-fit: contain; object-position: center;
}
.divider { width: 100%; height: 1px; background: var(--line); margin: 12px 0 9px; }
.card-title {
  font-size: 17px; text-align: center; margin-bottom: 12px; line-height: 1.3; min-height: 44px;
  width: 100%; /* constrain to the card so the name wraps instead of clipping */
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-word;
}
.card-stats { width: 100%; display: flex; justify-content: space-between; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat.right { text-align: right; }
.stat-label { font-size: 8px; opacity: .85; text-transform: uppercase; }
.stat-value { font-size: 14px; }
.stat-value.insured { color: var(--ok); }
.stat-value.grade { color: var(--accent); }
/* card-tile text: the "Insured Value"/"Grade" labels and their values */
.card .stat-label { font-size: 11px; letter-spacing: 1px; }
.card .stat-value { font-size: 18px; }

/* ---------- right pull panel ---------- */
.side-col { flex: 0 0 706px; width: 706px; display: flex; flex-direction: column; gap: 36px; align-self: flex-start; }
.recent { text-align: center; }
.recent .section-title { margin-top: 0; }
/* recent pulls feed — structured rows: thumbnail · name/meta · outcome + time */
.recent-list { text-align: left; max-height: 480px; overflow-y: auto; border: 1px solid rgba(255,255,255,.2); }
.recent-list::-webkit-scrollbar { width: 8px; }
.recent-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.22); }
.recent-list::-webkit-scrollbar-track { background: transparent; }
.recent-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; border-top: 1px solid rgba(255,255,255,.1);
  transition: background .15s ease;
}
.recent-row:first-child { border-top: none; }
.recent-row:hover { background: #0c0c0c; }
.recent-thumb { width: 38px; height: 50px; flex: 0 0 38px; object-fit: contain; background: #0c0c0c; }
.recent-main { flex: 1 1 auto; min-width: 0; }
.recent-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-meta { font-size: 11px; opacity: .6; margin-top: 3px; }
.recent-val { font-size: 17px; color: var(--ok); margin-bottom: 5px; }
.recent-right { flex: 0 0 auto; text-align: right; }
.recent-badge { font-size: 11px; letter-spacing: 1px; padding: 3px 9px; border: 1px solid var(--line); display: inline-block; }
.recent-badge.kept { color: var(--accent); border-color: var(--accent); }
.recent-badge.bought { opacity: .7; }
.recent-time { font-size: 11px; opacity: .5; margin-top: 5px; }
.panel { width: 706px; border: 2px solid var(--line); display: flex; flex-direction: column; }
.machine { width: 100%; height: 560px; object-fit: contain; object-position: center; display: block; background: var(--bg); }
.panel-footer { position: relative; padding: 120px 40px 40px; flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 22px; }
.ev-box {
  position: absolute; top: 18px; right: 40px; width: 100px; height: 80px;
  border: 1px solid var(--line); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; text-align: center;
}
.ev-label { font-size: 11px; text-transform: uppercase; }
.ev-value { font-size: 18px; color: var(--accent); }
.panel-title { position: absolute; top: 18px; left: 40px; right: 150px; height: 80px; margin: 0; display: flex; align-items: center; justify-content: center; text-align: center; font-family: var(--display); font-size: 36px; line-height: 1.1; }
.open-btn {
  width: 100%; height: 62px; background: #fff; color: #000; border: none;
  font-family: var(--mono); font-size: 26px; letter-spacing: 1px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 48px;
  transition: filter .15s ease, transform .15s ease;
}
.open-btn:hover:not(:disabled) { filter: drop-shadow(0 0 10px var(--accent)); transform: scale(1.01); }
.open-btn:disabled { opacity: .4; cursor: not-allowed; }
.open-facts { text-align: center; font-size: 13px; opacity: .8; display: flex; flex-direction: column; gap: 5px; }

/* ---------- stat strip / boxes ---------- */
.stat-strip { display: flex; gap: 24px; margin-bottom: 32px; flex-wrap: wrap; }
.stat-box { border: 1px solid var(--line); padding: 18px 26px; min-width: 200px; }
.stat-box .stat-label { font-size: 13px; }
.stat-box .stat-value { font-size: 30px; margin-top: 6px; }

.section-title { font-family: var(--display); font-size: 22px; margin: 36px 0 18px; letter-spacing: 1px; }
.muted { opacity: .65; font-size: 13px; line-height: 1.6; }
.accent-text { color: var(--accent); }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.85);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  border: 2px solid var(--line); background: var(--bg); padding: 36px;
  width: min(560px, 92vw); text-align: center; display: flex; flex-direction: column; gap: 18px;
}
.modal h2 { font-family: var(--display); font-size: 22px; }
.modal .card-img { width: auto; max-width: 100%; height: 240px; }
.modal-actions { display: flex; gap: 16px; justify-content: center; }
.fair-details { text-align: left; font-size: 10px; word-break: break-all; opacity: .6; border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------- card reveal animation ---------- */
.reveal-wrap { position: relative; display: inline-block; }
.reveal-card { position: relative; display: inline-block; perspective: 900px; animation: revealPop .5s ease-out both; }
@keyframes revealPop { 0% { transform: scale(.7); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
/* 3D flip: mystery card back -> the real card front */
.reveal-3d { position: relative; width: 172px; height: 240px; transform-style: preserve-3d; animation: cardFlip .6s cubic-bezier(.2,.7,.3,1.15) both; }
.reveal-face { position: absolute; inset: 0; backface-visibility: hidden; border: 1px solid var(--line); background: #0c0c0c; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.reveal-front img { width: 100%; height: 100%; object-fit: contain; display: block; }
.reveal-back { transform: rotateY(180deg); font-family: var(--display); font-size: 72px; color: var(--accent); }
@keyframes cardFlip { 0% { transform: rotateY(180deg); } 100% { transform: rotateY(0deg); } }
/* glitch burst as the flip lands */
.reveal-front { border: none; background: transparent; animation: revealGlitch .5s linear .55s 2; }
@keyframes revealGlitch {
  0%,100% { transform: translateX(0); filter: none; clip-path: inset(0); }
  15% { transform: translateX(-3px); filter: drop-shadow(2px 0 0 #ff2bd6) drop-shadow(-2px 0 0 #2bf0ff); clip-path: inset(8% 0 62% 0); }
  35% { transform: translateX(3px); clip-path: inset(48% 0 22% 0); }
  55% { transform: translateX(-2px); filter: drop-shadow(-2px 0 0 #ff2bd6) drop-shadow(2px 0 0 #2bf0ff); clip-path: inset(28% 0 44% 0); }
  75% { transform: translateX(2px); clip-path: inset(68% 0 6% 0); }
}
.reveal-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; animation: revealFlash .5s ease-out both; }
@keyframes revealFlash { 0% { opacity: .85; } 100% { opacity: 0; } }
/* tiered glow — none for tier 0, stronger as value rises */
.reveal-card.glow1 { box-shadow: 0 0 14px rgba(255,243,113,.45); }
.reveal-card.glow2 { box-shadow: 0 0 26px 2px rgba(255,243,113,.6); }
.reveal-card.glow3 {
  box-shadow: 0 0 40px 8px rgba(255,243,113,.9);
  animation: revealPop .5s ease-out both, glowPulse 1.3s ease-in-out .6s infinite;
}
@keyframes glowPulse {
  0%,100% { box-shadow: 0 0 30px 5px rgba(255,243,113,.7); }
  50%     { box-shadow: 0 0 50px 14px rgba(255,243,113,1); }
}
.reveal-shake { animation: revealShake .5s .08s 1; }
@keyframes revealShake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-6px); } 40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(3px); }
}
.reveal-name { font-size: 16px; min-height: 1.25em; letter-spacing: .5px; }
.spark {
  position: absolute; left: 50%; top: 50%; color: var(--accent);
  font-family: var(--mono); pointer-events: none;
  transform: translate(-50%,-50%); animation: sparkFly .85s ease-out forwards;
}
@keyframes sparkFly {
  0%   { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.6); }
}

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border: 1px solid var(--line); padding: 10px 14px; text-align: left; }
th { font-size: 10px; text-transform: uppercase; opacity: .8; }
/* sortable column headers (Sortable.enhance / table.sortable) */
th.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
th.th-sort:hover { color: var(--accent); }
th.th-sort.sort-active { color: var(--accent); }
.sort-ind { font-size: 9px; margin-left: 6px; opacity: .4; display: inline-block; }
th.th-sort.sort-active .sort-ind { opacity: 1; }

/* scrollable, height-capped table box (admin) with a sticky header row */
.table-scroll { max-height: 420px; overflow-y: auto; border: 1px solid rgba(255,255,255,.2); }
.table-scroll thead th { position: sticky; top: 0; background: var(--bg); box-shadow: inset 0 -1px 0 var(--line); }
.table-scroll::-webkit-scrollbar { width: 8px; }
.table-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.22); }
.table-scroll::-webkit-scrollbar-track { background: transparent; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  border: 1px solid var(--accent); background: var(--bg); padding: 18px 30px;
  font-size: 17px; display: none; z-index: 100; max-width: 80vw;
  box-shadow: 0 0 14px rgba(255, 243, 113, .35);
}

.spinner { display: inline-block; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- ascii loader ---------- */
.ascii-loader { display: flex; flex-direction: column; align-items: center; gap: 16px; font-family: var(--mono); }
.ascii-art {
  margin: 0; white-space: pre; line-height: 1.2; font-size: 19px;
  color: var(--ink); text-shadow: 0 0 8px rgba(255, 243, 113, .22);
}
.ascii-art.win { color: var(--accent); text-shadow: 0 0 14px var(--accent); }
/* kaomoji face box (pack-opening): a real CSS box with the face flex-centred,
   so centring doesn't depend on monospace glyph widths */
.ascii-art.kao {
  display: flex; align-items: center; justify-content: center;
  width: min(88vw, 300px); height: 92px; padding: 0 12px;
  border: 1px solid var(--line); white-space: nowrap; overflow: hidden;
  font-size: 24px; line-height: 1;
}
.ascii-art.kao.win { border-color: var(--accent); }
.ascii-status { font-size: 15px; letter-spacing: .5px; min-height: 1.3em; }
.ascii-status .ascii-spin { color: var(--accent); display: inline-block; min-width: 1ch; }
.ascii-status .ascii-msg { opacity: .9; }
.ascii-status.done .ascii-spin, .ascii-status.done .ascii-msg { color: var(--ok); opacity: 1; }
.ascii-bar { margin: 0; white-space: pre; font-size: 16px; color: var(--accent); opacity: .85; }
/* GIF loader (opt-in via Loader opts.sprite) — replaces the ASCII scene as the
   focal animation; pixelated so pixel-art GIFs stay crisp when scaled up. */
.loader-gif { height: 120px; width: auto; image-rendering: pixelated; image-rendering: crisp-edges; }
.loader-overlay .modal { gap: 22px; }
.loader-overlay .modal h2 { letter-spacing: 2px; }

/* laptops: shrink the gacha panel AND drop the card grid to 2 columns, so the
   cards stay large and aren't squeezed by the side panel */
@media (min-width: 1301px) and (max-width: 1700px) {
  .side-col { flex: 0 0 500px; width: 500px; }
  .panel { width: 500px; }
  .machine { height: 400px; }
  .panel-title { font-size: 24px; }
  .panel-footer { padding: 96px 28px 28px; }
  .pool-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 1300px) {
  .layout { flex-direction: column; }
  /* Promote the panel + recent out of side-col so they reorder around the pool:
     gacha machine + OPEN button on top, all cards below, recent pulls last. */
  .side-col { display: contents; }
  .panel { width: 100%; order: -1; }
  .pool { order: 0; }
  .recent { order: 1; }
  .nav-links { gap: 24px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .pool-grid, .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .nav { padding: 0 16px; gap: 14px; }
  .brand { margin-right: auto; }            /* push the controls to the right */
  .nav-toggle { display: inline-flex; align-items: center; }
  .nav-links {                              /* dropdown under the nav bar */
    display: none; position: absolute; top: 70px; left: 0; right: 0; margin: 0;
    flex-direction: column; gap: 0; font-size: 18px;
    background: var(--bg); border-bottom: 2px solid var(--line); z-index: 90;
  }
  .nav-links.open { display: flex; }
  .nav-links a { padding: 16px 24px; border-top: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }