/*
 * Custom styles for Hop Into Hangul
 *
 * Base utilities are provided by Tailwind CSS.
 * This file contains only project-specific custom styles.
 */

/* Form enhancements - custom focus states */
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="time"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

@media (prefers-color-scheme: dark) {
  input[type="text"]:focus,
  input[type="email"]:focus,
  input[type="password"]:focus,
  input[type="time"]:focus,
  select:focus,
  textarea:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.2);
  }
}

/* Flash message animation */
@keyframes slide-down {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.animate-slide-down {
  animation: slide-down 0.3s ease-out;
}

/* Toast notification slide in/out animations */
@keyframes slide-in {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slide-out {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

.animate-slide-in {
  animation: slide-in 0.3s ease-out;
}

.animate-slide-out {
  animation: slide-out 0.3s ease-out;
}

/* Word View Stamp Icon Animation */
.word-view-stamp-container {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.word-view-stamp {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Initial state - gray outline only */
.stamp-outline {
  stroke: #d1d5db;
  opacity: 0.4;
  transition: opacity 200ms ease;
}

@media (prefers-color-scheme: dark) {
  .stamp-outline {
    stroke: #4b5563;
    opacity: 0.3;
  }
}

/* Fill circle - starts invisible */
.stamp-fill {
  fill: #dc2626; /* Traditional Korean stamp red */
  transform-origin: center;
  transform: scale(0);
  opacity: 0;
}

@media (prefers-color-scheme: dark) {
  .stamp-fill {
    fill: #ef4444; /* Brighter in dark mode */
  }
}

/* Checkmark icon - starts invisible */
.stamp-icon {
  stroke: white;
  transform-origin: center;
  transform: scale(0) rotate(-10deg);
  opacity: 0;
}

/* Animated state (triggered by JS) */
.word-view-stamp-animated .stamp-outline {
  opacity: 0;
}

.word-view-stamp-animated .stamp-fill {
  animation: stamp-fill-in 400ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.word-view-stamp-animated .stamp-icon {
  animation: stamp-icon-in 300ms cubic-bezier(0.34, 1.56, 0.64, 1) 250ms forwards;
}

/* Stamp fill animation - ink spreading effect */
@keyframes stamp-fill-in {
  0% {
    transform: scale(0) rotate(-5deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.15) rotate(2deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* Icon appears after stamp */
@keyframes stamp-icon-in {
  0% {
    transform: scale(0) rotate(-10deg);
    opacity: 0;
  }
  70% {
    transform: scale(1.1) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .word-view-stamp-animated .stamp-fill,
  .word-view-stamp-animated .stamp-icon {
    animation: none;
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }

  .stamp-fill {
    transform: scale(1);
    opacity: 1;
  }

  .stamp-icon {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* Mobile size adjustment */
@media (max-width: 640px) {
  .word-view-stamp-container {
    width: 40px;
    height: 40px;
  }
}

/* ===========================================
   Flashcard 3D Flip & Swipe Styles
   =========================================== */

/* 3D perspective container */
.perspective-1000 {
  perspective: 1000px;
}

/* Preserve 3D transformations */
.preserve-3d {
  transform-style: preserve-3d;
}

/* Hide backface of flipped elements */
.backface-hidden {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Back of card rotated 180deg */
.rotate-y-180 {
  transform: rotateY(180deg);
}

/* Flipped state for card */
.flashcard.flipped {
  transform: rotateY(180deg);
}

/* Swipe feedback - green glow when swiping right (Know) */
.swiping-right {
  box-shadow: 0 0 30px rgba(34, 197, 94, 0.5);
}

/* Swipe feedback - red glow when swiping left (Still Learning) */
.swiping-left {
  box-shadow: 0 0 30px rgba(239, 68, 68, 0.5);
}

/* Smooth cursor for dragging */
.flashcard {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  transform-origin: center center;
}

/* Swipe exit animations */
@keyframes swipe-out-right {
  to {
    transform: translateX(500px) rotate(25deg);
    opacity: 0;
  }
}

@keyframes swipe-out-left {
  to {
    transform: translateX(-500px) rotate(-25deg);
    opacity: 0;
  }
}

.card-exit-right {
  animation: swipe-out-right 0.3s ease-out forwards;
}

.card-exit-left {
  animation: swipe-out-left 0.3s ease-out forwards;
}

/* Entrance animation for new cards */
@keyframes card-enter {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.flashcard-entering {
  animation: card-enter 0.2s ease-out;
}

.flashcard:active {
  cursor: grabbing;
}

/* Ensure card doesn't trigger text selection on swipe */
.flashcard * {
  pointer-events: none;
}

/* But allow buttons to be clicked */
button[data-action*="swipe"] {
  pointer-events: auto;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .flashcard {
    transition: none !important;
  }

  .flashcard.flipped {
    transform: none;
  }

  .flashcard .backface-hidden:first-child {
    display: block;
  }

  .flashcard .backface-hidden:last-child {
    display: none;
  }

  .flashcard.flipped .backface-hidden:first-child {
    display: none;
  }

  .flashcard.flipped .backface-hidden:last-child {
    display: block;
    transform: none;
  }
}

/* ===========================================
   Pull to Refresh (PWA)
   =========================================== */

/* Disable browser's default pull-to-refresh in PWA */
@media (display-mode: standalone) {
  html, body {
    overscroll-behavior-y: contain;
  }
}

/* Pull to refresh spinner */
.pull-spinner {
  border-width: 3px;
  transition: transform 0.2s ease;
}

/* Spinning animation when refreshing */
@keyframes pull-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

[data-pull-to-refresh-target="indicator"].refreshing .pull-spinner {
  animation: pull-spin 0.8s linear infinite;
}

/* Ready state - full rotation indicator */
[data-pull-to-refresh-target="indicator"].ready .pull-spinner {
  border-color: #4f46e5;
  border-top-color: transparent;
}

@media (prefers-color-scheme: dark) {
  [data-pull-to-refresh-target="indicator"].ready .pull-spinner {
    border-color: #818cf8;
    border-top-color: transparent;
  }
}

/* ===========================================
   Navigation Create Buttons - Touch Support
   =========================================== */

/* On touch devices, show + buttons at reduced opacity since hover isn't available */
@media (hover: none) and (pointer: coarse) {
  .nav-create-btn {
    opacity: 0.5 !important;
  }

  .nav-create-btn:active {
    opacity: 1 !important;
    transform: translateY(-50%) scale(0.95);
  }
}

/* ===========================================
   Korean Keyboard Practice Styles
   =========================================== */

/* Korean word display - better font rendering */
.korean-word {
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  letter-spacing: 0.05em;
}

/* Keyboard container */
.korean-keyboard-container {
  user-select: none;
  -webkit-user-select: none;
}

/* Individual keyboard key */
.keyboard-key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 56px;
  border-radius: 8px;
  background: white;
  border: 1px solid #e5e7eb;
  font-family: "Noto Sans KR", sans-serif;
  transition: all 0.15s ease;
  cursor: default;
}

@media (prefers-color-scheme: dark) {
  .keyboard-key {
    background: #374151;
    border-color: #4b5563;
  }
}

.keyboard-key .jamo {
  font-size: 20px;
  font-weight: 500;
  color: #111827;
  line-height: 1;
}

@media (prefers-color-scheme: dark) {
  .keyboard-key .jamo {
    color: #f9fafb;
  }
}

.keyboard-key .roman {
  font-size: 10px;
  color: #9ca3af;
  margin-top: 2px;
}

/* Consonant keys (left side) - subtle blue tint */
.keyboard-key-consonant {
  background: linear-gradient(180deg, #eff6ff 0%, #dbeafe 100%);
}

@media (prefers-color-scheme: dark) {
  .keyboard-key-consonant {
    background: linear-gradient(180deg, #1e3a5f 0%, #1e3a8a 100%);
  }
}

/* Vowel keys (right side) - subtle pink tint */
.keyboard-key-vowel {
  background: linear-gradient(180deg, #fdf2f8 0%, #fce7f3 100%);
}

@media (prefers-color-scheme: dark) {
  .keyboard-key-vowel {
    background: linear-gradient(180deg, #4a1d4a 0%, #701a75 100%);
  }
}

/* Home row keys - subtle indicator */
.keyboard-key-home::after {
  content: "";
  position: absolute;
  bottom: 6px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #9ca3af;
}

/* Highlighted key (next to press) */
.keyboard-key-highlighted {
  background: #fef3c7 !important;
  border-color: #f59e0b !important;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
  animation: key-pulse 1s ease-in-out infinite;
}

@media (prefers-color-scheme: dark) {
  .keyboard-key-highlighted {
    background: #78350f !important;
    border-color: #f59e0b !important;
  }
}

@keyframes key-pulse {
  0%, 100% {
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.2);
  }
}

/* Key pressed (correct) */
.keyboard-key-pressed {
  background: #d1fae5 !important;
  border-color: #10b981 !important;
  transform: scale(0.95);
}

@media (prefers-color-scheme: dark) {
  .keyboard-key-pressed {
    background: #064e3b !important;
  }
}

/* Key error (wrong key pressed) */
.keyboard-key-error {
  background: #fee2e2 !important;
  border-color: #ef4444 !important;
  animation: key-shake 0.3s ease;
}

@media (prefers-color-scheme: dark) {
  .keyboard-key-error {
    background: #7f1d1d !important;
  }
}

@keyframes key-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

/* Keyboard row divider */
.keyboard-divider {
  width: 12px;
  flex-shrink: 0;
}

/* Syllable progress indicators */
.syllable-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.syllable-char {
  font-size: 1.5rem;
  font-weight: 500;
}

.syllable-status {
  font-size: 0.75rem;
  height: 1rem;
}

.syllable-pending .syllable-char {
  color: #d1d5db;
}

@media (prefers-color-scheme: dark) {
  .syllable-pending .syllable-char {
    color: #4b5563;
  }
}

.syllable-current .syllable-char {
  color: #111827;
  animation: syllable-pulse 1s ease-in-out infinite;
}

@media (prefers-color-scheme: dark) {
  .syllable-current .syllable-char {
    color: #f9fafb;
  }
}

@keyframes syllable-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.syllable-completed .syllable-char {
  color: #10b981;
}

.syllable-completed .syllable-status {
  color: #10b981;
}

/* Composition display */
.composition-display {
  min-height: 80px;
}

.composition-display .label {
  font-weight: 500;
}

.composition-display .composing {
  color: #f59e0b;
  animation: composing-blink 0.5s ease-in-out infinite;
}

@keyframes composing-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.jamo-item {
  display: inline-block;
  padding: 2px 6px;
  background: #e0e7ff;
  border-radius: 4px;
  color: #4338ca;
}

@media (prefers-color-scheme: dark) {
  .jamo-item {
    background: #312e81;
    color: #a5b4fc;
  }
}

/* Shake animation for errors */
.shake-error {
  animation: shake-error 0.3s ease;
}

@keyframes shake-error {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-8px); }
  80% { transform: translateX(8px); }
}

/* Word complete animation */
.word-complete {
  animation: word-complete 0.5s ease;
}

@keyframes word-complete {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); color: #10b981; }
  100% { transform: scale(1); }
}

/* Word entering animation */
.word-entering {
  animation: word-enter 0.3s ease-out;
}

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

/* Streak milestone animation */
.streak-milestone {
  animation: streak-pop 0.6s ease;
}

@keyframes streak-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); color: #f59e0b; }
  100% { transform: scale(1); }
}

/* Responsive keyboard sizing */
@media (max-width: 640px) {
  .keyboard-key {
    width: 36px;
    height: 44px;
  }

  .keyboard-key .jamo {
    font-size: 16px;
  }

  .keyboard-key .roman {
    font-size: 8px;
  }

  .keyboard-divider {
    width: 6px;
  }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .keyboard-key-highlighted {
    animation: none;
  }

  .syllable-current .syllable-char {
    animation: none;
  }

  .composition-display .composing {
    animation: none;
  }

  .shake-error,
  .word-complete,
  .word-entering,
  .streak-milestone {
    animation: none;
  }
}
