:root {
  color-scheme: light dark;
  --app-bg: #eef2ee;
  --app-surface: rgba(250, 252, 250, .82);
  --app-surface-solid: #fafcfa;
  --app-text: #172019;
  --app-soft: #647068;
  --app-line: rgba(36, 55, 42, .15);
  --app-accent: #376d48;
  --app-accent-text: #f6faf7;
  --scrim: rgba(10, 15, 11, .62);
  --window-bg: #101712;
  --window-line: rgba(227, 239, 230, .2);
  --window-text: #eef5f0;
  --window-soft: #9dab9f;
  --danger: #b55248;
  --radius-panel: 18px;
  --radius-control: 12px;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", ui-sans-serif, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --app-bg: #121713;
    --app-surface: rgba(27, 35, 29, .84);
    --app-surface-solid: #1b231d;
    --app-text: #edf3ee;
    --app-soft: #a4b0a7;
    --app-line: rgba(223, 237, 227, .14);
    --app-accent: #9edfae;
    --app-accent-text: #152019;
    --scrim: rgba(5, 8, 6, .74);
  }
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 0; min-height: 100%; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--app-text);
  background:
    radial-gradient(circle at 80% 8%, rgba(74, 133, 91, .15), transparent 28rem),
    var(--app-bg);
}

button, a { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(1180px, calc(100% - 48px));
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  margin: 0 auto;
}

.app-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--app-line);
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--app-text);
  text-decoration: none;
}

.app-brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-control);
  background: var(--app-accent);
  color: var(--app-accent-text);
  font-size: 15px;
  font-weight: 800;
}

.app-brand strong, .app-brand small { display: block; }
.app-brand strong { font-size: 16px; letter-spacing: -.025em; }
.app-brand small { margin-top: 2px; color: var(--app-soft); font-size: 11px; }

.console-link {
  padding: 10px 13px;
  border: 1px solid var(--app-line);
  border-radius: var(--radius-control);
  color: var(--app-text);
  font-size: 12px;
  text-decoration: none;
  transition: background-color .2s ease, transform .2s ease;
}
.console-link:hover { background: var(--app-surface); transform: translateY(-1px); }

.launcher-content {
  display: grid;
  grid-template-columns: minmax(0, .8fr) minmax(300px, 1.2fr);
  align-items: center;
  gap: clamp(50px, 8vw, 120px);
  padding: 56px 5vw;
}

.launcher-copy { align-self: center; }
.launcher-kicker { margin: 0 0 12px; color: var(--app-accent); font-size: 12px; font-weight: 800; letter-spacing: .08em; }
.launcher-copy h1 { max-width: 9ch; margin: 0; font-size: clamp(42px, 5vw, 68px); line-height: 1.02; letter-spacing: -.065em; }
.launcher-copy > p:last-child { max-width: 30em; margin: 20px 0 0; color: var(--app-soft); font-size: 14px; line-height: 1.7; }

.game-grid { display: grid; justify-items: center; }
.game-entry { width: min(330px, 100%); display: grid; justify-items: stretch; }

.game-tile {
  width: 100%;
  display: grid;
  justify-items: center;
  padding: 28px;
  border: 1px solid var(--app-line);
  border-radius: var(--radius-panel);
  background: var(--app-surface);
  color: var(--app-text);
  box-shadow: 0 26px 70px rgba(40, 61, 47, .12), inset 0 1px 0 rgba(255, 255, 255, .16);
  backdrop-filter: blur(18px);
  cursor: pointer;
  transition: transform .28s cubic-bezier(.16, 1, .3, 1), box-shadow .28s ease, border-color .28s ease;
}

.game-tile:hover { transform: translateY(-8px); border-color: color-mix(in srgb, var(--app-accent) 55%, transparent); box-shadow: 0 34px 84px rgba(31, 56, 39, .18), inset 0 1px 0 rgba(255, 255, 255, .16); }
.game-tile:active { transform: translateY(-4px) scale(.985); }
.game-tile:disabled { cursor: wait; opacity: .72; }
.game-tile:disabled:hover, .game-tile:disabled:active { transform: none; border-color: var(--app-line); box-shadow: 0 26px 70px rgba(40, 61, 47, .12), inset 0 1px 0 rgba(255, 255, 255, .16); }

.game-icon-wrap {
  width: min(190px, 52vw);
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 26%;
  box-shadow: 0 18px 42px rgba(18, 39, 24, .24);
}
.game-icon-wrap img { width: 100%; height: 100%; display: block; object-fit: cover; }
.game-name { margin-top: 22px; font-size: 21px; font-weight: 750; letter-spacing: -.035em; }
.game-description { margin-top: 6px; color: var(--app-soft); font-size: 12px; }

.authorization-state {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--app-soft);
  font-size: 11px;
}
.authorization-copy { min-width: 0; text-align: center; }
.authorization-copy > span, .authorization-code { display: block; }
.authorization-code {
  max-width: min(520px, 84vw);
  margin-top: 6px;
  color: var(--app-soft);
  font: 10px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}
.authorization-state.is-ready { color: var(--app-accent); }
.authorization-state.is-error { color: var(--danger); }
.authorization-state button {
  padding: 6px 9px;
  border: 1px solid currentColor;
  border-radius: var(--radius-control);
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-weight: 750;
  white-space: nowrap;
}
.authorization-state button:active { transform: scale(.98); }

.app-footer {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--app-line);
  color: var(--app-soft);
  font-size: 11px;
}

.game-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  visibility: hidden;
  opacity: 0;
  background: var(--scrim);
  backdrop-filter: blur(12px);
  pointer-events: none;
  transition: opacity .24s ease, visibility 0s linear .24s;
}

.game-layer.is-open { visibility: visible; opacity: 1; pointer-events: auto; transition-delay: 0s; }
.has-game-open { overflow: hidden; }

.game-window {
  position: relative;
  width: min(66.666vw, calc((100dvh - 40px) * 9 / 16));
  height: auto;
  aspect-ratio: 9 / 16;
  min-width: 320px;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--window-line);
  border-radius: var(--radius-panel);
  background: var(--window-bg);
  box-shadow: 0 40px 120px rgba(3, 7, 4, .38), inset 0 1px 0 rgba(255, 255, 255, .09);
  transform: translateY(18px) scale(.97);
  transition: transform .28s cubic-bezier(.16, 1, .3, 1);
}

.game-layer.is-open .game-window { transform: none; }

.close-game {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0 0 2px;
  border: 1px solid rgba(232, 242, 235, .28);
  border-radius: var(--radius-control);
  background: rgba(10, 17, 12, .84);
  color: var(--window-text);
  box-shadow: 0 8px 24px rgba(3, 7, 4, .28), inset 0 1px 0 rgba(255, 255, 255, .1);
  backdrop-filter: blur(12px);
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
}

.close-game[hidden] { display: none; }

.close-game:active, .error-actions button:active { transform: scale(.98); }
.game-tile:focus-visible, .app-brand:focus-visible, .console-link:focus-visible, .close-game:focus-visible, .authorization-state button:focus-visible, .error-actions button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--app-accent) 65%, transparent);
  outline-offset: 3px;
}

.game-window-stage { position: absolute; inset: 0; overflow: hidden; background: #101712; }
.game-window-stage iframe { width: 100%; height: 100%; display: block; border: 0; opacity: 0; background: #101712; transition: opacity .2s ease; }
.game-window-stage iframe.is-ready { opacity: 1; }

.game-loading, .game-error { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; padding: 24px; background: #101712; color: var(--window-text); }
.game-loading[hidden], .game-error[hidden] { display: none; }
.game-loading { grid-template-columns: 72px minmax(0, 300px); gap: 20px; }
.loading-icon { width: 72px; height: 72px; border-radius: var(--radius-panel); background: #233529; }
.loading-copy { width: 100%; }
.loading-copy span { display: block; height: 12px; margin-top: 10px; border-radius: 6px; background: #26342a; }
.loading-copy span:first-child { width: 54%; height: 22px; margin-top: 0; }
.loading-copy p { margin: 16px 0 0; color: var(--window-soft); font-size: 12px; }

@media (prefers-reduced-motion: no-preference) {
  .loading-icon, .loading-copy span { animation: app-loading 1.1s ease-in-out infinite alternate; }
}
@keyframes app-loading { from { opacity: .45; } to { opacity: 1; } }

.game-error > div { width: min(440px, 90%); padding: 28px; border: 1px solid var(--window-line); border-radius: var(--radius-panel); background: #18211b; }
.error-label { color: #e98578; font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 800; }
.game-error h2 { margin: 10px 0 8px; font-size: 26px; letter-spacing: -.04em; }
.game-error p { margin: 0; color: var(--window-soft); line-height: 1.6; }
.error-actions { display: flex; gap: 10px; margin-top: 22px; }
.error-actions button { padding: 10px 14px; border-radius: var(--radius-control); cursor: pointer; }
.retry-game { border: 1px solid #9edfae; background: #9edfae; color: #142019; font-weight: 800; }
.return-app { border: 1px solid #506057; background: transparent; color: var(--window-text); }

@media (max-width: 900px) {
  .launcher-content { grid-template-columns: 1fr 1fr; gap: 34px; padding-right: 0; padding-left: 0; }
}

@media (max-width: 760px), (any-pointer: coarse) and (max-width: 1100px), (hover: none) and (max-width: 1100px) {
  .app-shell {
    width: 100%;
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
  }
  .app-header { min-height: 64px; gap: 12px; }
  .app-brand small { display: none; }
  .app-brand-mark { width: 38px; height: 38px; }
  .console-link { min-height: 40px; display: grid; place-items: center; padding: 8px 11px; }
  .launcher-content { grid-template-columns: 1fr; align-content: center; gap: 24px; padding: 28px 0; }
  .launcher-copy { text-align: left; }
  .launcher-kicker { margin-bottom: 8px; font-size: 11px; }
  .launcher-copy h1 { max-width: none; font-size: clamp(32px, 9.5vw, 44px); line-height: 1.05; }
  .launcher-copy > p:last-child { max-width: 34em; margin-top: 12px; font-size: 13px; line-height: 1.6; }
  .game-entry { width: 100%; }
  .game-tile {
    grid-template-columns: 84px minmax(0, 1fr);
    grid-template-rows: auto auto;
    justify-items: start;
    column-gap: 16px;
    padding: 16px;
    text-align: left;
    backdrop-filter: blur(12px);
  }
  .game-tile:hover { transform: none; }
  .game-tile:active { transform: scale(.985); }
  .game-icon-wrap { width: 84px; grid-row: 1 / span 2; }
  .game-name { align-self: end; margin-top: 0; font-size: 19px; }
  .game-description { align-self: start; margin-top: 4px; }
  .authorization-state { justify-content: flex-start; min-height: 34px; margin: 8px 2px 0; }
  .authorization-copy { text-align: left; }
  .authorization-code { max-width: calc(100vw - 36px); }
  .app-footer { min-height: 52px; padding-top: 10px; font-size: 10px; }
  .game-layer {
    place-items: stretch;
    padding: 0;
    background: var(--window-bg);
    backdrop-filter: none;
  }
  .game-window {
    width: 100%;
    height: 100dvh;
    aspect-ratio: auto;
    min-width: 0;
    min-height: 0;
    border: 0;
    border-radius: 0;
    transform: translateY(24px);
    box-shadow: none;
  }
  .close-game {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    width: 40px;
    height: 40px;
    font-size: 26px;
  }
  .game-loading { grid-template-columns: 56px minmax(0, 1fr); gap: 16px; }
  .loading-icon { width: 56px; height: 56px; }
  .game-error { padding: 16px; }
  .game-error > div { width: 100%; padding: 22px; }
  .game-error h2 { font-size: 23px; }
  .error-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .error-actions button { min-height: 44px; }
}

@media (max-height: 680px) and (min-width: 761px) and (any-hover: hover) {
  .game-window {
    width: min(66.666vw, calc((100dvh - 32px) * 9 / 16));
    min-width: 0;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .game-tile { background: var(--app-surface-solid); backdrop-filter: none; }
  .game-layer { backdrop-filter: none; }
}

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