/* Base styles */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  margin: 0;
  padding: 20px;
  background-color: #f5f5f5;
}

#app {
  max-width: 400px;
  margin: 0 auto;
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Mobile styles */
@media (max-width: 768px) {
  body {
    padding: 0;
    background: white;
  }
  
#app {
  max-width: 400px;
  margin: 0 auto;
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: relative;
}
}

/* Case toggles */
#case-toggles {
  display: flex;
  gap: 8px;
  margin-bottom: 100px;
  flex-wrap: wrap;
}

.case-toggle {
  flex: 1;
  min-width: 40px;
  padding: 8px;
  border: 1px solid #d6e7ff;
  border-radius: 5px;
  background-color: #d6e7ff;
  color: #666;
  cursor: pointer;
  font-size: 0.9em;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  touch-action: manipulation;
}

.case-toggle.active {
  background-color: #0381ff;
  color: #ffffff;
  border-color: #0381ff;
}

.case-toggle:hover {
  opacity: 0.9;
}

/* Remove iOS focus styles */
.case-toggle:focus {
  outline: none;
}

/* Prevent iOS active state */
.case-toggle:active {
  background-color: inherit;
}



/* Sentence section */
#sentence {
  font-size: 1.2em;
  margin-bottom: 30px;
  line-height: 1.6;
  word-wrap: break-word;
  min-height: 60px; /* Reserve space for at least 2 lines */
}

.ending {
  width: 3ch;
  text-align: center;
  font-size: 1em;
  padding: 2px;
  margin: 0 2px;
  border: 1px solid #ccc;
  border-radius: 3px;
}

.ending:focus {
  outline: 2px solid #4a90e2;
  border-color: #4a90e2;
}

.correct {
  background: #c8f3c8;
}

.wrong {
  background: #f9c4c4;
}

/* Controls */
#controls {
  margin-bottom: 20px;
}

button {
  padding: 10px;
  width: 100%;
  border: none;
  border-radius: 5px;
  background-color: #4a90e2;
  color: white;
  cursor: pointer;
  font-size: 1em;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/*button:hover {
  background-color: #357abd;
}*/

button:focus {
  outline: 2px solid #2c6ba7;
  outline-offset: 2px;
}

button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

/* Feedback - Fixed height */
#feedback {
  margin-bottom: 20px;
  height: 80px;
  font-weight: bold;
  line-height: 1.6;
  overflow: hidden;
}

#feedback strong {
  font-weight: bold;
  color: #2c6ba7;
}

/* Stats section */


.toggle-btn {
  width: 100%;
  text-align: left;
  background-color: #f0f0f0;
  color: #333;
  font-weight: bold;
  transition: background-color 0.2s;
}



#stats {
  overflow: hidden;
  padding: 10px 0;
}



#stats p {
  margin: 5px 0;
}

#resetBtn {
  background-color: #e74c3c;
  margin-top: 10px;
  width: 100%;
}

#resetBtn:hover {
  background-color: #c0392b;
}


#referenceOverlay #stats-container {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid #eee;
}

#referenceOverlay #stats {
  padding: 10px 0;
}


#referenceBtn {
  background-color: white !important;
  color: #0381ff !important;
  border-color: #0381ff !important;
  font-weight: bold;
  min-width: 40px;
  flex: 0;
}

#referenceBtn:hover {
  background-color: #f5f5f5 !important;
}

#referenceBtn:active {
  background-color: #e5e5e5 !important;
}

/* iOS-specific fix for the reference button */
@supports (-webkit-touch-callout: none) {
  #referenceBtn {
    background-color: white !important;
    color: #0381ff !important;
  }
}

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

/* Endings grid */
#endings-container {
  margin-bottom: 20px;
}

#endings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 10px;
  padding: 10px 0;
}

.ending-option {
  padding: 10px;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 5px;
  text-align: center;
  cursor: pointer;
  font-size: 1.1em;
  user-select: none;
  transition: all 0.2s;
}

.ending-option:hover {
  background-color: #e0e0e0;
}

.ending-option:active {
  transform: scale(0.95);
}

.ending-option.selected {
  background-color: #4a90e2;
  color: white;
  border-color: #357abd;
}

.ending-slot {
  display: inline-block;
  min-width: 3ch;
  width: 3ch;
  padding: 2px 4px;
  margin: 0 2px;
  border: 1px solid #ccc;
  border-radius: 3px;
  background-color: white;
  text-align: center;
  height: 1.5em;
  line-height: 1.5em;
  cursor: default; /* Explicitly set default cursor for all slots initially */
}

.ending-slot.active {
  border: 2px solid #4a90e2;
  outline: none;
}

.ending-slot.correct {
  background: #c8f3c8;
}

.ending-slot.wrong {
  background: #f9c4c4;
}

.ending-slot.filled {
  cursor: pointer; /* Make ONLY filled slots appear clickable */
}

.ending-slot.filled:hover {
  background-color: #f0f0f0;
}

.feedback-display {
  padding: 15px;
  font-weight: bold;
  line-height: 1.6;
  text-align: left;
  background-color: #f5f5f5;
  border-radius: 5px;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.feedback-display span {
  font-weight: normal;
}

.feedback-display strong {
  display: inline;
  font-weight: bold;
}

.feedback-display div {
  margin: 0;
  padding: 0;
}


/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
  .case-toggle {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0) !important;
  }
  
  .case-toggle:active {
    opacity: 1 !important;
  }
  
.case-toggle.active {
  background-color: #0381ff !important;  
  color: white !important;
}
  
  .case-toggle:not(.active) {
  background-color: #d6e7ff !important; 
  color: #666 !important;
  }
}

/* Reference Tables Overlay */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  overflow-y: auto;
  padding: 20px;
  box-sizing: border-box;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  background: white;
  border-radius: 8px;
  max-width: 800px;
  margin: 20px auto;
  padding: 20px;
  position: relative;
}

.close-btn {
  position: absolute;
  right: 10px;
  top: 10px;
  font-size: 24px;
  background: none;
  border: none;
  cursor: pointer;
  width: 30px;
  height: 30px;
  padding: 0;
  line-height: 1;
  color: #666;
}

.close-btn:hover {
  color: #000;
}

.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  border-bottom: 2px solid #eee;
  padding-bottom: 10px;
}

.tab {
  padding: 8px 16px;
  background: #f0f0f0;
  border: none;
  border-radius: 5px 5px 0 0;
  cursor: pointer;
  font-size: 1em;
  width: auto;
}

.tab.active {
  background: #4a90e2;
  color: white;
}

.tab:hover:not(.active) {
  background: #e0e0e0;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.reference-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

.reference-table th,
.reference-table td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: center;
}

.reference-table th {
  background-color: #f5f5f5;
  font-weight: bold;
}

.reference-table tr:hover {
  background-color: #f9f9f9;
}

.note {
  font-style: italic;
  color: #666;
  margin-top: 10px;
}

/* Article Trainer specific styles */
h1 {
  font-size: 1.5em;
  text-align: center;
  margin-bottom: 30px;
  color: #333;
}

#articles-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 15px;
  margin: 20px 0;
}

.article-option {
  padding: 15px;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 5px;
  text-align: center;
  cursor: pointer;
  font-size: 1.2em;
  font-weight: bold;
  user-select: none;
  transition: all 0.2s;
}

.article-option:hover {
  background-color: #e0e0e0;
}

.article-option:active {
  transform: scale(0.95);
}

.article-option.selected {
  background-color: #4a90e2;
  color: white;
  border-color: #357abd;
}

.article-slot {
  display: inline-block;
  min-width: 3ch;
  width: auto;
  padding: 2px 8px;
  margin: 0 2px;
  border: 1px solid #ccc;
  border-radius: 3px;
  background-color: white;
  text-align: center;
  height: 1.5em;
  line-height: 1.5em;
  font-weight: bold;
}

.article-slot.filled {
  background-color: #f0f0f0;
  min-width: 3ch;
  width: auto;
}

.article-slot.correct {
  background: #c8f3c8;
  border-color: #28a745;
}

.article-slot.wrong {
  background: #f9c4c4;
  border-color: #dc3545;
}

.reference-btn {
  display: block;
  width: auto;
  max-width: 200px;
  margin: 15px auto;
  background-color: white !important;
  color: #0381ff !important;
  border: 1px solid #0381ff !important;
  border-radius: 5px;
  font-weight: bold;
  cursor: pointer;
}

#sentence {
  font-size: 1.3em;
  margin: 30px 0;
  line-height: 1.6;
  min-height: 60px;
  text-align: center;
}

#articles-container {
  height: 130px;
  margin-bottom: 20px;
}

.feedback-display {
  height: 130px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0;
}

#articles-grid {
  height: 130px;
  margin: 30px 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 15px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .overlay {
    padding: 10px;
  }
  
  .overlay-content {
    margin: 10px;
    padding: 15px;
  }
  
  .tabs {
    flex-wrap: wrap;
  }
  
  .tab {
    flex: 1 1 auto;
    min-width: 100px;
  }
  
  .reference-table {
    font-size: 0.9em;
  }
  
  .reference-table th,
  .reference-table td {
    padding: 6px;
  }
}