:root {
  color-scheme: light;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background: radial-gradient(circle at 20% 10%, #122454 0%, #060910 55%, #020205 100%);
  color: #f5f7ff;
  --render-aspect-width: 9;
  --render-aspect-height: 16;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
}

.homepage {
  overflow-x: hidden;
}

.homepage-shell {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: clamp(14px, 4vw, 24px);
}

.page-header {
  margin-bottom: 24px;
}

.page-header--with-auth {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.page-header h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3rem);
  letter-spacing: 0.04em;
}

.auth-link {
  display: inline-flex;
  align-items: center;
  color: #b7ceff;
  text-decoration: none;
  font-weight: 700;
}

.auth-link:hover,
.auth-link:focus-visible {
  color: #f2f7ff;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 90px), 1fr));
  gap: 14px;
  min-width: 0;
}

.game-tile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-decoration: none;
  color: #e9f2ff;
  padding: 12px;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  border: 1px solid rgba(98, 145, 255, 0.45);
  background: var(--tile-color, #1D3557);
  box-shadow: 0 6px 18px rgba(4, 10, 28, 0.45);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.game-tile:hover,
.game-tile:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 12px 20px rgba(9, 16, 39, 0.52);
}

.tile-id {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
  word-break: break-word;
}


.empty-state {
  margin-top: 32px;
  color: #cfdbff;
}

@media (max-width: 520px) {
  .page-header--with-auth {
    align-items: center;
  }
}

.game-page {
  overflow: hidden;
  --bottom-tab-height: 68px;
  --edit-drawer-height: 86px;
  --game-layout-height: calc(100dvh - var(--bottom-tab-height));
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.game-page--public {
  --bottom-tab-height: 0px;
  --edit-drawer-height: 0px;
  --game-layout-height: 100dvh;
}

.game-layout {
  width: 100vw;
  height: var(--game-layout-height);
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
}

.game-layout--public {
  display: block;
}

.game-layout--public .game-stage {
  width: 100vw;
  height: var(--game-layout-height);
  flex: 1 1 auto;
  border-right: 0;
}

.game-layout--public .game-render-area {
  width: min(100vw, calc(var(--game-layout-height) * var(--render-aspect-width) / var(--render-aspect-height)));
  height: min(var(--game-layout-height), calc(100vw * var(--render-aspect-height) / var(--render-aspect-width)));
}

.game-stage {
  flex: 0 0 min(calc(var(--game-layout-height) * var(--render-aspect-width) / var(--render-aspect-height)), 58vw);
  height: var(--game-layout-height);
  display: grid;
  place-items: center;
  background: #030712;
  border-right: 1px solid rgba(86, 122, 202, 0.25);
}

.game-render-area {
  width: min(100%, calc(var(--game-layout-height) * var(--render-aspect-width) / var(--render-aspect-height)));
  height: min(var(--game-layout-height), calc(100% * var(--render-aspect-height) / var(--render-aspect-width)));
  background: #02060f;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.prompt-panel {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 24;
  height: var(--edit-drawer-height);
  padding: 12px 14px;
  background: rgba(5, 10, 28, 0.95);
  border-top: 1px solid rgba(120, 157, 237, 0.38);
  box-shadow: 0 -12px 24px rgba(2, 6, 17, 0.45);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  transform: translateY(calc(100% + 6px));
  opacity: 0.9;
  pointer-events: none;
  transition: transform 0.24s ease, opacity 0.24s ease;
}

.prompt-panel--open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.prompt-form {
  display: flex;
  gap: 10px;
  width: 100%;
  min-width: 0;
  margin: 0;
}

.game-codex-transcript {
  display: none;
  min-height: 0;
  border: 1px solid rgba(120, 157, 237, 0.35);
  border-radius: 12px;
  background: rgba(6, 12, 31, 0.72);
  overflow: hidden;
}

.game-codex-transcript--open {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  margin-bottom: 10px;
}

.game-codex-transcript-header {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(128, 163, 244, 0.28);
}

.game-codex-transcript-header h2 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.prompt-form input,
.prompt-form textarea {
  -webkit-user-select: text;
  user-select: text;
}

.prompt-form input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid rgba(185, 207, 255, 0.6);
  border-radius: 10px;
  background: rgba(10, 17, 40, 1);
  color: #f7f9ff;
  padding: 12px;
  font-size: 1rem;
}

.prompt-form input:focus {
  outline: 2px solid rgba(88, 148, 255, 0.9);
  outline-offset: 1px;
}


.prompt-record-button {
  flex: 0 0 auto;
  width: 52px;
  border: 1px solid rgba(185, 207, 255, 0.7);
  border-radius: 10px;
  background: rgba(28, 45, 87, 0.88);
  color: #f7f9ff;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.prompt-record-button span {
  display: block;
  transform: translateY(1px);
}

.prompt-record-button--recording {
  background: rgba(132, 28, 42, 0.9);
  border-color: rgba(255, 163, 176, 0.9);
}

.prompt-record-button--busy {
  opacity: 0.7;
}

.prompt-record-button:focus-visible {
  outline: 2px solid rgba(88, 148, 255, 0.9);
  outline-offset: 1px;
}

.prompt-codex-toggle {
  flex: 0 0 auto;
  width: 52px;
  border: 1px solid rgba(185, 207, 255, 0.7);
  border-radius: 10px;
  background: rgba(28, 45, 87, 0.88);
  color: #f7f9ff;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.prompt-codex-toggle:focus-visible {
  outline: 2px solid rgba(88, 148, 255, 0.9);
  outline-offset: 1px;
}

.prompt-codex-toggle span {
  display: block;
  transform: translateY(1px);
}

.game-bottom-tabs {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  height: var(--bottom-tab-height);
  padding: 0 14px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: flex-end;
  background: linear-gradient(180deg, rgba(3, 7, 20, 0.02) 0%, rgba(3, 7, 20, 0.96) 44%, rgba(3, 7, 20, 0.98) 100%);
  box-shadow: 0 -10px 24px rgba(3, 8, 24, 0.55);
  transform: translateY(0);
  transition: transform 0.24s ease;
}

.game-home-link {
  align-self: center;
  color: #d8e6ff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 2.15rem;
  font-weight: 700;
  line-height: 1;
  width: 40px;
  height: calc(var(--bottom-tab-height) - 16px);
  background: transparent;
}

.game-home-link:focus-visible,
.game-view-tab:focus-visible {
  outline: 2px solid rgba(103, 163, 255, 0.95);
  outline-offset: 1px;
}

.game-view-tab {
  --tab-fill: rgba(7, 22, 54, 0.98);
  position: relative;
  height: calc(var(--bottom-tab-height) - 10px);
  width: auto;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(161, 191, 255, 0.45);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  background: linear-gradient(165deg, rgba(13, 30, 72, 0.98), var(--tab-fill));
  color: #d8e6ff;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 20px 10px;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.game-view-tab--edit {
  gap: 16px;
}

.game-view-tab-label {
  display: inline-block;
}

.game-view-tab-spinner {
  display: none;
  width: 13px;
  height: 13px;
  border-radius: 999px;
  border: 2px solid transparent;
  border-top-color: #f7f9ff;
}

.game-view-tab--generating .game-view-tab-spinner {
  display: inline-block;
  animation: game-tab-spinner-rotate 0.8s linear infinite;
}

@keyframes game-tab-spinner-rotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.game-view-tab--active {
  --tab-fill: rgba(25, 63, 140, 0.96);
  color: #f5f8ff;
  border-color: rgba(186, 214, 255, 0.95);
  background: linear-gradient(170deg, rgba(37, 82, 172, 0.95), var(--tab-fill));
}

.game-page--edit-open .game-bottom-tabs {
  transform: translateY(calc(-1 * var(--edit-drawer-height)));
}

.game-page--edit-open .game-view-tab--edit {
  --tab-fill: rgba(6, 12, 31, 0.97);
  border-color: rgba(132, 168, 245, 0.55);
}

.game-page--codex-expanded .prompt-panel {
  height: calc(100dvh - var(--bottom-tab-height));
  padding-top: calc(var(--bottom-tab-height) + 10px);
}

.game-page--codex-expanded .game-bottom-tabs {
  transform: translateY(calc(-100dvh + var(--bottom-tab-height)));
}

.game-page--codex-expanded .codex-session-view--game {
  max-height: none;
}

.codex-page {
  overflow-y: auto;
}

.auth-page {
  overflow-y: auto;
}

.auth-shell {
  max-width: 520px;
  margin: 0 auto;
  padding: 30px 18px 44px;
}

.auth-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.auth-home-link {
  color: #b7ceff;
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px solid rgba(183, 206, 255, 0.4);
}

.auth-home-link:hover,
.auth-home-link:focus-visible {
  color: #eff5ff;
  border-bottom-color: rgba(239, 245, 255, 0.82);
}

.auth-status {
  margin: 4px 0 14px;
  color: #ccddff;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-label {
  color: #d5e5ff;
  font-size: 0.92rem;
}

.auth-input {
  width: 100%;
  border: 1px solid rgba(165, 193, 255, 0.55);
  border-radius: 10px;
  background: rgba(8, 15, 35, 0.95);
  color: #f4f8ff;
  padding: 12px;
  font-size: 1rem;
}

.auth-input:focus-visible {
  outline: 2px solid rgba(103, 163, 255, 0.95);
  outline-offset: 1px;
}

.auth-submit {
  width: fit-content;
  border: 1px solid rgba(182, 207, 255, 0.72);
  border-radius: 10px;
  background: rgba(24, 46, 96, 0.96);
  color: #f7fbff;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.auth-submit:focus-visible {
  outline: 2px solid rgba(103, 163, 255, 0.95);
  outline-offset: 1px;
}

.auth-error {
  margin: 0 0 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 180, 192, 0.65);
  background: rgba(127, 18, 39, 0.34);
  color: #ffcad4;
}

.codex-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 44px;
}

.codex-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.codex-home-link {
  color: #b7ceff;
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px solid rgba(183, 206, 255, 0.4);
}

.codex-home-link:hover,
.codex-home-link:focus-visible {
  color: #e4efff;
  border-bottom-color: rgba(228, 239, 255, 0.8);
}

.codex-controls {
  margin-top: 18px;
  margin-bottom: 18px;
  display: grid;
  gap: 8px;
}

.codex-label {
  font-size: 0.92rem;
  color: #d5e3ff;
  letter-spacing: 0.03em;
}

.codex-select {
  width: 100%;
  border: 1px solid rgba(165, 193, 255, 0.55);
  border-radius: 10px;
  background: linear-gradient(170deg, rgba(16, 29, 63, 0.95), rgba(8, 15, 35, 0.95));
  color: #f4f8ff;
  padding: 12px;
  font-size: 0.98rem;
}

.codex-select:focus-visible {
  outline: 2px solid rgba(103, 163, 255, 0.95);
  outline-offset: 1px;
}

.codex-session-view {
  min-height: 300px;
  border-radius: 14px;
  border: 1px solid rgba(128, 163, 244, 0.45);
  background: linear-gradient(155deg, rgba(7, 14, 34, 0.97), rgba(5, 10, 24, 0.97));
  box-shadow: 0 10px 26px rgba(2, 6, 17, 0.5);
  padding: 16px;
}

.codex-session-view--game {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  border-radius: 0;
  border: 0;
  box-shadow: none;
  padding: 16px 18px 22px;
  overflow-y: auto;
  overflow-x: hidden;
  background: transparent;
}

.codex-session-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  max-width: 100%;
  align-items: baseline;
  margin-bottom: 14px;
}

.codex-session-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.codex-session-id {
  font-size: 0.82rem;
  color: #a9c6ff;
  background: rgba(37, 63, 120, 0.26);
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(117, 155, 247, 0.35);
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.codex-thread {
  display: grid;
  gap: 12px;
  min-width: 0;
  max-width: 100%;
}

.codex-message {
  min-width: 0;
  max-width: 100%;
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(121, 158, 239, 0.28);
}

.codex-message--user {
  margin-left: 12%;
  background: linear-gradient(155deg, rgba(19, 50, 108, 0.6), rgba(12, 30, 73, 0.65));
}

.codex-message--assistant {
  margin-right: 12%;
  background: linear-gradient(155deg, rgba(18, 27, 51, 0.9), rgba(14, 18, 36, 0.9));
}

.codex-message-role {
  font-size: 0.74rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #b7cdfd;
  margin-bottom: 6px;
  font-weight: 700;
}

.codex-message-text {
  margin: 0;
  white-space: pre-wrap;
  color: #f2f7ff;
  font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  line-height: 1.5;
  font-size: 0.89rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.codex-empty-shell {
  padding: 6px 0;
}

.codex-empty-title {
  margin: 0 0 8px 0;
  font-size: 1rem;
  color: #d6e6ff;
}

.codex-empty {
  margin: 0;
  color: #b6caef;
}

@media (max-width: 760px) {
  .codex-shell {
    padding: 20px 14px 30px;
  }

  .codex-message--user,
  .codex-message--assistant {
    margin-left: 0;
    margin-right: 0;
  }

  .codex-session-header {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 980px) {
  .game-layout {
    display: block;
  }

  .game-stage {
    width: 100vw;
    height: var(--game-layout-height);
    border-right: 0;
  }

  .game-render-area {
    width: min(100vw, calc(var(--game-layout-height) * var(--render-aspect-width) / var(--render-aspect-height)));
    height: min(var(--game-layout-height), calc(100vw * var(--render-aspect-height) / var(--render-aspect-width)));
  }

  .codex-message--user,
  .codex-message--assistant {
    margin-left: 0;
    margin-right: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-view-tab--generating .game-view-tab-spinner {
    animation: none;
  }
}
