/* CSS Custom Properties & Reset */
:root {
  /* Color Palette - Judo Gi Blue Theme & Premium White Cards */
  --bg-gradient-start: #1e3a8a; /* Royal Judo Blue */
  --bg-gradient-end: #0f172a; /* Midnight Blue */
  --card-bg-front: #ffffff;
  --card-bg-back: #ffffff;
  --accent-color: #1d4ed8; /* Vibrant Judo Blue */
  --accent-glow: rgba(29, 78, 216, 0.3);
  --accent-gradient: linear-gradient(135deg, #3b82f6, #1d4ed8);
  --text-primary: #1f2937; /* Dark Gray for white background */
  --text-secondary: #4b5563; /* Medium Gray */
  --text-muted: #808080; /* Muted Gray */
  --border-color: rgba(0, 0, 0, 0.08);
  --border-glow: rgba(29, 78, 216, 0.15);
  
  /* Fonts */
  --font-ko: 'Noto Sans KR', sans-serif;
  --font-en: 'Outfit', sans-serif;

  /* Card Sizing */
  --card-width: 320px;
  --card-height: 480px;
}

@supports (background: linear-gradient(in oklch, red, blue)) {
  :root {
    --accent-gradient: linear-gradient(135deg in oklch, #3b82f6, #1d4ed8);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ko);
  background-color: var(--bg-gradient-start);
  background-image: radial-gradient(circle at 50% 30%, #1d4ed8 0%, var(--bg-gradient-end) 75%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Container Layout */
.app-container {
  width: 100%;
  max-width: 480px; /* Mobile focused container width */
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 24px 16px;
  position: relative;
}

/* Header Styling */
.app-header {
  text-align: center;
  margin-bottom: 16px;
  z-index: 10;
}

.logo {
  font-family: var(--font-ko);
  font-size: 2.1rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  background: linear-gradient(to right, #ffffff, #93c5fd);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
  filter: drop-shadow(0 2px 8px rgba(29, 78, 216, 0.4));
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  gap: 24px;
}

/* Card Area and 3D Flip System */
.card-area {
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 1200px; /* Perspective depth for 3D flip */
  width: 100%;
}

.card-container {
  width: var(--card-width);
  height: var(--card-height);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* The actual flippable element with swiping transitions */
.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.4s ease;
  border-radius: 24px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2), 
              0 0 20px rgba(29, 78, 216, 0.05);
}

/* Trigger flipped state in JS */
.card.is-flipped {
  transform: rotateY(180deg);
}

/* Swipe Left Animation (Next Card) */
.card.is-leaving {
  transform: translateX(-160%) rotate(-12deg) !important;
  opacity: 0;
}

/* Instant reposition to the right (transition turned off) */
.card.is-preparing {
  transition: none !important;
  transform: translateX(160%) rotate(12deg) !important;
  opacity: 0;
}

/* Swipe Right Animation (Previous Card) */
.card.is-leaving-right {
  transform: translateX(160%) rotate(12deg) !important;
  opacity: 0;
}

/* Instant reposition to the left (transition turned off) */
.card.is-preparing-left {
  transition: none !important;
  transform: translateX(-160%) rotate(-12deg) !important;
  opacity: 0;
}

/* Card Faces */
.card-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden; /* Hide back during flip */
  border-radius: 24px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* iOS Safari 3D render fixes */
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
}

/* Front Face (Image) */
.card-front {
  background-color: #ffffff; /* Solid white matching PNG background */
  background-image: none; /* Remove gradient to prevent boundaries */
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.card-front::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 24px;
  border: 1px solid rgba(0, 0, 0, 0.08); /* Keep card edge border */
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s;
}

.card-image-wrapper {
  width: 100%;
  height: 100%;
  border-radius: 24px;
  overflow: hidden;
  background-color: #ffffff;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px; /* Padding for drawing margin */
  border: none; /* Remove border between image and card */
  box-shadow: none;
}

.card-image-wrapper img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.card-front-overlay {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
}

.tap-hint {
  font-family: var(--font-en);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-color);
  background: rgba(255, 255, 255, 0.9);
  padding: 6px 14px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  letter-spacing: 0.15em;
  backdrop-filter: blur(4px);
  animation: pulse 2s infinite ease-in-out;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Back Face (Light Theme Cards) */
.card-back {
  background-color: var(--card-bg-back);
  background-image: linear-gradient(135deg, #ffffff, #f9fafb);
  transform: rotateY(180deg); /* Face backwards initially */
  padding: 28px 24px;
  justify-content: space-between;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

/* Details Header */
.card-back-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  padding-bottom: 14px;
}

.card-back-en {
  font-family: var(--font-en);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent-color);
  letter-spacing: 0.1em;
  display: block;
  margin-bottom: 4px;
}

.card-back-ko {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

.card-back-ja-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
}

.card-back-ja {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.card-back-alias {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 300;
}

/* Details Body */
.card-back-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px 0;
  gap: 16px;
}

.card-description {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-primary);
  font-weight: 400;
  text-align: justify;
  overflow-y: auto;
  max-height: 160px; /* Limit height to prevent overflow, scrollable if needed */
  padding-right: 4px;
}

/* Custom Scrollbar for Description */
.card-description::-webkit-scrollbar {
  width: 4px;
}
.card-description::-webkit-scrollbar-track {
  background: transparent;
}
.card-description::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 2px;
}

.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  font-size: 0.75rem;
  font-weight: 500;
  background-color: rgba(29, 78, 216, 0.08);
  color: #1d4ed8;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(29, 78, 216, 0.15);
}

/* Details Footer / Button */
.card-back-footer {
  margin-top: auto;
}

.video-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  background: var(--accent-gradient);
  color: #ffffff;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  gap: 8px;
  box-shadow: 0 4px 15px var(--accent-glow);
  transition: transform 0.2s, box-shadow 0.2s;
  border: none;
  outline: none;
}

.video-btn:active {
  transform: scale(0.97);
}

.play-icon {
  width: 16px;
  height: 16px;
}

/* Controls Area (Below Card) */
.controls-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
}

.buttons-row {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: center;
}

.nav-button {
  background: #ffffff;
  border: none;
  color: #1e3a8a; /* Judo deep blue for arrow */
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3),
              0 0 10px rgba(255, 255, 255, 0.1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.nav-button:active:not(:disabled) {
  transform: scale(0.92);
  background-color: #f3f4f6;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.nav-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.arrow-icon {
  width: 24px;
  height: 24px;
  transition: transform 0.3s;
}

.next-button:active:not(:disabled) .arrow-icon {
  transform: translateX(2px);
}

.prev-button:active:not(:disabled) .arrow-icon {
  transform: translateX(-2px);
}

.card-counter {
  font-family: var(--font-en);
  font-size: 0.8rem;
  font-weight: 500;
  color: #93c5fd;
  letter-spacing: 0.1em;
}

/* Footer Styling */
.app-footer {
  text-align: center;
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.dojo-logo {
  font-family: 'Ma Shan Zheng', 'Zhi Mang Xing', 'GungSeo', 'Gungsuh', '궁서', '궁서체', serif;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  background: linear-gradient(to right, #ffffff, #93c5fd);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 6px rgba(29, 78, 216, 0.4));
  margin-bottom: 2px;
}

.app-footer p {
  font-size: 0.7rem;
  color: #64748b;
  letter-spacing: 0.05em;
}

/* Animations */
@keyframes pulse {
  0%, 100% {
    opacity: 0.6;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.03);
  }
}

/* Mobile Screen Sizing Adjustments */
@media (max-height: 700px) {
  :root {
    --card-height: 400px;
    --card-width: 280px;
  }
  .logo {
    font-size: 1.7rem;
  }
  .app-container {
    padding: 12px 16px;
  }
  .card-back {
    padding: 20px 18px;
  }
  .card-back-ko {
    font-size: 1.4rem;
  }
  .card-description {
    font-size: 0.85rem;
    max-height: 120px;
  }
  .dojo-logo {
    font-size: 1.3rem;
  }
}

@media (max-width: 340px) {
  :root {
    --card-width: 270px;
    --card-height: 380px;
  }
  .card-back {
    padding: 16px 14px;
  }
  .dojo-logo {
    font-size: 1.2rem;
  }
}

/* Logo Row in Footer */
.logo-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 2px;
}

/* QR Code Button & Modal Styling */
.qr-button {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #ffffff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  margin-top: -2px; /* Visual alignment with Hanja text baseline */
}

.qr-button:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: scale(1.08);
}

.qr-button:active {
  transform: scale(0.95);
}

.qr-icon {
  width: 15px;
  height: 15px;
}

/* Modal Overlay styling */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.75); /* Dark slate semi-transparent */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #ffffff;
  padding: 32px 24px;
  border-radius: 28px;
  width: 90%;
  max-width: 320px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  transform: translateY(20px) scale(0.95);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.is-active .modal-content {
  transform: translateY(0) scale(1);
}

.modal-close-btn {
  position: absolute;
  right: 16px;
  top: 16px;
  background: #f1f5f9;
  border: none;
  color: #64748b;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.modal-close-btn:hover {
  background: #e2e8f0;
  color: #334155;
}

.modal-close-btn svg {
  width: 16px;
  height: 16px;
}

.modal-title {
  font-family: var(--font-ko);
  font-size: 1.25rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 20px;
  margin-top: 4px;
}

.qr-code-wrapper {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 12px;
  border-radius: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.qr-image {
  width: 180px;
  height: 180px;
  display: block;
}

.modal-description {
  font-family: var(--font-ko);
  font-size: 0.85rem;
  color: #64748b;
  text-align: center;
  line-height: 1.5;
  margin: 0;
}
