/* Mystery Island: base tokens, layout, buttons, dialogs and shared UI. */

:root {
  --sea-1: #0e7490;
  --sea-2: #22d3ee;
  --sand: #fde68a;
  --sand-2: #fef3c7;
  --ink: #1e293b;
  --ink-soft: #475569;
  --paper: #fffdf7;
  --card: #ffffff;
  --line: #e2e8f0;
  --primary: #f97316;
  --primary-dark: #c2410c;
  --secondary: #0ea5e9;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #dc2626;
  --star: #facc15;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 6px 0 rgba(15, 23, 42, 0.12), 0 10px 24px rgba(15, 23, 42, 0.12);
  --shadow-sm: 0 3px 0 rgba(15, 23, 42, 0.12);
  --tap: 56px;
  --font: 'Trebuchet MS', 'Segoe UI', system-ui, -apple-system, 'Noto Sans', sans-serif;
  --emoji: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  --world: var(--sea-1);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, #7dd3fc 0%, #bae6fd 45%, var(--sand-2) 100%) fixed;
  color: var(--ink);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
}

:focus-visible {
  outline: 4px solid #2563eb;
  outline-offset: 3px;
}

h1,
h2,
h3,
h4 {
  line-height: 1.2;
  margin: 0.3em 0;
}

h1:focus,
h2:focus {
  outline: none;
}

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

.app {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
  min-height: 100dvh;
  padding: 12px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: screen-in 0.3s ease-out;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.screen-title {
  font-size: 1.6rem;
  text-align: center;
  color: #0c4a6e;
}

.screen-sub {
  text-align: center;
  color: var(--ink-soft);
  margin: 0;
}

.center {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.row {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.help {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 4px 0;
}

.big-emoji {
  font-family: var(--emoji);
  font-size: 5rem;
  line-height: 1;
  text-align: center;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- buttons ---------- */
.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 10px 22px;
  border: none;
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  user-select: none;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: linear-gradient(180deg, #fb923c, var(--primary));
  color: #fff;
  box-shadow: 0 5px 0 var(--primary-dark);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.btn-secondary {
  background: linear-gradient(180deg, #38bdf8, var(--secondary));
  color: #fff;
  box-shadow: 0 5px 0 #0369a1;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.85);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 5px 0 #991b1b;
}

.btn-disabled {
  background: #e2e8f0;
  color: #64748b;
}

.btn-big {
  font-size: 1.25rem;
  padding: 14px 30px;
}

.btn-huge {
  font-size: 1.5rem;
  padding: 18px 44px;
  min-height: 72px;
}

.btn-small {
  min-height: 44px;
  padding: 6px 14px;
  font-size: 0.95rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 0;
  width: var(--tap);
  font-size: 1.5rem;
  font-family: var(--emoji);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  min-height: 44px;
  font-size: 0.95rem;
  padding: 6px 14px;
}

.text-input,
.select {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  display: block;
  padding: 14px 18px;
  font-size: 1.3rem;
  border-radius: var(--radius-sm);
  border: 3px solid #93c5fd;
  background: #fff;
  text-align: center;
}

.select {
  font-size: 1rem;
  padding: 8px 12px;
  width: auto;
  display: inline-block;
}

/* ---------- top bar & wallet ---------- */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 6px 0;
}

.topbar-title {
  font-size: 1.25rem;
  text-align: center;
  margin: 0;
  color: #0c4a6e;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-spacer {
  width: var(--tap);
}

.wallet {
  display: flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: var(--shadow-sm);
  font-weight: 700;
  font-size: 0.95rem;
}

.wallet-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font);
}

/* ---------- Kiki ---------- */
.kiki {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

.kiki-bird {
  font-family: var(--emoji);
  font-size: 3rem;
  line-height: 1;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  animation: bob 2.4s ease-in-out infinite;
  flex: 0 0 auto;
}

.kiki-big .kiki-bird {
  font-size: 4.5rem;
}

.kiki-bubble {
  position: relative;
  background: #fff;
  border-radius: 20px;
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  font-size: 1.05rem;
  flex: 1;
}

.kiki-bubble::before {
  content: '';
  position: absolute;
  left: -10px;
  bottom: 14px;
  border: 10px solid transparent;
  border-right-color: #fff;
  border-left: 0;
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0) rotate(-3deg);
  }
  50% {
    transform: translateY(-6px) rotate(3deg);
  }
}

/* ---------- avatar ---------- */
.avatar {
  position: relative;
  display: inline-grid;
  place-items: center;
  font-family: var(--emoji);
  width: 3.2em;
  height: 3.6em;
  font-size: 1rem;
}

.avatar-face {
  font-size: 2.2em;
  line-height: 1;
}

.avatar-hat {
  position: absolute;
  top: -0.2em;
  font-size: 1.5em;
  z-index: 2;
}

.avatar-outfit {
  position: absolute;
  bottom: -0.1em;
  font-size: 1.3em;
}

.avatar-pet {
  position: absolute;
  right: -0.8em;
  bottom: 0;
  font-size: 1.2em;
}

.avatar-sm {
  font-size: 0.7rem;
}

.avatar-lg {
  font-size: 1.5rem;
}

.avatar-xl {
  font-size: 2.4rem;
}

/* ---------- stars & progress ---------- */
.stars {
  display: inline-flex;
  gap: 2px;
  font-size: 1.3rem;
}

.star {
  color: #cbd5e1;
}

.star.on {
  color: var(--star);
  text-shadow: 0 1px 0 #a16207;
}

.stars.small {
  font-size: 0.95rem;
}

.progress {
  display: block;
  height: 14px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  overflow: hidden;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

.progress-sm {
  height: 8px;
}

.progress-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #4ade80, var(--good));
  border-radius: 999px;
  transition: width 0.5s ease;
}

/* ---------- banners, toasts, modals ---------- */
.banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  text-align: center;
}

.banner-warn {
  background: var(--warn-bg);
  color: var(--warn);
  border: 2px solid #fcd34d;
}

.toast-layer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 60;
  padding: 0 16px;
}

.toast {
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-weight: 700;
  max-width: 520px;
  text-align: center;
  animation: toast-in 0.25s ease-out;
  transition: opacity 0.4s, transform 0.4s;
}

.toast-good {
  background: var(--good);
}

.toast-warn {
  background: var(--warn);
}

.toast.out {
  opacity: 0;
  transform: translateY(10px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
  animation: fade-in 0.2s;
}

.modal {
  background: var(--paper);
  border-radius: 24px;
  padding: 22px;
  width: min(460px, 100%);
  max-height: 90dvh;
  overflow: auto;
  box-shadow: var(--shadow);
  text-align: center;
  animation: pop-in 0.25s ease-out;
}

.modal-title {
  font-size: 1.4rem;
  color: #0c4a6e;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
}

/* ---------- splash ---------- */
.splash {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 24px 16px;
}

.splash-logo {
  font-family: var(--emoji);
  font-size: 7rem;
  line-height: 1;
  animation: bob 3s ease-in-out infinite;
}

.splash-title {
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  margin: 0;
  color: #fff;
  text-shadow: 0 3px 0 #0e7490, 0 6px 16px rgba(14, 116, 144, 0.5);
  letter-spacing: 1px;
}

.splash-sub {
  font-size: 1.15rem;
  color: #0c4a6e;
  max-width: 460px;
  margin: 0;
}

.splash-kiki {
  font-family: var(--emoji);
  font-size: 3rem;
  animation: bob 2s ease-in-out infinite;
}

.noscript {
  padding: 24px;
  text-align: center;
}

.shake {
  animation: shake 0.45s;
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

.hint-pulse {
  animation: hint-pulse 0.8s ease-in-out 3;
  z-index: 3;
}

@keyframes hint-pulse {
  50% {
    transform: scale(1.25);
    box-shadow: 0 0 0 6px var(--star), 0 0 24px 8px rgba(250, 204, 21, 0.8);
    border-radius: 12px;
  }
}

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