@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/inter-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/inter-700.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('../fonts/poppins-800.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url('../fonts/poppins-900.woff2') format('woff2');
}

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

:root {
  --navy:  #191245;
  --ink:   #100F16;
  --mag:   #C11E5D;
  --pink:  #EA608D;
  --bd:    #2F3082;
  --bm:    #4265AF;
  --ice:   #E1F3F8;
  --bg:    #d4e9f5;
  --white: #ffffff;
  --r:     14px;
  --rs:    10px;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* ---- HEADER ---- */
#hdr-band {
  width: 100%;
  background: var(--navy);
  border-bottom: 5px solid var(--mag);
  flex-shrink: 0;
}

#hdr-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 13px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#hdr-logo {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ice);
  text-decoration: none;
  line-height: 1;
}

#hdr-logo-main { color: var(--white); }
#hdr-logo-sep { color: rgba(255,255,255,0.25); margin: 0 6px; font-weight: 600; }
#hdr-logo-sub { color: var(--pink); font-size: 14px; }

#hdr-tag {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.28);
}

/* ---- WRAP ---- */
#wrap {
  width: 100%;
  max-width: 680px;
  padding: 0 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- SCREENS ---- */
.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  /* No gap here -- each element manages its own spacing */
}
.screen.active { display: flex; }

/* ---- GAME LAYOUT ---- */
/* Strategy: top and bottom are fixed height, grid gets everything in between */

#game-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  padding: 12px 0 10px;
}

#game-theme-area { flex: 1; min-width: 0; }

#game-eyebrow {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--bm);
  margin-bottom: 3px;
}

#game-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#game-theme-name {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 900;
  font-size: clamp(18px, 4vw, 26px);
  color: var(--navy);
  line-height: 1.1;
}

/* MISTAKES */
#mistakes-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--white);
  padding: 8px 13px;
  border-radius: 100px;
  flex-shrink: 0;
}

#mistakes-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--bm);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-right: 3px;
}

.mdot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--mag);
  transition: background 0.3s;
}
.mdot.gone { background: rgba(47,48,130,0.15); }

/* TILE GRID -- takes all remaining vertical space */
#grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  flex: 1; /* grows to fill all space between top and bottom sections */
  min-height: 0; /* allows flex child to shrink */
}

/* Tile height is auto -- grid rows share the available space equally */
.tile {
  border-radius: var(--rs);
  border: 3px solid rgba(47,48,130,0.15);
  background: var(--white);
  cursor: pointer;
  user-select: none;
  /* No fixed height -- tile fills its grid row naturally */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  text-align: center;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: clamp(11px, 2.8vw, 14px);
  font-weight: 700;
  color: var(--navy);
  line-height: 1.2;
  word-break: break-word;
  overflow: hidden;
  transition: background 0.12s, border-color 0.12s, transform 0.12s, box-shadow 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.tile:hover {
  background: #c4e1f2;
  border-color: var(--bm);
  transform: translateY(-2px);
}
.tile:active { transform: scale(0.95); }

.tile.sel {
  background: var(--mag);
  border-color: var(--mag);
  color: var(--white);
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(193,30,93,0.32);
}

.tile.shake { animation: shk 0.38s ease; }
@keyframes shk {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-7px); }
  40%     { transform: translateX(7px); }
  60%     { transform: translateX(-4px); }
  80%     { transform: translateX(4px); }
}

.tile.pop { animation: popIt 0.3s ease; }
@keyframes popIt {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.1) translateY(-4px); }
  100% { transform: scale(1); }
}

/* MESSAGE */
#msg {
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--mag);
  height: 22px; /* fixed so layout doesn't jump */
  line-height: 22px;
  flex-shrink: 0;
  margin-top: 6px;
}

/* ACTION BUTTONS */
#actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-shrink: 0;
  padding: 6px 0 8px;
}

.abtn {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 11px;
  font-weight: 700;
  padding: 11px 16px;
  border-radius: 100px;
  border: 3px solid var(--bd);
  background: var(--white);
  color: var(--bd);
  cursor: pointer;
  transition: all 0.12s;
  letter-spacing: 0.02em;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.abtn:hover { background: var(--bd); color: var(--white); }
.abtn:active { transform: scale(0.96); }
.abtn.pri { background: var(--mag); border-color: var(--mag); color: var(--white); }
.abtn.pri:hover { background: var(--navy); border-color: var(--navy); }
.abtn:disabled { opacity: 0.28; cursor: not-allowed; transform: none; }

/* CATEGORY TRACKER -- sits at bottom, fixed height reference strip */
#cat-tracker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  flex-shrink: 0;
  padding-bottom: 10px;
}

.ct-item {
  border-radius: var(--rs);
  padding: 7px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
  transition: all 0.3s ease;
  border: 3px solid transparent;
}

.ct-label {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  flex: 1;
  transition: opacity 0.3s;
}

.ct-tick {
  font-size: 14px;
  font-weight: 900;
  color: rgba(255,255,255,0.9);
  opacity: 0;
  transition: opacity 0.3s;
  flex-shrink: 0;
}
.ct-item.solved .ct-tick { opacity: 1; }

/* ---- END SCREEN ---- */
#end {
  align-items: center;
  text-align: center;
  overflow-y: auto;
}

#end-title {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 900;
  font-size: clamp(30px, 8vw, 44px);
  color: var(--navy);
  line-height: 1.05;
}

#end-sub {
  font-size: 16px;
  font-weight: 500;
  color: var(--bm);
  line-height: 1.6;
  max-width: 320px;
}

#end-cats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.end-cat {
  border-radius: var(--r);
  padding: 14px 18px;
  position: relative;
  overflow: hidden;
}

.end-cat::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 60px; height: 60px;
  border-radius: 0 var(--r) 0 60px;
  background: rgba(255,255,255,0.12);
}

.end-cat-name {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.6);
  margin-bottom: 6px;
}

.end-cat-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.end-cat-word {
  font-size: 12px;
  font-weight: 700;
  color: rgba(255,255,255,0.95);
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 8px;
  padding: 5px 10px;
  line-height: 1.2;
  letter-spacing: 0.02em;
}

#end-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

#share-btn {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 900;
  font-size: 15px;
  padding: 14px 32px;
  border-radius: 100px;
  border: none;
  background: var(--mag);
  color: var(--white);
  cursor: pointer;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background 0.15s;
}
#share-btn:hover { background: var(--navy); }

#play-again-btn {
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 700;
  font-size: 15px;
  padding: 13px 28px;
  border-radius: 100px;
  border: 3px solid var(--bd);
  background: var(--white);
  color: var(--bd);
  cursor: pointer;
  transition: all 0.12s;
}
#play-again-btn:hover { background: var(--bd); color: var(--white); }

#share-done {
  font-size: 14px;
  font-weight: 700;
  color: var(--mag);
  display: none;
}

/* ---- ALREADY PLAYED SCREEN ---- */
#played {
  align-items: center;
  text-align: center;
  gap: 16px;
}

#played-title {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 900;
  font-size: clamp(26px, 7vw, 38px);
  color: var(--navy);
  line-height: 1.05;
}

#played-sub {
  font-size: 15px;
  font-weight: 500;
  color: var(--bm);
  line-height: 1.6;
  max-width: 300px;
}

#played-result {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

#played-share-btn {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 900;
  font-size: 15px;
  padding: 14px 32px;
  border-radius: 100px;
  border: none;
  background: var(--mag);
  color: var(--white);
  cursor: pointer;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background 0.15s;
}
#played-share-btn:hover { background: var(--navy); }

#played-share-done {
  font-size: 14px;
  font-weight: 700;
  color: var(--mag);
  display: none;
}

/* ---- FOOTER ---- */
#footer {
  padding: 12px 0 10px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--bm);
  opacity: 0.4;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
#footer a { color: inherit; text-decoration: none; }

/* ==============================
   SETTINGS BUTTON (cog in header)
   ============================== */
#settings-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.55);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#settings-btn:hover { color: var(--white); background: rgba(255,255,255,0.1); }
#settings-btn:active { background: rgba(255,255,255,0.18); }

/* ==============================
   SETTINGS OVERLAY + SHEET
   ============================== */
#settings-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16,15,22,0.72);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#settings-overlay.open { display: flex; }

#settings-sheet {
  width: 100%;
  max-width: 680px;
  background: var(--white);
  border-radius: 24px 24px 0 0;
  padding: 22px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  animation: slideUp 0.25s ease;
  /* Let content grow naturally -- overlay scrolls if needed */
  flex-shrink: 0;
  margin-top: auto;
}

/* HEADER */
#settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#settings-title {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 900;
  font-size: 22px;
  color: var(--navy);
}

#settings-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2.5px solid rgba(47,48,130,0.18);
  background: var(--bg);
  color: var(--bm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#settings-close:hover { background: var(--bm); color: var(--white); border-color: var(--bm); }

/* WELCOME BLOCK */
#settings-welcome {
  background: var(--navy);
  border-radius: var(--r);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
#settings-welcome::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 80px; height: 80px;
  border-radius: 0 var(--r) 0 80px;
  background: rgba(255,255,255,0.06);
}
#settings-welcome-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--pink);
  background: rgba(234,96,141,0.18);
  padding: 3px 10px;
  border-radius: 100px;
  margin-bottom: 10px;
}
#settings-welcome-title {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 900;
  font-size: 20px;
  color: var(--ice);
  margin-bottom: 8px;
  line-height: 1.2;
}
#settings-welcome-body {
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,0.62);
  line-height: 1.65;
}

/* SECTION TITLES */
.settings-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--bm);
  margin-bottom: 12px;
}

/* INSTRUCTIONS */
#settings-section-instructions { display: flex; flex-direction: column; }

.settings-instructions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.settings-step {
  background: var(--bg);
  border-radius: var(--rs);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.settings-step-num {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 900;
  font-size: 22px;
  color: var(--mag);
  line-height: 1;
  flex-shrink: 0;
}

.settings-step-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--navy);
  line-height: 1.5;
}
.settings-step-text strong { font-weight: 700; }

/* TOGGLE ROW */
#settings-section-cats { display: flex; flex-direction: column; }

#settings-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--bg);
  border-radius: var(--rs);
  padding: 14px 16px;
  margin-bottom: 10px;
}

#settings-toggle-text { flex: 1; }

#settings-toggle-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 3px;
}

#settings-toggle-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--bm);
  line-height: 1.5;
}

/* THE TOGGLE PILL */
#settings-cat-toggle {
  width: 52px;
  height: 28px;
  border-radius: 100px;
  background: rgba(47,48,130,0.18);
  border: none;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 0.22s;
  -webkit-tap-highlight-color: transparent;
}
#settings-cat-toggle.on { background: var(--mag); }
#settings-cat-toggle::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--white);
  top: 3px;
  left: 3px;
  transition: transform 0.22s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}
#settings-cat-toggle.on::after { transform: translateX(24px); }

/* CATEGORY PREVIEW (visible when toggle is on) */
#settings-cat-preview {
  display: none;
  flex-direction: column;
  gap: 8px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.settings-cat-card {
  border-radius: var(--rs);
  padding: 11px 14px;
  position: relative;
  overflow: hidden;
}
.settings-cat-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 44px; height: 44px;
  border-radius: 0 var(--rs) 0 44px;
  background: rgba(255,255,255,0.12);
}
.settings-cat-card-label {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 800;
  font-size: 14px;
  color: var(--white);
  margin-bottom: 2px;
}
.settings-cat-card-hint {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,0.68);
  font-style: italic;
}

/* ABOUT */
#settings-section-about { display: flex; flex-direction: column; }
#settings-about-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--bm);
  line-height: 1.7;
}
#settings-about-text a { color: var(--mag); text-decoration: none; font-weight: 700; }
#settings-about-text a:hover { text-decoration: underline; }

/* LET'S PLAY BUTTON (first visit only) */
#settings-play-btn {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 900;
  font-size: 16px;
  padding: 16px;
  border-radius: var(--r);
  border: none;
  background: var(--mag);
  color: var(--white);
  cursor: pointer;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  width: 100%;
  transition: background 0.15s;
}
#settings-play-btn:hover { background: var(--navy); }
