/* Math Facts Trainer — dark navy, big friendly type, phone/iPad first. */
:root {
  --bg: #0c1130; --bg2: #151b45; --card: #1b2150; --card2: #232a5e;
  --ink: #f4f5ff; --dim: #a7abd0; --accent: #ffcf4d; --coral: #ff7a59;
  --teal: #3ddbb9; --violet: #8f7bff; --good: #37d67a; --bad: #ff5d73;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 800px at 80% -10%, #232a63 0%, var(--bg) 55%);
  color: var(--ink); min-height: 100dvh;
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.hidden { display: none !important; }
h1 { font-size: 2rem; margin: .2em 0; } h2 { font-size: 1.7rem; margin: .4em 0 .6em; }
h3 { margin: .2em 0 .5em; } h4 { margin: 1em 0 .4em; color: var(--dim); }
.sub { color: var(--dim); } .error { color: var(--bad); min-height: 1.2em; }
button, input, select { font: inherit; color: inherit; }
input, select {
  background: var(--bg2); border: 2px solid #333c7d; border-radius: 12px;
  padding: .55em .7em; min-height: 48px;
}
input:focus, select:focus { outline: 2px solid var(--violet); }
label { display: block; margin: .6em 0; color: var(--dim); }
label input { display: block; width: 100%; margin-top: .25em; color: var(--ink); }

.screen { padding: 18px 16px calc(24px + var(--safe-b)); max-width: 900px; margin: 0 auto; }
.card {
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid #30387a; border-radius: 20px; padding: 18px; margin: 14px 0;
  box-shadow: 0 10px 24px rgba(0,0,0,.35);
}
.card.narrow { max-width: 440px; margin: 8dvh auto 0; }
.logo { font-size: 3rem; text-align: center; }
.card.narrow h1, .card.narrow .sub { text-align: center; }

.btn {
  background: var(--card2); border: 2px solid #39428a; border-radius: 14px;
  padding: .6em 1.1em; cursor: pointer; font-weight: 700; min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
}
.btn.primary { background: var(--coral); border-color: var(--coral); color: #22103a; }
.btn.big { font-size: 1.2rem; width: 100%; margin-top: 12px; padding: .8em; }
.btn.small { min-height: 38px; padding: .3em .8em; }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn:active { transform: scale(.97); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form.col { flex-direction: column; align-items: stretch; }
.file-btn { position: relative; }

/* app chrome */
#topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.brand { font-weight: 800; font-size: 1.15rem; }
.who-chip { margin-left: auto; color: var(--dim); font-weight: 700; }
#main { padding-bottom: calc(84px + var(--safe-b)); }
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(15,19,48,.97); border-top: 1px solid #30387a;
  padding-bottom: var(--safe-b);
}
#tabbar button {
  flex: 1; background: none; border: 0; padding: 10px 0 8px; cursor: pointer;
  font-size: 1.25rem; color: var(--dim); display: flex; flex-direction: column; align-items: center; gap: 2px;
}
#tabbar button span { font-size: .78rem; font-weight: 700; }
#tabbar button.on { color: var(--accent); }

/* who's playing */
.profile-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.profile-card {
  border: 3px solid; border-radius: 20px; padding: 16px 12px; text-align: center;
  background: var(--card); cursor: pointer; min-height: 128px;
}
.profile-card .avatar { font-size: 2.6rem; }
.profile-card .pname { font-size: 1.3rem; font-weight: 800; }
.profile-card .pteaser { color: var(--dim); font-size: .85rem; }

/* round setup */
.seg { display: flex; gap: 8px; margin: 6px 0 14px; }
.seg.wrap { flex-wrap: wrap; }
.seg button {
  background: var(--bg2); border: 2px solid #39428a; border-radius: 12px;
  min-width: 56px; min-height: 52px; padding: .4em .7em; cursor: pointer; font-weight: 800; font-size: 1.05rem;
}
.seg button.on { background: var(--violet); border-color: var(--violet); color: #171138; }

/* ---- PLAY: viewport-locked, no scroll, no tab bar ---- */
body.playing { overflow: hidden; }
body.playing #tabbar, body.playing #topbar { display: none; }
#screen-play {
  height: 100dvh; max-width: 720px; margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px calc(10px + var(--safe-b));
  display: flex; flex-direction: column;
}
.play-head { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.play-profile { background: var(--card2); border-radius: 999px; padding: .25em .8em; }
.play-progress { margin-left: auto; color: var(--dim); }
.play-streak { color: var(--accent); }
.progress-track { height: 10px; background: var(--bg2); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
#progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--teal), var(--violet)); transition: width 150ms ease; }
#fact-zone { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; position: relative; }
#fact-text { font-size: clamp(3.2rem, 14vw, 6.5rem); font-weight: 800; letter-spacing: .02em; line-height: 1; }
#answer-line { font-size: clamp(2.2rem, 9vw, 4rem); font-weight: 800; color: var(--teal); min-height: 1.2em; }
#answer-line .cursor { opacity: .45; }
#answer-line.has-input .cursor { display: none; }
.praise {
  position: absolute; top: 6%; font-size: clamp(1.4rem, 5vw, 2.2rem); font-weight: 800; color: var(--good);
  animation: pop-in-fast 175ms ease;
}
@keyframes pop-in-fast { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.correction {
  position: absolute; inset: auto 0 0 0; margin: 0 auto; max-width: 560px;
  background: #2b2150; border: 2px solid var(--violet); border-radius: 18px; padding: 16px; text-align: center;
  font-size: 1.35rem; font-weight: 700;
}
#pad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  width: 100%; max-width: 560px; margin: 8px auto 0;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
#pad button {
  height: clamp(48px, 11.5dvh, 76px); border-radius: 16px; border: 0;
  background: var(--card2); color: var(--ink);
  font-size: clamp(1.5rem, 6vw, 2.1rem); font-weight: 800; cursor: pointer;
  box-shadow: 0 4px 0 #0a0d26;
}
#pad button.util { font-size: 1.05rem; color: var(--dim); }
#pad button:active { background: var(--violet); transform: translateY(2px); box-shadow: 0 2px 0 #0a0d26; }
#pad .answer-btn { grid-column: 1 / -1; background: var(--good); color: #0d2b18; height: clamp(48px, 10dvh, 68px); }
#pad .answer-btn:active { background: var(--teal); }
#end-round { align-self: center; margin-top: 8px; }

/* medal toast — top edge, pointer-through */
.toast {
  position: fixed; top: calc(6px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%);
  z-index: 50; pointer-events: none; white-space: nowrap; max-width: 94vw; overflow: hidden; text-overflow: ellipsis;
  background: linear-gradient(90deg, #ffcf4d, #ff9d4d); color: #33200a; font-weight: 800;
  border-radius: 999px; padding: .35em 1em; font-size: .95rem; box-shadow: 0 6px 18px rgba(0,0,0,.4);
  opacity: 0; transition: opacity .25s ease;
}
.toast.show { opacity: 1; }

/* summary + medals */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin: 10px 0; }
.stat { background: var(--bg2); border-radius: 14px; padding: 10px 12px; }
.stat .v { font-size: 1.5rem; font-weight: 800; }
.stat .k { color: var(--dim); font-size: .85rem; }
.medal-list, .medal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.medal-cell { background: var(--bg2); border-radius: 16px; padding: 12px; text-align: center; }
.medal-cell .icon { font-size: 2.2rem; }
.medal-cell.locked { opacity: .45; filter: grayscale(.8); }
.medal-cell .mname { font-weight: 800; }
.medal-cell .mdesc { color: var(--dim); font-size: .8rem; }
.medal-bar { height: 8px; background: #0d1132; border-radius: 99px; margin-top: 8px; overflow: hidden; }
.medal-bar i { display: block; height: 100%; background: var(--accent); }
.medals-card { border-color: var(--accent); }

/* grown-ups */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 7px 8px; text-align: left; border-bottom: 1px solid #2c3373; white-space: nowrap; }
th { color: var(--dim); }
.slow-list { display: flex; flex-wrap: wrap; gap: 8px; }
.slow-chip { background: var(--bg2); border-radius: 12px; padding: 6px 10px; font-weight: 700; }
.slow-chip small { color: var(--bad); font-weight: 700; }
.heatmap {
  display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 4px;
  width: 100%; max-width: 100%; min-width: 0;
}
.hm-cell {
  width: 100%; min-width: 0; padding: 0; overflow: hidden;
  aspect-ratio: 1; border-radius: 8px; border: 0; cursor: pointer; color: #10142e;
  font-size: clamp(.55rem, 2vw, .85rem); font-weight: 800; display: flex; align-items: center; justify-content: center;
}
@media (max-width: 700px) {
  /* Phones get six readable, tappable columns instead of eleven squeezed ones. */
  .heatmap { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
  .hm-cell { aspect-ratio: 1.15; border-radius: 10px; font-size: .78rem; }
  th, td { padding: 6px 5px; }
  #gu-bytable { font-size: .88rem; }
  #gu-bytable th:last-child, #gu-bytable td:last-child { white-space: normal; }
}
@media (max-width: 380px) {
  .hm-cell { font-size: .7rem; }
}
.hm-New { background: #39406e; color: var(--dim); }
.hm-Learning { background: #ffd166; }
.hm-Fast { background: #7bd88f; }
.hm-Mastered { background: #37d67a; box-shadow: inset 0 0 0 2px #ffd700; }
.fact-detail { min-height: 1.4em; margin-top: 8px; }
.history-list .hrow, #gu-profiles .prow, #gu-users .urow {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 8px 0; border-bottom: 1px solid #2c3373;
}
.history-list .hrow span, .prow span, .urow span { margin-right: auto; }
.mini { min-height: 38px; padding: .25em .7em; font-size: .9rem; }

/* iPad landscape: pad sits lower-wider, fact left of pad when space allows */
@media (min-width: 900px) and (orientation: landscape) {
  #screen-play { max-width: 1100px; }
  #pad { max-width: 560px; }
  #fact-text { font-size: clamp(4rem, 10vw, 7rem); }
}
@media (max-height: 500px) {
  #fact-text { font-size: clamp(2.4rem, 9vw, 4rem); }
  #pad button { height: 48px; }
}

/* feedback / bug nub — kept away from the play screen by app.js + body.playing */
.bug-nub {
  position: fixed; right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(92px + var(--safe-b)); z-index: 45;
  width: 56px; height: 56px; border-radius: 50%; border: 2px solid #5963b8;
  background: linear-gradient(180deg, #39428a, #232a5e); color: var(--ink);
  font-size: 1.65rem; line-height: 1; cursor: pointer;
  box-shadow: 0 10px 24px rgba(0,0,0,.45);
  display: inline-flex; align-items: center; justify-content: center;
}
.bug-nub:active { transform: scale(.94); }
body.playing .bug-nub { display: none !important; }
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 100; overflow-y: auto;
  background: rgba(4, 6, 22, .72); padding: 18px 12px calc(12px + var(--safe-b));
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: min(680px, 100%); max-height: calc(100dvh - 30px - var(--safe-b)); overflow-y: auto;
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid #39428a; border-radius: 24px 24px 16px 16px;
  padding: 18px; box-shadow: 0 22px 60px rgba(0,0,0,.55);
}
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-head h3 { margin: 0 auto 0 0; font-size: 1.45rem; }
.feedback-tabs, .feedback-type { margin: 14px 0; }
.feedback-type button, .feedback-tabs button { flex: 1; }
.sheet textarea {
  display: block; width: 100%; margin-top: .25em; resize: vertical;
  background: var(--bg2); border: 2px solid #333c7d; border-radius: 12px;
  padding: .55em .7em; min-height: 48px; color: var(--ink); font: inherit;
}
.sheet textarea:focus { outline: 2px solid var(--violet); }
.feedback-success { text-align: center; padding: 22px 4px 8px; }
.feedback-success-icon { font-size: 3rem; }
.feedback-success .row { justify-content: center; }
.feedback-list { display: grid; gap: 10px; margin-top: 12px; }
.feedback-item {
  background: var(--bg2); border: 1px solid #30387a; border-radius: 16px; padding: 13px;
}
.feedback-item-head { display: flex; align-items: flex-start; gap: 10px; }
.feedback-item-head > span:first-child { margin-right: auto; overflow-wrap: anywhere; }
.feedback-meta { color: var(--dim); font-size: .85rem; margin-top: 3px; overflow-wrap: anywhere; }
.feedback-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: .55em 0; }
.feedback-resolution {
  background: rgba(55, 214, 122, .13); border-left: 4px solid var(--good);
  border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.status-chip {
  flex: 0 0 auto; border-radius: 999px; padding: .22em .65em;
  font-size: .8rem; font-weight: 800; background: #39406e; color: var(--ink);
}
.status-open { background: #8a5a14; }
.status-working { background: #315da8; }
.status-fixed { background: #19733f; }
.status-declined { background: #5c4a61; color: #d8c9dc; }
.feedback-filter { margin: 0; }
.feedback-admin-controls {
  display: grid; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #30387a;
}
.feedback-admin-controls label { margin: 0; }
.feedback-admin-controls textarea {
  display: block; width: 100%; margin-top: .25em; resize: vertical;
  background: var(--bg); border: 2px solid #333c7d; border-radius: 12px;
  padding: .55em .7em; color: var(--ink); font: inherit;
}
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 24px; }
  .bug-nub { bottom: calc(104px + var(--safe-b)); width: 60px; height: 60px; }
}
