:root{
  --placeCell: 42px;
  --placeGap: 10px;

  --tries: 10;
  --wordlen: 5;

  --bg:#05070b;
  --card:#0b0f16;
  --ink:#eaf0ff;
  --muted:#9aa7c0;

  --guessBar:#0d131d;
  --placeBar:#0d131d;
  --divider:#151e2c;

  --good:#1f7a3a;
  --mis:#c06c21;

  --tile:#0f1624;
  --tileBorder:#2a3853;
  --tileInk:#eaf0ff;

  --key:#131c2c;
  --keyBorder:#2a3853;
  --keyInk:#eaf0ff;

  --usedBg:#2b3446;
  --usedInk:#cfd6e6;

  --cancelBg:#c9d1dc;
  --cancelInk:#2b3443;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:var(--bg);
  color:var(--ink);
}

.hidden{ display:none !important; }

.app{
  padding-bottom: 46px;

  max-width: 980px;
  margin: 8px auto;
  padding: 8px;
}

.topbar{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap: 10px;
  background:rgba(12,16,24,.75);
  border:1px solid rgba(255,255,255,.06);
  border-radius:18px;
  padding: 10px 12px;
  box-shadow: 0 18px 32px rgba(0,0,0,.35);
  position:relative;
  z-index: 30;
}

.titleBlock h1{
  margin:0;
  font-size: 40px;
  letter-spacing: .2px;
}
.celebrate{ margin-left: 8px; }
.subtitle{
  margin-top: 2px;
  font-weight:700;
  color: var(--muted);
  font-size: 13px;
}
.today{
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.actions{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.btn{
  border:1px solid rgba(255,255,255,.12);
  border-radius:14px;
  background: rgba(19,28,44,.85);
  color: var(--ink);
  padding: 8px 10px;
  font-weight:800;
  cursor:pointer;
}
.btn:active{ transform: translateY(1px); }

.board{
  margin-top: 8px;
  background: rgba(12,16,24,.85);
  border:1px solid rgba(255,255,255,.06);
  border-radius: 18px;
  box-shadow: 0 18px 32px rgba(0,0,0,.35);
  overflow:hidden;
}

.boardHeader{
  display:grid;
  grid-template-columns: 1fr 120px;
}
.guessHeader{
  background: var(--guessBar);
  border-bottom: 1px solid var(--divider);
  padding: 6px 10px;
  min-height: 40px;
  display:flex;
  justify-content:center;
  align-items:center;
}
.placeHeader{
  background: var(--placeBar);
  border-left: 1px solid var(--divider);
  border-bottom: 1px solid var(--divider);
  padding: 6px 8px;
  min-height: 40px;
  display:flex;
  align-items:center;
  justify-content:flex-start;
}
.placeIcons{
  display: grid;
  grid-template-columns: repeat(2, var(--pcell));
  gap: var(--pgap);
  align-items: center;
  justify-items: center;
}

.iconPill{
  display:flex;
  align-items:center;
  justify-content:center;
  height: var(--pcell);
  
  width: var(--pcell);border:1px solid rgba(255,255,255,.12);
  border-radius: 14px;
  background: rgba(19,28,44,.85);
  font-size: 18px;
  font-weight: 900;
}

.revealBox{
  display:inline-flex;
  gap:6px;
  align-items:center;
  background: rgba(19,28,44,.85);
  border:1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  padding: 6px 10px;
  font-weight: 900;
}
.revealLabel{ color: var(--muted); }
.revealWord{ letter-spacing: 1px; }

.boardBody{
  display:grid;
  grid-template-columns: 1fr 120px;
}
.guessArea{
  padding: 8px 10px 8px;
  display:flex;
  flex-direction:column;
  align-items:center;
}
.placeArea{
  border-left: 1px solid var(--divider);
  padding: 8px 8px 8px;
}

/* sizing variables */
:root{
  --placeCell: 42px;
  --placeGap: 10px;

  --cell: 34px;
  --gap: 7px;
  --pcell: 30px;
  --pgap: 7px;
  --rowgap: 6px;
}

.grid{
  display:grid;
  grid-template-rows: repeat(var(--tries), auto);
  gap: var(--rowgap);
  align-content:start;
}
.placement{
  display:grid;
  grid-template-rows: repeat(var(--tries), auto);
  gap: var(--rowgap);
  align-content:start;
}

.row{
  display:grid;
  grid-template-columns: repeat(var(--wordlen), var(--cell));
  gap: var(--gap);
  align-items:center;
}
.placeRow{
  display:grid;
  grid-template-columns: repeat(2, var(--pcell));
  gap: var(--pgap);
  align-items:center;
  min-height: var(--cell);
}

.circle{
  width: var(--cell);
  height: var(--cell);
  border-radius: 10px;
  border: 1px solid var(--tileBorder);
  background: var(--tile);
  color: var(--tileInk);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight: 900;
  letter-spacing: .5px;
  user-select:none;
}

.circle.good{ background: rgba(31,122,58,.35); border-color: rgba(31,122,58,.7); }
.circle.mis{ background: rgba(192,108,33,.35); border-color: rgba(192,108,33,.7); }
.circle.used{ background: rgba(120,130,150,.25); border-color: rgba(255,255,255,.10); color: rgba(234,240,255,.92); }

.pcircle{
  width: var(--pcell);
  height: var(--pcell);
  border-radius: 10px;
  border: 1px solid var(--tileBorder);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight: 900;
  user-select:none;
  background: rgba(19,28,44,.85);

  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.pcircle.good{ border-color: rgba(31,122,58,.7); }
.pcircle.mis{ border-color: rgba(192,108,33,.7); }

.status{
  margin-top: 6px;
  text-align:center;
  font-weight: 800;
  color: var(--muted);
  min-height: 18px;
  font-size: 12px;
}

/* KEYBOARD */
.keyboardWrap{
  margin-top: 8px;
  background: rgba(12,16,24,.85);
  border:1px solid rgba(255,255,255,.06);
  border-radius: 18px;
  box-shadow: 0 18px 32px rgba(0,0,0,.35);
  padding: 10px 8px 12px;
}

.keyboard{
  display:flex;
  flex-direction:column;
  gap: 8px;
  align-items:center;
}
.krow{
  display:flex;
  gap: 6px;
  justify-content:center;
  flex-wrap:nowrap;
}
.key{
  min-width: 28px;
  height: 40px;
  padding: 0 9px;
  border-radius: 12px;
  border: 1px solid var(--keyBorder);
  background: var(--key);
  color: var(--keyInk);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:900;
  cursor:pointer;
  user-select:none;
  position:relative;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.key.used{
  background: var(--usedBg);
  color: var(--usedInk);
}

/* cancelled keys: strong visual */
.key.cancelled{
  background: #cfd6e0;
  color: #2b3443;
  border-color: rgba(0,0,0,.18);
  filter: none;
}
.key.cancelled::before{
  content:"✕";
  position:absolute;
  top:4px;
  right:6px;
  font-size:11px;
  font-weight:900;
  color: rgba(43,52,67,.75);
  pointer-events:none;
}
.key.wide{ min-width: 86px; }
.key.back{ min-width: 60px; }

/* Share menu */
.shareWrap{ position:relative; }
.shareMenu{
  position:absolute;
  top: 46px;
  right: 0;
  background: #ffffff;
  border: 1px solid rgba(0,0,0,.25);
  border-radius: 12px;
  box-shadow: 0 16px 30px rgba(0,0,0,.25);
  overflow:hidden;
  min-width: 150px;
  z-index: 60; /* above headers */
}
.menuItem{
  width:100%;
  border:0;
  background:#fff;
  padding: 12px 12px;
  text-align:left;
  cursor:pointer;
  font-weight:900;
  color:#111;
}
.menuItem:hover{ background:#f0f2f5; }

/* MODAL */
.modalOverlay{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.55);
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 14px;
  z-index: 600;
}
.modal{
  width: min(560px, 96vw);
  background:#fff;
  border-radius: 16px;
  padding: 16px 16px 14px;
  border: 1px solid rgba(0,0,0,.25);
  box-shadow: 0 16px 30px rgba(0,0,0,.25);

  display:flex;
  flex-direction: column;
  max-height: 86vh;
  overflow: hidden;
}
.modal, .modal *{ color:#111; }
.modalTitle{
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 8px;
}

.modalMeta{
  font-size: 12px;
  font-weight: 800;
  opacity: .55;
  margin-top: -6px;
  margin-bottom: 10px;
}
.modalList{ margin: 10px 0 0 18px; }
.modalActions{
  margin-top: 10px;
  display:flex;
  justify-content:flex-end;
}

/* tighter on small phones */
@media (max-width: 420px){
  .app{ padding: 6px; margin: 0 auto; }
  .titleBlock h1{ font-size: 34px; }
  .btn{ padding: 7px 9px; border-radius: 12px; }
  :root{
  --placeCell: 42px;
  --placeGap: 10px;

    --cell: 32px;
    --gap: 6px;
    --pcell: 28px;
    --pgap: 6px;
    --rowgap: 5px;
  }
  .key{ min-width: 26px; height: 38px; }
  .key.wide{ min-width: 78px; }
  .key.back{ min-width: 56px; }
  .boardHeader{ grid-template-columns: 1fr 112px; }
  .boardBody{ grid-template-columns: 1fr 112px; }
}

/* Segmented control (Daily / Practice) */
.seg{
  display:inline-flex;
  border:1px solid rgba(255,255,255,.14);
  border-radius:14px;
  overflow:hidden;
  background: rgba(19,28,44,.55);
}
.segBtn{
  border:0;
  padding: 8px 10px;
  font-weight: 900;
  cursor:pointer;
  color: var(--muted);
  background: transparent;
}
.segBtn.active {
  background: rgba(46, 160, 89, 0.28);
  border-color: rgba(46, 160, 89, 0.55);
  color: #e6fff0;
}

.infoIcon{
  width: 34px;
  padding: 8px 0;
  text-transform:none;

  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;}

/* Toast */
.toast{
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 10px);
  background: rgba(255,255,255,.92);
  color:#111;
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 900;
  z-index: 300;
  box-shadow: 0 12px 26px rgba(0,0,0,.35);
}

/* Footer */


.footer{display:none;}



/* Stats grid */
.statsGrid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.statCard{
  border:1px solid rgba(0,0,0,.12);
  border-radius: 14px;
  padding: 10px 10px;
  background:#fff;
  color:#111;
}
.statLabel{ font-size: 12px; color:#555; font-weight:800; }
.statValue{ font-size: 22px; font-weight: 900; margin-top: 4px; }

/* Result pulse (placement boxes) */
.pcircle.flash{
  animation: flashPulse .35s ease-out 0s 1;
}
@keyframes flashPulse{
  0%{ transform: scale(1); filter: brightness(1); }
  40%{ transform: scale(1.12); filter: brightness(1.35); }
  100%{ transform: scale(1); filter: brightness(1); }
}

/* Hint reveal flash on guess tiles */
.circle.hintFlash{
  /* Brighter + longer hint highlight */
  background: rgba(44, 255, 155, 0.22) !important;
  border-color: rgba(44, 255, 155, 0.75) !important;
  color: #eafff6 !important;
  box-shadow: 0 0 18px rgba(44,255,155,0.55), inset 0 0 10px rgba(44,255,155,0.25);
  animation: hintPulse 1.0s ease-in-out infinite;
}
@keyframes hintPulse{
  0%{ transform: scale(1); filter: brightness(1.0); }
  50%{ transform: scale(1.08); filter: brightness(1.9); }
  100%{ transform: scale(1); filter: brightness(1.0); }
}
  35%{ transform: scale(1.08); filter: brightness(1.45); }
  100%{ transform: scale(1); filter: brightness(1); }
}

/* Smaller keyboard for most phones */
.key{
  min-width: 24px;
  height: 34px;
  padding: 0 8px;
  font-size: 14px;
}
.key.wide{ min-width: 68px; }
.key.back{ min-width: 50px; }

/* Keep keyboard fixed at bottom */
.keyboardWrap{
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(980px, 100vw);
  margin: 0;
  border-radius: 18px 18px 0 0;
  z-index: 120;
  padding: 8px 6px calc(10px + env(safe-area-inset-bottom));
}

/* Make room for fixed keyboard */
.app{
  padding-bottom: 250px;
}
@media (max-width: 420px){
  .app{ padding-bottom: 240px; }
  .key{ min-width: 22px; height: 32px; font-size: 13px; }
  .key.wide{ min-width: 62px; }
  .key.back{ min-width: 46px; }
}

/* Fine alignment for header icons */
.placeIcons .pill:nth-child(2){ transform: translateX(-1px); }


/* Stats modal close button visibility */
.modalActions .btn {
  background: #111827;
  color: #ffffff;
  border: 1px solid rgba(255,255,255,0.18);
}
.modalActions .btn:hover { filter: brightness(1.08); }


/* Stats selectors */
.statsControls{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:flex-end;
  justify-content:space-between;
  margin: 10px 0 14px;
}
.statsControls label{
  display:flex;
  flex-direction:column;
  gap:6px;
  font-weight:800;
  letter-spacing:.2px;
}
.statsControlLabel{
  font-size:12px;
  opacity:.85;
}
.select{
  border:1px solid rgba(255,255,255,.14);
  border-radius:14px;
  background: rgba(19,28,44,.85);
  color: var(--ink);
  padding: 8px 10px;
  font-weight:800;
}
.btn.danger{
  border-color: rgba(255,255,255,.25);
}


/* Brand title */
.brand{
  font-family: 'Dancing Script', cursive;
  font-weight: 700;
  letter-spacing: .5px;
}


/* Stats modal actions */
.statsActions{
  display:flex;
  justify-content: space-between;
  gap: 10px;
}
.btn.statsReset{
  background: rgba(0,0,0,.45);
  border-color: rgba(0,0,0,.35);
  color: #ffffff;
}
.btn.statsReset:hover{ filter: brightness(1.05); }



/* Extra stats */
.statCard.wide{
  grid-column: 1 / -1;
}
.statSectionTitle{
  grid-column: 1 / -1;
  margin-top: 6px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: .4px;
}
.distGrid{
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
}
.distRow{
  display:grid;
  grid-template-columns: 18px 1fr 28px;
  align-items:center;
  gap: 8px;
}
.distNum, .distVal{
  font-weight: 800;
  color: var(--ink);
  opacity: .9;
}
.distBar{
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.distFill{
  height: 100%;
  border-radius: 999px;
  background: rgba(255,255,255,.35);
}


/* Last 10 games chart */
.last10Wrap{ margin: 8px 0 0; }
.last10Chart{
  box-sizing: border-box;
  display:flex;
  gap: 8px;
  align-items: flex-end;
  height: 120px;
  padding: 10px 12px;
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 14px;
  background: rgba(0,0,0,.02);
}
.lgBar{
  flex: 1 1 0;
  min-width: 8px;
  height: 100%;
  border-radius: 10px;
  background: rgba(0,0,0,.08);
  overflow:hidden;
  position: relative;
}
.lgBar .lgFill{
  width: 100%;
  position:absolute;
  bottom:0;
  left:0;
  background: rgba(0,0,0,.45);
}
.lgBar.win .lgFill{ background: rgba(0,0,0,.55); }
.lgBar.loss .lgFill{ background: rgba(0,0,0,.25); }
.lgBar.empty{ background: rgba(0,0,0,.04); }
.last10Legend{
  display:flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items:center;
  margin-top: 8px;
  color: rgba(0,0,0,.65);
  font-size: 13px;
}
.legendItem{ display:flex; align-items:center; gap:8px; }
.legendSwatch{
  width: 12px; height: 12px;
  border-radius: 4px;
  display:inline-block;
  background: rgba(0,0,0,.45);
}
.legendSwatch.win{ background: rgba(0,0,0,.55); }
.legendSwatch.loss{ background: rgba(0,0,0,.25); }
.legendNote{ opacity:.85; }

/* Horizontal "Last 10" chart (avoids iPhone/Safari clipping issues) */
.last10H{
  display:flex;
  flex-direction:column;
  gap: 8px;
  margin-top: 10px;
}
.last10HRow{
  display:grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  align-items:center;
}
.last10HLabel{
  font-size: 12px;
  color: rgba(0,0,0,.65);
  text-align:right;
}
.last10HBar{
  height: 14px;
  border-radius: 10px;
  background: rgba(0,0,0,.06);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
  overflow:hidden;
}
.last10HBar.empty{
  background: repeating-linear-gradient(45deg,#eee,#eee 6px,#f7f7f7 6px,#f7f7f7 12px);
}
.last10HFill{ height: 100%; border-radius: 10px; }
.last10HFill.win{ background: rgba(0,0,0,.55); }
.last10HFill.loss{ background: rgba(0,0,0,.25); }


/* Enhanced Last 10 games chart */
.last10Frame{
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.last10Axis{
  width: 24px;
  display:flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px 0;
  color: rgba(0,0,0,.55);
  font-size: 12px;
  text-align: right;
}
.axisTick.mid{ transform: translateY(2px); }

.last10Chart{
  position: relative;
  flex: 1;
  min-width: 0; /* allow flex item to shrink on iOS to avoid clipping the last bar */
  display:flex;
  gap: 8px;
  align-items: flex-end;
  height: 120px;
  padding: 10px 12px;
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 14px;
  background: rgba(0,0,0,.02);
  overflow: hidden;
}
.last10Grid{
  position:absolute;
  inset: 0;
  pointer-events:none;
  background:
    linear-gradient(to top, rgba(0,0,0,.06) 1px, transparent 1px) 0 33%/100% 33%,
    linear-gradient(to top, rgba(0,0,0,.06) 1px, transparent 1px) 0 66%/100% 33%;
  opacity: .6;
}

.lgBar{
  position: relative;
  flex: 1 1 0;
  min-width: 10px;
  height: 100%;
  border-radius: 10px;
  background: rgba(0,0,0,.08);
  overflow:hidden;
  z-index: 1; /* above grid */
}
.lgBar .lgFill{
  width: 100%;
  position:absolute;
  bottom:0;
  left:0;
  background: rgba(0,0,0,.45);
}
.lgBar.win .lgFill{ background: rgba(0,0,0,.58); }
.lgBar.loss .lgFill{ background: rgba(0,0,0,.28); }
.lgBar.empty{
  background: repeating-linear-gradient(
    45deg,
    rgba(0,0,0,.05),
    rgba(0,0,0,.05) 6px,
    rgba(0,0,0,.02) 6px,
    rgba(0,0,0,.02) 12px
  );
}
.lgBarTag{
  position:absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 6px;
  font-size: 10px;
  font-weight: 700;
  color: rgba(255,255,255,.95);
  text-shadow: 0 1px 1px rgba(0,0,0,.35);
  letter-spacing: .2px;
}
.lgBar.empty .lgBarTag{
  color: rgba(0,0,0,.45);
  text-shadow: none;
}

.last10Meta{
  margin-top: 8px;
  color: rgba(0,0,0,.7);
  font-size: 13px;
}

.legendSwatch.empty{
  background: repeating-linear-gradient(
    45deg,
    rgba(0,0,0,.18),
    rgba(0,0,0,.18) 4px,
    rgba(0,0,0,.08) 4px,
    rgba(0,0,0,.08) 8px
  );
}


/* Info modal content */
.infoBlock{
  display:flex;
  flex-direction:column;
  gap: 6px;
  margin: 8px 0 10px;
  font-size: 14px;
}
.infoLine{ color: rgba(0,0,0,.82); }
.dark .infoLine{ color: rgba(255,255,255,.82); }

.tutorialDetails{
  margin-top: 10px;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(0,0,0,.02);
}
.dark .tutorialDetails{
  border-color: rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
}
.tutorialDetails > summary{
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}
.tutorialDetails > summary::-webkit-details-marker{ display:none; }
.tutorialBody{ margin-top: 10px; }
.tutorialSteps{ margin: 0 0 6px 18px; padding: 0; }
.tutorialSteps li{ margin: 6px 0; }
.tutorialTip{
  margin-top: 8px;
  font-size: 13px;
  opacity: .9;
}

/* Ensure Info modal text remains readable (modal is light even in dark theme) */
.dark #infoOverlay .modal{
  background: #fff;
  color: #111;
}
.dark #infoOverlay .infoLine{ color: rgba(0,0,0,.82); }
.dark #infoOverlay .tutorialDetails{
  border-color: rgba(0,0,0,.12);
  background: rgba(0,0,0,.02);
}
.dark #infoOverlay .modalList,
.dark #infoOverlay .tutorialSteps,
.dark #infoOverlay .tutorialTip{
  color: rgba(0,0,0,.86);
}

/* Tutorial summary link styling */
.tutorialDetails > summary{
  color: #2a6df4;
  text-decoration: underline;
}
.tutorialDetails > summary:hover{
  opacity: .9;
}


/* Info modal polish */
#infoOverlay .modal{
  max-width: 860px;
}
.infoMeta{
  margin-top: 6px;
  font-size: 12px;
  opacity: .75;
}
.infoDivider{
  height: 1px;
  background: rgba(0,0,0,.10);
  margin: 14px 0;
}
.dark #infoOverlay .infoDivider{
  background: rgba(0,0,0,.10);
}
.infoBullets{
  margin: 8px 0 0 18px;
  padding: 0;
}
.infoBullets li{
  margin: 6px 0;
}
.infoCallout{
  margin: 10px 0 2px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(42,109,244,.08);
  border: 1px solid rgba(42,109,244,.22);
  font-size: 13px;
}
@media (max-width: 520px){
  #infoOverlay .modal{
    padding: 18px 16px;
  }
  .modalTitle{
    font-size: 22px;
  }
  .modalList{
    margin-left: 18px;
  }
  .tutorialSteps{
    margin-left: 18px;
  }
}

/* Link-style button for Info */
.linkBtn{
  background: transparent;
  border: none;
  padding: 10px 0;
  font-weight: 700;
  color: #2a6df4;
  text-decoration: underline;
  cursor: pointer;
}
.linkBtn:hover{ opacity:.9; }

/* Mobile safety: allow info/tutorial modals to scroll */
.modalOverlay .modal{
  max-height: 86vh;
  overflow: auto;
}

/* Always-highlighted toggle buttons (mode + length) */
.toggleBtn{
  font-weight: 700;
}
.toggleBtn{
  background: rgba(64, 210, 150, 0.22);
  border-color: rgba(64, 210, 150, 0.38);
}
.toggleBtn:hover{ filter: brightness(1.05); }

#modeToggleBtn{ margin: 0 10px; }
#lengthToggleBtn{ margin-right: 10px; }


/* ---- Stats modal mobile usability ---- */
.modal{
  max-height: 86vh;
  overflow: hidden;
}
#statsModal .modal{
  display: flex;
  flex-direction: column;
}
#statsModal .modalTitle,
#statsModal .statsControls{
  flex: 0 0 auto;
}
#statsModal #statsContent{
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 12px;
}
#statsModal .modalActions{
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  background: rgba(255,255,255,0.96);
  padding-top: 10px;
  padding-bottom: 10px;
  border-top: 1px solid rgba(0,0,0,0.08);
}

/* Compact cards on small screens so everything fits better */
@media (max-width: 520px){
  #statsModal .modal{ width: min(96vw, 520px); }
  #statsModal .statsGrid .statCard{ padding: 12px 14px; }
  #statsModal .statsGrid .statLabel{ font-size: 13px; }
  #statsModal .statsGrid .statValue{ font-size: 30px; }
}


/* Stats grid sizing tweaks */
#statsModal .statsGrid{ display:grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
#statsModal .statCard.wide{ grid-column: 1 / -1; }
#statsModal .statCard.half{ grid-column: auto; }
@media (max-width: 520px){
  #statsModal .statsGrid{ grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
}


/* Visually hidden but accessible */
.srOnly{ position:absolute !important; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }


/* Stats pill selectors */
#statsModal .statsPillRow{ display:flex; justify-content:space-between; gap:16px; flex-wrap:wrap; }
#statsModal .statsPillGroup{ display:flex; flex-direction:column; gap:8px; min-width: 220px; }
#statsModal .statsPills{ display:flex; gap:10px; }
#statsModal .statsControlLabel{ font-weight: 700; color: rgba(0,0,0,0.75); }
@media (max-width: 520px){
  #statsModal .statsPillRow{ flex-direction:column; }
  #statsModal .statsPillGroup{ min-width: unset; }
  #statsModal .statsPills{ width:100%; }
  #statsModal .statsPills .btn{ flex:1 1 0; }
}


/* Stats: make segmented toggles fit nicely */
#statsModal .seg{ width: fit-content; }
@media (max-width: 520px){
  #statsModal .seg{ width:100%; }
  #statsModal .segBtn{ flex:1 1 0; text-align:center; }
}


/* Make modal content usable on small screens: keep actions visible */
#statsContent.statsGrid{
  overflow: auto;
  flex: 1 1 auto;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.modalActions.statsActions{
  flex: 0 0 auto;
  gap: 10px;
  padding-top: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid rgba(0,0,0,.08);
}


@media (max-height: 700px){
  .modalOverlay{ align-items: flex-start; }
  .modal{ margin-top: 10px; }
}
@media (max-width: 420px){
  .statsGrid{ gap: 8px; margin-top: 8px; }
  .statCard{ padding: 8px 8px; border-radius: 12px; }
  .statLabel{ font-size: 11px; }
  .statValue{ font-size: 18px; }
  .modalTitle{ font-size: 18px; }
}


/* mobile last10 */
@media (max-width: 420px){
  .last10Frame{ width: 100%; gap: 8px; }
  .last10Axis{ width: 22px; font-size: 11px; }
  /* iOS/Safari flex rounding can clip the right-most bar when the flex item refuses to shrink */
  .last10Chart{ min-width: 0; justify-content: space-between; gap: 4px; padding: 10px 14px 10px 10px; }
  .lgBar{ min-width: 6px; }
}


/* iPhone/small-screen safety: ensure all 10 bars fit without clipping */
@media (max-width: 420px){
  .last10Frame{ gap: 8px; }
  .last10Axis{ width: 22px; font-size: 11px; }
  .last10Chart{
    gap: 4px;
    padding: 8px 10px;
    height: 112px;
  }
  .lgBar{
    min-width: 6px;
    border-radius: 8px;
  }
}
.last10HScale{
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  font-size:12px;
  color:#666;
  margin: 4px 6px 8px 34px; /* align with bars after index column */
  user-select:none;
}


