/* SnakeGame demo - intentionally isolated from the main game CSS. */

.demo-launch-button {
  width: min(220px, 72vw);
  min-height: 42px;
  margin: 10px auto 0;
  padding: 9px 22px;
  border: 1px solid rgba(126, 226, 59, .65);
  border-radius: 12px;
  background: #17351f;
  color: #c8ff9b;
  font: 800 15px/1 Nunito, sans-serif;
  letter-spacing: .04em;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(126, 226, 59, .08), 0 7px 20px rgba(0, 0, 0, .18);
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease, opacity .15s ease;
}

.demo-launch-button:hover:not(:disabled) {
  background: #214d2b;
  box-shadow: 0 0 18px rgba(126, 226, 59, .16), 0 7px 20px rgba(0, 0, 0, .2);
  transform: translateY(-1px);
}

.demo-launch-button:active:not(:disabled) {
  transform: scale(.98);
}

.demo-launch-button:disabled {
  opacity: .38;
  cursor: not-allowed;
}

body.demo-open {
  overflow: hidden;
}

.demo-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(3, 8, 16, .72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: demoFadeIn .18s ease-out;
}

.demo-overlay[hidden] {
  display: none;
}

.demo-modal {
  width: min(620px, 94vw);
  max-height: min(94vh, 760px);
  padding: 18px;
  overflow: auto;
  border: 1px solid rgba(126, 226, 59, .20);
  border-radius: 20px;
  background: #111827;
  box-shadow: 0 22px 70px rgba(0, 0, 0, .55), 0 0 30px rgba(16, 185, 129, .08);
}

.demo-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 13px;
}

.demo-header > div:first-child {
  min-width: 0;
}

.demo-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.demo-score-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  row-gap: 4px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #f9fafb;
}

.demo-score-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 24px;
  column-gap: 7px;
  font: 400 15px/1 Nunito, system-ui, sans-serif;
  color: #f9fafb;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.demo-header h2 {
  margin: 0;
  color: #7ee23b;
  font-size: clamp(20px, 4vw, 27px);
  line-height: 1.1;
  font-weight: 800;
}

.demo-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 15px;
  margin-top: 7px;
  color: #9ca3af;
  font-size: 13px;
  font-weight: 600;
}

.demo-close {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: #2563eb;
  color: #fff;
  font: 800 24px/38px Nunito, sans-serif;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}

.demo-close:hover {
  background: #3474ed;
  transform: scale(1.03);
}

.demo-close:active {
  transform: scale(.96);
}

.demo-board-wrap {
  width: min(520px, 100%);
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: 16px;
  overflow: hidden;
  background: #111c2c;
  box-shadow: 0 10px 32px rgba(0, 0, 0, .38);
}

.demo-board-wrap.bordered-canvas {
  border: 2px solid #aebbc9;
}

#demoCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.demo-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  margin-top: 11px;
  color: #9ca3af;
  font-size: 13px;
  width: 100%;
  box-sizing: border-box;
}

.demo-footer #demoHint {
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}

.demo-footer #demoAiRecordsBtn {
  flex-shrink: 0;
  margin-left: auto;
}

@keyframes demoFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (max-width: 520px) {
  .demo-overlay {
    padding: 10px;
  }

  .demo-modal {
    width: 96vw;
    padding: 13px;
    border-radius: 17px;
  }

  .demo-settings {
    font-size: 12px;
  }

  .demo-footer {
    font-size: 12px;
  }
}

@media (max-width: 430px) {
  .demo-score-row {
    font-size: 13px;
    line-height: 1;
    height: auto;
    column-gap: 4px;
  }
}

/* --- AI Demo Records Button & Modal --- */

.ai-records-badge-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  border-radius: 9999px;
  border: 1px solid rgba(126, 226, 59, 0.45);
  background: rgba(23, 53, 31, 0.85);
  color: #c8ff9b;
  font: 700 12px/1 Nunito, system-ui, sans-serif;
  letter-spacing: 0.02em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}

.ai-records-badge-btn:hover {
  background: #214d2b;
  border-color: rgba(126, 226, 59, 0.8);
  box-shadow: 0 0 14px rgba(126, 226, 59, 0.25);
  transform: translateY(-1px);
}

.ai-records-badge-btn:active {
  transform: scale(0.97);
}

.demo-records-overlay {
  z-index: 1100;
}

.demo-records-panel {
  width: min(460px, 94vw);
  max-width: 100%;
  box-sizing: border-box;
  max-height: min(90vh, 740px);
  padding: 16px;
  border: 1px solid rgba(126, 226, 59, 0.25);
  border-radius: 20px;
  background: #111827;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.6), 0 0 30px rgba(16, 185, 129, 0.1);
  overflow-x: hidden;
  overflow-y: auto;
}

.demo-records-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 8px;
  width: 100%;
  margin-bottom: 12px;
  box-sizing: border-box;
}

.demo-tab-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(17, 24, 39, 0.7);
  color: #94a3b8;
  font: 700 12px/1.2 Nunito, system-ui, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s ease;
  width: 100%;
  box-sizing: border-box;
}

.demo-tab-btn:hover {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(126, 226, 59, 0.35);
  color: #e2e8f0;
}

.demo-tab-btn.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(126, 226, 59, 0.75);
  color: #7ee23b;
  box-shadow: 0 0 12px rgba(126, 226, 59, 0.15);
}

.demo-tab-btn .tab-label {
  flex: 1;
  min-width: 0;
  white-space: normal;
  line-height: 1.2;
  text-align: left;
  word-break: break-word;
  overflow-wrap: break-word;
}

.demo-tab-btn .tab-badge {
  flex-shrink: 0;
  padding: 2px 6px;
  border-radius: 9999px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-left: 2px;
}

.demo-tab-btn.active .tab-badge {
  background: rgba(126, 226, 59, 0.2);
  border-color: rgba(126, 226, 59, 0.5);
  color: #c8ff9b;
}

.demo-snapshot-wrapper {
  position: relative;
  width: min(300px, 78vw);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 14px;
  overflow: hidden;
  background: #111c2c;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45);
  border: 2px solid transparent;
  transition: border-color 0.15s ease;
}

.demo-snapshot-wrapper.bordered-canvas {
  border-color: #aebbc9;
}

#demoSnapshotCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.demo-snapshot-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  background: rgba(17, 28, 44, 0.88);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: #94a3b8;
  pointer-events: none;
}

.demo-snapshot-empty .empty-icon {
  font-size: 32px;
  margin-bottom: 8px;
  opacity: 0.85;
}

.demo-snapshot-empty .empty-text {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: #cbd5e1;
}

.demo-snapshot-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  margin-top: 14px;
  width: 100%;
  box-sizing: border-box;
}

.demo-stat-card {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  min-width: 0;
  box-sizing: border-box;
}

.demo-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
  font-weight: 700;
  margin-bottom: 2px;
}

.demo-stat-value {
  font-size: 14px;
  color: #f1f5f9;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 480px) {
  .ai-records-badge-btn {
    height: 28px;
    padding: 0 9px;
    font-size: 11px;
  }

  .demo-records-panel {
    padding: 12px;
    width: 96vw;
  }

  .demo-records-tabs {
    gap: 6px;
  }

  .demo-tab-btn {
    min-height: 40px;
    padding: 6px 7px;
    font-size: 11px;
    gap: 4px;
  }

  .demo-tab-btn .tab-badge {
    padding: 2px 5px;
    font-size: 10px;
  }

  .demo-snapshot-wrapper {
    width: min(260px, 78vw);
  }

  .demo-snapshot-stats {
    gap: 6px 8px;
    margin-top: 10px;
  }

  .demo-stat-card {
    padding: 6px 8px;
  }

  .demo-stat-label {
    font-size: 10px;
  }

  .demo-stat-value {
    font-size: 13px;
  }
}
