@font-face {
  font-family: 'Silkscreen';
  src: url('../assets/fonts/Silkscreen-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

:root {
  --safe-bottom: 0px;
}

@media (max-width: 600px) {
  :root {
    --safe-bottom: 40px;
  }
}

#character-selection {
  display: none;
  justify-content: center;
  gap: 20px;
  margin-bottom: 40px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.char-card {
  cursor: pointer;
  background: rgba(255,255,255,0.05);
  border: 4px solid rgba(255,255,255,0.2);
  padding: 15px;
  border-radius: 0;
  transition: all 0.2s;
  flex: 0 1 calc(50% - 20px);
  min-width: 140px;
  max-width: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
}

.char-card canvas {
  image-rendering: pixelated;
  width: 128px;
  height: 128px;
  margin-bottom: 10px;
}

.char-name {
  font-weight: bold;
  font-size: 14px;
  text-align: center;
}

[data-char="fox"] .char-name { color: #ffaa44; }
[data-char="hare"] .char-name { color: #44aaff; }
[data-char="boarot"] .char-name { color: #88ff88; }
[data-char="marmot"] .char-name { color: #ff66aa; }

.char-card:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.5);
  transform: translateY(-5px);
}

.char-card.selected {
  background: rgba(255,255,255,0.2);
  border-color: #44ff44;
  box-shadow: 0 0 20px rgba(68, 255, 68, 0.3);
}

@media (max-width: 600px) {
  #character-selection {
    gap: 12px;
    padding: 0 10px;
    box-sizing: border-box;
  }
  .char-card {
    padding: 12px;
    flex: 0 1 calc(50% - 6px);
    min-width: 0;
  }
  .char-card canvas {
    width: 64px;
    height: 64px;
  }
  .char-name {
    font-size: 11px;
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  image-rendering: pixelated;
}

body, html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: 'Silkscreen', monospace;
}

a {
  pointer-events: auto !important;
  user-select: auto !important;
  -webkit-user-select: auto !important;
  touch-action: auto !important;
  cursor: pointer;
  position: relative;
  z-index: 210;
}

#dna-modal {
  touch-action: none !important;
}

#dnaCanvas {
  image-rendering: pixelated;
}

#intro-modal, #game-over {
  touch-action: auto !important;
  overflow-x: hidden;
  width: 100%;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {transform: translateX(-50%) translateY(0);}
  40% {transform: translateX(-50%) translateY(-10px);}
  60% {transform: translateX(-50%) translateY(-5px);}
}

@keyframes bounce-text {
  0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
  40% {transform: translateY(-10px);}
  60% {transform: translateY(-5px);}
}

#gameCanvas {
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

/* Mobile Safe Area Adjustments */
#intro-footer, #game-over-footer {
  padding-bottom: calc(20px + var(--safe-bottom) + env(safe-area-inset-bottom)) !important;
}

#help-btn {
  position: absolute;
  top: calc(15px + env(safe-area-inset-top)) !important;
  left: calc(15px + env(safe-area-inset-left)) !important;
  width: 40px;
  height: 40px;
  border-radius: 0;
  background: #fff9e6;
  border: 2px solid #5d3a1a;
  color: #2c3e50;
  font-weight: bold;
  font-size: 20px;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Silkscreen', monospace;
  z-index: 150;
  box-shadow: 2px 4px 12px rgba(0,0,0,0.3);
  transition: transform 0.1s;
}

#help-btn:active {
  transform: scale(0.95);
}

#stopwatch {
  position: absolute;
  top: calc(15px + env(safe-area-inset-top)) !important;
  left: calc(65px + env(safe-area-inset-left)) !important;
  height: 40px;
  padding: 0 12px;
  border-radius: 0;
  background: #fff9e6;
  border: 2px solid #5d3a1a;
  color: #2c3e50;
  font-weight: bold;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Silkscreen', monospace;
  z-index: 150;
  box-shadow: 2px 4px 12px rgba(0,0,0,0.3);
  pointer-events: none;
}

#ui-overlay {
  position: absolute;
  top: calc(15px + env(safe-area-inset-top)) !important;
  right: calc(15px + env(safe-area-inset-right)) !important;
  pointer-events: none;
  font-family: 'Silkscreen', monospace;
}

#status-panel {
  background: #fff9e6;
  padding: 8px 12px;
  border-radius: 0;
  border: 2px solid #5d3a1a;
  margin-bottom: 10px;
  width: 160px;
  box-sizing: border-box;
  color: #2c3e50;
  font-weight: bold;
  box-shadow: 2px 4px 12px rgba(0,0,0,0.3);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#selection-panel {
  background: #fff9e6;
  padding: 12px;
  border-radius: 0;
  border: 2px solid #5d3a1a;
  pointer-events: auto;
  width: 160px;
  box-sizing: border-box;
  color: #2c3e50;
  box-shadow: 2px 4px 12px rgba(0,0,0,0.3);
}

#selection-panel h2 {
  margin: 0 0 5px 0;
  font-size: 18px;
  word-wrap: break-word;
}

#selection-panel p {
  margin: 0 0 10px 0;
  font-size: 14px;
  opacity: 0.7;
}

.pixel-dna {
  display: inline-block;
  width: 14px;
  height: 14px;
  background-image: url('/assets/items/dna.png');
  background-size: contain;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  vertical-align: middle;
}

#selection-hint {
  background: rgba(0,0,0,0.05);
  padding: 8px;
  border-radius: 0;
  font-size: 12px;
  color: #555;
  margin-bottom: 15px;
  border-left: 3px solid #5d3a1a;
  line-height: 1.4;
}

#dna-test-btn {
  background: #44ff44;
  color: black;
  border: 2px solid #2d8a2d;
  padding: 8px 16px;
  border-radius: 0;
  cursor: pointer;
  font-weight: bold;
  width: 100%;
  margin-bottom: 8px;
  font-family: inherit;
}

#accuse-btn {
  background: #ff4444;
  color: white;
  border: 2px solid #8a2d2d;
  padding: 8px 16px;
  border-radius: 0;
  cursor: pointer;
  font-weight: bold;
  width: 100%;
  opacity: 0.5;
  font-family: inherit;
}

#play-again-ui {
  pointer-events: auto;
  background: #44ff44;
  color: black;
  border: 2px solid #2d8a2d;
  padding: 12px 20px;
  border-radius: 0;
  cursor: pointer;
  font-weight: bold;
  font-size: 14px;
  width: 160px;
  box-sizing: border-box;
  margin-top: 10px;
  font-family: 'Silkscreen', monospace;
  box-shadow: 2px 4px 12px rgba(0,0,0,0.3);
}

/* Custom Pixel Scrollbar */
::-webkit-scrollbar {
  width: 16px;
}
::-webkit-scrollbar-track {
  background: #000;
}
::-webkit-scrollbar-thumb {
  background: #555;
  border: 4px solid #000;
}
::-webkit-scrollbar-thumb:hover {
  background: #777;
}

/* Notebook Scrollbar */
#transcript-list::-webkit-scrollbar-track {
  background: #fff9e6;
}
#transcript-list::-webkit-scrollbar-thumb {
  background: #d1e5f0;
  border: 4px solid #fff9e6;
}

.pixel-button {
  image-rendering: pixelated;
  border: 4px solid #000 !important;
  box-shadow: inset -4px -4px 0 rgba(0,0,0,0.2), inset 4px 4px 0 rgba(255,255,255,0.3) !important;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  transition: transform 0.05s;
}

.pixel-button:active {
  transform: scale(0.98);
  box-shadow: inset 4px 4px 0 rgba(0,0,0,0.2), inset -4px -4px 0 rgba(255,255,255,0.3) !important;
}

.pixel-scroll-hint {
  display: block;
  width: 32px;
  height: 20px;
  margin: 0 auto;
  background: 
    linear-gradient(currentColor, currentColor) 0 0 / 32px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 4px 4px / 24px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 8px 8px / 16px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 12px 12px / 8px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 14px 16px / 4px 4px no-repeat;
}

.pixel-hourglass {
  display: block;
  width: 40px;
  height: 50px;
  margin: 0 auto;
  position: relative;
  background: 
    /* Top and bottom bars */
    linear-gradient(#888, #888) 0 0 / 40px 5px no-repeat,
    linear-gradient(#888, #888) 0 45px / 40px 5px no-repeat,
    /* Frame sides */
    linear-gradient(#888, #888) 0 5px / 5px 10px no-repeat,
    linear-gradient(#888, #888) 35px 5px / 5px 10px no-repeat,
    linear-gradient(#888, #888) 0 35px / 5px 10px no-repeat,
    linear-gradient(#888, #888) 35px 35px / 5px 10px no-repeat,
    /* Glass curves */
    linear-gradient(#fff, #fff) 5px 15px / 5px 5px no-repeat,
    linear-gradient(#fff, #fff) 30px 15px / 5px 5px no-repeat,
    linear-gradient(#fff, #fff) 10px 20px / 5px 5px no-repeat,
    linear-gradient(#fff, #fff) 25px 20px / 5px 5px no-repeat,
    linear-gradient(#fff, #fff) 15px 25px / 10px 5px no-repeat,
    linear-gradient(#fff, #fff) 10px 30px / 5px 5px no-repeat,
    linear-gradient(#fff, #fff) 25px 30px / 5px 5px no-repeat,
    linear-gradient(#fff, #fff) 5px 35px / 5px 5px no-repeat,
    linear-gradient(#fff, #fff) 30px 35px / 5px 5px no-repeat,
    /* Sand (Top) */
    linear-gradient(#44ff44, #44ff44) 10px 10px / 20px 5px no-repeat,
    linear-gradient(#44ff44, #44ff44) 15px 15px / 10px 5px no-repeat,
    /* Sand (Bottom) */
    linear-gradient(#44ff44, #44ff44) 15px 35px / 10px 5px no-repeat,
    linear-gradient(#44ff44, #44ff44) 10px 40px / 20px 5px no-repeat;
}

.pixel-arrow-up {
  display: inline-block;
  width: 12px;
  height: 12px;
  background: 
    linear-gradient(currentColor, currentColor) 4px 0 / 4px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 2px 4px / 8px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 0 8px / 12px 4px no-repeat;
  vertical-align: middle;
}

.pixel-arrow-dr { /* Down-Right */
  display: inline-block;
  width: 12px;
  height: 12px;
  background: 
    linear-gradient(currentColor, currentColor) 0 0 / 4px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 4px 4px / 4px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 8px 8px / 4px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 4px 8px / 4px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 8px 4px / 4px 4px no-repeat;
}

.pixel-arrow-dl { /* Down-Left */
  display: inline-block;
  width: 12px;
  height: 12px;
  background: 
    linear-gradient(currentColor, currentColor) 8px 0 / 4px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 4px 4px / 4px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 0 8px / 4px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 4px 8px / 4px 4px no-repeat,
    linear-gradient(currentColor, currentColor) 0 4px / 4px 4px no-repeat;
}

#transcript-container {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(calc(50vh - 120px)); /* Start tucked down so only 120px is visible */
  width: 100%;
  max-width: 600px;
  background-color: #fff9e6; /* Notebook paper color */
  border-top: 4px solid #5d3a1a; /* Dark wood top border */
  border-radius: 0;
  color: #2c3e50;
  font-family: 'Silkscreen', monospace;
  z-index: 100;
  transition: transform 0.3s ease;
  height: 50vh; /* Half the screen height */
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  box-sizing: border-box;
  padding-bottom: 0 !important;
  overflow: visible; /* Allow portrait to sit outside the container */
}

@media (max-height: 240px) {
  #transcript-container {
    height: 100vh; /* Full screen if the screen is tiny */
    transform: translateX(-50%) translateY(calc(100vh - 120px));
  }
}

@media (max-width: 600px) {
  #transcript-container {
    /* No longer overriding height here, transform handles it */
  }
}

#transcript-header {
  padding: 5px 15px 5px 60px; /* Smaller padding */
  cursor: pointer;
  display: flex;
  justify-content: center; /* Center the toggle button */
  align-items: center;
  border-bottom: 1px solid rgba(0,0,0,0.1);
  height: 30px; /* Reduced height */
  background-image: 
    linear-gradient(90deg, transparent 49px, #ff9999 50px, #ff9999 51px, transparent 52px), /* Red margin line */
    linear-gradient(#d1e5f0 1px, transparent 1px); /* Blue notebook lines */
  background-size: 100% 1.5rem;
  box-sizing: border-box;
  position: relative;
  flex-shrink: 0;
}

#transcript-toggle {
  font-size: 12px;
  font-weight: bold;
  opacity: 0.8;
  color: #5d3a1a;
  letter-spacing: 1px;
}

#transcript-list {
  flex-grow: 1; /* Take remaining space */
  overflow-y: auto;
  padding: 15px 20px calc(20px + var(--safe-bottom) + env(safe-area-inset-bottom)) 60px; /* Left padding for red margin line */
  display: block;
  font-size: 14px; /* Slightly smaller text for better density */
  line-height: 1.5rem; /* Match notebook line height */
  background-image: 
    linear-gradient(90deg, transparent 49px, #ff9999 50px, #ff9999 51px, transparent 52px), /* Red margin line */
    linear-gradient(#d1e5f0 1px, transparent 1px); /* Blue notebook lines */
  background-size: 100% 1.5rem;
  background-attachment: local;
  box-sizing: border-box;
  /* Ensure the newest content at the top is what's visible */
  display: flex;
  flex-direction: column;
  pointer-events: auto; /* Always allow interaction, even when parent is translated */
}

.transcript-entry {
  margin-bottom: 1.5rem; /* Match notebook line height for consistent spacing */
  position: relative;
  padding-left: 15px;
  min-height: 1.5rem;
  border-left: 3px solid transparent;
  flex-shrink: 0; /* ABSOLUTELY prevent squashing or overlapping */
}

.transcript-entry:first-child {
  font-weight: bold; /* Highlight the newest entry */
  background: rgba(93, 58, 26, 0.05);
  border-radius: 0;
  padding-top: 5px;
  padding-bottom: 5px;
}

.transcript-entry.system-message {
  font-weight: bold;
  opacity: 0.8;
  border-left: 4px solid #ff4444;
}

.animal-mention {
  background: rgba(0, 0, 0, 0.75);
  padding: 0px 6px;
  border-radius: 0;
  font-weight: bold;
  display: inline-block;
  line-height: 1.4;
  margin: 0 1px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  vertical-align: baseline;
  transition: all 0.1s ease;
}

.animal-mention:hover {
  background: rgba(0, 0, 0, 1);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

/* Ensure names are readable if any are left without the background */
#transcript-container span:not(.animal-mention) {
  filter: brightness(0.6) saturate(1.5);
}

#portrait-box {
  display: none;
  position: absolute;
  top: -134px;
  left: 10px;
  width: 128px;
  height: 128px;
  background: #000;
  border: 4px solid rgba(255,255,255,0.3);
  border-radius: 0;
  overflow: hidden;
  image-rendering: pixelated;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  cursor: pointer;
  /* Use same transition as parent for transform to prevent bouncing/lag */
  transition: transform 0.3s ease, top 0.3s ease, left 0.3s ease, opacity 0.3s ease;
  z-index: 110;
}

/* Wide screen: move portrait to the left of the case log */
@media (min-width: 800px) {
  #portrait-box {
    left: -148px;
    top: auto;
    bottom: 10px; /* 10px from the bottom of the screen */
  }
  
  /* Counter-act the parent's slide-down so portrait stays pinned to the screen bottom */
  #transcript-container:not(.open) #portrait-box {
    /* Parent slides down by calc(50vh - 120px). We slide UP by the same amount. */
    transform: translateY(calc(-50vh + 120px));
  }
}

#statsBadgeCanvas {
  filter: drop-shadow(0 0 15px rgba(68, 255, 68, 0.2));
}

@media (max-width: 450px) {
  #stats-modal h2 {
    font-size: 20px;
  }
  #stats-wins-count {
    font-size: 24px;
  }
  #stopwatch {
    font-size: 14px;
    padding: 0 8px;
    left: calc(60px + env(safe-area-inset-left)) !important;
  }
  #help-btn {
    width: 36px;
    height: 36px;
    left: calc(10px + env(safe-area-inset-left)) !important;
  }
  #stopwatch {
    top: calc(10px + env(safe-area-inset-top)) !important;
    left: calc(56px + env(safe-area-inset-left)) !important;
    height: 36px;
  }
  #help-btn {
    top: calc(10px + env(safe-area-inset-top)) !important;
  }
  #ui-overlay {
    top: calc(10px + env(safe-area-inset-top)) !important;
    right: calc(10px + env(safe-area-inset-right)) !important;
  }
  #status-panel, #selection-panel {
    width: 110px;
    font-size: 12px;
    padding: 6px 10px;
  }
  #play-again-ui {
    width: 110px;
    font-size: 10px;
    padding: 8px 10px;
  }
  .dna-label {
    display: none;
  }
  .dna-label-short {
    display: inline !important;
  }
}


#smart-hint {
  display: none;
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff9e6;
  border: 4px solid #5d3a1a;
  box-shadow: inset -4px -4px 0 rgba(0,0,0,0.1), inset 4px 4px 0 rgba(255,255,255,0.5), 0 4px 20px rgba(0,0,0,0.5);
  padding: 15px 20px;
  border-radius: 0;
  color: #2c3e50;
  font-family: 'Silkscreen', monospace;
  font-size: 14px;
  font-weight: bold;
  z-index: 150;
  max-width: 300px;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.5s ease;
  animation: hintSlideIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes hintSlideIn {
  from { top: -100px; opacity: 0; }
  to { top: 100px; opacity: 1; }
}

/* App Store Badge */
.app-store-badge {
  display: inline-block;
  height: 40px;
  transition: transform 0.2s;
  pointer-events: auto;
}

.app-store-badge:hover {
  transform: scale(1.05);
}

.app-store-badge img {
  height: 100%;
  width: auto;
}

/* Visibility Control */
body.is-native .web-only {
  display: none !important;
}

