:root {
  color-scheme: light;
  --ink: #241a3f;
  --muted: #6f6681;
  --paper: #fffdfa;
  --violet: #6d4aff;
  --violet-dark: #5031d2;
  --pink: #ff5c8a;
  --yellow: #ffd95a;
  --mint: #bff4db;
  --line: #e7e0f2;
  --shadow: 0 18px 50px rgba(64, 40, 116, .14);
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  min-height: 100%;
  background: #f7f3ff;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 5%, rgba(255, 217, 90, .34), transparent 23rem),
    radial-gradient(circle at 90% 24%, rgba(191, 244, 219, .5), transparent 24rem),
    linear-gradient(145deg, #fbf8ff, #f5f1ff 55%, #fff9ed);
  font-family: ui-rounded, "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
}

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

.hidden { display: none !important; }
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.screen-center {
  display: grid;
  place-items: center;
}

.page-shell,
.play-shell {
  width: min(100%, 960px);
  margin: 0 auto;
}

.panel {
  border: 1px solid rgba(109, 74, 255, .12);
  border-radius: 30px;
  background: rgba(255, 253, 250, .94);
  box-shadow: var(--shadow);
}

.login-panel {
  width: min(100%, 560px);
  padding: clamp(24px, 7vw, 48px);
  text-align: center;
}

.brand-mark {
  display: grid;
  width: 76px;
  height: 76px;
  margin: 0 auto 12px;
  place-items: center;
  border-radius: 24px;
  background: var(--yellow);
  box-shadow: 0 10px 25px rgba(255, 183, 0, .22);
  font-size: 40px;
  transform: rotate(-3deg);
}

h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 8px;
  font-size: clamp(32px, 7vw, 52px);
  line-height: 1;
  letter-spacing: -.035em;
}
h2 {
  margin-bottom: 6px;
  font-size: clamp(23px, 4vw, 30px);
  line-height: 1.1;
}

.lead {
  margin-bottom: 24px;
  color: var(--muted);
  font-size: clamp(17px, 3vw, 20px);
  line-height: 1.45;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--violet);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.profile-button {
  min-height: 112px;
  padding: 16px 8px;
  border: 2px solid var(--line);
  border-radius: 22px;
  color: var(--ink);
  background: #fff;
  font-weight: 900;
  cursor: pointer;
}
.profile-button span {
  display: block;
  margin-bottom: 7px;
  font-size: 38px;
}

.profile-button:hover,
.profile-button:focus-visible {
  border-color: var(--violet);
  outline: none;
  transform: translateY(-2px);
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  font-weight: 900;
}

input,
textarea {
  width: 100%;
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input { padding: 10px 13px; }
textarea {
  min-height: 92px;
  padding: 15px 60px 15px 16px;
  line-height: 1.45;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 4px rgba(109, 74, 255, .1);
}

.button,
.mini-button,
.quick-actions button,
.example-button {
  min-height: 44px;
  border: 0;
  border-radius: 14px;
  font-weight: 900;
  cursor: pointer;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
}

.button:disabled,
.mini-button:disabled,
.quick-actions button:disabled {
  cursor: default;
  opacity: .48;
}

.button-primary {
  color: #fff;
  background: var(--violet);
  box-shadow: 0 8px 18px rgba(109, 74, 255, .23);
}
.button-primary:hover:not(:disabled) { background: var(--violet-dark); }
.button-secondary { color: var(--violet-dark); background: #ece7ff; }
.button-accent { color: #5b3900; background: var(--yellow); }
.button-quiet { color: var(--violet-dark); background: transparent; }
.button-menu {
  flex: 0 0 auto;
  min-height: 48px;
  color: #fff;
  background: var(--violet);
  box-shadow: 0 8px 18px rgba(109, 74, 255, .23);
}
.button-menu:hover:not(:disabled) { background: var(--violet-dark); }
.button-large { min-height: 56px; padding: 14px 24px; font-size: 18px; }

.message {
  min-height: 24px;
  margin: 10px 0 0;
  color: var(--violet-dark);
  font-weight: 800;
  line-height: 1.35;
}
.message-error { color: #b5254d; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-label {
  padding: 9px 12px;
  border-radius: 999px;
  background: #fff;
  font-weight: 900;
}

.new-game-button {
  width: 100%;
  margin-bottom: 18px;
}

.game-list {
  display: grid;
  gap: 13px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.game-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 8px 24px rgba(64, 40, 116, .07);
}

.game-open {
  display: flex;
  min-width: 0;
  min-height: 54px;
  align-items: center;
  padding: 10px 14px;
  border: 0;
  border-radius: 16px;
  color: var(--ink);
  background: #f4f0ff;
  text-align: left;
  cursor: pointer;
}
.game-open strong {
  overflow: visible;
  overflow-wrap: anywhere;
  text-overflow: clip;
  white-space: normal;
}

.mini-button { padding: 8px 11px; color: var(--violet-dark); background: #ece7ff; }
.mini-button-danger { color: #a31f45; background: #ffe8ef; }
.game-delete { min-height: 44px; }

.empty-card {
  padding: 44px 20px;
  border: 2px dashed #d8cffa;
  border-radius: 28px;
  color: var(--muted);
  text-align: center;
}
.empty-card > span { display: block; margin-bottom: 10px; font-size: 48px; }
.empty-card h2 { color: var(--ink); }

.create-shell { width: min(100%, 760px); }
.back-button { margin-bottom: 10px; }
.create-panel { padding: clamp(22px, 6vw, 46px); }

.input-with-mic {
  position: relative;
}

.mic-button {
  position: absolute;
  right: 9px;
  bottom: 9px;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #ece7ff;
  cursor: pointer;
}
.mic-button.listening {
  color: #fff;
  background: var(--pink);
  animation: pulse 1s ease-in-out infinite;
}
.mic-icon {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hint {
  margin: -7px 0 2px;
  color: var(--muted);
  font-size: 14px;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}
.example-button {
  padding: 7px 11px;
  color: #513b18;
  background: #fff3c7;
}

#v2-play-screen {
  padding: 0 max(12px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.play-shell {
  width: min(100%, 860px);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.play-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 0;
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(247, 243, 255, .96);
  backdrop-filter: blur(12px);
}

.play-toolbar h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.play-toolbar .button {
  padding-inline: 13px;
}

.play-toolbar #v2-save {
  min-width: 98px;
}

.game-stage {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 4px solid #fff;
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
}

#v2-game-frame {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  border: 0;
  background: #fff;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  color: var(--violet-dark);
  background: rgba(255, 253, 250, .94);
  text-align: center;
  font-size: 20px;
  font-weight: 900;
}
.magic-spinner {
  font-size: 48px;
  animation: float 1s ease-in-out infinite alternate;
}

.quick-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin: 10px 0 8px;
  padding: 1px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: none;
}
.quick-actions::-webkit-scrollbar { display: none; }
.quick-actions button {
  flex: 0 0 auto;
  padding: 9px 12px;
  color: var(--violet-dark);
  background: #ece7ff;
  white-space: nowrap;
}

.refine-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px 44px;
  align-items: end;
  gap: 6px;
  scroll-margin-block: 72px 20px;
}

.refine-composer textarea {
  min-width: 0;
  min-height: 48px;
  max-height: 112px;
  padding: 11px 12px;
  resize: vertical;
}

.refine-composer .mic-button,
.composer-submit {
  position: static;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}

.refine-composer .mic-button {
  color: var(--violet-dark);
  background: #ece7ff;
}
.refine-composer .mic-button.listening {
  color: #fff;
  background: var(--pink);
}

.composer-submit {
  color: #fff;
  background: var(--violet);
  font-size: 25px;
  font-weight: 900;
  line-height: 1;
}

.composer-submit:disabled { cursor: default; opacity: .48; }

#v2-refine-message {
  min-height: 0;
  margin: 7px 2px 0;
  font-size: 14px;
}

.context-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

@keyframes pulse {
  50% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(255, 92, 138, .15); }
}
@keyframes float {
  to { transform: translateY(-8px) rotate(8deg); }
}

@media (max-width: 520px) {
  .screen { padding-inline: 12px; }
  .panel { border-radius: 24px; }
  .profile-grid { grid-template-columns: 1fr; }
  .profile-button {
    display: flex;
    min-height: 64px;
    align-items: center;
    justify-content: center;
    gap: 10px;
  }
  .profile-button span { display: inline; margin: 0; font-size: 28px; }
  .topbar { align-items: flex-start; }
  .topbar-actions { flex-direction: column; align-items: flex-end; }
  .play-toolbar .button { padding-inline: 10px; }
  .play-toolbar #v2-save { min-width: 88px; }
  .examples span { width: 100%; }
}

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