
/* =====================
   styles.css (light theme)
   ===================== */
:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --muted: #6b7280;
  --text: #1f2937;
  --brand: #3b82f6;
  --brand-2: #10b981;
  --red: #ef4444;
  --orange: #f59e0b;
  --border: #e5e7eb;
  --shadow: 0 10px 30px rgba(0,0,0,.1);
  --radius: 16px;
  --input-bg: #f9fafb;
  --hover-bg: #f3f4f6;
  --blue-bg1: #00497c;
  --blue-bg2: #3b5fab;
  --blue-bg3: #5780c2;
  --yellow-bg1: #cfb06b;
  --pink: #eecee3;
  --orange-1: #f2cd8c;
  --orange-2: #f39c71;
  --robot1: #538399;
  --robot2: #9fbbbb;
  --red: #e74c3c;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Noto Sans TC, Arial, sans-serif;
}
.container { 
  max-width: min(1100px, 95vw); 
  margin: 16px auto; 
  padding: 0 12px; 
  display: flex;
  flex-direction: column;
  gap: 16px; 
  min-height: calc(100vh - 32px);
}

.card { 
  background: var(--panel); 
  border: 1px solid var(--border); 
  border-radius: var(--radius); 
  box-shadow: var(--shadow); 
  padding: clamp(12px, 3vw, 22px); 
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

header.card { 
  padding-bottom: 14px; 
  flex: 0 0 auto;
  justify-content: flex-start;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform-origin: top center;
}

/* Fix for done view - don't stretch to full height */
#view-done.card {
  flex: 0 0 auto;
  justify-content: flex-start;
}

/* Fix for draw view - prevent vertical centering from hiding content */
#view-draw.card {
  justify-content: flex-start;
  align-items: center;
}

.header-content {
  /* display: flex; */
  align-items: center;
  gap: clamp(16px, 3vw, 24px);
  flex-wrap: wrap;
}

.header-text {
  flex: 1;
  min-width: 300px;
}

.header-text h1 {
  font-size: 45px;
  color: var(--blue-bg2);
}

.header-text p {
  font-size: 20px;
  color: var(--blue-bg2);
  font-weight: 600;
}

.header-image {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 1;
  transform: scale(1);
  width: 100%; /* Ensure container takes full width */
}

.header-image.hidden {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

.header-image img {
  /* max-width: clamp(120px, 20vw, 200px); */
  height: auto;
  width: 80%;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  transition: transform 0.3s ease;
}

.header-image img:hover {
  transform: scale(1.05);
}

body:not(.show-header-image) .header-image {
  display: none !important;
}

/* Hide entire header during drawing phases */
body.hide-header header.card {
  opacity: 0;
  transform: translateY(-20px) scale(0.95);
  pointer-events: none;
  margin-bottom: 0;
  padding: 0;
  height: 0;
  overflow: hidden;
}

/* Show header on form and done views */
body.show-header header.card {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  margin-bottom: 16px;
  padding: clamp(12px, 3vw, 22px);
  height: auto;
}

/* Acknowledgment Section (only in form view) */
.acknowledgment-section {
  /* background: linear-gradient(135deg, var(--blue-bg3), var(--blue-bg2)); */
  background: var(--input-bg);
  color: var(--muted);
  padding: 16px;
  margin-bottom: 30px;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.acknowledgment-section h3 {
  margin: 0 0 12px 0;
  font-size: 18px;
  color: var(--muted);
  text-align: center;
}

.acknowledgment-content {
  line-height: 1.6;
}

.acknowledgment-content p {
  margin: 8px 0;
  font-size: 14px;
}

.acknowledgment-content strong {
  color: var(--muted);
  font-weight: 600;
}

.acknowledgment-content a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.acknowledgment-content a:hover {
  color: var(--yellow-bg1);
  text-decoration: underline;
}

.acknowledgment-divider {
  border: none;
  height: 1px;
  background: var(--muted);
  margin: 12px 0;
}

.acknowledgment-note {
  font-size: 13px;
  text-align: center;
  color: rgba(255, 255, 255, 0.9);
  margin: 8px 0 0 0;
  font-style: italic;
}

h1 { 
  font-size: clamp(20px, 4vw, 26px); 
  margin: 0 0 6px; 
  letter-spacing: .2px; 
  color: var(--text); 
}

h2 { 
  margin: 4px 0 12px; 
  color: var(--text); 
  font-size: clamp(18px, 3vw, 24px);
}

.muted { 
  color: var(--muted); 
  font-size: 14px;
}
.center { text-align: center; }

/* View system - ensure proper separation */
.view { 
  display: none; 
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}
.view.active { 
  display: block; 
  opacity: 1;
}

/* Instruction page specific styles */
#view-instruct {
  text-align: center;
  justify-content: center;
}

#view-instruct .prompt {
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 800;
  margin: 20px 0;
  color: var(--blue-bg2);
  padding: clamp(15px, 4vw, 20px);
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  border-radius: var(--radius);
  border: 2px solid var(--blue-bg2);
}

/* Drawing page specific styles */
#view-draw {
  text-align: center;
  justify-content: flex-start;
}

#view-draw .prompt {
  font-size: clamp(18px, 4vw, 24px);
  font-weight: 700;
  margin: 10px 0;
  color: var(--text);
}

/* Done page specific styles */
#view-done {
  text-align: center;
  justify-content: center;
  /* max-width: 800px; */
  margin: 0 auto;
}

#view-done h2 {
  font-size: clamp(24px, 5vw, 32px);
  margin-bottom: 16px;
}

#view-done p {
  font-size: clamp(16px, 3vw, 18px);
  max-width: 600px;
  margin: 0 auto 20px;
}
.form-grid { 
  display: flex;
  flex-direction: column;
  gap: 20px; 
  margin-top: 12px; 
}

.form-row-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row { display: flex; flex-direction: column; gap: 8px; }
label { font-weight: 600; color: var(--text); }
input[type="text"], input[type="number"] { 
  background: var(--input-bg); 
  color: var(--text); 
  border: 1px solid var(--border); 
  border-radius: 10px; 
  padding: clamp(8px, 2vw, 12px); 
  outline: none; 
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  font-size: clamp(14px, 2.5vw, 16px);
}
input[type="text"]:focus, input[type="number"]:focus { 
  border-color: var(--brand); 
  box-shadow: 0 0 0 3px rgba(59,130,246,.12); 
}
.radio-group { 
  display: flex; 
  gap: clamp(8px, 3vw, 16px); 
  align-items: center; 
  flex-wrap: wrap; 
}
.radio-group label { 
  font-weight: normal; 
  display: flex; 
  align-items: center; 
  gap: 6px; 
  cursor: pointer; 
  font-size: clamp(14px, 2.5vw, 16px);
}
.error { color: var(--red); margin-top: 8px; min-height: 20px; }
/* Main container for side-by-side layout */
.draw-main-container {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  width: 100%;
  min-height: 400px;
}

/* Left side - Canvas */
.draw-left {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Right side - Controls and Predictions */
.draw-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 30px;
  padding: 10px;
  min-width: 250px;
}

.draw-wrap { 
  display: flex; 
  flex-direction: column;
  gap: 14px; 
  align-items: center; 
  width: 100%;
}

.canvas-shell { 
  background: #fff; 
  border-radius: 20px; 
  border: 2px solid var(--border); 
  padding: clamp(8px, 2vw, 12px); 
  box-shadow: var(--shadow); 
  max-width: 100%;
  overflow: visible;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Controls section styling */
.controls-section {
  background: var(--input-bg);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border);
}

.controls-section .toolbar {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 10px;
}

.submit-warning {
  text-align: center;
  font-size: 12px;
  color: #666;
  margin-top: 8px;
}

/* Predictions section styling */
.predictions-section {
  background: rgba(59, 130, 246, 0.05);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid rgba(59, 130, 246, 0.2);
  min-height: 80px;
}

.predictions-title {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--brand);
  text-align: center;
}

.predictions-display {
  background: white;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid rgba(59, 130, 246, 0.3);
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 500;
}

/* Time up section */
.time-up-section {
  display: none;
  font-weight: 700;
  color: var(--red);
  text-align: center;
  background: #fef2f2;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--red);
}

.toolbar { 
  display: flex; 
  gap: clamp(8px, 2vw, 10px); 
  align-items: center; 
  justify-content: center; 
  flex-wrap: wrap;
}

.actions { 
  margin-top: 10px; 
  display: flex; 
  gap: clamp(8px, 2vw, 10px); 
  flex-wrap: wrap; 
  justify-content: center;
}
.actions.center { justify-content: center; }

.btn { 
  appearance: none; 
  border: 1px solid var(--border); 
  color: var(--text); 
  background: var(--border); 
  padding: clamp(8px, 2vw, 14px) clamp(12px, 3vw, 18px); 
  border-radius: 12px; 
  font-weight: 600; 
  cursor: pointer; 
  transition: transform .08s ease, box-shadow .08s ease, background .15s ease, border-color .15s ease; 
  font-size: clamp(14px, 2.5vw, 16px);
  min-height: 44px; /* Touch-friendly minimum */
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn:hover { 
  transform: translateY(-1px); 
  border-color: var(--brand); 
  background: var(--hover-bg);
}
.btn:active { transform: translateY(0); }
.btn.primary { 
  background: linear-gradient(135deg, var(--brand), #2563eb); 
  color: white;
  border: none; 
}
.btn.primary:hover {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  transform: translateY(-1px);
}
.btn.brand { 
  background: linear-gradient(135deg, var(--brand), #2563eb); 
  color: white; 
  border: none; 
}
.btn.brand:hover {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  transform: translateY(-1px);
}
.btn.ghost { 
  background: transparent; 
  border: 1px solid var(--border);
}
.btn.ghost:hover {
  background: var(--hover-bg);
}
.badge { 
  position: fixed; 
  top: clamp(8px, 2vw, 10px); 
  right: clamp(8px, 2vw, 12px); 
  z-index: 1000; 
  background: #2563eb; 
  color: white; 
  padding: clamp(4px, 1vw, 6px) clamp(8px, 2vw, 10px); 
  border-radius: 999px; 
  font-size: clamp(12px, 2vw, 14px); 
  border: 1px solid #2563eb; 
  box-shadow: var(--shadow); 
}
.prompt { 
  font-size: clamp(20px, 4vw, 26px); 
  font-weight: 800; 
  text-align: center; 
  margin: 6px 0 4px; 
}
.timer { 
  text-align: center; 
  font-weight: 700; 
  margin-bottom: 6px; 
  color: var(--brand);
  font-size: clamp(16px, 3vw, 18px);
}
/* Old #res styling removed - now using .predictions-display */
#timeUpMsg { 
  display: none; 
  font-weight: 700; 
  color: var(--red); 
  text-align: center; 
  background: #fef2f2;
  padding: clamp(8px, 2vw, 10px);
  border-radius: var(--radius);
  border: 1px solid var(--red);
  margin-top: 10px;
  font-size: clamp(14px, 2.5vw, 16px);
}
.done-actions { 
  display: flex; 
  gap: clamp(6px, 2vw, 8px); 
  justify-content: center; 
  margin-top: 10px; 
  flex-wrap: wrap; 
}
.tips { 
  background: #f0f9ff; 
  color: var(--blue-bg3);
  padding: clamp(6px, 2vw, 8px) clamp(8px, 2vw, 10px); 
  border-radius: 10px; 
  border: 1px solid #bfdbfe; 
  margin-top: 30px; 
  font-size: clamp(13px, 2vw, 14px);
}

/* Touch and mobile optimizations */
/* Prevent page scrolling during drawing */
body.drawing-mode {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* Visual feedback when in drawing mode */
body.drawing-mode .canvas-shell {
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
  border-color: var(--brand);
}

body.drawing-mode #drawPrompt {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.8; }
  100% { opacity: 1; }
}

/* Enhanced canvas container for mobile drawing */
.canvas-shell {
  touch-action: none; /* Prevent all default touch behaviors */
  -webkit-touch-callout: none; /* Disable callout on iOS */
  -webkit-user-select: none; /* Prevent text selection */
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Prevent zoom on double tap for drawing area */
.canvas-shell canvas {
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Additional mobile optimizations for drawing */
@media (max-width: 820px) {
  /* Make canvas area more prominent on mobile */
  .canvas-shell {
    margin: 10px 0;
    border-width: 3px;
    /* Ensure larger canvas fits on mobile */
    max-width: 95vw;
    overflow: visible;
  }
  
  /* Ensure canvas scales properly on small screens */
  .canvas-shell canvas {
    max-width: 100%;
    height: auto;
  }
  
  /* Make result element more visible on mobile */
  #res {
    font-size: 14px;
    padding: 10px;
    margin: 15px 0;
    /* background: rgba(59, 130, 246, 0.15); */
  }
  
  /* Mobile header adjustments */
  body.show-header header.card {
    margin-bottom: 12px;
    padding: 14px;
  }
  
  body.hide-header header.card {
    margin-bottom: 0;
  }
}
  
  /* Ensure timer and prompt are easily visible */
  #timer {
    font-size: clamp(16px, 4vw, 20px);
    font-weight: bold;
    text-align: center;
    padding: 8px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    margin-bottom: 10px;
  }
  
  /* Make drawing prompt more prominent */
  #drawPrompt {
    font-size: clamp(18px, 4.5vw, 24px);
    font-weight: bold;
    text-align: center;
    padding: 12px;
    /* background: var(--brand); */
    color: white;
    border-radius: 12px;
    margin-bottom: 15px;
  }


@media (max-width: 820px) { 
  .form-row-pair { grid-template-columns: 1fr; gap: 12px; }
  .prompt { font-size: clamp(18px, 4vw, 22px); }
  #view-instruct .prompt { font-size: clamp(20px, 5vw, 24px); padding: 15px; }
  .actions { justify-content: center; }
  .done-actions { flex-direction: column; align-items: center; }
  .container { margin: 8px auto; padding: 0 8px; }
  
  /* Mobile: Stack canvas and controls vertically */
  .draw-main-container {
    flex-direction: column;
    gap: 15px;
  }
  
  .draw-left {
    flex: none;
    width: 100%;
  }
  
  .draw-right {
    flex: none;
    width: 100%;
    padding: 5px;
  }
  
  .controls-section, .predictions-section {
    padding: 12px;
  }
  
  .predictions-title {
    font-size: 14px;
  }
  
  .header-content {
    flex-direction: column;
    text-align: center;
    gap: 16px;
  }
   
  .header-text {
    min-width: auto;
  }
  .header-text h1 {
    font-size: 1.5rem; /* Adjust the size as needed */
   } 
  .header-image img {
    max-width: clamp(50px, 25vw, 150px);
  } 
  
  /* Acknowledgment mobile styles */
  .acknowledgment-section {
    padding: 14px;
    margin-bottom: 16px;
  }
  
  .acknowledgment-section h3 {
    font-size: 16px;
    margin-bottom: 10px;
  }
  
  .acknowledgment-content p {
    font-size: 12px;
    margin: 4px 0;
  }
  
  /* Canvas and result element mobile optimizations */
  .canvas-shell canvas {
    max-width: 100%;
    height: auto;
  }
  
  /* Mobile predictions display */
  .predictions-display {
    font-size: 14px;
    padding: 10px;
    min-height: 35px;
  }
}

@media (max-width: 480px) {
  .btn { min-height: 48px; } /* Larger touch targets on small screens */
  .radio-group { flex-direction: column; align-items: flex-start; gap: 8px; }
  .form-grid { gap: 12px; }
  .form-row-pair { gap: 8px; }
  
  .header-content {
    gap: 12px;
  }
  
  .header-image img {
    max-width: 80px;
  }
}