/* HissTastic Browser — Mobile-first responsive styles */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: monospace;
  background: #4CAF50;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  max-width: min(600px, 100vw - env(safe-area-inset-left) - env(safe-area-inset-right));
  margin: 0 auto;
  padding: 8px;
  position: relative;
}

#game-canvas {
  display: block;
  border: 2px solid #000;
  border-radius: 4px;
  background: #FFFFFF;
  touch-action: none;
  max-width: 100%;
  max-height: min(560px, 100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 120px);
  height: auto;
}

/* ---- Bottom controls ---- */
.controls {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: min(600px, 100vw - env(safe-area-inset-left) - env(safe-area-inset-right));
}

.ctrl-btn {
  padding: 8px 14px;
  border: 1px solid #999;
  border-radius: 8px;
  background: #f5f5f5;
  font-family: monospace;
  font-size: 12px;
  color: #333;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.ctrl-btn:active {
  background: #ddd;
}

.ctrl-btn.music-on {
  background: #4CAF50;
  color: #fff;
  border-color: #4CAF50;
}

/* ---- Music credit link ---- */
.music-credit {
  text-align: center;
  margin-top: 6px;
}

.music-credit a {
  font-family: monospace;
  font-size: 10px;
  color: #999;
  text-decoration: none;
  transition: color 0.15s;
}

.music-credit a:hover {
  color: #4CAF50;
  text-decoration: underline;
}

/* ---- Replay overlay ---- */
.replay-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.95);
  border: 2px solid #333;
  border-radius: 12px;
  padding: 20px;
  min-width: 260px;
  max-width: 90%;
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.replay-overlay h3 {
  font-size: 18px;
  margin-bottom: 12px;
  color: #4CAF50;
  text-align: center;
}

.replay-overlay table {
  width: 100%;
  font-size: 13px;
  margin-bottom: 14px;
}

.replay-overlay td {
  padding: 4px 8px;
  border-bottom: 1px solid #eee;
}

.replay-overlay td:first-child {
  font-weight: bold;
  color: #666;
  width: 40%;
}

.replay-overlay button {
  display: block;
  width: 100%;
  padding: 10px;
  margin-top: 6px;
  border: 1px solid #999;
  border-radius: 8px;
  background: #f5f5f5;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.1s;
}

.replay-overlay button:active {
  background: #ddd;
}

.replay-overlay button:first-of-type {
  background: #4CAF50;
  color: #fff;
  border-color: #4CAF50;
}

/* ---- Commentary box (live snake-fact roasts) ---- */
.commentary-box {
  position: relative;
  max-width: 560px;
  margin: 6px auto 0 auto;
  padding: 6px 12px;
  font-family: monospace;
  font-size: 12px;
  line-height: 1.4;
  color: #555;
  text-align: center;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #E0E0E0;
  border-radius: 8px;
  transition: opacity 0.6s ease;
  z-index: 5;
  pointer-events: none;
  word-wrap: break-word;
}

.commentary-visible {
  opacity: 1;
}

.commentary-fade {
  opacity: 0;
}

/* ---- Background snake canvas sits behind everything ---- */
#bg-snake-field {
  z-index: 0;
  pointer-events: none;
}

#game-container {
  z-index: 1;
  position: relative;
}

/* ---- Mobile landscape adjustments ---- */
@media (max-height: 500px) {
  .ctrl-btn {
    padding: 4px 10px;
    font-size: 11px;
  }
}

/* =============================================
   Page system — v0.5.2
   ============================================= */
.page {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.page.active {
  display: flex;
}

/* =============================================
   Home page
   ============================================= */
#page-home {
  z-index: 2;
  background: #FFFFFF;
}

.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 1;
  pointer-events: auto;
}

.home-title {
  font-family: monospace;
  font-size: 36px;
  color: #4CAF50;
  text-align: center;
  letter-spacing: 2px;
  margin-bottom: 0;
}

.home-subtitle {
  font-family: monospace;
  font-size: 14px;
  color: #666;
  margin-top: -4px;
  margin-bottom: 8px;
}

.play-btn {
  font-family: monospace;
  font-size: 22px;
  padding: 16px 56px;
  border: 3px solid #4CAF50;
  border-radius: 60px;
  background: #4CAF50;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, box-shadow 0.1s;
  letter-spacing: 1px;
}
.play-btn:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(255, 20, 147, 0.4);
}

.home-difficulty {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.diff-label {
  font-family: monospace;
  font-size: 12px;
  color: #666;
}

.diff-btn {
  font-family: monospace;
  font-size: 11px;
  padding: 4px 12px;
  border: 1px solid #ccc;
  border-radius: 12px;
  background: #f5f5f5;
  color: #555;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.diff-btn.active {
  background: #4CAF50;
  color: #fff;
  border-color: #4CAF50;
}
.diff-btn:active {
  opacity: 0.7;
}

.home-links {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}

.home-link {
  font-family: monospace;
  font-size: 13px;
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding: 6px 10px;
  transition: color 0.15s;
}
.home-link:active {
  color: #4CAF50;
}

.home-version {
  font-family: monospace;
  font-size: 10px;
  color: #ccc;
  margin-top: 12px;
}
.home-version a.privacy-link {
  color: #ccc;
  text-decoration: none;
}
.home-version a.privacy-link:hover {
  text-decoration: underline;
  color: #aaa;
}

/* =============================================
   Overlay system (game over, pause, scores)
   ============================================= */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: auto;
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 28px 24px;
  border: 2px solid #eee;
  border-radius: 16px;
  background: #fff;
  min-width: 260px;
  max-width: 90%;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.overlay-title {
  font-family: monospace;
  font-size: 24px;
  color: #4CAF50;
  text-align: center;
  margin: 0;
}

.go-score {
  font-family: monospace;
  font-size: 28px;
  font-weight: bold;
  color: #333;
  margin: 0;
}

.go-highscore {
  font-family: monospace;
  font-size: 16px;
  color: #4CAF50;
  margin: 0;
  animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to   { transform: scale(1.08); }
}

.go-roast {
  font-family: monospace;
  font-size: 12px;
  color: #888;
  text-align: center;
  max-width: 260px;
  margin: 0;
  line-height: 1.4;
}

.go-stats {
  font-family: monospace;
  font-size: 10px;
  color: #bbb;
  text-align: center;
  margin: 0;
}

.go-sync-status {
  font-family: monospace;
  font-size: 12px;
  color: #666;
  text-align: center;
  max-width: 260px;
  margin: 0;
  line-height: 1.35;
}

.overlay-btn {
  font-family: monospace;
  font-size: 15px;
  width: 200px;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 10px;
  background: #f5f5f5;
  color: #555;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, color 0.1s;
  text-align: center;
}
.overlay-btn:active {
  background: #ddd;
}
.overlay-btn.primary {
  background: #4CAF50;
  color: #fff;
  border-color: #4CAF50;
}
.overlay-btn.primary:active {
  background: #e0127e;
}

/* =============================================
   Settings modal
   ============================================= */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  pointer-events: auto;
}

.modal-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px 24px;
  border: 2px solid #eee;
  border-radius: 16px;
  background: #fff;
  min-width: 280px;
  max-width: 90%;
  position: relative;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.modal-close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 18px;
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding: 4px 8px;
}

.modal-title {
  font-family: monospace;
  font-size: 20px;
  color: #333;
  text-align: center;
  margin: 0 0 4px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: monospace;
  font-size: 14px;
  color: #555;
}

.setting-row label {
  min-width: 100px;
}

.profile-row {
  align-items: flex-start;
}

.profile-editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.profile-input {
  font-family: monospace;
  font-size: 13px;
  padding: 7px 9px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
  color: #333;
  width: 170px;
  user-select: text;
  -webkit-user-select: text;
}

.profile-input.large {
  width: 100%;
  font-size: 16px;
  padding: 10px;
}

.mini-btn {
  font-family: monospace;
  font-size: 11px;
  padding: 5px 9px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #f5f5f5;
  color: #555;
  cursor: pointer;
}

.profile-message {
  font-family: monospace;
  font-size: 11px;
  color: #b00020;
  text-align: center;
  margin: -4px 0 0;
  line-height: 1.35;
}

.profile-copy {
  font-family: monospace;
  font-size: 13px;
  line-height: 1.45;
  color: #555;
  text-align: center;
  margin: 0;
}

.profile-label {
  font-family: monospace;
  font-size: 12px;
  color: #666;
}

.profile-setup-content {
  max-width: 360px;
}

.profile-actions {
  display: flex;
  gap: 8px;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.toggle-btn {
  font-family: monospace;
  font-size: 13px;
  padding: 6px 16px;
  border: 1px solid #ccc;
  border-radius: 16px;
  background: #f5f5f5;
  color: #555;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-width: 56px;
  transition: background 0.1s, color 0.1s;
}
.toggle-btn.on {
  background: #4CAF50;
  color: #fff;
  border-color: #4CAF50;
}

.settings-diff {
  display: flex;
  gap: 4px;
}
.settings-diff .diff-btn {
  font-size: 11px;
  padding: 4px 10px;
}

.theme-select {
  font-family: monospace;
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #f5f5f5;
  color: #555;
  cursor: pointer;
}

.settings-link {
  font-family: monospace;
  font-size: 13px;
  color: #4CAF50;
  text-decoration: none;
}

.settings-version {
  font-family: monospace;
  font-size: 10px;
  color: #ccc;
  text-align: center;
  margin-top: 4px;
}

/* =============================================
   High Scores list
   ============================================= */
.scores-list {
  width: 100%;
  font-family: monospace;
  font-size: 14px;
  color: #333;
}

.score-entry {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
}

.score-entry:last-child {
  border-bottom: none;
}

.score-entry .score-rank {
  color: #999;
  min-width: 24px;
}

.score-entry .score-val {
  font-weight: bold;
  flex: 1;
}

.score-entry .score-meta {
  color: #999;
  font-size: 11px;
  text-align: right;
}

.score-entry .score-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scores-summary {
  font-family: monospace;
  font-size: 12px;
  color: #666;
  text-align: center;
  padding: 8px 0 10px;
  border-bottom: 1px solid #eee;
  margin-bottom: 6px;
}
.scores-summary.my-entry {
  color: #2e7d32;
  font-weight: bold;
  background: #e8f5e9;
  border-radius: 4px;
  padding: 10px;
  border-bottom: 1px solid #c8e6c9;
}

.scores-empty {
  font-family: monospace;
  font-size: 13px;
  color: #999;
  text-align: center;
  padding: 20px 0;
}

/* =============================================
   Mobile adjustments for pages
   ============================================= */
@media (max-height: 500px) {
  .home-title {
    font-size: 24px;
  }
  .play-btn {
    font-size: 18px;
    padding: 12px 40px;
  }
  .home-content {
    gap: 6px;
  }
  .overlay-content {
    padding: 18px 16px;
    gap: 8px;
  }
  .overlay-btn {
    width: 160px;
    padding: 8px;
    font-size: 13px;
  }
  .go-score {
    font-size: 22px;
  }
}


/* ---- Feedback link ---- */
.feedback-link {
  text-align: center;
  margin-top: 4px;
}

.feedback-link a {
  font-family: monospace;
  font-size: 10px;
  color: #999;
  text-decoration: none;
}

.feedback-link a:hover {
  color: #4CAF50;
  text-decoration: underline;
}
