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

body {
  background: #1a1a2e;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #eee;
  height: 100dvh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Celebration canvas ── */

#celebration-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* ── Home Screen ── */

#home-screen {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#home-header {
  padding: 20px 16px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 1px solid #1e3050;
}

#home-title-wrap {
  display: flex;
  align-items: flex-end;
  gap: 18px;
}

#home-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: #80d8ff;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
}

#nerd-badge {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  line-height: 1;
  margin-bottom: 4px;
}

#nerd-badge .nb-nerd,
#nerd-badge .nb-mode {
  display: inline-block;
  font-family: 'Satisfy', cursive;
  font-size: 0.9rem;
  font-weight: 700;
  color: #ff7a00;
  transform: rotate(-35deg);
  transform-origin: 0% 100%;
  white-space: nowrap;
}

#home-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#btn-celebrations {
  background: transparent;
  border: 1px solid #1e3050;
  border-radius: 6px;
  color: #8898aa;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 5px 8px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

#btn-celebrations:active {
  background: #0d1f3a;
}

#btn-celebrations.has-purchase {
  border-color: #c8a840;
  color: #c8a840;
}

#lang-toggle {
  display: flex;
  gap: 4px;
  background: #0d1f3a;
  border-radius: 8px;
  padding: 4px;
}

.lang-btn {
  background: transparent;
  border: none;
  color: #8898aa;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 13px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  touch-action: manipulation;
}

.lang-btn.lang-active {
  background: #1a3a6e;
  color: #80d8ff;
}


#category-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.category-card {
  background: #0d2137;
  border: 1px solid #1e3050;
  border-radius: 12px;
  padding: 10px 18px;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.1s;
  user-select: none;
}

.category-card:active:not(.locked) {
  transform: scale(0.98);
}

.category-card.locked {
  opacity: 0.45;
  cursor: default;
}

.category-card.maxed {
  border-color: #5a6878;
  background: linear-gradient(135deg, rgba(160,176,192,0.10) 0%, transparent 55%), #0d2137;
}

.category-title {
  flex: 1;
  font-size: 0.98rem;
  font-weight: 600;
  color: #bcd;
}

.level-selector {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.level-num {
  font-size: 0.9rem;
  font-weight: 700;
  color: #80d8ff;
  min-width: 22px;
  text-align: center;
}

.btn-lvl-dec,
.btn-lvl-inc {
  background: none;
  border: none;
  color: #80d8ff;
  font-size: 0.82rem;
  cursor: pointer;
  touch-action: manipulation;
  padding: 6px 7px;
  line-height: 1;
  user-select: none;
}

.btn-lvl-dec.invisible {
  visibility: hidden;
}

.btn-lvl-inc.lvl-locked {
  color: #7a8898;
  cursor: default;
}

.category-lock {
  font-size: 0.9rem;
  color: #7a8898;
  flex-shrink: 0;
}

/* ── Puzzle Screen ── */

#puzzle-screen {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#puzzle-header {
  padding: 0 16px;
  height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  border-bottom: 1px solid #1e3050;
  background: #0d1f3a;
}

#back-btn {
  background: none;
  border: none;
  color: #80d8ff;
  font-size: 1.5rem;
  cursor: pointer;
  touch-action: manipulation;
  padding: 4px 6px;
  margin-left: -6px;
  flex-shrink: 0;
}

#puzzle-level-title {
  flex: 1;
  font-size: 0.92rem;
  font-weight: 600;
  color: #bcd;
  white-space: nowrap;
  overflow: visible;
  display: flex;
  align-items: center;
  gap: 8px;
}

#puzzle-nerd-badge {
  display: inline-flex;
  align-items: flex-end;
  gap: 1px;
  line-height: 1;
  flex-shrink: 0;
}

#puzzle-nerd-badge .nb-nerd,
#puzzle-nerd-badge .nb-mode {
  display: inline-block;
  font-family: 'Satisfy', cursive;
  font-size: 0.52rem;
  font-weight: 700;
  color: #ff7a00;
  transform: rotate(-35deg);
  transform-origin: 0% 100%;
  white-space: nowrap;
}

#puzzle-solved-count {
  font-size: 0.85rem;
  font-weight: 700;
  color: #80d8ff;
  flex-shrink: 0;
}

#header-right-slot {
  display: grid;
  flex-shrink: 0;
}

#header-right-slot > * {
  grid-area: 1 / 1;
  align-self: center;
  justify-self: end;
}

#coin-counter {
  font-size: 0.85rem;
  font-weight: 700;
  color: #FFD700;
  letter-spacing: 0.02em;
}

@keyframes coinPop {
  0%   { transform: scale(0.7); opacity: 0; }
  60%  { transform: scale(1.2); }
  100% { transform: scale(1);   opacity: 1; }
}

.coin-pop {
  animation: coinPop 0.35s ease forwards;
}

#surrender-btn {
  background: transparent;
  border: 1px solid #5a3a1a;
  border-radius: 6px;
  color: #b07040;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  padding: 5px 9px;
  letter-spacing: 0.02em;
}

#puzzle-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}

/* ── Question Card ── */

.question-card {
  background: rgba(13, 33, 55, 0.82);
  border: 1px solid #1e3050;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color 0.3s;
  position: relative;
}

.question-diff {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 0.68rem;
  color: #7a8898;
  line-height: 1;
  user-select: none;
}

.question-card.is-solved {
  border-color: #1e4a2a;
}

.question-media {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.question-img {
  width: 84px;
  height: 84px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.question-text {
  font-size: 0.92rem;
  color: #bcd;
  line-height: 1.45;
}

/* ── Cryptogram ── */

.cryptogram {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: flex-start;
}

.crypto-word {
  display: flex;
  gap: 2px;
}

.cipher-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.answer-cell {
  width: 26px;
  height: 30px;
  border-bottom: 2px solid #2a4060;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: #dde;
  cursor: pointer;
  touch-action: manipulation;
  text-transform: uppercase;
  border-radius: 3px 3px 0 0;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
  user-select: none;
}

.answer-cell.focused {
  border-bottom-color: #80d8ff;
  background: rgba(128, 216, 255, 0.1);
}

.answer-cell.verified {
  color: #5dbf5d;
  border-bottom-color: #1e4a2a;
}

.answer-cell.surrendered {
  color: #c8a840;
  border-bottom-color: #4a3a10;
}

.answer-cell.wrong-flash {
  color: #e05050;
  border-bottom-color: #804040;
  animation: wrongFlash 0.5s ease forwards;
}

@keyframes wrongFlash {
  0%   { background: rgba(224, 80, 80, 0.2); }
  100% { background: transparent; }
}

.cipher-cell {
  font-size: 0.68rem;
  color: #7a8898;
  text-transform: uppercase;
  line-height: 1;
  letter-spacing: 0.02em;
  user-select: none;
}

/* ── Fact ── */

.question-fact {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: rgba(10, 40, 20, 0.7);
  border: 1px solid #1a4a22;
  border-radius: 8px;
  padding: 12px;
  font-size: 0.83rem;
  color: #8dbb9d;
  line-height: 1.55;
  animation: factReveal 0.4s ease;
}

@keyframes factReveal {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fact-icon {
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ── Complete Bar ── */

#puzzle-complete-bar {
  flex-shrink: 0;
  background: #091a0e;
  border-top: 1px solid #1a4a22;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#complete-msg {
  flex: 1;
  color: #5dbf5d;
  font-weight: 600;
  font-size: 0.9rem;
}

#btn-continue,
#btn-home-from-complete {
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  padding: 9px 14px;
  border: 1px solid;
}

#btn-continue {
  background: #1a4a1a;
  border-color: #2a7a2a;
  color: #5dbf5d;
}

#btn-home-from-complete {
  background: transparent;
  border-color: #2a4060;
  color: #80d8ff;
}

#puzzle-surrender-bar {
  flex-shrink: 0;
  background: #130f00;
  border-top: 1px solid #4a3a10;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#surrender-msg {
  flex: 1;
  color: #c8a840;
  font-weight: 600;
  font-size: 0.9rem;
}

#btn-restart-from-surrender,
#btn-home-from-surrender {
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  padding: 9px 14px;
  border: 1px solid;
}

#btn-restart-from-surrender {
  background: #2a2200;
  border-color: #6a5020;
  color: #c8a840;
}

#btn-home-from-surrender {
  background: transparent;
  border-color: #2a4060;
  color: #80d8ff;
}

/* ── On-screen Keyboard ── */

#onscreen-kbd {
  flex-shrink: 0;
  background: #0d1525;
  border-top: 1px solid #1e3050;
  padding: 8px 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.kbd-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.kbd-key {
  width: 32px;
  height: 44px;
  flex-shrink: 0;
  background: #1a3050;
  border: 1px solid #2a4060;
  border-radius: 5px;
  color: #cde;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kbd-key:active {
  background: #2a4a70;
}

.kbd-back {
  width: 50px;
  background: #162030;
  border-color: #253545;
  font-size: 1.1rem;
}

.kbd-back:active {
  background: #223040;
}

.kbd-key.kbd-used {
  color: #5c6878;
  background: #0d1a28;
  border-color: #162030;
}

.kbd-key.kbd-verified {
  color: #5dbf5d;
  background: #091a0e;
  border-color: #1e4a22;
}

/* ── Celebration Selection Screen ── */

#celebration-screen {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#celebration-header {
  padding: 0 16px;
  height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  border-bottom: 1px solid #1e3050;
  background: #0d1f3a;
}

#btn-back-from-celebrations {
  background: none;
  border: none;
  color: #80d8ff;
  font-size: 1.5rem;
  cursor: pointer;
  touch-action: manipulation;
  padding: 4px 6px;
  margin-left: -6px;
  flex-shrink: 0;
}

#celebration-screen-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  color: #bcd;
}

#celebration-coins {
  font-size: 0.85rem;
  font-weight: 700;
  color: #FFD700;
  flex-shrink: 0;
}

#celebration-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 12px;
  overflow-y: auto;
  align-content: start;
}

.celebration-card {
  background: #0d2137;
  border: 2px solid #1e3050;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s;
  user-select: none;
}

.celebration-card.selected {
  border-color: #80d8ff;
}

.celebration-card.locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.celebration-card.purchasable {
  position: relative;
  border-color: #3a4a5a;
  cursor: default;
}

.celebration-card.purchasable:not(.affordable) .celebration-lock-cover {
  opacity: 0.55;
}

.celebration-card.purchasable .lock-cost {
  position: absolute;
  bottom: 36px;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 1;
}

.celebration-card.purchasable.affordable {
  border-color: #c8a840;
  cursor: pointer;
}


.celebration-lock-cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 200px;
  background: #0d1520;
  border-radius: 10px 10px 0 0;
}

.lock-icon {
  font-size: 1.6rem;
}

.lock-cost {
  font-size: 1rem;
  font-weight: 700;
  color: #FFD700;
}

.celebration-card:active {
  opacity: 0.85;
}

.celebration-preview {
  display: block;
  width: 100%;
  height: 200px;
  background: #1a1a2e;
  border-radius: 10px 10px 0 0;
}

.celebration-card-label {
  padding: 7px 6px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: #bcd;
  border-top: 1px solid #1e3050;
}

.celebration-card.selected .celebration-card-label {
  color: #80d8ff;
}

/* ── Pack Screen ── */

#pack-screen {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#pack-header {
  padding: 0 16px;
  height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  border-bottom: 1px solid #1e3050;
  background: #0d1f3a;
}

#btn-back-from-packs {
  background: none;
  border: none;
  color: #80d8ff;
  font-size: 1.5rem;
  cursor: pointer;
  touch-action: manipulation;
  padding: 4px 6px;
  margin-left: -6px;
  flex-shrink: 0;
}

#pack-screen-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  color: #bcd;
}

#btn-share-pack {
  background: none;
  border: none;
  color: #3a6888;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  padding: 8px;
  flex-shrink: 0;
}

#btn-share-pack:active {
  color: #80d8ff;
}

#btn-delete-pack {
  background: none;
  border: none;
  color: #c05040;
  font-size: 1.2rem;
  cursor: pointer;
  touch-action: manipulation;
  padding: 8px;
  margin-right: -6px;
  flex-shrink: 0;
}

#btn-delete-pack:active {
  color: #ff7060;
}

#pack-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.pack-panel {
  padding: 18px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pack-section-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 16px 0;
  color: #4a6a8a;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.pack-section-divider::before,
.pack-section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #1e3050;
}

.pack-instructions {
  color: #8898aa;
  font-size: 0.85rem;
  line-height: 1.55;
  margin-bottom: 4px;
}

.pack-label {
  color: #7a8898;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-top: 6px;
}

.pack-input {
  background: #0d2137;
  border: 1px solid #1e3050;
  border-radius: 8px;
  color: #eee;
  font-size: 0.95rem;
  padding: 10px 12px;
  width: 100%;
  outline: none;
  font-family: inherit;
}

.pack-input:focus {
  border-color: #3a5878;
}

.pack-textarea {
  background: #0d2137;
  border: 1px solid #1e3050;
  border-radius: 8px;
  color: #eee;
  font-size: 0.88rem;
  padding: 10px 12px;
  width: 100%;
  min-height: 130px;
  resize: vertical;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
}

.pack-textarea:focus {
  border-color: #3a5878;
}

.pack-btn-primary {
  background: #1a3a6e;
  border: 1px solid #2a5a9e;
  border-radius: 10px;
  color: #80d8ff;
  font-size: 1rem;
  font-weight: 700;
  padding: 14px;
  width: 100%;
  cursor: pointer;
  touch-action: manipulation;
  margin-top: 6px;
}

.pack-btn-primary:active {
  background: #0d2a5e;
}

.pack-btn-copy {
  background: #0e2e1a;
  border: 1px solid #1e5a2e;
  border-radius: 10px;
  color: #5dbf8d;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 14px;
  width: 100%;
  cursor: pointer;
  touch-action: manipulation;
  margin-top: 4px;
}

.pack-btn-copy:active {
  background: #082010;
}

.pack-error {
  color: #e07070;
  font-size: 0.82rem;
  line-height: 1.5;
  padding: 6px 0 2px;
  white-space: pre-wrap;
}

.pack-textarea-questions {
  min-height: 260px;
  font-family: monospace;
  font-size: 0.85rem;
}

.pack-generate {
  margin-top: 8px;
  border: 1px solid #1e3050;
  border-radius: 10px;
  overflow: hidden;
}

.pack-generate > summary {
  list-style: none;
  padding: 12px 14px;
  color: #5dbf8d;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.pack-generate > summary::-webkit-details-marker { display: none; }

.pack-generate[open] > summary {
  border-bottom: 1px solid #1e3050;
}

.pack-generate-body {
  padding: 4px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pack-generate-hint {
  color: #4a6a8a;
  font-size: 0.8rem;
  margin: 2px 0 0;
}

/* ── Personal pack cards on home screen ── */

.personal-pack-card {
  border-style: dashed;
}

.personal-pack-card.maxed {
  border-style: solid;
}

.pack-q-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: #5a7a8a;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.pack-edit-btn {
  background: none;
  border: none;
  color: #3a5878;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 3px 12px;
  touch-action: manipulation;
  flex-shrink: 0;
}

.pack-edit-btn:active {
  color: #80d8ff;
}

.pack-delete-btn {
  background: none;
  border: none;
  color: #3a5060;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  touch-action: manipulation;
  flex-shrink: 0;
}

.pack-delete-btn:active {
  color: #e07070;
}

.add-pack-card {
  background: transparent;
  border: 1px dashed #2a4060;
  border-radius: 12px;
  padding: 10px 18px;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4a6a8a;
  font-size: 0.9rem;
  font-weight: 600;
}

.add-pack-card:active {
  border-color: #4a6888;
  color: #80d8ff;
}

#kbd-row-4 {
  border-top: 1px solid #162030;
  padding-top: 3px;
  margin-top: 1px;
}

.pack-list-divider {
  color: #4a6078;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 4px 2px;
}

