:root {
  color-scheme: dark;
  --night: #1d1737;
  --plum: #2b1c47;
  --text: #fff8ff;
  --muted: #e9d9f4;
  --gold: #ffe5a8;
  --gold-deep: #f6b652;
  --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);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--night);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

#fyd-app {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
}

#fyd-background {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(180deg, #21153f38, #21153f12 38%, #20123280),
    url("velthia-campus.webp") 65% center / cover no-repeat,
    linear-gradient(165deg, #533d80, #1d1737);
  transition: filter 500ms ease, transform 500ms ease;
}

#fyd-app:is([data-state="ready"], [data-state="running"]) #fyd-background {
  filter: brightness(0.57) blur(6px);
  transform: scale(1.03);
}

#game-stage {
  position: relative;
  width: min(100%, calc(100dvh * 9 / 16));
  height: min(100%, calc(100vw * 16 / 9));
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  container-type: inline-size;
  contain: layout paint size;
  isolation: isolate;
}

#unity-canvas,
#html-loading-layer,
#transition-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#unity-canvas {
  display: block;
  z-index: 1;
  border: 0;
  outline: 0;
  background: var(--night);
  opacity: 0;
  transition: opacity 260ms ease;
}

#fyd-app:is([data-state="ready"], [data-state="running"]) #unity-canvas {
  opacity: 1;
}

#html-loading-layer {
  z-index: 5;
  display: grid;
  place-items: center;
  padding:
    max(14px, var(--safe-top))
    max(13px, var(--safe-right))
    max(14px, var(--safe-bottom))
    max(13px, var(--safe-left));
  opacity: 1;
  visibility: visible;
  transition: opacity 340ms ease, visibility 340ms step-start;
}

#fyd-app:is([data-state="ready"], [data-state="running"], [data-state="stopped"]) #html-loading-layer {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 340ms ease, visibility 340ms step-end;
}

.loader-panel {
  position: relative;
  display: grid;
  justify-items: center;
  width: min(100%, 26rem);
  min-width: 0;
  padding: clamp(14px, 7cqw, 34px) clamp(12px, 8cqw, 36px);
  border: 1px solid #f5d9ff83;
  border-radius: clamp(16px, 7cqw, 28px);
  background: linear-gradient(158deg, #4c356cef 0%, #32224fea 43%, #211632f5 100%);
  box-shadow: inset 0 1px 0 #ffe6ff42, 0 20px 50px #1d103d6b;
  text-align: center;
}

#entry-panel, #loading-details { width: 100%; }
#entry-panel[hidden], #loading-details[hidden] { display: none; }

#entry-panel {
  display: grid;
  gap: 10px;
}

#entry-panel h2 {
  margin: 0;
  color: #ffe5a9;
  font: 700 clamp(18px, 5cqw, 26px)/1.32 "Segoe UI", system-ui, sans-serif;
  text-wrap: balance;
  text-shadow: 0 0 18px #ebac6645;
}

#entry-panel p {
  margin: 0 0 4px;
  color: #f0dff6;
  font-size: clamp(12px, 3.6cqw, 15px);
}

#entry-panel .entry-status:empty { display: none; }

.entry-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid;
  border-radius: 999px;
  font: 750 clamp(13px, 4cqw, 17px)/1.3 system-ui, sans-serif;
  text-decoration: none;
  cursor: pointer;
  transition: filter 140ms ease, transform 140ms ease;
}

.entry-action-gold {
  border-color: #fff1bf;
  background: linear-gradient(177deg, #fff0ab, #f4b958 74%, #e7a044);
  box-shadow: inset 0 1px 0 #fff9da, 0 3px 0 #9b592b, 0 0 24px #f8b55a28;
  color: #432047;
}

.entry-action-violet {
  border-color: #dab6f6a0;
  background: linear-gradient(165deg, #8460ab63, #43275d86);
  color: #fff0ff;
}

.entry-action[aria-disabled="true"] {
  opacity: .64;
  cursor: default;
}

.entry-action:not([aria-disabled]):hover { filter: brightness(1.12); }
.entry-action:not([aria-disabled]):active { transform: translateY(2px); }
.entry-action:focus-visible { outline: 2px solid #fff1bf; outline-offset: 3px; }

.velthia-crest {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(46px, 21cqw, 92px);
  aspect-ratio: 1;
  margin-bottom: clamp(5px, 2cqw, 12px);
}

.velthia-crest::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid #f8d8915e;
  border-radius: 50%;
  animation: crest-glow 2.6s ease-out infinite;
}

.velthia-crest img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 50%;
  box-shadow: 0 0 24px #e1a7ff33;
}

@keyframes crest-glow {
  from { transform: scale(0.92); opacity: 0.9; }
  to { transform: scale(1.23); opacity: 0; }
}

#loading-product {
  margin: 0;
  color: var(--gold);
  font-family: "Segoe Script", "Snell Roundhand", "Brush Script MT", Georgia, serif;
  font-size: clamp(24px, 14cqw, 61px);
  font-style: italic;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.045em;
  text-shadow: 0 3px 0 #4a214a, 0 0 24px #ffae6a44;
}

#loading-product span {
  display: inline-block;
  margin-left: 0.12em;
  color: #ffdb82;
  font-family: system-ui, sans-serif;
  font-size: 0.42em;
  font-style: normal;
  vertical-align: 0.45em;
}

.brand-tagline {
  margin: 0.5em 0 0;
  color: var(--text);
  font-size: clamp(9px, 2.7cqw, 12px);
  font-weight: 750;
  line-height: 1.4;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.loader-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-block: clamp(12px, 5cqw, 25px);
  color: #dcc28b;
}

.loader-divider::before,
.loader-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, #e0c68978);
}

.loader-divider::after {
  transform: scaleX(-1);
}

.loader-divider span {
  width: 5px;
  height: 5px;
  transform: rotate(45deg);
  background: currentColor;
}

.progress-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin-bottom: 9px;
}

#loading-status,
#loading-percent {
  margin: 0;
  font-size: clamp(11px, 3.45cqw, 15px);
  line-height: 1.45;
}

#loading-status {
  min-width: 0;
  color: var(--muted);
  text-align: left;
  overflow-wrap: anywhere;
}

#loading-percent {
  flex-shrink: 0;
  color: var(--gold);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

#unity-progress-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border: 1px solid #d4a6e55e;
  border-radius: 999px;
  background: #170e2b;
}

#unity-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold-deep), #ffedb2);
  box-shadow: 0 0 12px #ffd3789e;
  transition: width 180ms linear;
}

#retry-button {
  min-height: 44px;
  margin-top: 14px;
  padding: 8px 22px;
  border: 1px solid #fff1bf;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffecb1, var(--gold-deep));
  color: #3b204b;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

#retry-button:hover {
  filter: brightness(1.08);
}

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

#transition-layer {
  z-index: 9;
  display: grid;
  place-items: center;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  background: var(--night);
  transition: opacity 300ms ease, visibility 300ms step-end;
}

#transition-layer.is-visible {
  visibility: visible;
  opacity: 1;
  transition: opacity 300ms ease, visibility 300ms step-start;
}

#transition-layer[data-theme="light"] {
  background: #fff4da;
}

.transition-core {
  width: 10%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ffe5a8e6;
  box-shadow: 0 0 70px 42px #ffcd7d66;
  opacity: 0;
  transform: scale(0.2);
  transition: opacity 300ms ease, transform 650ms ease;
}

#transition-layer.is-visible .transition-core {
  opacity: 1;
  transform: scale(12);
}

#unity-warning {
  position: absolute;
  z-index: 12;
  top: max(12px, var(--safe-top));
  left: 50%;
  width: calc(100% - 24px);
  display: grid;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.unity-banner {
  padding: 10px 12px;
  border: 1px solid #d5bbec77;
  border-radius: 12px;
  background: var(--plum);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.unity-banner.error {
  border-color: #fca5a5aa;
  background: #59203a;
}

#fullscreen-button {
  position: absolute;
  z-index: 8;
  right: max(10px, var(--safe-right));
  bottom: max(10px, var(--safe-bottom));
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid #dec4f67a;
  border-radius: 50%;
  background: #291741d9;
  color: var(--gold);
  font-size: 22px;
  cursor: pointer;
}

#google-login-container {
  position: absolute;
  z-index: 11;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

#google-login-container > * {
  pointer-events: auto;
}

@media (min-width: 760px) {
  #game-stage {
    border-radius: 18px;
  }

  #fyd-app:is([data-state="ready"], [data-state="running"]) #game-stage {
    box-shadow: 0 0 0 1px #f2d6ff40, 0 16px 72px #1d103d99;
  }
}

@media (max-width: 759px) {
  #fullscreen-button {
    display: none;
  }
}

@container (max-width: 230px) {
  .progress-label {
    flex-wrap: wrap;
  }

  #loading-percent {
    margin-left: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
