:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-light: #f8fafc;
  --border: #e2e8f0;
  --text-main: #1e293b;
  --rec: #ef4444;
  --rec-hover: #dc2626;
}

body, html {
  margin: 0;
  padding: 0;
  height: 100vh;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: var(--text-main);
}

/* --- Header & Accordion --- */
header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  z-index: 10;
}

summary {
  list-style: none;
  cursor: pointer;
  padding: 15px 0;
}

summary::-webkit-details-marker { display: none; }

.summary-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.summary-content h1 {
  margin: 0;
  font-size: 1.2rem;
}

.chevron {
  transition: transform 0.3s ease;
  width: 20px;
  height: 20px;
}

details[open] .chevron {
  transform: rotate(180deg);
}

/* --- Controls --- */
.controls {
  display: flex;
  gap: 20px;
  padding: 15px 0;
  align-items: center;
  border-top: 1px solid var(--border);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.custom-select, .primary-btn, .secondary-btn {
  height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  outline: none;
}

.custom-select {
  background: var(--bg-light);
  cursor: pointer;
  min-width: 180px;
}

.primary-btn {
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
}

.primary-btn:hover { background: var(--primary-hover); }

.secondary-btn {
  background: white;
  cursor: pointer;
}

.secondary-btn:hover { background: var(--bg-light); }

/* --- Progress --- */
progress {
  width: 150px;
  height: 10px;
  accent-color: var(--primary);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--border);
}

progress::-webkit-progress-bar {
  background-color: var(--bg-light);
  border-radius: 5px;
}

progress::-webkit-progress-value {
  background-color: var(--primary);
  border-radius: 5px;
}

#progressText {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  min-width: 35px;
}

/* --- Layout --- */
.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  background: #f1f5f9;
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 15px;
  overflow: hidden;
  min-width: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  min-height: 40px;
  flex-wrap: wrap;
  gap: 8px;
}

.panel-header h3 {
  margin: 0;
  font-size: 1rem;
}

.left-panel {
  border-right: 1px solid var(--border);
}

/* --- Zoom controls --- */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.zoom-controls button {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--primary);
  padding: 0;
  display: flex;
}

/* --- Pagination --- */
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 15px;
  background: white;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 500;
}

.pagination-controls button {
  padding: 0;
  height: auto;
  color: var(--primary);
}

.pagination-controls button:disabled {
  color: #cbd5e1;
  cursor: not-allowed;
}

/* --- Image Tools (Deskew / Perspective) --- */
.image-tools {
  display: flex;
  gap: 6px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-main);
  transition: all 0.2s;
  white-space: nowrap;
}

.tool-btn:hover {
  background: var(--bg-light);
  border-color: #94a3b8;
}

.tool-btn--perspective {
  border-color: #818cf8;
  color: #4338ca;
}

.tool-btn--perspective:hover {
  background: #eef2ff;
}

/* --- Perspective Toolbar --- */
.perspective-header {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 10px;
  flex-wrap: nowrap !important;
}

.perspective-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: #1d4ed8;
  font-weight: 500;
}

.perspective-hint svg {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

.perspective-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.perspective-actions .secondary-btn,
.perspective-actions .primary-btn {
  height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
}

/* --- Canvas --- */
.canvas-wrapper {
  flex: 1;
  overflow: auto;
  background: #cbd5e1;
  display: flex;
  border-radius: 8px;
  padding: 20px;
  justify-content: center;
  align-items: flex-start;
}

.canvas-wrapper.zoomed {
  justify-content: flex-start;
}

canvas {
  background: white;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto !important;
  margin: 0;
}

.canvas-wrapper.perspective-active canvas {
  cursor: crosshair;
}

.zoomed canvas {
  width: auto;
  max-width: none;
}

/* --- Right Panel header actions --- */
.right-panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --- Icon button (copy) --- */
.icon-btn {
  border: none;
  background: #f1f5f9;
  cursor: pointer;
  color: #64748b;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.icon-btn:hover {
  color: var(--primary);
  background: #e2e8f0;
}

/* --- Record button --- */
.record-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--rec);
  background: white;
  color: var(--rec);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.record-btn:hover {
  background: #fef2f2;
}

.record-btn svg {
  width: 14px;
  height: 14px;
}

/* Active recording state */
.record-btn.recording {
  background: var(--rec);
  color: white;
  border-color: var(--rec);
  animation: pulse-border 1.2s ease-in-out infinite;
}

.record-btn.recording:hover {
  background: var(--rec-hover);
}

#recordTimer {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  font-size: 0.8rem;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50%       { box-shadow: 0 0 0 5px rgba(239, 68, 68, 0);  }
}

/* --- Textarea --- */
textarea {
  flex: 1;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
  resize: none;
  font-size: 1rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* --- Toast --- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 9999;
  white-space: nowrap;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .controls {
    flex-wrap: wrap;
    gap: 10px;
  }

  .control-group:has(#lang),
  #lang {
    display: none !important;
  }

  .primary-btn {
    flex: 1;
    justify-content: center;
  }

  .primary-btn span { display: none; }

  .main-container {
    flex-direction: column;
    overflow-y: auto;
  }

  .panel {
    flex: none;
    height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .panel-header {
    width: 100%;
    box-sizing: border-box;
    padding-right: 5px;
  }

  textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .left-panel { order: 1; }

  .right-panel {
    order: 2;
    min-width: 0;
    display: flex;
    flex-direction: column;
  }

  .tool-btn span { display: none; }

  .perspective-hint span { display: none; }

  .perspective-header { flex-wrap: nowrap !important; }

  /* On mobile, hide "Record" label text, show just icon + timer */
  #recordLabel { display: none; }
}
