html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: #577ecc; /* pleasant blue color */
  font-family: Arial, Helvetica, sans-serif;
}

#app-header {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 15px 20px;
  position: relative;
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#header {
  text-align: center;
  font-size: 5em;
  height: 1.2em;
  margin: 0;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#draw-container {
  position: relative;
  width: fit-content; /* or max-content */
  max-width: 90%; /* Prevent it from getting too wide */
  margin: 20px auto;
  background-color: white; /* Keep the background white */
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  overflow: hidden; /* Ensure everything inside stays within the rounded corners */
}

#answer-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1; /* Ensure it's above the canvas background */
  pointer-events: none;
}

#answer-bg.visible {
  display: flex;
}

#answer-bg-text {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  text-align: center;
  font-size: clamp(4rem, 25vw, 20rem);
  font-weight: bold;
  white-space: nowrap; /* Prevent text from wrapping to a new line */
  overflow: hidden; /* Hide any overflow if text is still too large */
  color: #3a5a9f;
  text-shadow: 0 0 8px rgba(255,255,255,0.8);
  user-select: none;
  opacity: 0.4; /* Make the trace slightly more visible */
}

canvas {
  display: block;
  touch-action: none;
  background: rgba(255, 255, 255, 0.75); /* Slightly transparent background */
  border-radius: 16px;
  margin: 0;
  position: relative;
  z-index: 2; /* Place on top of answer for drawing */
  box-shadow: inset 0 0 10px rgba(0,0,0,0.05);
  max-width: 500px;
  max-height: 500px;
}

#answer {
  display: none !important;
}

#controls {
  text-align: center;
  margin: 20px auto 30px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

#controls button {
  font-size: 1.5em;
  padding: 12px 24px;
  border-radius: 10px;
  border: none;
  background-color: #fff;
  color: #3a5a9f;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s;
  min-width: 150px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  font-weight: bold;
}

#controls button:hover {
  background-color: #f0f5ff;
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(0,0,0,0.15);
}

#controls button:active, #controls button:focus {
  background-color: #e0e8ff;
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#settings-container {
  position: fixed;
  bottom: 20px;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  z-index: 100;
  pointer-events: none; /* This allows clicks to pass through to elements below */
}

#menu {
  position: relative;
  z-index: 10;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  padding: 16px;
  transition: all 0.3s ease;
  touch-action: manipulation;
  user-select: none;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  width: 280px;
  pointer-events: auto; /* Re-enable pointer events for the menu */
}

#menu.collapsed {
  display: none;
}

#menu-toggle {
  background: #3a5a9f;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 14px 20px;
  font-size: 1.2em;
  cursor: pointer;
  min-height: 48px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  transition: all 0.2s;
  font-weight: bold;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  min-width: 180px;
}

#menu-toggle:hover {
  background: #304a85;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#menu-toggle:active, #menu-toggle:focus {
  background: #263c70;
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

#menu label, #menu select {
  font-size: 1.1em;
  margin-top: 8px;
  padding: 8px 0; /* Larger touch target */
  display: block; /* Ensure the entire area is clickable */
}
#menu select {
  min-width: 180px;
  min-height: 2.5em;
  border-radius: 6px;
  padding: 6px;
  font-size: 1.1em;
  outline: none;
  touch-action: manipulation;
}
#menu.collapsed label,
#menu.collapsed select {
  display: none;
}
#menu-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

#menu-checkboxes label {
  font-size: 1.1em;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  padding: 10px;
  border-radius: 8px;
  transition: background-color 0.2s;
}

#menu-checkboxes input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: #3a5a9f;
  cursor: pointer;
}

#menu-character-set {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

#menu-display-mode {
  margin-top: 10px;
}

#menu-display-mode p, #menu-checkboxes p {
  margin: 10px 0 6px 0;
  font-weight: bold;
  color: #3a5a9f;
  font-size: 1.2em;
}

#menu-character-set p, #menu-display-mode p {
  margin: 10px 0 6px 0;
  font-weight: bold;
  color: #3a5a9f;
  font-size: 1.2em;
}

#menu-character-set label, #menu-display-mode label {
  font-size: 1.1em;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  padding: 10px;
  border-radius: 8px;
  transition: background-color 0.2s;
}

#menu-character-set label:hover, #menu-display-mode label:hover, #menu-checkboxes label:hover {
  background-color: #f0f5ff;
}

#menu-character-set label:active, #menu-display-mode label:active, #menu-checkboxes label:active {
  background-color: #e0e8ff;
}

#menu-character-set input[type="radio"], #menu-display-mode input[type="radio"] {
  width: 20px;
  height: 20px;
  accent-color: #3a5a9f;
  cursor: pointer;
}

hr {
  border: none;
  height: 1px;
  background-color: #e0e8ff;
  margin: 15px 0;
}

#menu.collapsed #menu-checkboxes,
#menu.collapsed #menu-display-mode,
#menu.collapsed #menu-character-set,
#menu.collapsed hr {
  display: none;
}

#settings-button-container {
  text-align: center;
  margin: 5px auto 30px;
  width: 100%;
}

/* Responsive styles */
@media (max-width: 768px) {
  #app-header {
    flex-direction: column;
    align-items: center;
  }
  
  #header {
    font-size: 4em;
    margin-bottom: 10px;
  }
  
  #menu {
    width: 250px;
    max-height: 70vh;
  }
  
  #draw-container {
    margin-top: 20px;
    margin-bottom: 20px;
  }
  
  #controls, #settings-button-container {
    flex-direction: column;
    align-items: center;
  }
  
  #controls button, #menu-toggle {
    width: 80%;
    max-width: 300px;
  }
  
  #settings-container {
    bottom: 15px;
  }
}

@media (max-width: 480px) {
  #header {
    font-size: 3em;
  }
  
  #menu {
    width: 90%;
    max-width: 280px;
    max-height: 60vh;
  }
  
  #menu-toggle {
    font-size: 1em;
    padding: 12px 10px;
  }
  
  #menu-character-set label, #menu-display-mode label, #menu-checkboxes label {
    font-size: 1em;
    padding: 8px;
  }
  
  #controls button, #menu-toggle {
    font-size: 1.2em;
    padding: 10px 20px;
  }
  
  #settings-container {
    bottom: 10px;
  }
}

/* Styles for the main container */
main {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 800px; /* Reduced from 1200px to better suit the limited canvas size */
  margin: 0 auto;
}

/* Style for group-chars display */
.group-chars {
  font-weight: bold;
  color: #3a5a9f;
}

/* Focus styles for accessibility */
button:focus, input:focus {
  outline: 2px solid #3a5a9f;
  outline-offset: 2px;
}

/* Make sure the tracing color is visible but not too dominant */
#answer-bg.visible + canvas {
  background: rgba(255, 255, 255, 0.65);
}