/* Global Styles */
:root {
  --primary-color: #6c5ce7;
  --secondary-color: #a29bfe;
  --accent-color: #00b894;
  --error-color: #d63031;
  --bg-color: #dfe6e9;
  /* Light gray background */
  --card-bg: #ffffff;
  --text-color: #2d3436;
  --shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
  --radius: 20px;
  --font-main: 'Noto Sans KR', sans-serif;
  --font-display: 'Jua', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

.app-container {
  width: 100%;
  max-width: 600px;
  background: #f1f2f6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.05);
}

/* Header */
.main-header {
  background: var(--card-bg);
  padding: 1rem;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  position: sticky;
  top: 0;
  text-align: center;
}

.main-header h1 {
  font-family: var(--font-display);
  color: var(--primary-color);
  margin-bottom: 0.5rem;
  font-size: 1.8rem;
}

nav {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.nav-btn {
  background: transparent;
  border: 2px solid transparent;
  padding: 0.5rem 1rem;
  border-radius: 50px;
  font-weight: bold;
  color: #b2bec3;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: var(--font-display);
  font-size: 1rem;
}

.nav-btn.active {
  background: var(--primary-color);
  color: white;
  box-shadow: 0 4px 10px rgba(108, 92, 231, 0.3);
}

/* Main Content Area */
main {
  flex: 1;
  padding: 1rem;
  padding-bottom: 3rem;
  overflow-y: auto;
}

.view {
  display: none;
  animation: fadeIn 0.3s ease;
}

.view.active {
  display: block;
}

.view.hidden {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Grid View */
.grid-controls {
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: #636e72;
}

.hanja-search {
  flex: 1;
  min-width: 140px;
  max-width: 220px;
  padding: 0.5rem 0.75rem;
  border: 2px solid #dfe6e9;
  border-radius: 12px;
  font-size: 0.95rem;
  font-family: var(--font-main);
  outline: none;
  transition: border-color 0.2s;
}

.hanja-search:focus {
  border-color: var(--primary-color);
}

.grid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 1rem;
}

.grid-item {
  background: var(--card-bg);
  border-radius: 15px;
  padding: 1rem 0.5rem;
  text-align: center;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  aspect-ratio: 1;
}

.grid-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}

.g-hanja {
  font-size: 2rem;
  font-weight: bold;
  color: var(--text-color);
  margin-bottom: 0.2rem;
  font-family: serif;
}

.g-info {
  font-size: 0.8rem;
  color: #636e72;
  word-break: keep-all;
}

/* Study View */
.study-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: center;
}

.study-progress {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--primary-color);
  margin-bottom: 1rem;
}

.card-scene {
  width: 280px;
  height: 380px;
  perspective: 1000px;
  margin-bottom: 2rem;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
  transform-style: preserve-3d;
  cursor: pointer;
}

.card.is-flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.03);
}

.card-front {
  background: linear-gradient(135deg, #ffffff 0%, #f9f9f9 100%);
  color: var(--text-color);
}

.card-back {
  background: #ffffff;
  /* White background */
  transform: rotateY(180deg);
  display: flex;
  padding: 0;
  overflow: hidden;
  border: 1px solid #dfe6e9;
  /* Light border */
}

/* New Card Back Styles */
.card-back-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.5rem;
  box-sizing: border-box;
  align-items: center;
  position: relative;
  z-index: 2;
  /* Ensure content is above the background image */
}

/* Background Illustration Styling */
.card-bg-illustration {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  /* Adjust size as needed, maybe not full bleed to keep it neat */
  height: 90%;
  object-fit: contain;
  opacity: 0.25;
  /* Low opacity to not interfere with text */
  z-index: 1;
  pointer-events: none;
}

.cb-top {
  text-align: center;
  border-bottom: 2px solid rgba(0, 0, 0, 0.05);
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
  width: 100%;
}

.card-back {
  justify-content: center;
  /* centering for absolute elements fallback */
  background: #fff;
}

.meaning-sound-back {
  font-family: var(--font-display);
  font-size: 2rem;
  color: #fdcb6e;
  /* Yellow-Orange for meaning/sound */
  text-shadow: none;
  -webkit-text-stroke: 1px #d35400;
}

.cb-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.big-hanja-back {
  font-size: 8rem;
  font-weight: bold;
  font-family: serif;
  color: #2d3436;
  text-shadow: none;
}

.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.7);
  /* Stronger overlay to mute the illustration slightly */
  backdrop-filter: blur(2px);
  /* Blur the image slightly to focus on text */
}

.overlay-hanja {
  font-size: 8rem;
  font-weight: bold;
  font-family: serif;
  color: #2d3436;
  /* No shadow needed if overlay is strong, but let's keep a subtle one */
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.card-text.footer {
  position: absolute;
  bottom: 20px;
  background: rgba(255, 255, 255, 0.9);
  padding: 10px 20px;
  border-radius: 50px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.big-hanja {
  font-size: 8rem;
  font-weight: bold;
  font-family: serif;
  display: block;
}

.hint-text {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: #b2bec3;
}

.meaning-sound {
  font-size: 1.5rem;
  font-family: var(--font-display);
  color: var(--primary-color);
}

.study-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.control-btn {
  background: white;
  border: none;
  border-radius: 50px;
  padding: 0.8rem 1.5rem;
  font-size: 1rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  font-family: var(--font-display);
  transition: all 0.2s;
}

.control-btn:active {
  transform: scale(0.95);
}

.control-btn.play {
  background: var(--accent-color);
  color: white;
}

.control-btn.play.playing {
  background: var(--error-color);
}

.control-btn.prev,
.control-btn.next {
  color: var(--primary-color);
  font-weight: bold;
}

.control-btn.prev::before {
  content: "⬅️";
  margin-right: 5px;
}

.control-btn.next::after {
  content: "➡️";
  margin-left: 5px;
}

.speed-control {
  background: white;
  padding: 0.5rem 1rem;
  border-radius: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* Quiz View */
.quiz-container {
  text-align: center;
}

.quiz-header {
  margin-bottom: 2rem;
}

.score-board {
  display: inline-block;
  background: var(--primary-color);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-family: var(--font-display);
  margin-top: 1rem;
}

.quiz-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 3rem;
  margin-bottom: 2rem;
  display: inline-block;
  min-width: 200px;
}

.quiz-hanja {
  font-size: 6rem;
  font-family: serif;
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  max-width: 400px;
  margin: 0 auto;
}

.quiz-options button {
  background: white;
  border: 2px solid #dfe6e9;
  border-radius: 15px;
  padding: 1rem;
  font-size: 1.2rem;
  font-family: var(--font-display);
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-color);
}

.quiz-options button:hover {
  border-color: var(--secondary-color);
  background: #fdfdfd;
}

.quiz-options button:active {
  background: var(--secondary-color);
  color: white;
}

.quiz-feedback {
  height: 2rem;
  font-size: 1.5rem;
  font-family: var(--font-display);
  margin-bottom: 1rem;
  font-weight: bold;
}

.next-quiz-btn {
  margin-top: 2rem;
  background: var(--text-color);
  color: white;
  border: none;
  padding: 0.8rem 2rem;
  border-radius: 50px;
  font-family: var(--font-display);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.next-quiz-btn.show {
  opacity: 1;
  pointer-events: auto;
}

/* Responsive */
@media (max-width: 400px) {
  .card-scene {
    width: 240px;
    height: 340px;
  }

  .big-hanja,
  .overlay-hanja {
    font-size: 6rem;
  }
}