* {
  box-sizing: border-box;
}

/* Prevent scrolling and bounce on mobile */
html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  max-width: 600px;
  margin: 0 auto;
}

h1 {
  font-size: 1.6rem;
  margin: 0;
}

h2 {
  font-size: 1.4rem;
  margin: 12px 0 0 0;
  text-align: center;
  line-height: 1.3;
}

p {
  margin: 0;
  font-size: 0.95rem;
  color: #444;
}

#canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #ddd;
  background: #ffffff;
  touch-action: none;
  /* important for touch drawing */
  flex-shrink: 0;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

button {
  padding: 12px 18px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: transform 0.1s ease, opacity 0.1s ease;
  min-height: 44px;
  /* Touch target size */
  -webkit-tap-highlight-color: transparent;
}

button:active {
  transform: scale(0.96);
  opacity: 0.8;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#clear-btn {
  background: #eeeeee;
  flex: 1;
}

#submit-btn {
  background: #111111;
  color: white;
  flex: 1;
}

#status {
  font-size: 0.9rem;
  color: #555;
  min-height: 1.2em;
  width: 100%;
  text-align: center;
}

/* Mobile optimizations */
@media (max-width: 640px) {
  body {
    background: #ffffff;
    padding: 8px;
    border-radius: 0;
    max-width: 100%;
    width: 100%;
    height: 100vh;
    box-shadow: none;
    gap: 6px;
  }

  h2 {
    font-size: 0.95rem;
    line-height: 1.2;
    margin: 0;
  }

  #canvas-wrapper {
    border-radius: 6px;
  }

  button {
    padding: 12px 16px;
    font-size: 0.9rem;
  }

  .button-group {
    width: 100%;
  }

  #status {
    font-size: 0.8rem;
  }
}

/* Extra small mobile devices */
@media (max-width: 375px) {
  .app {
    padding: 8px;
    gap: 8px;
  }

  h2 {
    font-size: 1rem;
  }

  button {
    font-size: 0.9rem;
  }
}

/* Mobile landscape orientation */
@media (max-width: 932px) and (max-height: 500px) and (orientation: landscape) {
  body {
    padding: 12px;
    gap: 8px;
  }

  h2 {
    font-size: 0.85rem;
  }

  .button-group {
    flex-direction: row;
  }

  button {
    padding: 10px 16px;
    font-size: 0.85rem;
  }

  #status {
    font-size: 0.75rem;
  }
}