/* The Noah Game */
:root {
  --ink: #2B1B4A;
  --ink-soft: #5A4A78;
  --paper: #FFF6E5;
  --paper-2: #FFE7B8;
  --star: #FFC107;
  --star-deep: #FF8C00;
  --got: #1FB34A;
  --got-ink: #FFFFFF;
  --miss: #E13B4A;
  --miss-ink: #FFFFFF;
  --card-radius: 28px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --font-ui: "Nunito", "Trebuchet MS", "Segoe UI", sans-serif;
  --font-glyph: "Baloo 2", "Nunito", "Arial Rounded MT Bold", ui-rounded, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 700;
  overflow: hidden;
  height: 100%;
  height: 100dvh;
}
button { font-family: inherit; font-weight: 800; cursor: pointer; }
img { display: block; }
button, a { color: inherit; }

@font-face {
  font-family: "Baloo 2";
  src: url("../fonts/Baloo2.ttf") format("truetype");
  font-weight: 400 800;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("../fonts/Nunito.ttf") format("truetype");
  font-weight: 400 900;
  font-display: swap;
}

#app {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

.view {
  display: none;
  position: absolute;
  inset: 0;
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 16px) calc(var(--safe-bot) + 16px) calc(var(--safe-left) + 16px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.view.active { display: flex; flex-direction: column; }
.view.play-view {
  overflow: hidden;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 12px) calc(var(--safe-bot) + 12px) calc(var(--safe-left) + 12px);
}

/* Home */
.home-bg {
  background:
    radial-gradient(1200px 600px at 50% -10%, #fff 0%, transparent 60%),
    radial-gradient(800px 400px at 100% 100%, #FFD6A0 0%, transparent 50%),
    radial-gradient(600px 300px at 0% 80%, #FFC2D1 0%, transparent 50%),
    var(--paper);
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 8px;
  text-align: center;
}
.brand-mark {
  width: 84px;
  height: 84px;
  border-radius: 22px;
  background: linear-gradient(160deg, #FFD54A 0%, #FF9F1C 100%);
  box-shadow: 0 8px 0 #E07A00, 0 12px 24px rgba(43, 27, 74, 0.18);
  display: grid;
  place-items: center;
  margin-bottom: 10px;
}
.brand-mark span {
  font-family: var(--font-glyph);
  font-size: 58px;
  line-height: 1;
  color: #2B1B4A;
  transform: translateY(-2px);
}
.brand h1 {
  font-family: var(--font-glyph);
  font-size: clamp(2.1rem, 8vw, 3.2rem);
  margin: 0;
  letter-spacing: -0.02em;
  line-height: 1;
}
.brand p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 1.02rem;
  font-weight: 700;
  max-width: 22em;
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0 8px;
}
.chip {
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.95rem;
  box-shadow: 0 3px 0 rgba(43, 27, 74, 0.08);
  border: 2px solid rgba(43, 27, 74, 0.08);
  color: var(--ink);
}
.chip.ahead { background: #D8F5E3; border-color: #1FB34A; color: #0C6A2C; }
.chip.on-track { background: #D8F5E3; border-color: #1FB34A; color: #0C6A2C; }
.chip.behind { background: #FFE0E3; border-color: #E13B4A; color: #9B1220; }
.chip.ready { background: #FFF; }

.mastered-line {
  text-align: center;
  font-size: 1.2rem;
  margin: 4px 0 0;
}
.mastered-line strong { font-family: var(--font-glyph); font-size: 1.45rem; }

.play-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  gap: 16px;
}

.btn-play {
  width: min(280px, 78vw);
  height: min(280px, 78vw);
  max-height: 320px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #FFE066, #FFB703 45%, #FB8500 100%);
  color: var(--ink);
  font-family: var(--font-glyph);
  font-size: clamp(3rem, 12vw, 4.4rem);
  box-shadow:
    0 12px 0 #D56A00,
    0 22px 40px rgba(251, 133, 0, 0.35);
  transition: transform 0.08s ease;
  line-height: 1;
  display: grid;
  place-items: center;
  position: relative;
}
.btn-play:active { transform: translateY(6px); box-shadow: 0 6px 0 #D56A00, 0 10px 20px rgba(251,133,0,0.3); }
.btn-play .play-sub {
  position: absolute;
  bottom: 18%;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
  opacity: 0.75;
  letter-spacing: 0.04em;
}

.sessions-meter {
  text-align: center;
  font-size: 1.15rem;
}
.pips {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}
.pip {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #E0C899;
}
.pip.on {
  background: linear-gradient(160deg, #FFD54A, #FF9F1C);
  border-color: #E07A00;
}

.home-nav {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.nav-btn {
  background: #fff;
  border: 3px solid rgba(43, 27, 74, 0.1);
  border-radius: 18px;
  padding: 14px 8px 12px;
  font-size: 0.95rem;
  box-shadow: 0 4px 0 rgba(43, 27, 74, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.nav-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(43,27,74,0.08); }
.nav-btn .ico { font-size: 1.5rem; line-height: 1; }

.install-tip {
  margin-top: 12px;
  background: #fff8;
  border: 2px dashed rgba(43,27,74,0.2);
  border-radius: 16px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink-soft);
  display: none;
  position: relative;
}
.install-tip.show { display: block; }
.install-tip button {
  position: absolute;
  right: 8px;
  top: 6px;
  border: 0;
  background: transparent;
  font-size: 1.1rem;
}

/* Play */
.play-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
}
.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  border: 0;
  background: #fff;
  box-shadow: 0 3px 0 rgba(43,27,74,0.1);
  font-size: 1.4rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.icon-btn:active { transform: translateY(2px); }
.progress-mini {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  color: var(--ink-soft);
}
.progress-mini strong { color: var(--ink); font-size: 1.1rem; }

.card-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 10px 0;
}
.glyph-card {
  flex: 1;
  min-height: 0;
  border-radius: var(--card-radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 16px 20px;
  box-shadow: 0 10px 0 rgba(0,0,0,0.12), 0 18px 40px rgba(43,27,74,0.18);
  position: relative;
  overflow: hidden;
  animation: popin 0.28s cubic-bezier(.2,1.4,.4,1);
  color: #fff;
}
@keyframes popin {
  from { transform: scale(0.92) translateY(12px); opacity: 0.5; }
  to { transform: none; opacity: 1; }
}
.glyph-card .prompt {
  font-size: clamp(0.95rem, 2.6vw, 1.2rem);
  opacity: 0.92;
  margin: 0 0 4px;
  text-align: center;
}
.glyph {
  font-family: var(--font-glyph);
  font-weight: 700;
  font-size: min(72vw, 46vh, 18rem);
  line-height: 0.82;
  letter-spacing: -0.04em;
  user-select: none;
  text-shadow: 0 10px 0 rgba(0,0,0,0.12);
}
.glyph.num {
  font-size: min(62vw, 42vh, 16rem);
}
.hint {
  min-height: 3.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: clamp(1.4rem, 4.5vw, 2rem);
  font-family: var(--font-glyph);
  opacity: 0;
  transform: translateY(6px);
  transition: 0.2s ease;
  text-align: center;
}
.hint.show { opacity: 1; transform: none; }
.hint .emoji { font-size: 1.3em; font-style: normal; }
.dots-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 260px;
  margin: 0 auto;
}
.dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.95;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.25);
}
.case-pair {
  display: none;
  gap: 18px;
  font-family: var(--font-glyph);
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  line-height: 1;
}
.case-pair.show { display: flex; }
.case-pair .pair-item { opacity: 0.95; text-align: center; }
.case-pair small {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  opacity: 0.9;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex-shrink: 0;
}
.btn-got, .btn-miss, .btn-next {
  border: 0;
  border-radius: 22px;
  padding: 18px 10px;
  font-size: clamp(1.25rem, 4.2vw, 1.6rem);
  min-height: 74px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18);
}
.btn-got { background: var(--got); color: var(--got-ink); box-shadow: 0 6px 0 #148A36; }
.btn-miss { background: var(--miss); color: var(--miss-ink); box-shadow: 0 6px 0 #A31F2C; }
.btn-next {
  grid-column: 1 / -1;
  background: var(--ink);
  color: #fff;
  display: none;
  box-shadow: 0 6px 0 #1A1030;
}
.btn-got:active, .btn-miss:active, .btn-next:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.2); }
.actions.revealed .btn-got,
.actions.revealed .btn-miss { display: none; }
.actions.revealed .btn-next { display: block; }

/* Celebrate */
.celebrate {
  background:
    radial-gradient(circle at 50% 0%, #FFF 0%, transparent 50%),
    linear-gradient(180deg, #FFE7A0 0%, var(--paper) 50%);
  align-items: center;
  text-align: center;
  overflow: hidden;
}
#confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.sticker {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #FFE066, #FFB703 60%, #FB8500);
  box-shadow: 0 10px 0 #D56A00, 0 16px 30px rgba(0,0,0,0.15);
  display: grid;
  place-items: center;
  font-size: 84px;
  margin: 24px auto 8px;
  animation: popin 0.45s cubic-bezier(.2,1.4,.4,1);
  position: relative;
  z-index: 1;
}
.celebrate h2 {
  font-family: var(--font-glyph);
  font-size: clamp(2rem, 8vw, 3rem);
  margin: 8px 0 0;
  position: relative;
  z-index: 1;
}
.celebrate .sub {
  font-size: 1.2rem;
  color: var(--ink-soft);
  position: relative;
  z-index: 1;
}
.cele-stats {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px 0 24px;
  position: relative;
  z-index: 1;
}
.btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, 92%);
  position: relative;
  z-index: 1;
}
.btn-primary, .btn-secondary {
  border: 0;
  border-radius: 18px;
  padding: 16px;
  font-size: 1.2rem;
  min-height: 58px;
}
.btn-primary { background: var(--ink); color: #fff; box-shadow: 0 5px 0 #1A1030; }
.btn-secondary { background: #fff; color: var(--ink); box-shadow: 0 5px 0 rgba(43,27,74,0.12); border: 3px solid rgba(43,27,74,0.08); }
.btn-primary:active, .btn-secondary:active { transform: translateY(3px); }

/* Progress + settings + practice */
.screen-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.screen-head h2 {
  font-family: var(--font-glyph);
  font-size: 1.9rem;
  margin: 0;
  flex: 1;
  line-height: 1.1;
}

.plan-banner {
  background: #fff;
  border-radius: 20px;
  padding: 14px 16px;
  border: 3px solid rgba(43,27,74,0.08);
  margin: 8px 0 16px;
  box-shadow: 0 4px 0 rgba(43,27,74,0.06);
}
.plan-banner .big { font-family: var(--font-glyph); font-size: 1.7rem; line-height: 1.1; }
.plan-banner .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0 0 10px;
}
.legend span { display: flex; align-items: center; gap: 6px; }
.swatch {
  width: 14px; height: 14px; border-radius: 4px; display: inline-block;
  border: 2px solid rgba(43,27,74,0.12);
}
.swatch.unseen { background: #F3EDE0; }
.swatch.learning { background: #FFD000; }
.swatch.mastered { background: #1FB34A; }
.swatch.locked { background: repeating-linear-gradient(45deg, #eee, #eee 3px, #fff 3px, #fff 6px); }

section.block h3 {
  font-family: var(--font-glyph);
  font-size: 1.3rem;
  margin: 16px 0 8px;
}
.grid-letters, .grid-numbers {
  display: grid;
  gap: 7px;
}
.grid-letters { grid-template-columns: repeat(7, 1fr); }
.grid-numbers { grid-template-columns: repeat(5, 1fr); }

.cell {
  aspect-ratio: 1;
  border-radius: 14px;
  border: 0;
  background: #F3EDE0;
  color: var(--ink);
  font-family: var(--font-glyph);
  font-size: clamp(1.15rem, 4.2vw, 1.55rem);
  position: relative;
  padding: 0;
  line-height: 1;
  box-shadow: 0 3px 0 rgba(43,27,74,0.08);
  overflow: hidden;
}
.cell .up { font-size: 1.05em; }
.cell .lo { font-size: 0.72em; opacity: 0.9; margin-left: 1px; }
.cell.learning { background: #FFD000; color: #2B1B4A; }
.cell.mastered { background: #1FB34A; color: #fff; }
.cell.locked { background: #EFE8DA; color: #B5A78C; }
.cell.mixed { background: linear-gradient(180deg, #1FB34A 0 50%, #FFD000 50% 100%); color: #2B1B4A; }
.cell.mixed .up { color: #fff; }
.cell .case-dot {
  position: absolute;
  right: 4px;
  bottom: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ccc;
}
.cell .case-dot.learning { background: #F77F00; }
.cell .case-dot.mastered { background: #FFF; box-shadow: 0 0 0 2px #0C6A2C; }
.cell.mastered .case-dot.mastered { background: #FFD000; box-shadow: none; }

.danger {
  margin: 20px 0 8px;
  background: transparent;
  color: var(--miss);
  border: 2px solid #F5C2C6;
  border-radius: 14px;
  padding: 12px;
  width: 100%;
}

/* Settings / practice */
.setting-row {
  background: #fff;
  border-radius: 18px;
  padding: 14px 16px;
  margin: 0 0 10px;
  border: 3px solid rgba(43,27,74,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.setting-row label { font-size: 1.05rem; }
.toggle {
  width: 52px;
  height: 32px;
  border-radius: 999px;
  background: #D9D0C3;
  border: 0;
  position: relative;
  flex-shrink: 0;
}
.toggle.on { background: #1FB34A; }
.toggle::after {
  content: "";
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 4px;
  left: 4px;
  transition: 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle.on::after { left: 24px; }
.seg {
  display: flex;
  background: #F3EDE0;
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.95rem;
}
.seg button.on { background: #fff; box-shadow: 0 2px 0 rgba(43,27,74,0.08); }

.practice-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.practice-list button {
  background: #fff;
  border: 3px solid rgba(43,27,74,0.08);
  border-radius: 18px;
  padding: 18px 16px;
  text-align: left;
  font-size: 1.2rem;
  box-shadow: 0 4px 0 rgba(43,27,74,0.08);
}
.practice-list button small {
  display: block;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 700;
  margin-top: 2px;
}

/* Sheet */
.sheet-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(43,27,74,0.45);
  z-index: 20;
  align-items: flex-end;
  justify-content: center;
}
.sheet-backdrop.show { display: flex; }
.sheet {
  background: #fff;
  width: min(560px, 100%);
  border-radius: 24px 24px 0 0;
  padding: 16px 16px calc(var(--safe-bot) + 16px);
  max-height: 80%;
  overflow: auto;
}
.sheet h3 { font-family: var(--font-glyph); font-size: 1.8rem; margin: 0 0 8px; }
.sheet-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid #F0E6D4;
  font-size: 1.05rem;
}
.pill {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.85rem;
  background: #F3EDE0;
}
.pill.learning { background: #FFD000; }
.pill.mastered { background: #1FB34A; color: #fff; }
.pill.locked { color: #8A7A66; }

.confirm-box { text-align: center; padding: 8px 4px 0; }
.confirm-box p { font-size: 1.05rem; color: var(--ink-soft); }

/* iPad / wide */
@media (min-width: 700px) {
  .view:not(.play-view) {
    max-width: 720px;
    margin: 0 auto;
    left: 0;
    right: 0;
  }
  .play-view {
    max-width: 900px;
    margin: 0 auto;
    left: 0;
    right: 0;
  }
  .glyph { font-size: min(56vw, 48vh, 24rem); }
  .grid-letters { gap: 10px; }
  .cell { border-radius: 18px; }
  .btn-got, .btn-miss, .btn-next { min-height: 88px; font-size: 1.7rem; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .brand-mark { width: 56px; height: 56px; }
  .brand-mark span { font-size: 38px; }
  .btn-play { width: 150px; height: 150px; font-size: 2.4rem; }
  .glyph { font-size: min(36vw, 42vh, 10rem); }
  .btn-got, .btn-miss, .btn-next { min-height: 56px; padding: 10px; font-size: 1.15rem; }
}

.hidden { display: none !important; }
