:root {
  color-scheme: light;
  --ink: #20223b;
  --muted: #69708d;
  --white: #ffffff;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --shadow: 0 18px 48px rgba(31, 40, 91, 0.24);
  --pink: #ff4fa3;
  --coral: #ff7e54;
  --cyan: #20bff2;
  --green: #20c66b;
  --purple: #8657e8;
  --gold: #ffd15a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, #31c6ff 0%, #54d8ff 40%, #e9fbff 100%);
  color: var(--ink);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  font: inherit;
}

.preloader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 79, 163, 0.24), transparent 34%),
    linear-gradient(180deg, #31c6ff 0%, #8657e8 58%, #253057 100%);
  transition:
    opacity 260ms ease,
    visibility 260ms ease;
}

.preloader-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(360px, 78vw);
  padding: 28px 24px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  text-align: center;
}

.preloader-logo {
  width: min(180px, 42vw);
  height: min(180px, 42vw);
  object-fit: contain;
}

.preloader p {
  margin: 0;
  color: var(--ink);
  font-size: 30px;
  font-weight: 900;
}

.preloader span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

body.preload-done .preloader {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

button:focus-visible {
  outline: 4px solid rgba(255, 255, 255, 0.95);
  outline-offset: 3px;
  box-shadow:
    0 0 0 7px rgba(32, 191, 242, 0.5),
    0 12px 28px rgba(25, 33, 76, 0.22);
}

.game-shell {
  position: relative;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  min-height: 620px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(31, 190, 242, 0.2), rgba(255, 255, 255, 0.02)),
    #31c6ff;
}

#runwayCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.hud-layer {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding:
    calc(14px + var(--safe-top))
    calc(16px + var(--safe-right))
    calc(14px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  pointer-events: none;
}

.top-hud {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(92px, 160px) minmax(190px, 340px) minmax(74px, 110px);
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.brand-lockup,
.wallet,
.theme-board,
.score-strip,
.closet-panel,
.result-sheet {
  pointer-events: auto;
}

.brand-lockup {
  display: grid;
  gap: 0;
  width: fit-content;
  max-width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 10px 24px rgba(30, 74, 116, 0.16);
  text-transform: uppercase;
}

.brand-lockup span {
  color: #208ac1;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
}

.brand-lockup strong {
  color: #26304f;
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 1000;
  line-height: 1;
  letter-spacing: 0;
}

.theme-board {
  justify-self: center;
  display: grid;
  place-items: center;
  min-width: min(320px, 45vw);
  padding: 14px 34px 13px;
  border: 3px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  background: linear-gradient(135deg, #8657e8 0%, var(--theme-accent, #e25cc8) 55%, #ff7e54 100%);
  color: var(--white);
  box-shadow: 0 14px 30px rgba(95, 56, 153, 0.25);
  text-align: center;
  text-transform: uppercase;
}

.theme-board span {
  position: absolute;
  top: -10px;
  padding: 3px 10px;
  border-radius: 6px;
  background: #17a55e;
  font-size: 0.73rem;
  font-weight: 950;
  box-shadow: 0 4px 0 rgba(27, 102, 68, 0.2);
}

.theme-board strong {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(1.7rem, 3.2vw, 2.9rem);
  font-weight: 1000;
  line-height: 0.9;
  letter-spacing: 0;
  text-shadow: 0 3px 0 rgba(61, 39, 94, 0.18);
}

.wallet {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 78px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(25, 33, 76, 0.72);
  color: var(--white);
  box-shadow: 0 12px 28px rgba(23, 45, 91, 0.22);
  font-size: 1.22rem;
  font-weight: 1000;
}

.gem-shape {
  width: 24px;
  height: 24px;
  background: linear-gradient(145deg, #ff7aff 0%, #9258ff 58%, #5934bc 100%);
  clip-path: polygon(50% 100%, 5% 38%, 24% 9%, 76% 9%, 95% 38%);
  filter: drop-shadow(0 2px 0 rgba(41, 25, 98, 0.3));
}

.score-strip {
  z-index: 4;
  align-self: start;
  justify-self: center;
  display: grid;
  grid-template-columns: auto minmax(130px, 260px) auto;
  align-items: center;
  gap: 10px;
  margin-top: 17px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 10px 24px rgba(45, 77, 120, 0.16);
}

.score-block {
  display: grid;
  gap: 1px;
  min-width: 54px;
  text-align: center;
  text-transform: uppercase;
}

.score-block span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 950;
}

.score-block strong {
  color: var(--pink);
  font-size: 1.28rem;
  font-weight: 1000;
  line-height: 1;
}

.score-block.rival strong {
  color: var(--cyan);
}

.score-meter {
  height: 12px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(44, 56, 100, 0.16);
}

.score-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--pink), var(--gold), var(--green));
  transition: width 220ms ease;
}

.reaction-stack {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
}

.reaction-stack span {
  position: absolute;
  right: clamp(34px, 15vw, 250px);
  top: clamp(210px, 38vh, 420px);
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255, 255, 255, 0.86);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, #ffffff 0 8%, transparent 9%),
    linear-gradient(135deg, #ff4fa3, #ffd15a);
  box-shadow: 0 9px 22px rgba(75, 50, 120, 0.22);
  animation: reaction-float 1200ms ease-out forwards;
}

.reaction-stack span::before,
.reaction-stack span::after {
  position: absolute;
  width: 12px;
  height: 18px;
  border-radius: 12px 12px 0 0;
  background: #d7215d;
  content: "";
}

.reaction-stack span::before {
  left: 14px;
  top: 13px;
  transform: rotate(-45deg);
  transform-origin: 0 100%;
}

.reaction-stack span::after {
  left: 19px;
  top: 13px;
  transform: rotate(45deg);
  transform-origin: 100% 100%;
}

@keyframes reaction-float {
  0% {
    opacity: 0;
    transform: translate3d(0, 20px, 0) scale(0.62);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--drift, 0), -90px, 0) scale(1.12);
  }
}

.closet-panel {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(110px, 152px) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
  width: min(1180px, 100%);
  min-height: 142px;
  margin: 0 auto;
  padding: 10px;
  border: 2px solid rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.category-rail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.category-tab,
.item-card,
.tool-button,
.primary-button {
  min-width: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease, box-shadow 160ms ease;
}

.category-tab {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 6px;
  background: #e9f3ff;
  color: #4e5b7f;
  font-size: 0.72rem;
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

.category-tab:disabled {
  cursor: default;
  opacity: 1;
}

.category-tab[aria-selected="true"] {
  background: linear-gradient(135deg, var(--tab-color), #ff7e54);
  color: var(--white);
  box-shadow: 0 6px 0 rgba(124, 51, 124, 0.18);
}

.category-tab.is-complete {
  background: linear-gradient(135deg, #20c66b, #20bff2);
  color: var(--white);
}

.category-tab.is-complete::after {
  content: "OK";
  margin-top: 2px;
  font-size: 0.58rem;
  line-height: 1;
}

.item-rail {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(130px, 1fr);
  gap: 9px;
  overflow-x: auto;
  padding: 1px 2px 5px;
  scrollbar-width: thin;
}

.item-card {
  position: relative;
  display: grid;
  grid-template-rows: 58px auto;
  gap: 6px;
  min-height: 116px;
  padding: 9px;
  border: 3px solid transparent;
  background: var(--panel-solid);
  color: #2e3559;
  text-align: left;
  box-shadow: 0 9px 20px rgba(51, 69, 126, 0.12);
}

.item-card:disabled {
  cursor: default;
}

.item-card.is-locked {
  opacity: 0.58;
  filter: grayscale(0.18);
}

.item-card.is-locked::after {
  position: absolute;
  right: 8px;
  top: 8px;
  display: grid;
  place-items: center;
  min-width: 50px;
  height: 22px;
  padding: 0 7px;
  border-radius: 99px;
  background: rgba(32, 34, 59, 0.72);
  color: #ffffff;
  content: "WAIT";
  font-size: 0.58rem;
  font-weight: 950;
}

.item-card.is-selected {
  border-color: var(--pink);
  box-shadow: 0 12px 24px rgba(255, 79, 163, 0.26);
}

.item-card.is-selected::after {
  position: absolute;
  right: 8px;
  top: 8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--green);
  color: var(--white);
  content: "";
}

.item-card.is-selected::before {
  position: absolute;
  z-index: 2;
  right: 15px;
  top: 11px;
  width: 5px;
  height: 11px;
  border-right: 3px solid var(--white);
  border-bottom: 3px solid var(--white);
  content: "";
  transform: rotate(42deg);
}

.item-card.is-locked::after {
  display: grid;
  min-width: 50px;
  height: 22px;
  padding: 0 7px;
  border-radius: 99px;
  background: rgba(32, 34, 59, 0.72);
  color: #ffffff;
  content: "WAIT";
  font-size: 0.58rem;
  font-weight: 950;
}

.item-card.is-locked::before {
  content: none;
}

.item-card:hover,
.tool-button:hover,
.primary-button:hover {
  filter: brightness(1.04);
  transform: translateY(-2px);
}

.item-preview {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--preview-a) 70%, #ffffff 30%), var(--preview-b));
  overflow: hidden;
}

.item-preview::before {
  position: absolute;
  width: var(--shape-width, 42px);
  height: var(--shape-height, 50px);
  border-radius: var(--shape-radius, 7px);
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--preview-a) 84%, #ffffff 16%), var(--preview-b));
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.09);
  clip-path: var(--shape);
  content: "";
}

.item-card strong,
.item-card span {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.item-card strong {
  font-size: 0.9rem;
  font-weight: 950;
  line-height: 1.05;
}

.item-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 850;
  line-height: 1.1;
  text-transform: uppercase;
}

.action-row {
  display: grid;
  grid-template-rows: auto 1fr 1fr;
  gap: 7px;
  min-width: 128px;
}

.gate-status {
  position: relative;
  display: grid;
  align-content: center;
  min-height: 30px;
  overflow: hidden;
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(32, 34, 59, 0.1);
  color: #35405f;
  font-size: 0.66rem;
  font-weight: 950;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
}

.gate-status span {
  position: relative;
  z-index: 1;
}

.gate-status b {
  position: absolute;
  inset: auto 0 0;
  width: 0;
  height: 5px;
  background: linear-gradient(90deg, var(--pink), var(--gold), var(--green));
  transition: width 140ms linear;
}

.game-shell[data-gate="ready"] .gate-status {
  background: rgba(32, 198, 107, 0.15);
  color: #177844;
}

.tool-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  color: var(--white);
  font-weight: 950;
  text-transform: uppercase;
  box-shadow: 0 7px 0 rgba(72, 59, 110, 0.2);
}

.tool-button:disabled,
.primary-button:disabled {
  cursor: default;
  filter: grayscale(0.14) brightness(0.98);
  opacity: 0.72;
  transform: none;
}

.tool-button {
  background: linear-gradient(135deg, var(--cyan), var(--purple));
}

.primary-button {
  background: linear-gradient(135deg, var(--pink), var(--coral));
}

.tool-button svg,
.primary-button svg {
  width: 18px;
  height: 18px;
  stroke-width: 3;
}

.result-panel {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding:
    calc(20px + var(--safe-top))
    calc(20px + var(--safe-right))
    calc(20px + var(--safe-bottom))
    calc(20px + var(--safe-left));
  background: rgba(37, 52, 101, 0.36);
  backdrop-filter: blur(4px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.result-panel.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.result-sheet {
  width: min(430px, 92vw);
  padding: 24px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  text-align: center;
}

.result-sheet > span {
  display: block;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
}

.result-sheet h1 {
  margin: 4px 0 18px;
  color: #253057;
  font-size: clamp(2.3rem, 7vw, 4.2rem);
  font-weight: 1000;
  line-height: 0.92;
  letter-spacing: 0;
  text-transform: uppercase;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result-stats div {
  padding: 12px;
  border-radius: 8px;
  background: #edf6ff;
}

.result-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 950;
  text-transform: uppercase;
}

.result-stats strong {
  display: block;
  color: var(--pink);
  font-size: 2rem;
  font-weight: 1000;
  line-height: 1;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.game-shell[data-phase="runway"] .closet-panel {
  opacity: 0.86;
}

.game-shell[data-phase="runway"] .action-row {
  opacity: 0.45;
  pointer-events: none;
}

@media (max-width: 760px) {
  .game-shell {
    min-height: 690px;
  }

  .hud-layer {
    padding:
      calc(10px + var(--safe-top))
      calc(10px + var(--safe-right))
      calc(10px + var(--safe-bottom))
      calc(10px + var(--safe-left));
  }

  .top-hud {
    grid-template-columns: minmax(64px, 94px) minmax(130px, 1fr) minmax(60px, 74px);
    gap: 7px;
  }

  .brand-lockup {
    padding: 8px 9px;
  }

  .brand-lockup span {
    font-size: 0.56rem;
  }

  .brand-lockup strong {
    font-size: 0.92rem;
  }

  .theme-board {
    min-width: 0;
    padding: 12px 12px 10px;
  }

  .theme-board span {
    display: none;
  }

  .theme-board strong {
    font-size: 1.35rem;
  }

  .wallet {
    min-width: 0;
    gap: 5px;
    padding: 8px;
    font-size: 0.96rem;
  }

  .gem-shape {
    width: 18px;
    height: 18px;
  }

  .score-strip {
    grid-template-columns: auto minmax(82px, 160px) auto;
    gap: 7px;
    margin-top: 10px;
    padding: 7px;
  }

  .score-block {
    min-width: 44px;
  }

  .score-block span {
    font-size: 0.58rem;
  }

  .score-block strong {
    font-size: 1.03rem;
  }

  .closet-panel {
    grid-template-columns: 1fr;
    width: calc(100vw - 20px);
    min-height: 214px;
    gap: 8px;
    overflow: hidden;
  }

  .category-rail {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }

  .category-tab {
    min-height: 32px;
    padding: 4px;
    font-size: 0.52rem;
  }

  .category-tab.is-complete::after {
    display: none;
  }

  .item-rail {
    grid-auto-columns: minmax(112px, 37vw);
  }

  .item-card {
    grid-template-rows: 48px auto;
    min-height: 101px;
    padding: 8px;
  }

  .item-card strong {
    font-size: 0.78rem;
  }

  .item-card span {
    font-size: 0.58rem;
  }

  .action-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    width: 100%;
    min-width: 0;
  }

  .gate-status {
    grid-column: 1 / -1;
    min-height: 25px;
    padding: 4px 8px;
    font-size: 0.58rem;
  }

  .tool-button,
  .primary-button {
    width: 100%;
    min-height: 43px;
    padding: 0 8px;
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .tool-button svg,
  .primary-button svg {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .game-shell {
    min-height: 0;
  }

  .hud-layer {
    padding: 8px;
  }

  .top-hud {
    grid-template-columns: 92px minmax(150px, 270px) 76px;
  }

  .brand-lockup {
    padding: 7px 9px;
  }

  .theme-board {
    padding: 9px 22px 8px;
  }

  .theme-board strong {
    font-size: clamp(1.1rem, 3vw, 1.8rem);
  }

  .theme-board span {
    top: -8px;
    font-size: 0.6rem;
  }

  .score-strip {
    margin-top: 7px;
  }

  .closet-panel {
    grid-template-columns: 120px minmax(0, 1fr) 116px;
    min-height: 116px;
    padding: 8px;
  }

  .category-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .category-tab {
    font-size: 0.57rem;
  }

  .item-rail {
    grid-auto-columns: minmax(116px, 1fr);
    gap: 7px;
  }

  .item-card {
    grid-template-rows: 38px auto;
    min-height: 88px;
    padding: 7px;
    border-width: 2px;
  }

  .gate-status {
    min-height: 24px;
    font-size: 0.54rem;
  }

  .item-card strong {
    font-size: 0.72rem;
  }

  .item-card span {
    font-size: 0.54rem;
  }

  .tool-button,
  .primary-button {
    min-height: 39px;
    padding: 0 8px;
    font-size: 0.68rem;
  }
}
