:root {
  --bg: #f4f6fb;
  --card: #fff;
  --muted: #666;
}

body {
  font-family: system-ui, Segoe UI, Roboto, Arial;
  background: var(--bg);
  margin: 0;
  padding: 14px;
  color: #111;
}

h1 {
  margin: 0 0 12px;
  font-size: 24px;
  text-align: center;
  font-weight: 600;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 10px;
}

.panel {
  display: flex;
  gap: 12px;
}

.hidden-preload {
  display: none;
}

.hidden-by-default {
  display: none;
}

.instructions-launch {
  text-align: center;
  margin-bottom: 12px;
}

.toolbar-spacer {
  width: 12px;
}

.input-w84 {
  width: 84px;
}

.input-w70 {
  width: 70px;
}

.input-w80 {
  width: 80px;
}

.editor-panel {
  flex: 0 0 720px;
}

.canvas-column {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preview-panel {
  flex: 1 1 640px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.range-full {
  width: 100%;
}

.log-pane {
  height: 120px;
  overflow: auto;
  background: #fff;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #eee;
}

.privacy-notice {
  text-align: center;
  margin: 30px auto 20px;
  padding: 0 20px;
  max-width: 900px;
}

.privacy-text {
  font-size: 13px;
  color: #666;
  line-height: 1.6;
  margin: 0;
}

.privacy-strong {
  color: #333;
}

.ad-container {
  max-width: 1200px;
  margin: 30px auto 20px;
  padding: 0 14px;
  text-align: center;
}

.ad-block {
  display: block;
}

.editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card);
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.06);
}

.drop {
  border: 2px dashed #c7d0df;
  padding: 8px;
  border-radius: 8px;
  min-width: 220px;
  text-align: center;
  cursor: pointer;
  background: #fff;
  box-shadow: 0 2px 8px rgba(11, 116, 222, 0.15);
  transition: all 0.3s ease;
}

.drop:hover {
  border-color: #0b74de;
  background: #f0f7ff;
  box-shadow: 0 4px 12px rgba(11, 116, 222, 0.25);
  transform: translateY(-2px);
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

button {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #c9d6ea;
  background: #fff;
  cursor: pointer;
  transition: all 0.2s;
}

button:hover {
  background: #f5f8fa;
}

button.primary {
  background: #0b74de;
  color: #fff;
  border-color: #0a66c2;
}

button.primary:hover {
  background: #095bb8;
}

/* Active mode highlight - NEW */
button.primary.active-mode {
  box-shadow: 0 0 0 3px rgba(11, 116, 222, 0.3);
  transform: scale(1.05);
}

button.danger {
  background: #e04b4b;
  color: #fff;
  border-color: #c83b3b;
}

button.danger:hover {
  background: #c83b3b;
}

/* Active delete mode highlight - NEW */
button.danger.active-mode {
  box-shadow: 0 0 0 3px rgba(224, 75, 75, 0.4);
  transform: scale(1.05);
  background: #d63939;
}

.canvases {
  display: flex;
  gap: 12px;
}

canvas.editorCanvas {
  border-radius: 8px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: crosshair;
}

#glCanvas {
  border-radius: 10px;
  border: 1px solid #bbb;
  display: block;
  margin: 12px auto 0;
  background: #111;
  max-width: 100%;
  height: auto;
}

.small {
  font-size: 13px;
  color: var(--muted);
}

.info {
  margin-top: 8px;
  font-size: 13px;
  color: #333;
}

.pointList {
  max-height: 160px;
  overflow: auto;
  border-top: 1px dashed #eee;
  padding-top: 8px;
  margin-top: 8px;
  font-size: 13px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

input[type=file] {
  display: none;
}

label {
  font-size: 13px;
}

input[type=number], 
input[type=range],
select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #c9d6ea;
}

/* ============================================================
   RESCALE MODAL
   ============================================================ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

/* Keep modal hidden on initial load when class is present. */
.modal-overlay.hidden-by-default {
  display: none;
}

.modal {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 16px 0;
  color: #111;
}

.modal-content {
  margin-bottom: 24px;
  line-height: 1.6;
  color: #333;
}

.modal-note {
  margin-top: 16px;
  font-size: 14px;
  color: #666;
}

.modal-size-info {
  background: #f5f8fa;
  padding: 12px;
  border-radius: 8px;
  margin: 12px 0;
  font-family: 'Courier New', monospace;
  font-size: 14px;
}

.modal-size-label {
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-size-value {
  font-size: 16px;
  color: #111;
  margin-top: 4px;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-buttons button {
  min-width: 100px;
}

.modal-inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.modal-loading {
  text-align: center;
  padding: 20px;
}

.modal-spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #0b74de;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ============================================================
   RESPONSIVE LAYOUT
   ============================================================ */

/* Desktop styles (default - no changes needed to existing) */
/* Everything above this works for screens > 1024px */

/* Tablet Layout (768px - 1024px) */
@media (max-width: 1024px) {
  .panel {
    flex-direction: column;
    align-items: center;
  }
  
  .editor {
    max-width: 100%;
    width: 100%;
    flex: 1 1 auto;
  }
  
  .canvases {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }
  
  .toolbar {
    justify-content: center;
  }
  
  /* Editor canvases will be resized via JS */
  canvas.editorCanvas {
    max-width: 100%;
    height: auto;
  }
  
  #glCanvas {
    max-width: 90%;
    height: auto;
  }
}

/* Mobile Layout (<768px) */
@media (max-width: 768px) {
  body {
    padding: 8px;
  }
  
  h1 {
    font-size: 20px;
    text-align: center;
    margin-bottom: 10px;
  }
  
  .toolbar {
    flex-direction: column;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    padding: 0;
  }
  
  .toolbar > * {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  
  .controls {
    flex-direction: column;
    width: 100%;
    gap: 12px;
  }
  
  .drop {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    margin: 0 !important;
  }
  
  button {
    width: 100%;
    padding: 12px;
    font-size: 14px;
  }
  
  .row {
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }
  
  .row button {
    width: 100%;
  }
  
  .toolbar-spacer {
    display: none;
  }

  /* Controls row buttons (Build Triangulation, Preview, etc.) */
  .preview-panel {
    max-width: 100vw !important;
    box-sizing: border-box !important;
    padding: 0 8px !important;
  }

  .preview-controls {
    flex-wrap: wrap !important;
    gap: 6px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .preview-controls button {
    flex: 0 1 calc(50% - 3px);
    max-width: calc(50% - 3px);
    min-width: 0;
    font-size: 12px;
    padding: 10px 4px;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  label {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  
  input[type="number"],
  input[type="range"],
  select {
    width: 100%;
  }
  
  .pointList {
    max-height: 200px;
    font-size: 12px;
  }
  
  .editor {
    padding: 8px;
  }
  
  .small {
    font-size: 12px;
  }
  
  #glCanvas {
    max-width: 100%;
  }
}

/* Keyboard shortcut hints */
.kbd-hint {
  display: inline-block;
  padding: 2px 6px;
  margin: 0 2px;
  background: #f5f5f5;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-family: monospace;
  font-size: 11px;
  color: #666;
}

/* Instructions Button */
.help-btn {
  font-size: 14px;
  padding: 8px 20px;
  margin: 0 auto;
  background: #4CAF50;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-block;
  min-width: 160px;
  max-width: 200px;
}

.help-btn:hover {
  background: #45a049;
  transform: translateY(-1px);
}

/* Instructions Modal */
.instructions-modal {
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 32px;
  color: #666;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 32px;
  height: 32px;
}

.modal-close:hover {
  color: #000;
}

.instructions-content {
  padding-bottom: 20px;
}

.instruction-section {
  margin-bottom: 30px;
}

.instruction-section h3 {
  color: #0b74de;
  font-size: 18px;
  margin-bottom: 12px;
  border-bottom: 2px solid #e0e0e0;
  padding-bottom: 8px;
}

.instruction-list {
  margin: 0;
  padding-left: 25px;
  line-height: 1.8;
}

.instruction-list li {
  margin-bottom: 10px;
}

.instruction-list strong {
  color: #333;
}

.tips-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tips-list li {
  padding: 8px 0 8px 30px;
  position: relative;
  line-height: 1.6;
}

.tips-list li:before {
  content: "💡";
  position: absolute;
  left: 0;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-top: 15px;
}

.mode-item p {
  margin: 0;
  font-size: 14px;
  color: #555;
  line-height: 1.5;
}

/* Size guide grid */
.size-guide {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 15px;
  margin-top: 15px;
}

.size-item {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
  border-left: 4px solid #4CAF50;
}

.size-item strong {
  display: block;
  color: #4CAF50;
  margin-bottom: 10px;
  font-size: 15px;
}

.size-item ul {
  margin: 0;
  padding-left: 20px;
  line-height: 1.7;
}

.size-item li {
  margin-bottom: 6px;
  font-size: 14px;
  color: #555;
}

.size-item li strong {
  display: inline;
  color: #333;
  font-size: 14px;
}

.mode-item {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
  border-left: 4px solid #0b74de;
}

.mode-item strong {
  display: block;
  color: #0b74de;
  margin-bottom: 8px;
  font-size: 15px;
}

.mode-item p {
  margin: 0;
  font-size: 14px;
  color: #555;
  line-height: 1.5;
}

.shortcuts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 15px;
}

.shortcut-item {
  background: #f5f5f5;
  padding: 10px;
  border-radius: 6px;
  font-size: 14px;
}

.shortcut-item kbd {
  display: inline-block;
  padding: 3px 8px;
  background: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-family: monospace;
  font-weight: bold;
  margin-right: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.tip-box {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  border-radius: 10px;
  border: none;
}

.tip-box h3 {
  color: white;
  border-bottom: 2px solid rgba(255,255,255,0.3);
  margin-bottom: 15px;
}

.tip-box p {
  margin: 0;
  line-height: 1.6;
  font-size: 15px;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .help-btn {
    font-size: 13px;
    padding: 8px 16px;
    margin: 0 auto;
    min-width: 140px;
  }

  .instructions-modal {
    max-width: 95%;
    max-height: 85vh;
    margin: 20px;
  }

    .mode-grid,
  .shortcuts-grid {
    grid-template-columns: 1fr;
  }
  
  .size-guide {
    grid-template-columns: 1fr;
  }

  .modal-title {
    font-size: 20px;
    padding-right: 40px;
  }
}

/* ============================================================
   RECORDING TIMER ANIMATION
   ============================================================ */

/* Gentle pulse animation for recording button */
@keyframes recordingPulse {
  0%, 100% { 
    transform: scale(1);
    box-shadow: 0 2px 8px rgba(224, 75, 75, 0.3);
  }
  50% { 
    transform: scale(1.03);
    box-shadow: 0 4px 16px rgba(224, 75, 75, 0.5);
  }
}

/* Faster pulse for warning (last 10 seconds) */
@keyframes recordingPulseWarning {
  0%, 100% { 
    transform: scale(1);
    box-shadow: 0 2px 8px rgba(224, 75, 75, 0.4);
  }
  50% { 
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(224, 75, 75, 0.7);
  }
}

/* Apply pulse to recording button */
.recording-active {
  animation: recordingPulse 1.5s ease-in-out infinite;
  white-space: nowrap;
  min-width: 140px;
}

/* Warning pulse (last 10 seconds) */
.recording-warning {
  animation: recordingPulseWarning 0.8s ease-in-out infinite;
  background: #d63939 !important;
  white-space: nowrap;
  min-width: 140px;
}

/* Ensure button doesn't change size when text changes */
#recordBtn {
  min-width: 140px;
  white-space: nowrap;
  transition: all 0.2s ease;
}
