/* Maintenance-mode crossword game — pixel-art styling.
   Baseline tokens use Rubik, #4a4a4a, #E0E0E0, and #F5F5F5.
   NOTE: the full game UI is scaled +25% vs. the original anagram version
   (every dimension below is the original value x 1.25). */

@font-face {
  font-family: 'Rubik';
  src: url('Rubik-Regular.ttf') format('truetype');
}

@font-face {
  font-family: 'RubikSemiBold';
  src: url('Rubik-SemiBold.ttf') format('truetype');
}

:root {
  --px: 5px;
  --ink: #4a4a4a;
  --paper: #f5f5f5;
  --line: #e0e0e0;
  --brand: #10a8e5;
  --brand-dark: #0b75a0;
  --brand-soft: #e6f5fb;
  --good: #2e7d32;
  --bad: #c62828;
  --gold: #f9a825;
  --cell-max: 60px; /* original slot 48px x 1.25 */
  --board-gap: 5px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  width: 100%;
  font-size: 14px;
  font-style: normal;
  font-weight: 400;
  line-height: 20px;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background:
    linear-gradient(var(--brand-soft) 1px, transparent 1px) 0 0 / 100% 30px,
    linear-gradient(90deg, var(--brand-soft) 1px, transparent 1px) 0 0 / 30px 100%,
    #ffffff;
  font-family: 'Rubik', sans-serif;
  color: var(--ink);
  image-rendering: pixelated;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  max-width: 525px;
  margin: 0 auto;
  padding: 30px 20px 50px;
  text-align: center;
}

/* ---------- header ---------- */

.kb-branding {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: max-content;
  line-height: 0;
  margin: 10px auto 25px;
}

.kb-logo {
  display: block;
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex: 0 0 auto;
}

.pixel-heart {
  display: block;
  width: 35px;
  height: 35px;
  background: var(--brand);
  clip-path: polygon(
    14.2857% 0, 42.8571% 0, 42.8571% 14.2857%,
    57.1429% 14.2857%, 57.1429% 0, 85.7143% 0,
    85.7143% 14.2857%, 100% 14.2857%, 100% 42.8571%,
    85.7143% 42.8571%, 85.7143% 71.4286%, 71.4286% 71.4286%,
    71.4286% 85.7143%, 57.1429% 85.7143%, 57.1429% 100%,
    42.8571% 100%, 42.8571% 85.7143%, 28.5714% 85.7143%,
    28.5714% 71.4286%, 14.2857% 71.4286%, 14.2857% 42.8571%,
    0 42.8571%, 0 14.2857%, 14.2857% 14.2857%
  );
}

.kb-brand-separator {
  display: block;
  --pixel: 5px;
  position: relative;
  width: calc(var(--pixel) * 5);
  height: calc(var(--pixel) * 5);
  color: var(--ink);
  flex: 0 0 auto;
}

.kb-brand-separator::before,
.kb-brand-separator::after {
  content: '';
  position: absolute;
  width: var(--pixel);
  height: var(--pixel);
  background: var(--ink);
  top: 0;
  left: 0;
  box-shadow: calc(var(--pixel) * 1) calc(var(--pixel) * 1) 0 var(--ink),
    calc(var(--pixel) * 2) calc(var(--pixel) * 2) 0 var(--ink),
    calc(var(--pixel) * 3) calc(var(--pixel) * 3) 0 var(--ink),
    calc(var(--pixel) * 4) calc(var(--pixel) * 4) 0 var(--ink);
}

.kb-brand-separator::after {
  right: 0;
  top: 0;
  left: auto;
  box-shadow: calc(var(--pixel) * -1) calc(var(--pixel) * 1) 0 var(--ink),
    calc(var(--pixel) * -2) calc(var(--pixel) * 2) 0 var(--ink),
    calc(var(--pixel) * -3) calc(var(--pixel) * 3) 0 var(--ink),
    calc(var(--pixel) * -4) calc(var(--pixel) * 4) 0 var(--ink);
}

.kb-subtitle {
  margin: 20px auto 30px;
  font-size: 16.25px;
  line-height: 25px;
  text-align: center;
  color: #6a6a6a;
}

.kb-subtitle strong { color: var(--brand-dark); font-weight: 600; }

/* ---------- game frame ---------- */

.kb-game {
  border: 3.75px solid var(--ink);
  border-radius: 0;
  background: #ffffff;
  box-shadow: 7.5px 7.5px 0 var(--brand-soft), 7.5px 7.5px 0 3.75px var(--ink);
  padding: 20px 15px 15px;
}

.kb-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 15px;
}

.kb-badge {
  font-family: 'RubikSemiBold', 'Rubik', sans-serif;
  font-size: 13.75px;
  letter-spacing: 1.25px;
  background: var(--ink);
  color: #ffffff;
  padding: 7.5px 10px;
  box-shadow: 2.5px 2.5px 0 var(--line);
  white-space: nowrap;
}

.kb-badge b { color: var(--gold); font-weight: 600; }

.kb-badge-alt { background: var(--brand); }

.kb-score-group {
  display: inline-flex;
  align-items: center;
  gap: 7.5px;
}

.kb-help {
  width: 35px;
  height: 35px;
  padding: 0;
  border: 2.5px solid var(--ink);
  background: #ffffff;
  color: var(--ink);
  font-family: 'RubikSemiBold', 'Rubik', sans-serif;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.kb-dots { display: inline-flex; gap: 7.5px; }

.kb-dot {
  width: 15px;
  height: 15px;
  border: 2.5px solid var(--ink);
  background: #ffffff;
}

.kb-dot.done { background: var(--brand); }
.kb-dot.now { background: var(--gold); animation: blink 1s steps(2) infinite; }

@keyframes blink { 50% { opacity: 0.35; } }

.kb-theme {
  display: inline-block;
  font-size: 13.75px;
  font-weight: 600;
  letter-spacing: 1.25px;
  color: var(--brand-dark);
  background: var(--brand-soft);
  border: 2.5px dashed var(--brand);
  padding: 5px 12.5px;
  margin-bottom: 7.5px;
}

/* ---------- crossword board ---------- */

.kb-board {
  display: grid;
  gap: var(--board-gap);
  justify-content: center;
  width: 100%;
  margin: 0 auto 22.5px;
}

.kb-gap { aspect-ratio: 1; }
.kb-hidden-cell { visibility: hidden; }

.kb-cell {
  position: relative;
  width: auto;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 3.75px solid var(--ink);
  border-bottom-width: 7.5px;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'RubikSemiBold', 'Rubik', sans-serif;
  font-size: 27.5px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  transition: none;
}

.kb-cell.filled { background: #ffffff; }
.kb-cell.good { background: #e8f5e9; border-color: var(--good); color: var(--good); }
.kb-cell.locked:not(.good) { background: #eeeeee; border-color: var(--line); color: #8a8a8a; cursor: not-allowed; }
.kb-cell.selected { background: #fff8e1; border-color: var(--gold); }
.kb-cell.hi { background: var(--brand-soft); border-color: var(--brand-dark); }
.kb-cell.selected.hi { background: #fff8e1; border-color: var(--gold); }
.kb-cell.shake { animation: shake 0.3s steps(2) 2; border-color: var(--bad); color: var(--bad); }
.kb-cell.shared::after {
  content: '+';
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-family: 'RubikSemiBold', 'Rubik', sans-serif;
  font-size: 10px;
  line-height: 1;
  color: var(--brand-dark);
  pointer-events: none;
}
.kb-cell.shared.good::after { color: var(--good); }

.kb-letter { pointer-events: none; }

.kb-num {
  position: absolute;
  top: 1.25px;
  left: 2.5px;
  font-family: 'Rubik', sans-serif;
  font-size: 10px;
  font-weight: 400;
  line-height: 1;
  color: #6a6a6a;
  pointer-events: none;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
  100% { transform: translateX(0); }
}

/* ---------- letter tiles ---------- */

.kb-tiles {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 75px;
  margin-bottom: 15px;
}

.kb-tile {
  width: 65px;
  height: 65px;
  padding: 0;
  border: 3.75px solid var(--ink);
  box-shadow: 0 6.25px 0 var(--ink);
  background: var(--brand);
  color: #ffffff;
  font-family: 'RubikSemiBold', 'Rubik', sans-serif;
  font-size: 27.5px;
  line-height: 1;
  cursor: pointer;
  transition: none;
}

.kb-tile:active {
  transform: translateY(6.25px);
  box-shadow: 0 0 0 var(--ink);
}

.kb-tile.selected { background: var(--gold); color: var(--ink); }
.kb-tile.used { visibility: hidden; }

.kb-tile.pop, .kb-cell.pop { animation: pop 0.2s steps(3); }

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ---------- clues ---------- */

.kb-clues {
  list-style: none;
  margin: 0 0 15px;
  padding: 0;
  display: grid;
  gap: 7.5px;
  text-align: left;
}

.kb-clue {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 8.75px 12.5px;
  border: 2.5px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-family: 'Rubik', sans-serif;
  font-size: 15px;
  line-height: 20px;
  text-align: left;
  cursor: pointer;
}

.kb-clue-num {
  font-family: 'RubikSemiBold', 'Rubik', sans-serif;
  font-size: 13.75px;
  letter-spacing: 1.25px;
  color: var(--brand-dark);
  white-space: nowrap;
  min-width: 37.5px;
}

.kb-clue.active { border-color: var(--brand); background: var(--brand-soft); }
.kb-clue.done { border-color: var(--good); background: #e8f5e9; color: var(--good); text-decoration: line-through; }
.kb-clue.locked:not(.done) { color: #8a8a8a; cursor: not-allowed; }
.kb-clue.done .kb-clue-num { color: var(--good); }

/* ---------- message & controls ---------- */

.kb-msg {
  min-height: 27.5px;
  font-size: 16.25px;
  font-weight: 600;
  color: var(--brand-dark);
  margin-bottom: 15px;
}

.kb-msg.good { color: var(--good); }
.kb-msg.bad { color: var(--bad); }

.kb-controls { display: flex; justify-content: center; gap: 15px; }

.kb-btn {
  font-family: 'RubikSemiBold', 'Rubik', sans-serif;
  font-size: 16.25px;
  letter-spacing: 1.25px;
  color: #ffffff;
  background: var(--brand);
  border: 3.75px solid var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  padding: 12.5px 27.5px;
  cursor: pointer;
}

.kb-btn-alt { background: #ffffff; color: var(--ink); }

.kb-btn:active {
  transform: translateY(5px);
  box-shadow: 0 0 0 var(--ink);
}

/* ---------- accessibility ---------- */

.kb-cell:focus-visible,
.kb-tile:focus-visible,
.kb-clue:focus-visible,
.kb-btn:focus-visible,
.kb-help:focus-visible,
.kb-modal-close:focus-visible {
  outline: 3.75px solid var(--gold);
  outline-offset: 2.5px;
}

@media (prefers-reduced-motion: reduce) {
  .kb-dot.now, .pixel-spark, .kb-cell.shake, .kb-tile.pop, .kb-cell.pop { animation: none; }
  .confetti { display: none; }
  .kb-banner { animation: none; opacity: 1; }
}

@media (max-width: 480px) {
  #app { padding: 20px 12px 36px; }
  .kb-game { padding: 16px 10px 12px; }
  .kb-subtitle { margin-bottom: 24px; }
  .kb-board { margin-bottom: 18px; }
  .kb-tiles { gap: 8px; }
}

/* ---------- footer ---------- */

.kb-footer {
  margin-top: 30px;
  font-size: 15px;
  color: #6a6a6a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.kb-copyright {
  font-size: 11px;
  line-height: 16px;
}

/* ---------- how-to-play modal ---------- */

.kb-modal {
  position: fixed;
  inset: 0;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(74, 74, 74, 0.7);
}

.kb-modal[hidden] { display: none !important; }

.kb-modal-card {
  position: relative;
  width: min(100%, 420px);
  padding: 25px 22.5px 20px;
  border: 3.75px solid var(--ink);
  background: #ffffff;
  box-shadow: 7.5px 7.5px 0 var(--brand-soft), 7.5px 7.5px 0 3.75px var(--ink);
  text-align: left;
}

.kb-modal-card h2 {
  margin: 0 35px 15px 0;
  font-family: 'RubikSemiBold', 'Rubik', sans-serif;
  font-size: 22.5px;
}

.kb-modal-card p { margin: 0 0 10px; }

.kb-modal-card ul {
  margin: 0;
  padding-left: 22.5px;
}

.kb-modal-card li + li { margin-top: 7.5px; }

.kb-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 2.5px solid var(--ink);
  background: #ffffff;
  color: var(--ink);
  font-size: 22.5px;
  line-height: 1;
  cursor: pointer;
}

.pixel-spark {
  width: var(--px);
  height: var(--px);
  background: var(--gold);
  color: var(--gold);
  box-shadow: 10px 0, 5px -5px, 5px 5px;
  animation: blink 1.4s steps(2) infinite;
}

/* ---------- effects ---------- */

#fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 9; }

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -12.5px;
  animation: fall linear forwards;
}

@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); }
}

.kb-banner {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  background: var(--ink);
  color: #ffffff;
  font-family: 'RubikSemiBold', 'Rubik', sans-serif;
  font-size: 22.5px;
  letter-spacing: 2.5px;
  padding: 20px 30px;
  border: 3.75px solid var(--brand);
  box-shadow: 7.5px 7.5px 0 var(--brand-soft);
  z-index: 10;
  animation: banner 1.6s steps(16) forwards;
}

@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}
