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

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e9f2 100%);
  min-height: 100vh;
  padding: 2vh 1.5rem;
  color: #2d3748;
}

.container {
  background: white;
  padding: 2vh 1.5rem;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  max-width: 1000px;
  width: 100%;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.header {
  text-align: right;
}

.language-btn {
  background: none;
  border: 2px solid #667eea;
  color: #667eea;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s;
}

.language-btn:hover {
  background: #667eea;
  color: white;
}

.epigraph {
  text-align: center;
  font-style: italic;
  margin-bottom: 2vh;
  color: #718096;
}

.epigraph-author {
  margin-top: 0.5rem;
  font-weight: 500;
}

h1 {
  color: #2d3748;
  margin: 0 0 1.5vh 0;
  font-size: 4vh;
  font-weight: 700;
  text-align: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  text-align: center;
  color: #718096;
  margin-bottom: 1.5vh;
  font-size: 2vh;
}

.instruction {
  text-align: center;
  margin: 1.2vh 0;
  padding: 1.5vh;
  background: #f7fafc;
  border-radius: 12px;
  line-height: 1.5;
}

#canvas {
  width: 100%;
  flex-grow: 1; /* Allow canvas to grow and fill available space */
  min-height: 200px; /* Set a minimum height to prevent it from collapsing */
  flex-shrink: 0; /* Prevent canvas from shrinking if content overflows */
  border-radius: 20px;
  background-color: white;
  cursor: crosshair;
  border: 2px solid transparent;
  background-clip: padding-box, border-box;
  background-origin: padding-box, border-box;
  background-image: linear-gradient(white, white),
    linear-gradient(135deg, rgba(102, 126, 234, 0.5), rgba(118, 75, 162, 0.5));
}

.controls {
  background: #f7fafc;
  padding: 1.5vh 1rem;
  border-radius: 12px;
  margin: 1.2vh 0;
  display: flex;
  gap: 2rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

#colorPicker {
  width: 60px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

#brushSize {
  width: 150px;
  accent-color: #667eea;
}

label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

#brushSizeValue {
  background: #667eea;
  color: white;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  min-width: 2.5rem;
  text-align: center;
}

.button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 1vh 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: transform 0.1s;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.button:active {
  transform: translateY(0);
}

.privacy-consent {
  margin-top: 1vh;
  padding: 0.7rem;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  font-size: 0.9rem;
  color: #2d3748;
}

.privacy-consent label {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.privacy-consent a {
  display: inline-block;
  margin-top: 0.4rem;
  color: #4c51bf;
  text-decoration: underline;
}

.button-container {
  display: flex;
  justify-content: flex-end;
  margin-top: 1.5vh;
  gap: 1rem;
}

#submitButton {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.site-footer {
  max-width: 1000px;
  width: 100%;
  margin: 1.5vh auto 0 auto;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-align: center;
  padding: 1.5vh;
  border-radius: 16px;
  font-size: 0.9rem;
  box-shadow: 0 8px 20px rgba(102, 126, 234, 0.2);
}

/* ============================================
   PHONE – PORTRAIT (vertical) LAYOUT
   ============================================ */
@media (max-width: 600px) and (orientation: portrait) {
  /* Less side padding, full-width card */
  body {
    padding: 1vh !important;
  }

  .container {
    max-width: 100%;
    width: 100%;
    padding: 1.5vh 1rem !important;
  }

  /* Tighter vertical rhythm */
  .epigraph {
    margin-bottom: 1vh;
    font-size: 1.5vh;
  }

  .epigraph-author {
    font-size: 1.4vh;
  }

  h1 {
    font-size: 3.5vh;
    margin-bottom: 1vh;
  }

  .subtitle {
    font-size: 1.8vh;
    margin-bottom: 1vh;
  }

  .instruction {
    margin-bottom: 1vh;
    padding: 1.5vh;
    font-size: 1.6vh;
  }

  .control-group {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
  }

  .controls {
    padding: 1.2vh;
    border-radius: 12px;
    gap: 0.8vh;
    flex-direction: column;
    align-items: stretch;
  }

  label {
    font-size: 1.7vh;
    white-space: nowrap;
  }

  #colorPicker {
    width: 52px;
    height: 3.2vh;
    border-radius: 8px;
  }

  #brushSize {
    width: 38%;
  }

  #brushSizeValue {
    padding: 0.3vh 0.45rem;
    font-size: 1.3vh;
  }

  #clearButton {
    align-self: center;
    margin-top: 0; /* Removed margin to tighten space */
  }

  #canvas {
    width: 100%;
    height: 35vh !important; /* main control on size */
    max-height: 35vh !important;
    aspect-ratio: 4 / 3;
    margin-top: 1vh;
  }

  .button {
    padding: 1vh 0.9rem;
    font-size: 1.8vh;
  }

  .button-container {
    margin-top: 1vh;
  }

  .site-footer {
    margin-top: 1.5vh;
    padding: 1.5vh;
    font-size: 1.5vh;
  }
}

/* ============================================================
   PHONE – LANDSCAPE (horizontal) LAYOUT
   Centered controls, larger title, taller/less-wide canvas.
   ============================================================ */
@media (orientation: landscape) and (max-height: 500px) {
  /* Remove side padding, full-width card */
  body {
    padding: 1vh 0; /* Use viewport height for vertical padding */
  }

  .container {
    width: 80%;
    max-width: 1200px;
    border-radius: 16px; /* Restore rounded corners */
    padding: 1.5vh 0.8rem; /* Vertical padding in vh */
    margin: 1vh auto; /* Vertical margin in vh */
    display: flex;
    flex-direction: column;
    gap: 0.8vh; /* Use vh for gap */
  }

  /* Header + language button */
  .header {
    margin-bottom: 0.8vh;
  }

  #langToggle {
    padding: 0.8vh 0.6rem;
    font-size: 1.8vh; /* Font size based on viewport height */
    border-radius: 6px;
  }

  .epigraph {
    font-size: 2.5vh;
    margin-bottom: 0.8vh;
    text-align: center;
  }

  h1 {
    font-size: 5vh; /* Scalable title */
    margin-bottom: 0.8vh;
    text-align: center;
  }

  .subtitle {
    font-size: 2vh;
    margin-bottom: 0.8vh;
    text-align: center;
  }

  .instruction {
    font-size: 2.5vh;
    padding: 1vh;
    margin: 0 auto 0.8vh; /* Centered with reduced bottom margin */
    text-align: center;
    width: 100%;
  }

  .controls {
    padding: 1vh;
    border-radius: 12px;
    display: flex;
    flex-direction: row; /* Arrange controls horizontally */
    justify-content: space-between; /* Space out items */
    align-items: center; /* Vertically align items */
    width: 100%;
    margin: 0 auto;
  }

  .control-group {
    width: auto; /* shrink to content */
    display: flex;
    align-items: center;
    gap: 0.8rem;
    justify-content: center; /* center each row */
  }

  label {
    font-size: 2.5vh;
  }

  #colorPicker {
    width: 40px;
    height: 5vh;
    border-radius: 6px;
  }

  #brushSize {
    width: 120px;
  }

  #brushSizeValue {
    font-size: 2.5vh;
    padding: 0.3vh 0.3rem;
  }

  #canvas {
    display: block;
    width: 80vh; /* Increased width to take more vertical space */
    max-width: 90%; /* Don't exceed 90% of screen width */
    margin: 0.8vh auto 0; /* centered, with reduced top margin */
    height: auto; /* Let aspect-ratio determine height */
    aspect-ratio: 2 / 1; /* Enforce 2:1 width-to-height ratio */
  }

  #clearButton {
    margin-top: 0; /* Remove margin now that it's in a flex row */
    font-size: 2.5vh;
    padding: 0.8vh 0.7rem;
    height: 5vh;
  }

  .button-container {
    margin-top: 0.8vh;
    display: flex;
    justify-content: center;
  }

  #submitButton {
    padding: 1vh 0.8rem;
    font-size: 2.5vh;
    height: 5.5vh;
  }

  .site-footer {
    width: 80%; /* Match container width */
    max-width: 1200px; /* Match container max-width */
    margin: 1.2vh auto 0; /* Center the footer */
    padding: 1.2vh;
    font-size: 2.5vh;
    border-radius: 16px; /* Match container border-radius */
  }
}
