/* ==========================================================================
   Design System & Variable Declarations
   ========================================================================== */
:root {
  /* Transitions */
  --transition-speed: 0.3s;
  --transition-curve: cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: all var(--transition-speed) var(--transition-curve);

  /* Fonts */
  --font-japanese: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-english: 'Outfit', sans-serif;
}

/* --- Theme Light --- */
.theme-light {
  --bg-app: radial-gradient(circle at top left, #fbfbfd, #f1f2f6);
  --bg-card: rgba(255, 255, 255, 0.75);
  --border-color: rgba(0, 0, 0, 0.08);
  --shadow-color: rgba(31, 38, 135, 0.08);

  --primary-color: #4f46e5;
  --primary-hover: #4338ca;
  --primary-glow: rgba(79, 70, 229, 0.15);

  --secondary-color: #ffffff;
  --secondary-hover: #f3f4f6;
  --secondary-border: rgba(0, 0, 0, 0.12);

  --text-main: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;

  --accent-color: #10b981;
}

/* --- Theme Dark --- */
.theme-dark {
  --bg-app: radial-gradient(circle at top left, #0f172a, #0b0f19);
  --bg-card: rgba(30, 41, 59, 0.65);
  --border-color: rgba(255, 255, 255, 0.08);
  --shadow-color: rgba(0, 0, 0, 0.3);

  --primary-color: #6366f1;
  --primary-hover: #818cf8;
  --primary-glow: rgba(99, 102, 241, 0.3);

  --secondary-color: #1e293b;
  --secondary-hover: #334155;
  --secondary-border: rgba(255, 255, 255, 0.15);

  --text-main: #f3f4f6;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;

  --accent-color: #34d399;
}

/* --- Theme Sepia --- */
.theme-sepia {
  --bg-app: radial-gradient(circle at top left, #fbf6ec, #efe8d9);
  --bg-card: rgba(253, 246, 227, 0.8);
  --border-color: rgba(93, 78, 56, 0.1);
  --shadow-color: rgba(93, 78, 56, 0.05);

  --primary-color: #c25e00;
  --primary-hover: #b05000;
  --primary-glow: rgba(194, 94, 0, 0.15);

  --secondary-color: #fdf6e3;
  --secondary-hover: #eee8d5;
  --secondary-border: rgba(93, 78, 56, 0.2);

  --text-main: #586e75;
  --text-secondary: #657b83;
  --text-muted: #93a1a1;

  --accent-color: #859900;
}

/* ==========================================================================
   Base Elements Reset & Styles
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-japanese);
  background: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  transition: var(--transition-smooth);
}

.app-container {
  width: 100%;
  max-width: 960px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
}

/* ==========================================================================
   Screen Transitions
   ========================================================================== */
.screen {
  display: none;
  opacity: 0;
  transform: translateY(15px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  width: 100%;
}

.screen.active {
  display: flex;
  flex-direction: column;
  opacity: 1;
  transform: translateY(0);
}

.screen#completion-screen.active {
  min-height: calc(100vh - 48px);
  justify-content: center;
  align-items: center;
}

/* ==========================================================================
   Card Styling (Glassmorphism Pattern)
   ========================================================================== */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 48px;
  box-shadow: 0 8px 32px 0 var(--shadow-color);
  transition: var(--transition-smooth);
  width: 100%;
}

.divider {
  height: 1px;
  background: var(--border-color);
  margin: 32px 0;
}

/* ==========================================================================
   Introduction / Setup Screen Styling
   ========================================================================== */
.main-title {
  font-family: var(--font-japanese);
  font-weight: 900;
  font-size: 2.2rem;
  letter-spacing: -0.02em;
  text-align: center;
  margin-bottom: 4px;
  background: linear-gradient(135deg, var(--text-main), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-family: var(--font-english);
  font-weight: 400;
  font-size: 1rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 8px;
}

.instructions {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 16px;
  padding: 24px;
  border-left: 4px solid var(--primary-color);
}

.instructions h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.instructions ul {
  list-style-type: none;
}

.instructions li {
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 10px;
  color: var(--text-secondary);
  position: relative;
  padding-left: 20px;
}

.instructions li::before {
  content: "•";
  color: var(--primary-color);
  font-weight: bold;
  font-size: 1.2rem;
  position: absolute;
  left: 5px;
  top: -2px;
}

.setup-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

@media (min-width: 768px) {
  .setup-controls {
    grid-template-columns: repeat(3, 1fr);
  }
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.control-group input[type="text"],
.control-group select {
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--secondary-color);
  color: var(--text-main);
  outline: none;
  transition: var(--transition-smooth);
}

.control-group input[type="text"]:focus,
.control-group select:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Theme buttons custom group */
.theme-toggle-group {
  display: flex;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.02);
}

.theme-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 0;
  font-family: var(--font-english);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.theme-btn.active {
  background: var(--primary-color);
  color: #ffffff;
}

.theme-btn:hover:not(.active) {
  background: rgba(0, 0, 0, 0.05);
}

/* Button Custom Styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-lg {
  padding: 16px 32px;
  font-size: 1.1rem;
  width: 100%;
}

.btn-primary {
  background: var(--primary-color);
  color: #ffffff;
  box-shadow: 0 4px 14px 0 var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px 0 var(--primary-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--secondary-color);
  color: var(--text-main);
  border: 1px solid var(--secondary-border);
}

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

/* ==========================================================================
   Presentation Screen Styling
   ========================================================================== */
.experiment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
}

.participant-badge,
.block-badge {
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 12px;
  font-family: var(--font-english);
  font-size: 0.9rem;
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.participant-badge .label,
.block-badge .label {
  color: var(--text-muted);
  font-weight: 400;
}

.participant-badge .value,
.block-badge .value {
  color: var(--text-main);
  font-weight: 700;
}

/* Progress indicator bar */
.progress-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.progress-bar-wrapper {
  width: 100%;
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary-color);
  border-radius: 3px;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.slide-counter {
  font-family: var(--font-english);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.slide-counter .current {
  color: var(--primary-color);
  font-size: 1.1rem;
}

.slide-counter .separator {
  color: var(--text-muted);
  margin: 0 2px;
}

/* The core presentation canvas */
.presentation-canvas {
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  margin-bottom: 24px;
}

.stimulus-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  box-shadow: 0 10px 40px 0 var(--shadow-color);
  width: 100%;
  min-height: 380px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 40px;
  text-align: center;
  position: relative;
  transition: var(--transition-smooth);
}

.stimulus-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

/* Carrier phrase: HUGE */
.carrier-text {
  max-width: 100%;
  overflow: hidden;
  font-family: var(--font-japanese);
  font-weight: 700;
  font-size: 4rem;
  /* Desktop default, will scale on smaller devices */
  line-height: 1.4;
  color: var(--text-main);
  white-space: nowrap;
  transition: opacity 0.2s ease;
}

/* Japanese translation sentence: smaller and muted */
.translation-text {
  max-width: 100%;
  overflow: hidden;
  font-family: var(--font-japanese);
  font-weight: 500;
  font-size: 2.1rem;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-top: 2.5rem;
  white-space: nowrap;
  transition: opacity 0.2s ease;
  opacity: 0.85;
}

/* Metainfo at the bottom of stimulus card for researcher reference */
.stimulus-metadata {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
  opacity: 0.15;
  transition: opacity var(--transition-speed) ease;
}

.stimulus-card:hover .stimulus-metadata {
  opacity: 0.7;
}

.meta-tag {
  background: var(--border-color);
  color: var(--text-secondary);
  font-family: var(--font-english);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
}

/* Footer / Navigation Control Bar */
.experiment-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

.shortcuts-guide {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  text-align: center;
  display: none;
}

@media (min-width: 768px) {
  .shortcuts-guide {
    display: block;
  }
}

.kbd {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: var(--font-english);
  font-size: 0.75rem;
  font-weight: 700;
  box-shadow: 0 1px 1px var(--border-color);
}

/* Slide Transition Animations (Triggered via JS class toggle) */
.slide-fade-out {
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.slide-fade-in {
  animation: slideInAnimation 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes slideInAnimation {
  0% {
    opacity: 0;
    transform: scale(0.97) translateY(8px);
  }

  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Responsive typography adjustments */
@media (max-width: 768px) {
  .carrier-text {
    font-size: 2.6rem;
  }

  .translation-text {
    font-size: 1.4rem;
    margin-top: 1.5rem;
  }

  .presentation-canvas {
    min-height: 320px;
  }

  .stimulus-card {
    min-height: 300px;
    padding: 24px;
  }
}

/* ==========================================================================
   Completion Screen Styling
   ========================================================================== */
.completion-card {
  text-align: center;
  max-width: 600px;
  margin: 0 auto;
}

.success-icon-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.success-icon {
  background: var(--accent-color);
  color: #ffffff;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.3);
  animation: pulseGreen 2s infinite;
}

@keyframes pulseGreen {
  0% {
    transform: scale(1);
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.3);
  }

  70% {
    transform: scale(1.05);
    box-shadow: 0 8px 30px rgba(16, 185, 129, 0.5);
  }

  100% {
    transform: scale(1);
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.3);
  }
}

.completion-title {
  font-size: 2rem;
  font-weight: 900;
  margin-bottom: 8px;
}

.completion-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
}

.completion-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  background: rgba(0, 0, 0, 0.02);
  padding: 24px;
  border-radius: 16px;
  text-align: left;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.completion-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (min-width: 576px) {
  .completion-actions {
    flex-direction: row;
    justify-content: center;
  }

  .completion-actions .btn {
    flex: 1;
  }
}