:root {
  color-scheme: dark;
  --bg: #0c0d10;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.13);
  --line: rgba(255, 255, 255, 0.17);
  --text: #f5f1e9;
  --muted: #afa79b;
  --accent: #e6b85c;
  --accent-2: #63d4b6;
  --danger: #f07272;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(230, 184, 92, 0.19), transparent 32rem),
    linear-gradient(135deg, #121317 0%, #191414 42%, #0b1010 100%);
  color: var(--text);
}

button,
textarea {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 34px 0 46px;
}

.intro,
.status-panel,
.tag-section,
.deck-section {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  min-height: 210px;
  padding: clamp(24px, 5vw, 56px);
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-2);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 760px;
  margin-bottom: 14px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.75rem, 7vw, 6.2rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.intro-copy,
.section-note,
.deck-comment {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.98rem, 1.6vw, 1.12rem);
  line-height: 1.45;
}

.section-note,
.deck-comment {
  margin-top: 10px;
}

.deck-comment {
  color: #d9caa7;
  font-weight: 750;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 3vw, 2.1rem);
  line-height: 1.05;
}

.roll-button,
.copy-button,
.tag-roll-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  color: #14120e;
  font-weight: 850;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease, border-color 160ms ease;
}

.roll-button {
  width: clamp(132px, 22vw, 190px);
  padding: 18px 26px;
  background: linear-gradient(135deg, var(--accent), #f5dba0);
  font-size: 1.08rem;
  box-shadow: 0 18px 45px rgba(230, 184, 92, 0.28);
}

.roll-button:not(:disabled):hover,
.copy-button:not(:disabled):hover,
.tag-roll-button:not(:disabled):hover {
  transform: translateY(-2px);
}

.roll-button:disabled {
  cursor: not-allowed;
  background: #595b61;
  color: #c6c7ca;
  box-shadow: none;
  opacity: 0.75;
}

.status-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 24px;
  padding: 14px 16px;
  border-radius: 8px;
}

.status-panel p {
  margin: 0;
  color: var(--muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--accent-2);
  box-shadow: 0 0 22px rgba(99, 212, 182, 0.7);
}

.status-dot.busy {
  background: var(--accent);
  box-shadow: 0 0 22px rgba(230, 184, 92, 0.7);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 22px rgba(240, 114, 114, 0.7);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.card-choice {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.card-choice:hover,
.card-choice.selected {
  transform: translateY(-4px);
  border-color: rgba(230, 184, 92, 0.8);
  background: var(--panel-strong);
}

.commander-locked .card-choice:not(.selected) {
  cursor: default;
  opacity: 0.28;
  filter: grayscale(1) saturate(0.35);
  transform: scale(0.985);
}

.commander-locked .card-choice:not(.selected):hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.07);
  transform: scale(0.985);
}

.card-choice img {
  width: 100%;
  aspect-ratio: 488 / 680;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.08);
}

.commander-spinning .loading-card {
  cursor: wait;
  pointer-events: none;
}

.loading-card-face {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 488 / 680;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(230, 184, 92, 0.18), transparent 34%),
    linear-gradient(180deg, rgba(99, 212, 182, 0.18), rgba(5, 6, 8, 0.95));
}

.loading-card-face::before {
  position: absolute;
  inset: 8%;
  border: 1px solid rgba(245, 241, 233, 0.18);
  border-radius: 8px;
  content: "";
}

.loading-card-face::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transform: translateX(-120%);
  animation: commanderShine 950ms linear infinite;
}

.loading-card-pip {
  width: clamp(64px, 8vw, 104px);
  aspect-ratio: 1;
  border: 2px solid rgba(230, 184, 92, 0.72);
  border-radius: 999px;
  box-shadow: 0 0 36px rgba(230, 184, 92, 0.22), inset 0 0 22px rgba(99, 212, 182, 0.16);
  animation: commanderPulse 700ms ease-in-out infinite alternate;
}

.loading-card-lines {
  position: absolute;
  right: 14%;
  bottom: 12%;
  left: 14%;
  height: 18%;
  border-block: 1px solid rgba(245, 241, 233, 0.2);
  opacity: 0.72;
}

.loading-card .card-body h3 {
  animation: commanderTextTick 140ms ease-out;
}

.mobile-mana-loader {
  display: none;
}

.card-body {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 18px;
}

.card-body h3 {
  margin: 0;
  font-size: clamp(1.05rem, 2.1vw, 1.45rem);
  line-height: 1.08;
}

.type-line,
.oracle {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.oracle {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
}

.tag-section,
.deck-section {
  margin-top: 24px;
  padding: clamp(20px, 4vw, 32px);
  border-radius: 8px;
}

.section-heading {
  margin-bottom: 18px;
}

.deck-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.slot-machine {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 14px;
  align-items: stretch;
}

.slot-window {
  position: relative;
  display: grid;
  min-height: 104px;
  overflow: hidden;
  border: 1px solid rgba(99, 212, 182, 0.48);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(4, 5, 7, 0.88), rgba(30, 31, 32, 0.88));
  box-shadow: inset 0 14px 34px rgba(0, 0, 0, 0.44), inset 0 -14px 34px rgba(0, 0, 0, 0.36);
}

.slot-window::before,
.slot-window::after {
  position: absolute;
  right: 0;
  left: 0;
  z-index: 1;
  content: "";
  pointer-events: none;
}

.slot-window::before {
  top: 50%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(230, 184, 92, 0.92), transparent);
  transform: translateY(-50%);
}

.slot-window::after {
  top: 0;
  height: 100%;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.72), transparent 26%, transparent 74%, rgba(0, 0, 0, 0.72)),
    linear-gradient(90deg, rgba(0, 0, 0, 0.28), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.28));
}

.slot-reel {
  display: grid;
  grid-template-rows: 1fr auto auto 1fr;
  align-content: center;
  gap: 6px;
  min-width: 0;
  padding: 18px;
  text-align: center;
  transform-origin: center;
  transition: filter 180ms ease;
}

.slot-row {
  display: block;
  overflow-wrap: anywhere;
}

.slot-row.active {
  font-size: clamp(1.6rem, 4vw, 3rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0 24px rgba(230, 184, 92, 0.18);
}

.slot-row.ghost {
  min-height: 1em;
  color: rgba(245, 241, 233, 0.34);
  font-size: clamp(0.82rem, 1.8vw, 1.05rem);
  font-weight: 800;
  line-height: 1.1;
}

.slot-reel small {
  color: var(--muted);
  font-weight: 800;
}

.slot-tick {
  animation: slotTick 140ms cubic-bezier(0.2, 0.8, 0.2, 1);
  filter: blur(0.3px);
}

.slot-locked {
  animation: slotLock 520ms cubic-bezier(0.16, 1, 0.3, 1);
  filter: drop-shadow(0 0 18px rgba(99, 212, 182, 0.2));
}

.tag-roll-button {
  width: 100%;
  min-height: 104px;
  background: rgba(99, 212, 182, 0.96);
}

.tag-roll-button:disabled {
  cursor: not-allowed;
  background: #595b61;
  color: #c6c7ca;
  opacity: 0.75;
}

.copy-button {
  width: 112px;
  background: var(--accent);
}

textarea {
  width: 100%;
  min-height: 460px;
  resize: vertical;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: rgba(4, 5, 7, 0.62);
  color: var(--text);
  line-height: 1.55;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.deck-stats {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.type-ratio {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.type-ratio span {
  min-height: 44px;
  overflow: hidden;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.type-ratio strong {
  display: block;
  color: var(--text);
  font-size: 0.88rem;
}

.hidden {
  display: none;
}

@media (max-width: 820px) {
  .intro {
    align-items: flex-start;
    flex-direction: column;
  }

  .roll-button {
    width: 100%;
  }

  .cards-grid,
  .slot-machine {
    grid-template-columns: 1fr;
  }

  .card-choice {
    grid-template-columns: 132px 1fr;
    grid-template-rows: auto;
  }

  .card-choice img {
    height: 100%;
    aspect-ratio: auto;
  }

  .theme-locked .card-choice:not(.selected) {
    display: none;
  }

  .commander-spinning {
    display: block;
  }

  .mobile-mana-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    min-height: 160px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.07);
    box-shadow: var(--shadow);
  }

  .mana-dot {
    position: relative;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    opacity: 0.42;
    animation: manaPulse 2600ms cubic-bezier(0.2, 0.8, 0.2, 1) infinite;
  }

  .mana-dot::after {
    position: absolute;
    inset: -9px;
    border-radius: inherit;
    content: "";
    background: currentColor;
    opacity: 0;
    filter: blur(10px);
    animation: manaAura 2600ms ease-in-out infinite;
  }

  .mana-white {
    background: #f4ead2;
    color: #f4ead2;
  }

  .mana-blue {
    background: #74b8e8;
    color: #74b8e8;
    animation-delay: 360ms;
  }

  .mana-black {
    background: #211d23;
    color: #b9aebf;
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation-delay: 720ms;
  }

  .mana-red {
    background: #d85b3f;
    color: #d85b3f;
    animation-delay: 1080ms;
  }

  .mana-green {
    background: #5fa567;
    color: #5fa567;
    animation-delay: 1440ms;
  }

  .mana-blue::after {
    animation-delay: 360ms;
  }

  .mana-black::after {
    animation-delay: 720ms;
  }

  .mana-red::after {
    animation-delay: 1080ms;
  }

  .mana-green::after {
    animation-delay: 1440ms;
  }
}

@keyframes slotTick {
  from {
    transform: translateY(-18px) scale(0.985);
    opacity: 0.35;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slotLock {
  0% {
    transform: scale(1);
  }

  42% {
    transform: scale(1.035);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes commanderShine {
  to {
    transform: translateX(120%);
  }
}

@keyframes commanderPulse {
  from {
    transform: scale(0.92);
    opacity: 0.58;
  }

  to {
    transform: scale(1.06);
    opacity: 1;
  }
}

@keyframes commanderTextTick {
  from {
    transform: translateY(8px);
    opacity: 0.35;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes manaPulse {
  0%,
  100% {
    transform: translateY(0) scale(0.82);
    opacity: 0.42;
  }

  18% {
    transform: translateY(-12px) scale(1.18);
    opacity: 1;
  }

  34% {
    transform: translateY(0) scale(0.96);
    opacity: 0.64;
  }
}

@keyframes manaAura {
  0%,
  100% {
    opacity: 0;
    transform: scale(0.7);
  }

  18% {
    opacity: 0.36;
    transform: scale(1.35);
  }

  38% {
    opacity: 0;
    transform: scale(1.7);
  }
}

@media (max-width: 520px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 10px;
  }

  .intro {
    min-height: 180px;
  }

  .card-choice {
    grid-template-columns: 1fr;
  }

  .deck-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .copy-button {
    width: 100%;
  }
}
