/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

@font-face {
  font-family: 'Black Nory';
  src: url('/assets/fonts/Black-Nory-Regular.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'GT Pressura Mono';
  src: url('/assets/fonts/GT-Pressura-Mono-Light.otf') format('opentype');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'GT Pressura Mono';
  src: url('/assets/fonts/GT-Pressura-Mono-Regular.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'GT Pressura Mono';
  src: url('/assets/fonts/GT-Pressura-Mono-Bold.otf') format('opentype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Matched from training.midevils.com */
  --bg: #856e49;
  --bg-floor: #9a9169;
  --bg-card: #78573b;
  --bg-card-hover: #8a6845;
  --text: #000;
  --text-dim: #3a2e1e;
  --text-light: #f0e8d8;
  --red: #ff3939;
  --red-dark: #cc2020;
  --green: #1a6b1a;
  --green-bright: #2a8a2a;
  --border: #000;
  --border-light: #6b5a42;
  --shadow: rgba(0, 0, 0, 0.3);
  --font-display: 'Black Nory', serif;
  --font-body: 'GT Pressura Mono', monospace;

  /* Layout knobs. Mobile overrides in the @media (max-width:640px) block. */
  --title-size: 7rem;
  --page-pad-top: 56px;
  --header-gap: 48px;
  /* Tile size derives from shell height (which is locked to the banner
     aspect ratio in index.html). Only gap + pointer dimensions remain
     tunable here. */
  --slice-gap: 10px;
  --pointer-w: 28px;
  --pointer-top: -30px;
  --pointer-h-extra: 60px;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: clip;
}

/* === Page Container === */
.page-container {
  max-width: 1000px;
  margin: 0 auto;
  padding: var(--page-pad-top) 16px 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* === Header === */
.header {
  text-align: center;
  margin-bottom: var(--header-gap);
}

.title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--title-size);
  color: var(--red);
  line-height: 1.25;
  padding-top: 0.15em;
  -webkit-text-stroke: 1px #000;
}

.subtitle {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text);
  margin-top: 16px;
  letter-spacing: 0.5px;
}

/* === Screens === */
.screen { width: 100%; }
.hidden { display: none !important; }

/* === Connect Screen === */
#connectScreen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 30px;
}

.error-text {
  color: var(--red);
  font-size: 0.95rem;
  min-height: 1.4em;
  font-weight: 600;
}

/* === Buttons === */
.btn {
  font-family: var(--font-body);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.btn-connect {
  background: var(--red);
  color: var(--text);
  font-size: 1.2rem;
  padding: 14px 40px;
  border: 1px solid var(--text);
  border-radius: 0;
}
.btn-connect:hover {
  background: var(--red-dark);
}

.btn-spin {
  background: var(--red);
  color: var(--text);
  font-size: 1.5rem;
  padding: 16px 48px;
  margin-top: 24px;
  border: 1px solid var(--text);
  border-radius: 0;
  width: 100%;
  max-width: 280px;
}
.btn-spin:hover:not(:disabled) {
  background: var(--red-dark);
}
.btn-spin:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-discord {
  display: inline-block;
  background: #5865F2;
  color: white;
  font-size: 1rem;
  padding: 12px 32px;
  text-decoration: none;
  border-radius: 0;
  border: none;
  font-family: var(--font-body);
  font-weight: 700;
  letter-spacing: 1px;
}
.btn-discord:hover { background: #4752C4; }

.btn-share-x {
  display: inline-block;
  background: #000;
  color: #fff;
  font-size: 1rem;
  padding: 12px 32px;
  text-decoration: none;
  border-radius: 0;
  border: 1px solid #fff;
  font-family: var(--font-body);
  font-weight: 700;
  letter-spacing: 1px;
}
.btn-share-x:hover { background: #1a1a1a; }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.95rem;
  padding: 10px 28px;
  border: 1px solid var(--text);
  border-radius: 0;
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
}

/* === Spin Layout === */
.spin-layout {
  display: flex;
  gap: 40px;
  align-items: flex-start;
  width: 100%;
}

.wheel-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.roster-area {
  width: 280px;
  flex-shrink: 0;
}

/* === Wheel === */
.wheel-container {
  position: relative;
  width: 340px;
  height: 340px;
}

.wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: none;
  overflow: hidden;
  position: relative;
  box-shadow: 0 4px 20px var(--shadow);
  transition: transform 3s cubic-bezier(0.17, 0.67, 0.12, 0.99);
}

/* Wheel image */
.wheel-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* Pointer image */
.wheel-pointer {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: auto;
  z-index: 10;
  filter: drop-shadow(0 2px 6px var(--shadow));
}

/* Spinning state */
.wheel.spinning {
  transition: transform 3.5s cubic-bezier(0.17, 0.67, 0.12, 0.99);
}

/* === Reset Timer === */
.reset-timer {
  margin-top: 12px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.5px;
}

.reset-timer .countdown {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.landing-countdown {
  margin: 0 auto 28px;
  max-width: 520px;
  text-align: center;
}
.landing-countdown__label {
  margin: 0 0 10px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.landing-countdown__slab {
  background: #050505;
  background-clip: padding-box;
  border-style: solid;
  border-width: 32px;
  border-image: url('/assets/raffle/banner-frame.png?v=2') 80 / 32px round;
  box-shadow: inset 0 0 28px rgba(220, 38, 38, 0.22);
  padding: 20px 26px;
}
.landing-countdown__slab #landingCountdown {
  display: inline-block;
  font-family: 'Courier New', ui-monospace, monospace;
  font-weight: 900;
  font-size: 2.6rem;
  letter-spacing: 2px;
  color: #ef4444;
  text-shadow:
    0 0 8px rgba(239, 68, 68, 0.85),
    0 0 18px rgba(239, 68, 68, 0.45);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}
@media (max-width: 600px) {
  .landing-countdown__slab {
    border-width: 24px;
    border-image: url('/assets/raffle/banner-frame.png?v=2') 80 / 24px round;
    padding: 16px 18px;
  }
  .landing-countdown__slab #landingCountdown {
    font-size: 2.1rem;
    letter-spacing: 1px;
  }
}

/* === Roster Header === */
.roster-header {
  margin-bottom: 12px;
}

.roster-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.btn-select-all {
  background: var(--bg-card);
  color: var(--text-light);
  font-size: 0.8rem;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 0;
}
.btn-select-all:hover {
  background: var(--red);
}

.selected-count {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 600;
}

/* === MidEvil Roster === */
.roster-title {
  margin-bottom: 0;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.midevil-roster {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.midevil-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s ease;
}
.midevil-card:hover:not(.midevil-card--spent) {
  background: var(--bg-card-hover);
  border-color: var(--red);
}

.midevil-card--selected {
  border-color: var(--red);
  background: var(--bg-card-hover);
  box-shadow: 0 0 0 1px var(--red);
}

.midevil-card--spent {
  opacity: 0.4;
  cursor: not-allowed;
}

.midevil-card__img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border: 2px solid var(--border);
}

.midevil-card__info {
  flex: 1;
  min-width: 0;
}

.midevil-card__name {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
}

.midevil-card__status {
  font-size: 0.8rem;
  color: var(--green-bright);
  font-weight: 600;
}

.midevil-card--spent .midevil-card__status {
  color: #a09080;
}

.midevil-card__timer {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* A spun MidEvil that landed a prize. Overrides the --spent dimming and
   greying so a win is unmissable — and clickable to re-open its claim
   instructions — even if a network error hid the live result. */
.midevil-card--won {
  opacity: 1;
  cursor: pointer;
}
.midevil-card--won .midevil-card__status {
  color: #f5b833;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  margin-top: 80px;
}

.empty-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--red);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.empty-text {
  color: var(--text-dim);
  font-size: 1.05rem;
}

/* === How To Play (connect screen) === */
.how-to-play {
  margin-top: 56px;
  width: 100%;
  max-width: 560px;
  background: var(--bg-floor);
  border: 1px solid var(--border);
  padding: 28px 32px;
  text-align: left;
}

.how-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2.4rem;
  color: var(--red);
  line-height: 1.15;
  padding-top: 0.1em;
  margin-bottom: 8px;
  text-align: center;
}

.how-duration {
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 24px;
  letter-spacing: 0.5px;
}

.how-steps {
  list-style: decimal;
  padding-left: 1.4em;
  margin: 0 0 24px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.55;
}
.how-steps li { margin-bottom: 8px; }
.how-steps li::marker { font-weight: 700; }

.how-fairness {
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  margin: 0 0 24px;
  letter-spacing: 0.3px;
  line-height: 1.45;
  font-style: italic;
}

.how-prizes-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text);
  margin-bottom: 12px;
  border-top: 1px solid rgba(0,0,0,0.25);
  padding-top: 18px;
}

.how-prizes {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
}
.how-prizes li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(0,0,0,0.12);
}
.how-prizes li:last-child { border-bottom: none; }
.how-prizes li strong {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.how-prizes li span {
  color: var(--text-dim);
  text-align: right;
}

/* === Result Modal === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(40, 30, 18, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: var(--bg-floor);
  border: 1px solid var(--border);
  padding: 32px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.result-icon {
  font-size: 3rem;
  line-height: 1;
}

.result-icon-img {
  width: 200px;
  height: 200px;
  object-fit: contain;
  border: 1px solid var(--border);
}

.result-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2.2rem;
  color: var(--red);
  line-height: 1.1;
}

.result-text {
  color: var(--text-dim);
  font-size: 1rem;
}

/* Win glow */
.modal-card.win {
  border-color: var(--red);
  box-shadow: 0 0 40px rgba(139, 26, 26, 0.3);
}

/* === Report Modal === */
.report-card {
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
}

.report-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.report-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(0,0,0,0.15);
}

.report-row__name {
  flex: 1;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text);
}

.report-row__result {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
}

.report-row__result--win {
  color: var(--red);
}

.report-row__result--spin-again {
  color: var(--green);
}

.report-row__result--lose {
  color: var(--text-dim);
}

.report-summary {
  width: 100%;
  padding: 12px 0;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  text-align: center;
  border-top: 2px solid var(--border);
}

/* === Wallet Bar === */
.wallet-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--bg-floor);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
}

.wallet-address {
  font-size: 0.85rem;
  color: var(--text);
  font-family: monospace;
}

.btn-disconnect {
  background: none;
  border: 2px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.75rem;
  padding: 4px 12px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.btn-disconnect:hover {
  border-color: var(--red);
  color: var(--red);
}

/* === Wallet Modal (injected by wallet.js) === */
.wallet-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(40, 30, 18, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.wallet-modal-card {
  background: var(--bg-floor);
  border: 1px solid var(--border);
  padding: 0;
  width: 320px;
  max-width: 90vw;
  overflow: hidden;
}

.wallet-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 2px solid var(--border);
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--text);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.wallet-modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}
.wallet-modal-close:hover { color: var(--text); }

.wallet-modal-list {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wallet-modal-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.wallet-modal-option:hover {
  border-color: var(--text);
  background: var(--bg-card-hover);
}
/* Anchor variant used for mobile "Open in <wallet>" deep links */
a.wallet-modal-option {
  text-decoration: none;
  justify-content: center;
  font-weight: 600;
}

.wallet-modal-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.wallet-modal-hint {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
  padding: 12px;
}

/* === Spin Again badge === */
.spin-again-badge {
  display: inline-block;
  background: var(--green);
  color: white;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.75rem;
  padding: 4px 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* === Loading spinner === */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Mobile === */
@media (max-width: 768px) {
  .page-container {
    padding: 48px 12px 20px;
  }

  .title {
    font-size: 4.4rem;
  }

  .subtitle {
    font-size: 0.85rem;
  }

  .how-to-play {
    padding: 22px 20px;
    margin-top: 40px;
  }
  .how-title { font-size: 1.9rem; }
  .how-prizes li {
    flex-direction: column;
    gap: 2px;
  }
  .how-prizes li span { text-align: left; }

  .spin-layout {
    flex-direction: column;
    align-items: center;
    gap: 24px;
  }

  .roster-area {
    width: 100%;
    order: 2;
  }

  .wheel-area {
    order: 1;
  }

  .wheel-container {
    width: 280px;
    height: 280px;
  }

  .btn-spin {
    font-size: 1.3rem;
    padding: 14px 40px;
    margin-top: 24px;
  }

  .midevil-roster {
    flex-direction: row;
    flex-wrap: wrap;
    max-height: none;
    overflow-y: visible;
  }

  .midevil-card {
    flex: 1 1 calc(50% - 4px);
    min-width: 140px;
  }

  .midevil-card__img {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 380px) {
  .wheel-container {
    width: 240px;
    height: 240px;
  }

  .midevil-card {
    flex: 1 1 100%;
  }
}
