:root {
  --sky-top: #6ec6ff;
  --sky-bottom: #c9efff;
  --grass: #7ed957;
  --ink: #1d3557;
  --primary: #ff6b6b;
  --primary-dark: #e85555;
  --accent: #ffd23f;
  --ok: #38b000;
  --wrong: #ef476f;
  --card: #ffffff;
  --shadow: 0 6px 18px rgba(29, 53, 87, 0.18);
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  /* Kill iOS double-tap-to-zoom on every element (still allows scroll/pan). */
  touch-action: manipulation;
}

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

body {
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
  color: var(--ink);
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px 16px;
  gap: 14px;
}

h1,
h2 {
  margin: 0;
}

.big-title {
  font-size: 2rem;
  text-align: center;
  color: var(--ink);
}

.subtitle {
  text-align: center;
  font-size: 1.1rem;
  margin: 0;
  opacity: 0.85;
}

.btn {
  border: none;
  border-radius: 16px;
  padding: 16px 22px;
  font-size: 1.15rem;
  font-weight: 700;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.08s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.text-input {
  width: 100%;
  border: 3px solid #fff;
  border-radius: 16px;
  padding: 16px;
  font-size: 1.25rem;
  font-family: inherit;
  text-align: center;
  box-shadow: var(--shadow);
}

.icon-btn {
  border: none;
  background: rgba(255, 255, 255, 0.85);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  flex: 0 0 auto;
}

/* Profile screen */
.profile-screen {
  justify-content: center;
  align-items: center;
}

.balloon-logo {
  font-size: 5rem;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-12px);
  }
}

.profile-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  width: 100%;
}

.profile-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border: none;
  background: #fff;
  border-radius: 18px;
  padding: 16px 20px;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-family: inherit;
}

.profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--ink);
}

.profile-name {
  font-weight: 700;
}

.new-profile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

/* Home screen */
.home-header,
.game-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.home-title {
  flex: 1;
  text-align: center;
  font-size: 1.5rem;
}

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

.table-card {
  border: none;
  background: #fff;
  border-radius: 20px;
  padding: 18px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-family: inherit;
  aspect-ratio: 1 / 1;
  justify-content: center;
}

.table-card .table-num {
  font-size: 2rem;
  font-weight: 800;
  color: var(--ink);
}

.table-card.locked {
  background: rgba(255, 255, 255, 0.55);
  filter: grayscale(0.5);
  cursor: not-allowed;
}

.stars {
  font-size: 1.1rem;
  letter-spacing: 1px;
}

.stars-filled {
  color: var(--accent);
}

.stars-empty {
  color: #d6d6d6;
}

.stars.locked {
  font-size: 1.2rem;
}

/* Game screen */
.game-screen {
  padding-bottom: 16px;
}

.game-header-mid {
  flex: 1;
  text-align: center;
}

.game-title {
  font-size: 1.3rem;
}

.game-progress {
  font-size: 0.95rem;
  opacity: 0.8;
}

.sky {
  position: relative;
  flex: 1 1 auto;
  min-height: 180px;
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(180deg, #8fd3ff, #d6f0ff);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.5);
}

.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14%;
  background: var(--grass);
  border-top: 4px solid #5cb338;
}

.cloud {
  position: absolute;
  width: 70px;
  height: 24px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 20px;
  filter: blur(0.4px);
}

.cloud::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 16px;
  width: 34px;
  height: 34px;
  background: inherit;
  border-radius: 50%;
}

.cloud-1 {
  top: 18%;
  left: 12%;
  animation: drift 14s linear infinite;
}

.cloud-2 {
  top: 40%;
  right: 10%;
  animation: drift 20s linear infinite reverse;
}

@keyframes drift {
  from {
    transform: translateX(-20px);
  }
  to {
    transform: translateX(20px);
  }
}

.balloon {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 75%;
  transition: bottom 0.18s ease-out;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.balloon-body {
  width: 64px;
  height: 78px;
  background: radial-gradient(circle at 34% 30%, #ff9a9a, var(--primary));
  border-radius: 50% 50% 48% 48%;
  box-shadow: var(--shadow);
}

.balloon-body::after {
  content: "";
  display: block;
  margin: 76px auto 0;
  width: 10px;
  height: 8px;
  background: var(--primary-dark);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.balloon-string {
  width: 2px;
  height: 26px;
  background: rgba(0, 0, 0, 0.35);
}

.balloon.danger .balloon-body {
  animation: wobble 0.4s ease-in-out infinite;
}

@keyframes wobble {
  0%,
  100% {
    transform: rotate(-5deg);
  }
  50% {
    transform: rotate(5deg);
  }
}

.play-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.question {
  text-align: center;
  font-size: 2.4rem;
  font-weight: 800;
}

.entry {
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  background: #fff;
  border-radius: 14px;
  padding: 8px;
  box-shadow: var(--shadow);
  min-height: 52px;
}

.entry.correct {
  animation: pop 0.3s ease;
  color: var(--ok);
}

.entry.wrong {
  animation: shake 0.3s ease;
  color: var(--wrong);
}

@keyframes pop {
  50% {
    transform: scale(1.12);
  }
}

@keyframes shake {
  25% {
    transform: translateX(-8px);
  }
  75% {
    transform: translateX(8px);
  }
}

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

.key {
  border: none;
  border-radius: 16px;
  background: #fff;
  font-size: 1.8rem;
  font-weight: 800;
  font-family: inherit;
  padding: 16px 0;
  cursor: pointer;
  box-shadow: var(--shadow);
  color: var(--ink);
}

.key:active {
  transform: scale(0.94);
}

.key-ok {
  background: var(--ok);
  color: #fff;
}

.key-fn {
  background: var(--accent);
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(29, 53, 87, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.overlay.show {
  display: flex;
}

.overlay-card {
  background: #fff;
  border-radius: 22px;
  padding: 26px 22px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  box-shadow: var(--shadow);
  animation: pop 0.3s ease;
}

.overlay-emoji,
.result-emoji,
.lock-emoji {
  font-size: 3.5rem;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

/* Result screen */
.result-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
}

.result-stats {
  width: 100%;
  max-width: 320px;
  background: #fff;
  border-radius: 18px;
  padding: 12px 18px;
  box-shadow: var(--shadow);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
  font-weight: 700;
}

.stat-row:last-child {
  border-bottom: none;
}

.result-message {
  max-width: 320px;
}

.medal {
  font-weight: 800;
}

.medal.none {
  opacity: 0.5;
}

/* Gate + dashboard */
.gate-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
}

.gate-screen .text-input {
  max-width: 280px;
}

.gate-error {
  color: var(--wrong);
  font-weight: 700;
  min-height: 1.2em;
}

.card {
  background: #fff;
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.2rem;
  margin-bottom: 10px;
}

.kv-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.kv-label {
  display: block;
  font-size: 0.85rem;
  opacity: 0.7;
}

.kv-value {
  font-size: 1.4rem;
  font-weight: 800;
}

.table-progress-row {
  display: grid;
  grid-template-columns: 1.2fr 1.6fr 2fr 1fr 1fr;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.95rem;
}

.table-progress-row.head {
  font-weight: 800;
  opacity: 0.7;
  font-size: 0.8rem;
}

.tp-name {
  font-weight: 800;
}

.weak-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.weak-row {
  display: flex;
  justify-content: space-between;
  background: #fff4f4;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
}

.weak-acc {
  color: var(--wrong);
}

.muted {
  opacity: 0.6;
}

.progress-graph {
  width: 100%;
  height: auto;
}

.graph-grid {
  stroke: #e6e6e6;
  stroke-width: 1;
}

.graph-axis {
  fill: #9aa5b1;
  font-size: 9px;
  text-anchor: end;
}

.graph-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.graph-dot {
  fill: var(--primary);
}

.graph-empty {
  fill: #9aa5b1;
  font-size: 12px;
}
