*, *::before, *::after { box-sizing: border-box; }

:root {
  --m3d-bg: #070609;
  --m3d-panel: rgba(11, 8, 10, 0.74);
  --m3d-panel-strong: rgba(17, 10, 13, 0.92);
  --m3d-line: rgba(229, 194, 113, 0.28);
  --m3d-line-hot: rgba(244, 216, 139, 0.78);
  --m3d-text: #f6edda;
  --m3d-muted: rgba(246, 237, 218, 0.66);
  --m3d-red: #d33b50;
  --m3d-green: #56bc65;
  --m3d-gold: #e8c876;
  --m3d-blue: #7daeff;
  --m3d-purple: #b58cff;
  --m3d-display: "Cinzel", "Georgia", serif;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--m3d-bg);
  color: var(--m3d-text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

button,
select {
  font: inherit;
}

button,
select {
  min-height: 34px;
  border: 1px solid var(--m3d-line);
  border-radius: 4px;
  background: rgba(7, 5, 7, 0.78);
  color: var(--m3d-text);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.025);
}

button {
  padding: 0 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s ease, background .15s ease, color .15s ease, transform .15s ease;
}

button:hover,
button:focus-visible {
  border-color: var(--m3d-line-hot);
  background: rgba(49, 18, 24, .94);
  color: #fff9e8;
  outline: none;
}

button:active {
  transform: translateY(1px);
}

select {
  min-width: 150px;
  max-width: 250px;
  padding: 0 28px 0 10px;
  color: #fff3dc;
}

#c3d {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.m3d-topbar {
  position: fixed;
  top: 12px;
  left: 14px;
  right: 14px;
  z-index: 30;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  pointer-events: none;
}

.m3d-brand,
.m3d-links,
.m3d-card-detail,
.m3d-command,
.m3d-hud,
.m3d-camera,
.m3d-pile-panel {
  backdrop-filter: blur(14px);
}

.m3d-brand,
.m3d-links {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--m3d-line);
  border-radius: 5px;
  background: linear-gradient(180deg, rgba(22, 14, 17, .86), rgba(7, 5, 7, .72));
  box-shadow: 0 16px 44px rgba(0, 0, 0, .42);
}

.m3d-brand {
  height: 48px;
  padding: 7px 14px 7px 10px;
  color: var(--m3d-text);
  text-decoration: none;
}

.m3d-brand img {
  height: 30px;
  width: auto;
  filter: brightness(1.45) drop-shadow(0 0 12px rgba(211, 59, 80, .55));
}

.m3d-brand span,
.m3d-links a,
.m3d-side-tab,
.m3d-side-name,
.m3d-turn-button,
.m3d-detail-title strong,
.m3d-selected-mini strong {
  font-family: var(--m3d-display);
  font-weight: 900;
}

.m3d-brand span {
  font-size: 14px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.m3d-links {
  min-height: 44px;
  padding: 6px;
}

.m3d-links a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 3px;
  color: var(--m3d-muted);
  font-size: 11px;
  letter-spacing: .08em;
  text-decoration: none;
  text-transform: uppercase;
}

.m3d-links a:hover {
  color: #fff8e8;
  background: rgba(232, 200, 118, .08);
}

.m3d-card-detail {
  position: fixed;
  top: 74px;
  left: 16px;
  z-index: 28;
  width: min(440px, calc(100vw - 32px));
  min-height: 224px;
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 14px;
  padding: 13px;
  border: 1px solid rgba(232, 200, 118, .55);
  border-radius: 4px;
  background:
    linear-gradient(90deg, rgba(12, 44, 40, .78), rgba(14, 10, 13, .92) 38%, rgba(7, 5, 7, .86)),
    rgba(8, 6, 8, .9);
  box-shadow:
    0 22px 58px rgba(0, 0, 0, .5),
    inset 0 0 0 1px rgba(255, 255, 255, .035);
  pointer-events: auto;
}

.m3d-card-detail::before,
.m3d-command::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(232, 200, 118, .13);
  pointer-events: none;
}

.m3d-detail-art {
  position: relative;
  align-self: start;
}

.m3d-detail-art img {
  display: block;
  width: 116px;
  height: 162px;
  object-fit: cover;
  border: 1px solid rgba(232, 200, 118, .42);
  border-radius: 4px;
  background: #0b0709;
  box-shadow: 0 14px 28px rgba(0, 0, 0, .48);
}

.m3d-cost-gem {
  position: absolute;
  left: -9px;
  top: -9px;
  min-width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #d7f3aa;
  border-radius: 50%;
  color: #fff;
  background:
    radial-gradient(circle at 35% 25%, #e8ffd0, #4caf48 54%, #1d5c28 100%);
  font-family: var(--m3d-display);
  font-size: 16px;
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .65);
}

.m3d-detail-main {
  min-width: 0;
}

.m3d-detail-title {
  min-height: 52px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(232, 200, 118, .18);
}

.m3d-detail-title strong {
  display: block;
  color: #fff3dc;
  font-size: 18px;
  line-height: 1.2;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .9);
}

.m3d-detail-title span {
  display: block;
  margin-top: 5px;
  color: #d5c099;
  font-size: 12px;
}

.m3d-detail-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 25px;
  margin: 9px 0;
}

.m3d-detail-stats span {
  min-height: 23px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border: 1px solid rgba(232, 200, 118, .2);
  border-radius: 999px;
  color: #ffe7ad;
  background: rgba(0, 0, 0, .28);
  font-size: 11px;
  font-weight: 800;
}

.m3d-detail-effect {
  min-height: 74px;
  max-height: 122px;
  overflow: auto;
  color: #f1e2c9;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.m3d-detail-flavor {
  margin-top: 8px;
  color: rgba(246, 237, 218, .52);
  font-size: 12px;
  font-style: italic;
  line-height: 1.4;
}

.m3d-command {
  position: fixed;
  top: 74px;
  right: 16px;
  z-index: 28;
  width: 292px;
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1px solid rgba(232, 200, 118, .42);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(18, 10, 13, .94), rgba(8, 5, 7, .82)),
    rgba(8, 6, 8, .9);
  box-shadow: 0 22px 58px rgba(0, 0, 0, .5);
  pointer-events: auto;
}

.m3d-side-status {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  align-items: center;
  gap: 5px;
  min-height: 54px;
  padding: 8px;
  border: 1px solid rgba(232, 200, 118, .18);
  background: rgba(0, 0, 0, .24);
}

.m3d-side-status.opp {
  border-color: rgba(125, 174, 255, .24);
}

.m3d-side-name {
  color: #fff1d1;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.m3d-side-status strong {
  width: 46px;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffe1e8;
  border: 1px solid rgba(211, 59, 80, .72);
  border-radius: 3px;
  background: linear-gradient(180deg, #842033, #3a0d17);
  font-family: var(--m3d-display);
  font-size: 18px;
}

.m3d-side-status b {
  width: 30px;
  color: #d9ffd0;
  text-align: center;
  font-family: var(--m3d-display);
  font-size: 18px;
}

.m3d-side-status span:not(.m3d-side-name) {
  color: var(--m3d-muted);
  font-size: 11px;
  font-weight: 800;
}

.m3d-side-status small {
  grid-column: 1 / -1;
  color: rgba(246, 237, 218, .58);
  font-size: 11px;
}

.m3d-turn-wheel {
  display: grid;
  grid-template-rows: auto auto auto;
  justify-items: center;
  gap: 6px;
  padding: 2px 0;
}

.m3d-n-banner {
  min-width: 172px;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid rgba(232, 200, 118, .44);
  background:
    linear-gradient(90deg, rgba(6, 50, 48, .88), rgba(18, 83, 61, .9), rgba(6, 50, 48, .88));
  clip-path: polygon(9% 0, 91% 0, 100% 50%, 91% 100%, 9% 100%, 0 50%);
}

.m3d-n-banner span {
  color: #c7ffb7;
  font-family: var(--m3d-display);
  font-weight: 900;
}

.m3d-n-banner strong {
  color: #fff8df;
  font-family: var(--m3d-display);
  font-size: 24px;
}

.m3d-turn-button {
  width: 142px;
  height: 142px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 3px solid rgba(232, 200, 118, .58);
  border-radius: 50%;
  color: #ffe9ef;
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 145, 160, .38), transparent 30%),
    radial-gradient(circle, #af1f3a 0%, #6f1427 57%, #2c0710 100%);
  box-shadow:
    0 0 0 8px rgba(7, 5, 7, .72),
    0 0 0 10px rgba(232, 200, 118, .22),
    0 20px 44px rgba(0, 0, 0, .55);
}

.m3d-turn-button span,
.m3d-turn-button strong,
.m3d-turn-button small {
  pointer-events: none;
}

.m3d-turn-button span {
  font-size: 18px;
  line-height: 1;
}

.m3d-turn-button strong {
  font-size: 26px;
  line-height: 1;
}

.m3d-turn-button small {
  margin-top: 4px;
  color: rgba(255, 248, 223, .74);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 800;
}

.m3d-selected-mini {
  min-height: 50px;
  padding: 8px;
  border: 1px solid rgba(232, 200, 118, .14);
  background: rgba(0, 0, 0, .22);
}

.m3d-selected-mini strong,
.m3d-selected-mini span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m3d-selected-mini strong {
  color: #fff3dc;
  font-size: 13px;
}

.m3d-selected-mini span {
  margin-top: 4px;
  color: var(--m3d-muted);
  font-size: 12px;
}

.m3d-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.m3d-action-grid button {
  min-height: 31px;
  font-size: 12px;
}

.m3d-table-actions,
.m3d-camera {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.m3d-table-actions button,
.m3d-camera button {
  flex: 1 1 auto;
  min-height: 31px;
  font-size: 12px;
}

.m3d-camera {
  position: fixed;
  right: 16px;
  bottom: 14px;
  z-index: 29;
  width: 292px;
  padding: 8px;
  border: 1px solid rgba(232, 200, 118, .22);
  border-radius: 4px;
  background: var(--m3d-panel);
  pointer-events: auto;
}

.m3d-hud {
  position: fixed;
  left: 14px;
  bottom: 12px;
  z-index: 29;
  width: min(880px, calc(100vw - 340px));
  display: grid;
  gap: 6px;
  pointer-events: none;
}

.m3d-player {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px;
  border: 1px solid rgba(232, 200, 118, .20);
  border-radius: 4px;
  background: rgba(9, 6, 8, .62);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .35);
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(232, 200, 118, .45) rgba(0, 0, 0, .22);
}

.m3d-player::-webkit-scrollbar,
.m3d-action-grid::-webkit-scrollbar,
.m3d-detail-effect::-webkit-scrollbar {
  height: 6px;
  width: 6px;
}

.m3d-player::-webkit-scrollbar-track,
.m3d-action-grid::-webkit-scrollbar-track,
.m3d-detail-effect::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, .22);
  border-radius: 99px;
}

.m3d-player::-webkit-scrollbar-thumb,
.m3d-action-grid::-webkit-scrollbar-thumb,
.m3d-detail-effect::-webkit-scrollbar-thumb {
  background: rgba(232, 200, 118, .45);
  border-radius: 99px;
}

.m3d-player.active {
  border-color: rgba(232, 200, 118, .55);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .35), 0 0 24px rgba(211, 59, 80, .13);
}

.m3d-side-tab {
  min-width: 92px;
  color: #fff2d8;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .055), transparent 48%),
    rgba(44, 17, 23, .82);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.m3d-stat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 0 6px;
  border: 1px solid rgba(232, 200, 118, .14);
  border-radius: 4px;
  background: rgba(0, 0, 0, .24);
}

.m3d-stat span {
  color: var(--m3d-muted);
  font-family: var(--m3d-display);
  font-size: 10px;
  font-weight: 900;
}

.m3d-stat strong {
  min-width: 38px;
  text-align: center;
  color: #ffefba;
  font-family: var(--m3d-display);
  font-size: 16px;
}

.m3d-stat button {
  min-height: 25px;
  padding: 0 7px;
}

.m3d-pile-panel {
  position: fixed;
  left: 50%;
  bottom: 84px;
  z-index: 35;
  width: min(720px, calc(100vw - 36px));
  max-height: min(58vh, 520px);
  transform: translateX(-50%);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid rgba(232, 200, 118, .45);
  border-radius: 4px;
  background: var(--m3d-panel-strong);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .62);
  overflow: hidden;
}

.m3d-pile-panel[hidden] {
  display: none;
}

.m3d-pile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(232, 200, 118, .16);
}

.m3d-pile-head strong {
  font-family: var(--m3d-display);
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.m3d-pile-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
  padding: 12px;
  overflow: auto;
}

.m3d-pile-card {
  display: grid;
  gap: 7px;
  padding: 7px;
  border: 1px solid rgba(232, 200, 118, .12);
  border-radius: 5px;
  background: rgba(0, 0, 0, .22);
}

.m3d-pile-card img {
  width: 100%;
  aspect-ratio: 5 / 7;
  object-fit: cover;
  border-radius: 4px;
}

.m3d-pile-card strong {
  min-height: 34px;
  overflow: hidden;
  color: #fff4de;
  font-size: 12px;
  line-height: 1.35;
}

.m3d-pile-card div {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.m3d-pile-card button {
  flex: 1 1 42px;
  min-height: 28px;
  padding: 0 6px;
  font-size: 11px;
}

.m3d-loading {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background:
    radial-gradient(circle at 50% 42%, rgba(211, 59, 80, .20), transparent 35%),
    radial-gradient(circle at 50% 68%, rgba(125, 174, 255, .12), transparent 42%),
    #08070a;
  color: #ffefba;
  font-family: var(--m3d-display);
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
  transition: opacity .35s ease;
}

.m3d-loading.hide {
  opacity: 0;
  pointer-events: none;
}

.m3d-loading img {
  width: min(190px, 42vw);
  filter: brightness(1.24) drop-shadow(0 0 24px rgba(211, 59, 80, .45));
}

.m3d-toast,
.m3d-error {
  position: fixed;
  z-index: 70;
  pointer-events: none;
  border-radius: 4px;
  background: rgba(6, 4, 6, .88);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .42);
}

.m3d-toast {
  left: 50%;
  top: 78px;
  max-width: min(520px, calc(100vw - 28px));
  min-height: 38px;
  padding: 10px 16px;
  transform: translate(-50%, -12px);
  border: 1px solid rgba(232, 200, 118, .32);
  color: #fff2d8;
  opacity: 0;
  transition: opacity .18s ease, transform .18s ease;
}

.m3d-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.m3d-error {
  left: 14px;
  bottom: 118px;
  max-width: min(620px, calc(100vw - 28px));
  padding: 10px 12px;
  border: 1px solid rgba(211, 59, 80, .56);
  color: #ff9eae;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.m3d-error:empty {
  display: none;
}

@media (max-width: 1120px) {
  .m3d-card-detail {
    width: min(390px, calc(100vw - 32px));
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .m3d-detail-art img {
    width: 92px;
    height: 129px;
  }

  .m3d-detail-effect {
    max-height: 86px;
  }

  .m3d-command {
    width: 260px;
  }

  .m3d-turn-button {
    width: 116px;
    height: 116px;
  }

  .m3d-hud {
    width: calc(100vw - 292px);
  }
}

@media (max-width: 780px) {
  .m3d-topbar {
    left: 10px;
    right: 10px;
    gap: 8px;
  }

  .m3d-brand {
    flex: 1 1 auto;
    min-width: 0;
    height: 42px;
    padding-right: 8px;
  }

  .m3d-brand img {
    height: 24px;
  }

  .m3d-brand span {
    font-size: 11px;
  }

  .m3d-links {
    min-height: 42px;
    gap: 2px;
  }

  .m3d-links a {
    min-height: 30px;
    padding: 0 7px;
    font-size: 9px;
  }

  .m3d-card-detail {
    top: 62px;
    left: 10px;
    width: calc(100vw - 20px);
    min-height: 92px;
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 9px;
    padding: 8px;
  }

  .m3d-card-detail::before,
  .m3d-command::before {
    display: none;
  }

  .m3d-detail-art img {
    width: 54px;
    height: 76px;
  }

  .m3d-cost-gem {
    min-width: 25px;
    height: 25px;
    left: -5px;
    top: -5px;
    font-size: 11px;
  }

  .m3d-detail-title {
    min-height: 0;
    padding-bottom: 5px;
  }

  .m3d-detail-title strong {
    font-size: 13px;
  }

  .m3d-detail-title span,
  .m3d-detail-flavor {
    display: none;
  }

  .m3d-detail-stats {
    margin: 6px 0;
    min-height: 0;
  }

  .m3d-detail-stats span {
    min-height: 20px;
    font-size: 10px;
  }

  .m3d-detail-effect {
    min-height: 0;
    max-height: 38px;
    font-size: 11px;
    line-height: 1.35;
  }

  .m3d-command {
    top: 164px;
    right: 10px;
    width: 154px;
    gap: 6px;
    padding: 6px;
  }

  .m3d-side-status {
    min-height: 38px;
    grid-template-columns: 1fr auto;
    padding: 6px;
  }

  .m3d-side-status strong,
  .m3d-side-status b,
  .m3d-side-status span:not(.m3d-side-name),
  .m3d-side-status small {
    display: none;
  }

  .m3d-turn-wheel {
    gap: 4px;
  }

  .m3d-n-banner {
    min-width: 116px;
    min-height: 29px;
  }

  .m3d-n-banner strong {
    font-size: 18px;
  }

  .m3d-turn-button {
    width: 92px;
    height: 92px;
  }

  .m3d-turn-button span {
    font-size: 13px;
  }

  .m3d-turn-button strong {
    font-size: 19px;
  }

  .m3d-selected-mini,
  .m3d-action-grid,
  .m3d-table-actions {
    display: none;
  }

  .m3d-camera {
    display: none;
  }

  .m3d-hud {
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
  }

  .m3d-player {
    min-height: 42px;
    padding: 5px;
  }

  .m3d-side-tab {
    min-width: 78px;
  }

  select {
    min-width: 132px;
  }
}

@media (max-height: 720px) and (min-width: 781px) {
  .m3d-card-detail {
    width: 392px;
    min-height: 178px;
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .m3d-detail-art img {
    width: 92px;
    height: 129px;
  }

  .m3d-detail-effect {
    max-height: 70px;
  }

  .m3d-command {
    width: 276px;
    gap: 7px;
  }

  .m3d-turn-button {
    width: 108px;
    height: 108px;
  }

  .m3d-action-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
