:root{
  /* ===============================
     Color palette
     =============================== */

  --bg: #ffffff;
  --surface: #ffffff;

  /* Primary action button */
  --btn-bg: transparent;
  --btn-text: #111111;

  --btn-hover-bg: #f3f4f6;

  /* Selection */
  --select-bg: #878a8c;
  --select-text: #ffffff;

  --text-primary: #111111;
  --text-muted: #6b7280;
  --text-invert: #ffffff;

  --border-default: #d3d6da;
  --border-strong: #878a8c;

  --slot-bg: #ffffff;
  --turn-bg: #f1f3f4;

  --status-good: #8f6db3;
  --border-good:  #878a8c;

  --status-close: #d1b454;
  --border-close: #9f8b3e;

  --status-bad: #b24a5a;   /* less saturated, less clash */
  --border-bad: #7a2f3b;;  

  --overlay-bg: rgba(0,0,0,0.35);

  /* Solid / fixed words (flat steel-blue) */
  --solid-bg: #e6ebf3;        /* very light desaturated blue */
  --solid-border: #9fb0c9;    /* muted blue-grey border */
  --solid-text: #2b3a55;      /* navy-ish text, readable */
  --solid-shadow: none;

  /* ===============================
     Typography
     =============================== */

  --font-base: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;

  --weight-regular: 600;
  --weight-bold: 800;
  --weight-heavy: 900;

  --size-title: 22px;
  --size-slot: clamp(15px, 4.6vw, 20px);
  --size-verse: clamp(16px, 4.6vw, 20px);
  --size-stat: 22px;
  --size-small: 12px;
  --size-xsmall: 11px;

  --letter-wide: 0.08em;
  --letter-tight: 0.02em;

  /* ===============================
     Layout & spacing
     =============================== */

  --max-width: 98%;
  /* min | preferred | max */
  --board-max-width: clamp(320px, 98vw, 560px);
  --gap: clamp(6px, 1.8vw, 10px);

  --tap-size: 30px;

  --radius: clamp(8px, 2.4vw, 12px);
  --radius-small: 8px;

  --slot-height: clamp(44px, 12vw, 58px);
  --slot-padding-x: clamp(8px, 2.8vw, 14px);

  --button-height: clamp(44px, 12vw, 50px);
}

/* ===============================
   Base
   =============================== */

*{ box-sizing:border-box; }

html,body{
  height:100%;
  user-select:none;
  -webkit-user-select:none;
}

body{
  margin:0;
  font-family: var(--font-base);
  background: var(--bg);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Allow text selection in modals */
.modalBody{
  user-select:text;
}

/* ===============================
   Header
   =============================== */

.topbar{
  position: sticky;
  top:0;
  z-index:10;
  background: var(--surface);
  border-bottom: 1px solid var(--border-default);
  padding-top: calc(env(safe-area-inset-top) + 10px);
  padding-bottom: 10px;
}

.topbarInner{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 0 12px;
  gap: 10px;
}

.brandText{
  flex:1;
  text-align:center;
}

.title{
  display: inline-flex;
  align-items: center;
  gap: 6px;

  font-size: var(--size-title);
  font-weight: var(--weight-bold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.title-normal{
  color: var(--text-primary);
}

.title-good{
  background: var(--status-good);
  border: 2px solid var(--status-good);
  color: var(--text-invert);
  border-radius: var(--radius);
  padding: 4px 6px;
}

body.dark .title-good{
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

.iconBtn{
  width: var(--tap-size);
  height: var(--tap-size);
  border:none;
  background:transparent;
  cursor:pointer;
  outline:none;
}

/* Icons */
#homeBtn{ background:url('./img/home.png') center/cover no-repeat; }
#helpBtn{ background:url('./img/help.png') center/cover no-repeat; }
#statsBtn{ background:url('./img/stats.png') center/cover no-repeat; }
#settingsBtn{ background:url('./img/settings.png') center/cover no-repeat; }

.dark #helpBtn{ background:url('./img/help_light.png') center/cover no-repeat; }
.dark #homeBtn{ background:url('./img/home_light.png') center/cover no-repeat; }
.dark #statsBtn{ background:url('./img/stats_light.png') center/cover no-repeat; }
.dark #settingsBtn{ background:url('./img/settings_light.png') center/cover no-repeat; }

/* ===============================
   Verse header
   =============================== */

.verseBar{
  max-width: var(--max-width);
  margin: 10px auto 6px;
  padding: 0 14px;
}

.verseRef{
  font-size: var(--size-verse);
  font-weight: var(--weight-bold);
  text-align:center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===============================
   Board
   =============================== */

.board{
  margin: 10px auto 0;          /* center horizontally */
  padding: 10px;

  max-width: var(--board-max-width);  /* ← key line */
  width: 100%;

  display:flex;
  flex-wrap:wrap;
  gap: var(--gap);
  justify-content: center;
}


/* ===============================
   Slots
   =============================== */

.slot{
  height: var(--slot-height);
  padding: 0 var(--slot-padding-x);
  border-radius: var(--radius);
  border: 2px solid var(--border-default);
  background: var(--slot-bg);
  color: var(--text-primary);
  font-size: var(--size-slot);
  font-weight: var(--weight-bold);
  letter-spacing: var(--letter-tight);
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
}

.slot.selected{
  background: var(--select-bg);
  border-color: var(--select-bg);
  color: var(--select-text);

  /* optional polish */
  box-shadow: 0 4px 10px rgba(0,0,0,0.18);
}

.slot.selected.close{
  background: var(--text-invert);
  border-color: var(--border-default);
  color: var(--status-close);
}

.slot.selected.bad{
  background: var(--text-invert);
  border-color: var(--border-default);
  color: var(--status-bad);
}

.slot.good{
  background: var(--status-good);
  border-color: var(--status-good);
  color: var(--text-invert);
}

.slot.close{
  background: var(--status-close);
  border-color: var(--status-close);
  color: var(--text-invert);
}

.slot.bad{
  background: var(--status-bad);
  border-color: var(--status-bad);
  color: var(--text-invert);
}

/* SOLID / LOCKED WORDS */
.slot.solid{
  background: var(--solid-bg);
  border-color: var(--solid-border);
  border-style: dashed;
  color: var(--solid-text);
  cursor: default;
  pointer-events: none;
  box-shadow: none;
}

@keyframes solidSettle {
  0%   { transform: translateY(-4px); opacity: 0.0; }
  60%  { transform: translateY(1px);  opacity: 1.0; }
  100% { transform: translateY(0); }
}

.slot.animated{
  animation: solidSettle 180ms ease-out;
}

.dark .slot.solid{
  box-shadow: none;
}

.slot.locked{
  cursor:default;
}

.slot:disabled{
  opacity:1;
}

/* ===============================
   Punctuation
   =============================== */

.punct{
  height: var(--slot-height);
  color: var(--solid-text);
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 0 2px;
  font-weight: var(--weight-heavy);
  font-size: var(--size-slot);
  pointer-events:none;
}

/* ===============================
   Bottom bar
   =============================== */

.wrap{
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 90px);
}

/*===============================
  Bottom fixed bar 
  =============================== */
.bottomBar{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 10px);
}

.bottomInner{
  max-width: var(--board-max-width);
  margin: 0 auto;

  /* layout group */
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* left area | center | right area */
  align-items: center;                 /* vertical centering */
  column-gap: 10px;
  height: 52px;
}

/* Place items into grid areas */
#shuffleBtn{
  justify-self: start;   /* sit toward left edge */
}

#submitBtn{
  justify-self: center;  /* hard centered */
}

/* Keep turn pill compact */
.turnPill{
  height: 46px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: none;
  background: #f1f3f4;
  display:flex;
  align-items:center;
  gap: 8px;
  font-weight: 900;
  color: #111;
  white-space: nowrap;
  justify-self: start;   /* sit just to the right of the centered button */
  margin-left: 0;        /* ensure tight adjacency */
}

#attemptsLabel.animated{
  display: inline-block;
  animation: countPop 220ms ease-out;
}

@keyframes countPop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.22); }
  60%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}

/* Optional: reduce shuffle width so it doesn't dominate */
.btnSubtle{
  height: 46px;
  padding: 0 14px;
  border: 2px solid var(--btn-border);
  background: transparent;
  color: var(--btn-text);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 900;
  font-size: 12px;
}

.btn.btnCheck{
  height: var(--button-height);
  min-width: 140px;
  padding: 0 16px;
  border-color: var(--status-good);
}

.checkGroup{
  display:flex;
  align-items:center;
  gap: 8px; /* tight adjacency */
}

.btn{
  height: 46px;
  padding: 0 18px;

  border-radius: var(--radius);
  border: 2px solid var(--border-default);
  background: var(--btn-bg);

  color: var(--btn-text);
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;

  cursor: pointer;
}

.btn:disabled{
  opacity: 0.4;
  cursor: default;
}

.btn:hover{
  background: var(--btn-hover-bg);
}

.btn:active{
  filter: brightness(0.95);
}

.turnTxt{
  font-size: var(--size-small);
  letter-spacing: var(--letter-wide);
  color: var(--text-muted);
}

/* ===============================
   Modal
   =============================== */

.modalBg{
  position:fixed;
  inset:0;
  background: var(--overlay-bg);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:14px;

  z-index: 1000; /* 👈 higher than header + bottom bar */
}

body.modal-open{
  overflow: hidden;
  touch-action: none;
}

.modalBg.hidden{ display:none; }

.modal{
  width: min(420px, 100%);
  max-height: min(80vh, 620px);
  display:flex;
  flex-direction:column;
  background: var(--surface);
  border-radius: var(--radius);
  border:1px solid var(--border-default);
}

.modalHead{
  padding:12px;
  border-bottom:1px solid var(--border-default);
  display:flex;
  justify-content:space-between;
  align-items: center;
}

.modalTitle{
  font-weight: var(--weight-heavy);
}

#modalCloseBtn{
  color: var(--text-primary);
}

.modalBody{
  padding:12px;
  overflow:auto;
  max-height: 55vh; /* keeps header/actions visible */
}

.modalBody .muted{
  color: var(--text-muted);
  font-size: var(--size-small);
}

.modalActions{
  padding:12px;
  border-top:1px solid var(--border-default);

  display:flex;
  justify-content:center;   /* <-- center horizontally */
  align-items:center;
  gap:10px;
}

.modalActions .btn{
  flex: 0 0 auto;          /* <-- stop flex:1 behaviour */
  height: 48px;
  min-width: 160px;        /* nice Wordle-ish size */
  padding: 0 18px;
  letter-spacing: normal;
  text-transform: none;
}

.helpWrap{
  display:flex;
  flex-direction:column;
  gap: 12px;
}

.helpIntro,
.helpStep{
  line-height: 1.45;
}

.helpLegend{
  display:flex;
  flex-direction:column;
  gap: 10px;
  margin-top: 4px;
}

.helpLegendRow{
  display:flex;
  align-items:center;
  gap: 12px;
}

.helpTile{
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 8px;
}

.helpTile--good{
  background-image: url("./img/correct-word.png");
}

.helpTile--close{
  background-image: url("./img/close-word.png");
}

.helpTile--bad{
  background-image: url("./img/wrong-word.png");
}

.helpTile--solid{
  background-image: url("./img/solid-word.png");
}

/* ===============================
   Results panel
   =============================== */

.resultsPanel{
  padding: 10px 0;
}

.versePanel{
  margin-top: 10px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--turn-bg, #f1f3f4);
}

.versePanelRef{
  font-weight: 900;
  margin-bottom: 6px;
}

.versePanelText{
  line-height: 1.5;
  font-size: var(--verse-size);
  font-weight: 700;
}

.shareBox{
  margin-top: 8px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--turn-bg, #f1f3f4);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}


/* ===============================
   Settings
   =============================== */

.settingsRow{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:14px 0;
  font-weight: var(--weight-bold);
}

.switch{
  width:46px;
  height:26px;
  position:relative;
}

.switch input{ display:none; }

.slider{
  position:absolute;
  inset:0;
  background:#d1d5db;
  border-radius:999px;
}

.slider::before{
  content:"";
  position:absolute;
  width:20px;
  height:20px;
  top:3px;
  left:3px;
  background:#fff;
  border-radius:50%;
  transition: transform .2s;
}

.switch input:checked + .slider{
  background: var(--status-good);
}

.switch input:checked + .slider::before{
  transform: translateX(20px);
}

/* ===============================
   Stats
   =============================== */

.statsGrid{
  display:grid;
  grid-template-columns: repeat(3,1fr);
  gap:12px;
  text-align:center;
}

.statValue{
  font-size: var(--size-stat);
  font-weight: var(--weight-heavy);
}

.statLabel{
  font-size: var(--size-xsmall);
  letter-spacing: var(--letter-wide);
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ===============================
   Results modal (isolated)
   =============================== */

.resultsBg{
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 14px;
  z-index: 9999; /* above header + bottom bar */
}

.resultsBg.hidden{ display:none; }

.resultsModal{
  width: min(440px, calc(100% - 24px));
  max-height: min(82vh, 640px);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border-default);
  overflow: hidden;
  display:flex;
  flex-direction:column;
}

.resultsTitle{
  font-weight: var(--weight-heavy);
}

.resultsClose{
  width: var(--tap-size);
  height: var(--tap-size);
  border: none;
  background: transparent;
  cursor: pointer;
  outline: none;
  font-size: 18px;
  line-height: 1;
  display:grid;
  place-items:center;
  border-radius: var(--radius-small);
}

.resultsBody{
  padding: 12px;
  overflow:auto;
}

/* Results content blocks */
.resultsSub{
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.resultsVerse{
  padding: 12px;
  border-radius: var(--radius);
  background: var(--turn-bg);
}

.resultsVerseText{
  font-size: clamp(16px, 4vw, 19px);
  font-weight: 800;
  line-height: 1.45;
}

.resultsRefRow{
  margin-top: 10px;
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap: 10px;
}

.resultsRefLink{
  font-weight: 900;
  text-decoration: none;
  color: var(--status-good);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

.resultsPerf{
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--turn-bg);
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.perfItem{ display:flex; flex-direction:column; gap:4px; }
.perfValue{ font-weight: 900; font-size: 18px; }
.perfLabel{
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.resultsFooter{
  margin-top: 12px;
  display:flex;
  justify-content:center;
}

.resultsFooter .btn{
  min-width: 160px;
}

/* Header layout: title left, subtitle+X on right */
.resultsHead{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  padding: 12px;
  border-bottom: 1px solid var(--border-default);
}

.resultsHeadLeft{
  display:flex;
  flex-direction:column;
  gap: 2px;
}

.resultsHeadRight{
  display:flex;
  align-items:flex-start;
  gap: 10px;
}

.resultsSubtitle{
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 700;
  margin-top: 2px;
  white-space: nowrap;
}

/* Statistics header row with Share on right */
.resultsSectionRow{
  margin-top: 12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
}

.resultsSectionTitle{
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--text-primary);
}

/* Share icon sits here (not under verse) */
.resultsShareBtn{
  width: 32px;
  height: 32px;
  border: none;
  background: url("./img/share.png") center/cover no-repeat;
  cursor: pointer;
  outline: none;
}

body.dark .resultsShareBtn{
  background: url("./img/share_light.png") center/cover no-repeat;
}

/* Emoji progress grid */
.resultsProgress{
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--turn-bg);
}

.progressLabel{
  font-size: var(--size-small);
  font-weight: var(--weight-bold);
  letter-spacing: .08em;
  text-transform: uppercase;
  letter-spacing: var(--letter-wide);
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
  margin-bottom: 8px;
}

.progressGrid{
  display: flex;
  justify-content: center;   /* horizontal centering */
  text-align: center;
  font-size: 18px;
  line-height: 1.25;
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}


/* ===============================
   Toasts
   =============================== */
.toastHost{
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 0;
  right: 0;
  z-index: 9999;
  display:flex;
  justify-content:center;
  pointer-events:none;
}

.toast{
  pointer-events:none;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  transform: translateY(-12px);
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
  max-width: min(520px, calc(100% - 24px));
  text-align:center;

  /* defaults */
  background: var(--toast-bg, #111);
  color: var(--toast-text, #fff);
}

.toast.show{
  transform: translateY(0);
  opacity: 1;
}

/* Tag variants */
.toast--info{ --toast-bg: var(--select-bg); --toast-text: var(--select-text); }
.toast--good{ --toast-bg: var(--status-good); --toast-text: #fff; }
.toast--close{ --toast-bg: var(--status-close); --toast-text: #111; } /* gold reads better with dark text */
.toast--bad{ --toast-bg: var(--status-bad); --toast-text: #fff; }

/* ===============================
   Dark mode
   =============================== */

body.dark{
  /* Surfaces */
  --bg: #0f1117;
  --surface: #0f1117;

  /* Text */
  --text-primary: #f3f4f6;
  --text-muted: #9aa3b2;
  --text-invert: #ffffff;

  /* Buttons */
  --btn-text: #ffffff;
  --btn-hover-bg: #1f2933;

  /* Neutrals */
  --slot-bg: #151823;            /* tile fill */
  --turn-bg: #1b2030;            /* pill fill */
  --border-default: #2a3145;     /* tile border */
  --border-strong: #3b4663;      /* selected/strong border */

  /* Status fills (keep your distinctive palette) */
  --status-good:  #8f6db3;
  --border-good:  #6f4f94;

  --status-close: #d1b454;
  --border-close: rgb(219, 194, 92);

  --status-bad: #c85a6b;   /* slightly lifted for dark mode */
  --border-bad: #8f3a47;

  --select-bg: #ffffff;
  --select-text: #121213;
  --select-border: #ffffff;

  --solid-bg: #222a36;        /* cool slate */
  --solid-border: #5c6f8d;    /* muted blue-grey */
  --solid-text: #d6e1f2;

  /* Overlay */
  --overlay-bg: rgba(0,0,0,0.55);
}


/* ===============================
   Desktop tweaks
   =============================== */

@media (min-width: 740px){
  :root{
    --slot-height: 56px;
    --gap: 10px;
  }

  .title{
    font-size: 26px;
  }
}
