:root {
  --fd-page-bg: #f2f7f7;
  --fd-card-bg: #ffffff;
  --fd-bg-alt: #f8fafc;
  --fd-bg-hover: #f1f5f9;
  --fd-border: #e2e8f0;
  --fd-border-strong: #cbd5e1;
  --fd-text-faint: #94a3b8;
  --fd-text-muted: #64748b;
  --fd-text-secondary: #475569;
  --fd-text: #334155;
  --fd-text-strong: #1e293b;
  --fd-text-strongest: #0f172a;
}

:root.fd-dark {
  --fd-page-bg: #14181a;
  --fd-card-bg: #1e2426;
  --fd-bg-alt: #262d2f;
  --fd-bg-hover: #2a3234;
  --fd-border: #3a4245;
  --fd-border-strong: #454d50;
  --fd-text-faint: #8a9497;
  --fd-text-muted: #a8b2b4;
  --fd-text-secondary: #c7d0d2;
  --fd-text: #dfe6e8;
  --fd-text-strong: #eef2f3;
  --fd-text-strongest: #ffffff;
}

html.fd-dark {
  background: var(--fd-page-bg);
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--fd-page-bg);
  color: var(--fd-text);
  font-family: 'Fira Sans Condensed', 'Roboto', system-ui, sans-serif;
  padding-top: 70px;
}

.headline {
  background-color: rgb(3, 79, 70, 0.98);
  color: #fff;
  padding: 10px 20px;
  font-family: 'Fira Sans', sans-serif;
  font-weight: 600;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  box-sizing: border-box;
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.headline-text {
  flex-grow: 1;
  text-align: left;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.menu-link {
  color: white;
  font-size: 12px;
  text-decoration: none;
  margin-left: 10px;
  cursor: pointer;
}

.menu-link:hover {
  color: #25d96a;
}

.game-container {
  max-width: 620px;
  margin: 0 auto;
  padding: 20px;
  text-align: center;
}

.title {
  font-size: 26px;
  font-weight: 700;
  color: #1e2937;
  margin-bottom: 6px;
}

.subtitle {
  color: #64748b;
  font-size: 14px;
  margin-bottom: 20px;
}

.mistakes {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 15px 0;
  font-size: 15px;
  font-weight: 600;
  color: #334155;
}

.mistake-dot {
  font-size: 0.85rem;
  transition: color 0.3s;
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.15rem;
  color: #64748b;
  cursor: pointer;
  padding: 4px;
  transition: all 0.2s ease;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  transform: scale(1.15);
  color: #3b82f6;
}

.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
  transform: none;
  color: #94a3b8 !important;
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(4, 78px);
  grid-template-rows: repeat(4, 78px);
  gap: 10px;
  justify-content: center;
  background-color: #ffffff;
  border: 1.5px solid #d4d4d4;
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin: 0 auto 30px;
}

html.fd-dark .grid-container,
body.fd-dark .grid-container {
  background-color: #1c2224;
  border-color: #3a4245;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* Summary Share/status card (win green / fail red) */
.conn-status-card.completed-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}
.conn-status-card.completed-fail {
  background: #fef2f2;
  border: 1px solid #fecaca;
}
.conn-status-card.completed-success .conn-status-title {
  color: #166534;
}
.conn-status-card.completed-fail .conn-status-title {
  color: #991b1b;
}
.conn-share-btn {
  background: transparent;
  border: none;
  color: #3b82f6;
  font-weight: bold;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}
html.fd-dark .conn-status-card.completed-success,
body.fd-dark .conn-status-card.completed-success {
  background: #1d3b25;
  border-color: #2d6a40;
}
html.fd-dark .conn-status-card.completed-fail,
body.fd-dark .conn-status-card.completed-fail {
  background: #3d2020;
  border-color: #7a3a3a;
}
html.fd-dark .conn-status-card.completed-success .conn-status-title,
body.fd-dark .conn-status-card.completed-success .conn-status-title {
  color: #86efac;
}
html.fd-dark .conn-status-card.completed-fail .conn-status-title,
body.fd-dark .conn-status-card.completed-fail .conn-status-title {
  color: #fca5a5;
}
html.fd-dark .conn-share-btn,
body.fd-dark .conn-share-btn {
  color: #6cb2ff;
}

.conn-archive-nav {
  display: flex;
  gap: 10px;
  margin: 0 0 20px;
  padding: 14px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}
html.fd-dark .conn-archive-nav,
body.fd-dark .conn-archive-nav {
  background: #2a241c;
  border-color: #6b4a2a;
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
}

html.fd-dark .fd-other-games-grid [style*="background"],
body.fd-dark .fd-other-games-grid [style*="background"] {
  background-color: #262d2f !important;
}
html.fd-dark .fd-other-games-grid [style*="border"],
body.fd-dark .fd-other-games-grid [style*="border"] {
  border-color: #454d50 !important;
}
html.fd-dark .fd-other-games-grid [style*="color"],
body.fd-dark .fd-other-games-grid [style*="color"] {
  color: #dfe6e8 !important;
}

.card-tile {
  cursor: pointer;
  border: 2px solid #ccc;
  border-radius: 10px;
  width: 74px;
  height: 74px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: #f8f8f8;
  transition: all 0.2s ease;
  overflow: hidden;
  position: relative;
}

.card-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  border-color: #888;
}

.card-tile.selected {
  border-color: #166534;
  background-color: #dcfce7;
  box-shadow: 0 0 0 3px rgba(22, 101, 52, 0.3);
}

.card-tile img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.card-tile .card-name {
  font-size: 8px;
  font-weight: 600;
  color: #444;
  margin-top: 2px;
  text-align: center;
  line-height: 1.05;
  padding: 0 2px;
  max-height: 22px;
  overflow: hidden;
}

.coolButton {
  background-color: rgba(5, 44, 31, 0.85);
  border: none;
  color: white;
  padding: 10px 18px;
  font-family: 'Fira Sans Condensed', sans-serif;
  font-size: 13px;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
  margin: 6px 4px;
  transition: background-color 0.3s ease;
}

.coolButton:hover {
  background-color: #034519;
}

.coolButton:disabled {
  background-color: #94a3b8;
  cursor: not-allowed;
}

.solved-groups {
  margin-top: 25px;
  max-width: 580px;
  margin-left: auto;
  margin-right: auto;
}

.solved-group {
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: 10px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
}

.solved-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 8px;
}

.solved-card {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.group-name {
  font-weight: 700;
  font-size: 13px;
  text-align: center;
}

.shake {
  animation: shakeAnim 0.5s ease;
}

@keyframes shakeAnim {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

@keyframes solvePulse {
  0% { transform: scale(1); z-index: 10; }
  40% { transform: scale(1.08); z-index: 10; }
  60% { transform: scale(1.08); z-index: 10; }
  100% { transform: scale(1); z-index: 10; }
}

.tile-solving {
  animation: solvePulse 0.8s cubic-bezier(0.25, 1, 0.5, 1);
  transition: background-color 0.3s ease;
}

@keyframes rowAppear {
  from { opacity: 0; transform: translateY(-15px) scale(0.95); }
  to { opacity: 0.95; transform: translateY(0) scale(1); }
}

.solved-row-anim {
  animation: rowAppear 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.solved-cat-info-btn {
  border: none;
  background: rgba(255, 255, 255, 0.35);
  color: #1e293b;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  font-style: italic;
  cursor: pointer;
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.solved-cat-info-btn:hover {
  background: rgba(255, 255, 255, 0.6);
}

.end-screen {
  background: var(--fd-bg-alt);
  color: var(--fd-text);
  border: 1px solid var(--fd-border);
  border-radius: 10px;
  padding: 25px;
  margin-top: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.end-screen-title { margin-top: 0; }
.end-screen-solved { color: #d97706; }
.end-screen-win { color: #166534; }
.end-screen-lose { color: #991b1b; }
html.fd-dark .end-screen,
body.fd-dark .end-screen {
  background: #1e2426;
  border-color: #3a4245;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
html.fd-dark .end-screen-win,
body.fd-dark .end-screen-win { color: #86efac; }
html.fd-dark .end-screen-lose,
body.fd-dark .end-screen-lose { color: #fca5a5; }
html.fd-dark .end-screen-solved,
body.fd-dark .end-screen-solved { color: #fbbf24; }

.reference-badge {
  display: inline-block;
  padding: 12px 18px;
  background: #fef08a;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(234, 179, 8, 0.4), 0 0 0 3px #eab308 inset;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.reference-badge:hover {
  transform: scale(1.03);
}

.reference-title {
  margin: 0 0 8px 0;
  font-weight: 900;
  color: #854d0e;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}

.reference-img {
  width: 72px;
  height: auto;
  border-radius: 3px;
  display: block;
  margin: 0 auto;
  object-fit: contain;
}

.reference-name {
  margin: 8px 0 0 0;
  font-weight: bold;
  color: #422006;
  font-size: 1.05rem;
}

.hint-badge {
  position: absolute;
  top: -6px;
  right: -8px;
  background: #ef4444;
  color: white;
  font-size: 0.6rem;
  font-weight: bold;
  padding: 2px 5px;
  border-radius: 50%;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.archive-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  z-index: 2147483000;
  justify-content: center;
  align-items: center;
}

.archive-modal {
  display: none;
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--fd-card-bg, #ffffff);
  padding: 16px 14px;
  border-radius: 6px;
  width: 90%;
  max-width: 360px;
  z-index: 2147483001;
}

/* JS nests the panel inside the overlay. Without this, the overlay
   (blur) shows while the popup stays display:none. */
.archive-modal-overlay .archive-modal {
  display: block;
  position: relative;
  inset: auto;
  margin: 0;
  height: auto;
  z-index: auto;
}

.archive-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  font-family: inherit;
}

.archive-btn:hover {
  background: #eef2ff;
}

.close-modal {
  float: right;
  cursor: pointer;
  font-size: 20px;
  color: #64748b;
}

.game-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: white;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 10020;
}

/* Generic small modal shell, reused by options / fail-choice / category-info
   / card-info modals. */
.small-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  z-index: 10030;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(3px);
}

.small-modal {
  background: white;
  padding: 22px;
  border-radius: 12px;
  width: 90%;
  max-width: 340px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: center;
  position: relative;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.small-modal h3 {
  margin: 0 0 14px 0;
  font-size: 1.1rem;
  color: #1e293b;
}

.small-modal .option-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13.5px;
  font-weight: 600;
  color: #334155;
}

.small-modal .option-row:last-of-type {
  border-bottom: none;
}

.small-modal-btn {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  color: white;
  background: #334155;
}

.small-modal-btn:hover {
  filter: brightness(1.1);
}

/* Stats / rating end-game modal */
.stats-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  z-index: 10040;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(3px);
}

.stats-modal {
  background: white;
  padding: 22px;
  border-radius: 14px;
  width: 92%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.3);
  text-align: left;
  font-size: 13.5px;
}

.stats-modal h2 {
  margin: 0 0 4px 0;
  font-size: 1.2rem;
  text-align: center;
  color: #1e293b;
}

.stats-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px;
  margin-top: 14px;
}

.stats-card-title {
  font-weight: 800;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #64748b;
  margin-bottom: 10px;
}

.avg-stars {
  color: #ffc107;
  font-size: 1.1rem;
  display: inline-flex;
  gap: 2px;
}

.avg-stars .bi-star {
  color: #ccc;
}

.rate-stars {
  display: flex;
  gap: 4px;
  font-size: 1.6rem;
  justify-content: center;
  margin: 6px 0 10px;
}

.rate-stars i {
  cursor: pointer;
  color: #ccc;
}

.rate-stars i.active {
  color: #ffc107;
}

.rate-select,
.rate-comment {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  margin-top: 8px;
  font-family: inherit;
  font-size: 13px;
}

.rate-submit-btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
  color: #ffffff;
  background-color: #4b5563;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  display: block;
  width: fit-content;
  margin: 10px auto 0;
}

.rate-submit-btn:hover:not(:disabled) {
  background-color: #374151;
}

.rate-submit-btn:disabled {
  background-color: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
}

.comment-bubble {
  background: #f1f5f9;
  border-radius: 14px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 12.5px;
  color: #334155;
}

.comment-bubble .comment-meta {
  font-size: 10.5px;
  color: #94a3b8;
  margin-top: 3px;
}

.mistake-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: #475569;
}

.mistake-bar-label {
  width: 14px;
  text-align: center;
  flex-shrink: 0;
}

.mistake-bar-track {
  flex: 1;
  background: #e2e8f0;
  border-radius: 6px;
  height: 14px;
  overflow: hidden;
}

.mistake-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.4s ease;
}

.mistake-bar-row.own-row .mistake-bar-track {
  outline: 2px solid #f97316;
  outline-offset: 1px;
}

.mistake-bar-pct {
  width: 34px;
  text-align: right;
  flex-shrink: 0;
}

/* Archive extras: legend + rate/difficulty badges */
.archive-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.archive-btn-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.archive-btn-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 10.5px;
  color: #64748b;
  flex-shrink: 0;
}

.archive-btn-rate {
  color: #b45309;
  font-weight: 700;
}

.archive-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  padding: 4px 0;
  color: #334155;
}

.end-screen .coolButton {
  margin: 6px 4px 0;
}

/* Keep Playwire/Ramp shells under game modals (summary overlay is 2147483000). */
html body .pw-corner-ad-video.pw-corner-ad-video.pw-corner-ad-video,
html body .pw-corner-ad-video,
html body .pw-fixed-footer,
html body .pw-sticky,
html body [data-pw-desk-side],
html body [data-pw-sticky],
html body .sticky-left-ad {
    z-index: 500 !important;
}
