/* css/handwriting.css - Styling for Chinese Handwriting Recognition & Real-time Pad */

.hw-pad-wrapper {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
}

/* 1. Composed Text Buffer Box (Hiển thị các chữ đã chọn liền mạch) */
.hw-buffer-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-card, #FFFFFF);
  border: 1.5px solid var(--border-color, #E2E8F0);
  border-radius: 12px;
  padding: 6px 10px;
  margin-bottom: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

.hw-buffer-display {
  display: flex;
  align-items: center;
  flex: 1;
  min-height: 36px;
  overflow-x: auto;
  scrollbar-width: none;
}
.hw-buffer-display::-webkit-scrollbar {
  display: none;
}

.hw-buffer-content {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary, #0F172A);
  letter-spacing: 2px;
  white-space: nowrap;
  font-family: var(--font-hanzi, "Noto Sans SC", sans-serif);
}

.hw-buffer-placeholder {
  font-size: 12.5px;
  color: var(--text-muted, #94A3B8);
  white-space: nowrap;
}

.hw-buffer-cursor {
  display: inline-block;
  width: 2px;
  height: 20px;
  background: var(--accent, #E8344E);
  margin-left: 3px;
  animation: hw-blink 1s infinite;
}
@keyframes hw-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.hw-buffer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.hw-buffer-btn {
  font-size: 13px;
  padding: 5px 9px;
  min-width: 32px;
  height: 34px;
}

.hw-buffer-confirm-btn {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
  white-space: nowrap;
}

/* 2. Candidate Bar (Thanh gợi ý thời gian thực) */
.hw-candidate-bar {
  display: flex;
  align-items: center;
  min-height: 48px;
  background: var(--bg-card, #FFFFFF);
  border: 1.5px solid var(--border-color, #E2E8F0);
  border-radius: 12px;
  padding: 4px 8px;
  margin-bottom: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  overflow-x: auto;
  scrollbar-width: none;
}
.hw-candidate-bar::-webkit-scrollbar {
  display: none;
}

.hw-candidates-list {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.hw-placeholder-text {
  font-size: 12.5px;
  color: var(--text-muted, #94A3B8);
  padding: 0 6px;
  white-space: nowrap;
}

/* Candidate item button */
.hw-candidate-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  background: var(--bg-muted, #F8FAFC);
  border: 1px solid var(--border-color, #E2E8F0);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.hw-candidate-item:hover,
.hw-candidate-item:focus {
  background: var(--accent-light, #FFF1F2);
  border-color: var(--accent, #E8344E);
  transform: translateY(-1px);
}
.hw-candidate-item:active {
  transform: scale(0.95);
}

.hw-cand-char {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary, #0F172A);
  line-height: 1;
  font-family: var(--font-hanzi, "Noto Sans SC", sans-serif);
}

.hw-cand-key {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted, #94A3B8);
}

/* Loading Spinner */
.hw-candidate-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
}
.hw-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-color, #CBD5E1);
  border-top-color: var(--accent, #E8344E);
  border-radius: 50%;
  animation: hw-spin 0.6s linear infinite;
}
@keyframes hw-spin {
  to { transform: rotate(360deg); }
}

/* 3. Canvas Container */
.hw-canvas-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 360px;
  max-height: 360px;
  margin: 0 auto 10px;
  background: var(--bg-card, #FFFFFF);
  border: 2px solid var(--border-color, #E2E8F0);
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.hw-canvas {
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* 4. Bottom Action Bar (Hoàn tác, Xóa nét, Đổi lưới) */
.hw-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.hw-action-left,
.hw-action-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hw-btn {
  font-size: 12.5px;
  padding: 6px 10px;
}

/* Dark Mode Theme */
[data-theme="dark"] .hw-buffer-box {
  background: #1E293B;
  border-color: #334155;
}
[data-theme="dark"] .hw-buffer-content {
  color: #F8FAFC;
}
[data-theme="dark"] .hw-candidate-bar {
  background: #1E293B;
  border-color: #334155;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
[data-theme="dark"] .hw-candidate-item {
  background: #0F172A;
  border-color: #334155;
}
[data-theme="dark"] .hw-candidate-item:hover {
  background: #334155;
  border-color: var(--accent, #E8344E);
}
[data-theme="dark"] .hw-cand-char {
  color: #F8FAFC;
}
[data-theme="dark"] .hw-canvas-container {
  background: #1E293B;
  border-color: #334155;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .hw-canvas-container {
    max-width: 280px;
    max-height: 280px;
  }
  .hw-candidate-item {
    min-width: 36px;
    height: 38px;
    padding: 0 8px;
  }
  .hw-cand-char {
    font-size: 18px;
  }
  .hw-btn .hw-btn-label {
    display: none;
  }
  .hw-btn {
    padding: 6px 8px;
  }
}
