/* FunCalc — Pass 3A core game loop (mock data)
   Visual language ported from FunCalc_PersonaC_Build2.dc.html (read-only reference). */

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

html, body {
  margin: 0;
  height: 100%;
  background: #f4f2ed;
  font-family: 'Gaegu', system-ui, sans-serif;
  color: #1a1a1a;
  -webkit-text-size-adjust: 100%;
}

button { font-family: inherit; touch-action: manipulation; }
button:active { opacity: .7; transform: scale(.98); }

@keyframes fcpulse { 0% { transform: scale(1);} 45% { transform: scale(1.14);} 100% { transform: scale(1);} }
@keyframes fcshake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-7px)} 40%{transform:translateX(7px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }

/* ---------- phone shell: mobile-first, 375px primary target ---------- */
#phone {
  position: relative;
  width: 100%;
  max-width: 375px;
  margin: 0 auto;
  height: 100%;
  min-height: 100dvh;
  background: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
@media (min-width: 420px) {
  body { padding: 12px 0; }
  #phone { height: 667px; min-height: 0; border: 2px solid #1a1a1a; border-radius: 26px; box-shadow: 4px 4px 0 rgba(0,0,0,.1); }
}

.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.hidden { display: none !important; }

.scrollbody { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---------- shared controls ---------- */
.btn {
  width: 100%;
  min-height: 56px;
  border-radius: 8px;
  font: 700 19px 'Gaegu', cursive;
  cursor: pointer;
  padding: 0 14px;
}
.btn-primary { border: none; background: #1a1a1a; color: #fff; }
.btn-secondary { border: 2px solid #1a1a1a; background: #fff; color: #1a1a1a; }

.iconbtn {
  width: 48px; height: 48px; min-width: 48px; flex: none; padding: 0;
  border: 2px solid #1a1a1a; border-radius: 8px; background: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

/* ---------- A6 dashboard ---------- */
#screen-dashboard .scrollbody { padding: 16px 16px 24px; display: flex; flex-direction: column; gap: 14px; }

.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dash-greet { display: flex; flex-direction: column; gap: 3px; }
.greet-name { font: 700 26px 'Gaegu', cursive; }
.greet-sub { font: 400 12.5px 'IBM Plex Mono', monospace; color: rgba(0,0,0,.6); }

.statbox-group { display: flex; flex-direction: column; gap: 8px; }
.statbox {
  border: 2px solid #1a1a1a; border-radius: 6px; padding: 8px 12px;
  font: 700 16px 'Gaegu', cursive;
}
.statbox-split { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.whatsthis {
  border: none; background: none; padding: 4px 2px; cursor: pointer;
  font: 400 12px 'IBM Plex Mono', monospace; color: rgba(0,0,0,.55);
  text-decoration: underline; flex: none;
}

.op-group { display: flex; flex-direction: column; gap: 8px; }
.op-title { font: 700 22px 'Gaegu', cursive; }
.tier-tile {
  border: 2px solid #1a1a1a; border-radius: 8px; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 72px; background: #fff; width: 100%; text-align: left; cursor: pointer;
}
/* Tier 2 differentiates by structure (filled tint) as well as tone, so Tier 1
   never reads as a disabled button. Both tiers are always tappable. */
.tier-tile.tier-2 { background: rgba(26,26,26,.06); border-style: solid; }
.tier-tile.tier-1 { background: #fff; }
.tier-meta { display: flex; flex-direction: column; gap: 5px; }
.tier-level { font: 400 11px 'IBM Plex Mono', monospace; color: rgba(0,0,0,.5); }
.tier-range { font: 700 21px 'Gaegu', cursive; }
.tier-pill {
  border: 2px solid #1a1a1a; border-radius: 20px; padding: 1px 9px;
  font: 700 13px 'Gaegu', cursive; flex: none; white-space: nowrap;
}

/* ---------- modal ---------- */
.modal { position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.42); }
.modal-card {
  position: relative; width: 100%; background: #fff;
  border-top: 2px solid #1a1a1a; border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}
.modal-title { font: 700 24px 'Gaegu', cursive; }
.modal-copy { margin: 0; font: 400 13px/1.6 'IBM Plex Mono', monospace; color: rgba(0,0,0,.7); }

/* ---------- A7 quiz / A9b retry ---------- */
#screen-quiz { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); gap: 10px; }
#screen-retry { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); gap: 10px; }

.quiz-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: none; }
.progress-text { font: 700 18px 'Gaegu', cursive; }
.progress-track { height: 5px; flex: none; background: rgba(0,0,0,.12); border-radius: 3px; overflow: hidden; }
.progress-fill { width: 0%; height: 5px; background: #1a1a1a; transition: width .2s ease; }

.newlevel {
  flex: none; border: 2px dashed #1a1a1a; border-radius: 6px; padding: 7px 10px;
  font: 700 15px 'Gaegu', cursive; text-align: center;
}

.retry-head { font: 700 24px 'Gaegu', cursive; text-align: center; flex: none; }

.problem-area {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 14px;
}
.problem { font: 700 52px 'Gaegu', cursive; white-space: nowrap; }
.problem-sm { font-size: 46px; }
.equals { font: 700 38px 'Gaegu', cursive; color: rgba(0,0,0,.3); }
.answerbox {
  min-width: 104px; height: 64px; border: 2px solid #1a1a1a; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font: 700 34px 'Gaegu', cursive; color: rgba(0,0,0,.28); padding: 0 8px;
}
.answerbox.filled { color: #1a1a1a; }
.answerbox.shake { animation: fcshake .4s ease; border-color: #c0392b; }
.answerbox-sm { min-width: 100px; height: 60px; font-size: 30px; }

.keypad-wrap { flex: none; display: flex; justify-content: center; }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(56px, 84px)); gap: 9px; }
.key {
  height: 48px; border: 2px solid #1a1a1a; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font: 700 20px 'Gaegu', cursive; background: #fff; color: #1a1a1a; cursor: pointer;
}
.key-enter { background: #1a1a1a; color: #fff; }

/* ---------- A9 reveal ---------- */
.reveal-body {
  flex: 1; min-height: 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; align-items: center;
}
.bigx { font: 700 54px 'Gaegu', cursive; color: #c0392b; line-height: 1; flex: none; }
.reveal-head { font: 400 13px 'IBM Plex Mono', monospace; color: #c0392b; letter-spacing: .06em; flex: none; }
.reveal-box {
  width: 100%; flex: 1; min-height: 0;
  border: 2px dashed #c0392b; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font: 700 40px 'Gaegu', cursive; color: #1a1a1a; padding: 0 10px;
}

/* ---------- A8 reward: top ~75% media, bottom ~25% copy + CTA ---------- */
#screen-reward { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); gap: 12px; }
.reward-media { flex: 3; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 18px; }
.reward-square {
  aspect-ratio: 1 / 1; max-height: 100%; max-width: 100%; width: 100%;
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
}
.reward-emoji { font-size: 96px; line-height: 1; animation: fcpulse 1s ease-in-out infinite; }
.reward-gif {
  width: 100%; height: 100%; border-radius: 12px; background: #ffd479;
  border: 2px solid #1a1a1a;
  display: flex; align-items: center; justify-content: center;
  font: 700 22px 'Gaegu', cursive; color: #1a1a1a;
}
.reward-foot { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px; width: 100%; }
.reward-headline { font: 700 38px 'Gaegu', cursive; }
.reward-equation { font: 700 22px 'Gaegu', cursive; color: rgba(0,0,0,.55); }

/* ---------- A10 summary ---------- */
.summary-body { padding: 16px 16px 26px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.trophy {
  width: 110px; height: 110px; flex: none;
  border: 2px dashed rgba(0,0,0,.4); border-radius: 10px;
  background: repeating-linear-gradient(45deg, rgba(0,0,0,.04) 0 6px, transparent 6px 12px);
  display: flex; align-items: center; justify-content: center; text-align: center;
  font: 400 10.5px/1.5 'IBM Plex Mono', monospace; color: rgba(0,0,0,.5);
}
.summary-head { font: 700 34px 'Gaegu', cursive; text-align: center; }
.summary-stat { min-height: 28px; flex: none; display: flex; align-items: center; font: 400 13px 'IBM Plex Mono', monospace; color: rgba(0,0,0,.6); }
.summary-mastered {
  width: 100%; border: 2px solid #1a1a1a; border-radius: 8px; padding: 10px 12px;
  font: 700 16px/1.5 'Gaegu', cursive; text-align: center;
}
.summary-bar {
  flex: none; background: #fff; padding: 0 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}

/* RewardEngine's own DOM nodes — present and wired, visually inert in Pass 3A. */
.re-overlay { position: absolute; width: 0; height: 0; overflow: hidden; opacity: 0; pointer-events: none; }

/* ============================================================
 * Pass 3B — boot / auth / paywall / sync notice
 * ========================================================== */

.centered-body {
  flex: 1; min-height: 0;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  text-align: center;
}

.boot-mark { font: 700 40px 'Gaegu', cursive; }
.boot-note { font: 400 12.5px 'IBM Plex Mono', monospace; color: rgba(0,0,0,.55); }

/* ---------- auth ---------- */
.auth-body { padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.auth-title { font: 700 40px 'Gaegu', cursive; text-align: center; }

.auth-tabs { display: flex; gap: 8px; }
.auth-tab {
  flex: 1; min-height: 48px; border: 2px solid #1a1a1a; border-radius: 8px;
  background: #fff; color: #1a1a1a; font: 700 17px 'Gaegu', cursive; cursor: pointer;
}
.auth-tab.is-active { background: #1a1a1a; color: #fff; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font: 400 11px 'IBM Plex Mono', monospace; color: rgba(0,0,0,.55); letter-spacing: .04em; }
.field input, .field select {
  min-height: 48px; box-sizing: border-box;
  border: 2px solid #1a1a1a; border-radius: 8px; background: #fff;
  padding: 0 12px; font: 700 18px 'Gaegu', cursive; color: #1a1a1a;
  -webkit-appearance: none; appearance: none;
}
.field select { background-image: none; }
.field input:focus, .field select:focus { outline: 3px solid rgba(42,120,214,.45); outline-offset: 1px; }

.auth-error {
  border: 2px solid #c0392b; border-radius: 8px; padding: 9px 11px;
  font: 400 12px/1.5 'IBM Plex Mono', monospace; color: #c0392b; background: #fff;
}

.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- paywall ---------- */
.paywall-title { font: 700 34px 'Gaegu', cursive; }
.paywall-copy { font: 400 13px/1.6 'IBM Plex Mono', monospace; color: rgba(0,0,0,.6); max-width: 280px; }
#screen-paywall .btn { max-width: 300px; }

/* ---------- sync notice ---------- */
.sync-notice {
  border: 2px solid #c0392b; border-radius: 6px; padding: 8px 11px;
  font: 400 11px/1.5 'IBM Plex Mono', monospace; color: #c0392b;
}
