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

body {
  font-family: sans-serif;
  background: white;
  color: black;
  padding: 20px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 20px 20px 15px 20px;
  border-bottom: 2px solid black;
  flex-wrap: wrap;
  gap: 10px;
}

.data-controls {
  display: flex;
  gap: 10px;
}

.data-btn {
  padding: 6px 12px;
  background: black;
  color: white;
  border: 1px solid black;
  cursor: pointer;
  font-size: 14px;
}

.data-btn:hover {
  background: #333;
}

#import-file {
  display: none;
}

h1 {
  font-size: 24px;
}

.nav-tabs {
  display: flex;
  gap: 10px;
}

.tab-btn {
  padding: 8px 16px;
  background: white;
  border: 1px solid black;
  cursor: pointer;
  color: black;
}

.tab-btn.active {
  background: black;
  color: white;
}

.page {
  display: none;
  padding: 20px;
}

.page.active {
  display: block;
}

.legend {
  display: flex;
  gap: 15px;
  margin-bottom: 15px;
  padding: 10px;
  border: 1px solid black;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
}

.legend-color {
  width: 20px;
  height: 20px;
  border: 1px solid black;
}

.kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
  gap: 2px;
  border: 1px solid black;
  padding: 10px;
  max-height: 600px;
  overflow-y: auto;
}

.kanji-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  border: 1px solid #ccc;
}

.kanji-cell:hover {
  border: 2px solid black;
}

.kanji-cell.unknown { background: black; color: black; }
.kanji-cell.learning { background: #555; color: black; }
.kanji-cell.familiar { background: #888; color: black; }
.kanji-cell.known { background: #bbb; color: black; }
.kanji-cell.mastered { background: white; color: black; border: 1px solid #ccc; }

/* Legend colors to match grid cells */
.legend-color.unknown { background: black; }
.legend-color.learning { background: #555; }
.legend-color.familiar { background: #888; }
.legend-color.known { background: #bbb; }
.legend-color.mastered { background: white; border: 1px solid #ccc; }

.study-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  margin-bottom: 30px;
  padding: 20px;
  background: transparent;
  transition: all 0.3s ease;
  overflow: hidden;
}

.study-controls.collapsed {
  display: none;
}

#toggle-filters-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: black;
  color: white;
  border: 1px solid black;
  cursor: pointer;
  justify-content: center;
}

#toggle-filters-btn:hover {
  background: #333;
}

#toggle-filters-icon {
  transition: transform 0.3s ease;
  display: inline-block;
}

#toggle-filters-icon.rotated {
  transform: rotate(-90deg);
}

.mobile-study-nav {
  display: none; /* Hidden on desktop */
}

#simple-mode-btn,
#detailed-mode-btn {
  background: white;
  color: black;
  border: 2px solid black;
}

#simple-mode-btn:hover,
#detailed-mode-btn:hover {
  background: #f0f0f0;
}

#simple-mode-btn.active,
#detailed-mode-btn.active {
  background: black;
  color: white;
}

/* Mobile responsive layout */
@media (max-width: 768px) {
  body {
    padding: 0;
    margin: 0;
  }
  
  .container {
    padding: 0;
    margin: 0;
    max-width: 100%;
  }
  
  .page {
    padding: 0;
  }
  
  #study-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }
  
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px;
    flex-shrink: 0;
  }
  
  h1 {
    font-size: 20px;
    text-align: center;
  }
  
  .nav-tabs {
    justify-content: center;
  }
  
  .tab-btn {
    flex: 1;
    padding: 10px;
  }
  
  /* Hide entire header on mobile by default */
  header {
    display: none !important;
  }
  
  /* Show normal header on grid page */
  body:has(#grid-page.active) header {
    display: flex !important;
    flex-direction: column;
  }
  
  /* Show data controls on grid page mobile */
  body:has(#grid-page.active) .data-controls {
    display: flex !important;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  body:has(#grid-page.active) .data-btn {
    font-size: 12px;
    padding: 8px 10px;
  }
  
  /* Mobile nav bar styling - hide by default */
  .mobile-study-nav {
    display: none !important;
  }
  
  /* Only show mobile nav when study page is active */
  #study-page.active .mobile-study-nav {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: black;
    color: white;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  }
  
  .mobile-study-nav button {
    background: transparent;
    color: white;
    border: 1px solid white;
    padding: 10px 16px;
    font-size: 15px;
    cursor: pointer;
    border-radius: 4px;
    min-width: 70px;
  }
  
  .mobile-study-nav button:active {
    background: #333;
  }
  
  /* Add padding to study page for fixed nav only when active */
  #study-page.active {
    padding-top: 50px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  
  #toggle-filters-btn {
    display: none; /* Hide on mobile */
  }
  
  .filter-toggle-wrapper {
    display: none !important; /* Hide entire wrapper on mobile */
  }
  
  .study-controls {
    display: none; /* Hide all filters on mobile */
  }
  
  .legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 8px;
    justify-content: center;
  }
  
  .legend-item {
    justify-content: flex-start;
    font-size: 12px;
  }
  
  .legend-color {
    width: 16px;
    height: 16px;
  }
  
  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 15px;
  }
  
  .stat-card {
    padding: 10px;
  }
  
  .stat-value {
    font-size: 24px;
  }
  
  .stat-label {
    font-size: 11px;
  }
  
  .kanji-grid {
    grid-template-columns: repeat(auto-fill, minmax(35px, 1fr));
    gap: 3px;
    padding: 8px;
    max-height: none;
  }
  
  .kanji-cell {
    font-size: 18px;
  }
  
  #grid-page {
    padding: 10px;
  }
  
  /* Hide mode selection and all toggles on mobile study */
  #study-page .study-card > div:first-child {
    display: none !important; /* Mode buttons container */
  }
  
  /* Show mode buttons in settings when opened */
  #study-page .study-card > div:first-child.mobile-visible {
    display: flex !important;
    margin-bottom: 15px;
  }
  
  #study-page .study-options {
    display: none !important; /* All checkbox toggles */
  }
  
  /* Show toggles when settings are open */
  #study-page .study-options.mobile-visible {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
    margin-bottom: 15px;
  }
  
  #study-page .study-options.mobile-visible label {
    padding: 8px 10px;
    background: #333;
    border: 1px solid #555;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: white;
  }
  
  #study-page .study-options.mobile-visible input[type="checkbox"] {
    width: 18px;
    height: 18px;
  }
  
  .study-card {
    padding: 5px 10px;
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    margin-bottom: 0;
    border: none;
    overflow: hidden;
  }
  
  .session-progress {
    display: none; /* Hidden on mobile - shown in nav bar instead */
  }
  
  .kanji-display {
    font-size: min(20vw, 100px) !important;
    margin: 0;
    line-height: 1;
    flex-shrink: 0;
  }
  
  .context-display {
    font-size: min(5vw, 20px) !important;
    margin: 5px 0;
    flex-shrink: 0;
  }
  
  .kanji-info {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 5px 0;
    min-height: 0;
    overflow: hidden;
  }
  
  .reading {
    font-size: min(5vw, 18px);
    margin: 3px 0;
  }
  
  .meaning {
    font-size: min(4vw, 15px);
    margin: 3px 0;
  }
  
  .examples {
    display: none; /* Hide examples on mobile for simplicity */
  }
  
  .show-answer-btn {
    font-size: min(4vw, 16px);
    padding: min(3vw, 12px);
    margin: 5px 0;
    font-weight: 600;
    flex-shrink: 0;
  }
  
  .rating-buttons {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin: 0;
    flex-shrink: 0;
  }
  
  .rating-btn {
    padding: min(2.5vw, 10px) 2px;
    font-size: min(2.8vw, 11px);
    font-weight: 600;
    line-height: 1.2;
  }
}

@media (max-width: 1024px) and (min-width: 769px) {
  .study-controls {
    grid-template-columns: repeat(2, 1fr);
  }
}

.control-group {
  min-width: 0;
}

.control-group label {
  display: block;
  font-size: 14px;
  margin-bottom: 8px;
  font-weight: 500;
}

select, button {
  width: 100%;
  padding: 8px;
  border: 1px solid black;
  background: white;
  color: black;
  cursor: pointer;
}

button {
  background: black;
  color: white;
}

button:hover {
  background: #333;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.study-card {
  border: 2px solid black;
  padding: 40px 20px;
  text-align: center;
  margin-bottom: 20px;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.study-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 15px 20px;
  margin-bottom: 20px;
}

.study-options label {
  margin: 0 !important;
  white-space: nowrap;
  font-size: 14px;
}

.study-options input[type="checkbox"] {
  margin-right: 5px;
}

.kanji-display {
  font-size: 120px;
  margin-bottom: 20px;
}

.context-display {
  font-size: 32px;
  color: #666;
  margin-top: -10px;
  margin-bottom: 20px;
}

.kanji-info {
  display: none;
}

.kanji-info.visible {
  display: block;
}

.stroke-order {
  font-size: 120px;
  margin-bottom: 20px;
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stroke-order svg {
  width: 200px;
  height: 200px;
  display: block;
}

.reading {
  font-size: 24px;
  margin-bottom: 10px;
}

.meaning {
  font-size: 18px;
  margin-bottom: 20px;
}

.examples {
  text-align: left;
  max-width: 600px;
  margin: 0 auto;
}

.example-item {
  margin-bottom: 15px;
  padding: 10px;
  border-left: 2px solid black;
}

.example-ja {
  font-size: 16px;
  margin-bottom: 5px;
}

.example-en {
  font-size: 14px;
  color: #666;
}

.show-answer-btn {
  max-width: 300px;
}

.rating-buttons {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 20px;
  width: 100%;
  max-width: 600px;
}

.rating-buttons.visible {
  display: grid;
}

.rating-btn {
  padding: 10px;
  border: 2px solid black;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  border: 1px solid black;
  padding: 15px;
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: bold;
  display: block;
}

.stat-label {
  font-size: 12px;
  margin-top: 5px;
}

.no-kanji {
  text-align: center;
  padding: 40px 20px;
}

.drop-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  pointer-events: none;
}

.drop-overlay.active {
  display: flex;
}

.drop-message {
  color: white;
  font-size: 32px;
  font-weight: bold;
  text-align: center;
  padding: 40px;
  border: 4px dashed white;
  border-radius: 10px;
}

.session-progress {
  text-align: center;
  font-size: 14px;
  color: #666;
  margin-bottom: 10px;
}

/* Dark mode styles - invert all colors */
body.dark-mode {
  background: #1a1a1a;
  color: #e0e0e0;
}

body.dark-mode .container {
  background: #2a2a2a;
  border-color: #404040;
}

body.dark-mode .tab-btn {
  background: #2a2a2a;
  color: #e0e0e0;
  border-color: #404040;
}

body.dark-mode .tab-btn.active {
  background: #1a1a1a;
  color: #4a9eff;
  border-bottom-color: #1a1a1a;
}

body.dark-mode .kanji-grid {
  background: #2a2a2a;
}

body.dark-mode .kanji-cell {
  background: #1a1a1a;
  color: #000;
  border-color: #404040;
}

body.dark-mode .kanji-cell:hover {
  border-color: #777;
}

/* Dark mode: All kanji text is black - visibility increases as backgrounds lighten */
body.dark-mode .kanji-cell.unknown { background: black; color: black; }
body.dark-mode .kanji-cell.learning { background: #555; color: black; }
body.dark-mode .kanji-cell.familiar { background: #888; color: black; }
body.dark-mode .kanji-cell.known { background: #bbb; color: black; }
body.dark-mode .kanji-cell.mastered { background: white; color: black; border: 1px solid #444; }

body.dark-mode .study-page {
  background: #2a2a2a;
}

body.dark-mode .study-card {
  background: #333;
  border-color: #404040;
}

body.dark-mode .context-display {
  color: #999;
}

body.dark-mode .show-answer-btn {
  background: #4a9eff;
  color: white;
}

body.dark-mode .show-answer-btn:hover {
  background: #3a8eef;
}

body.dark-mode #toggle-filters-btn {
  background: #404040;
  color: #e0e0e0;
  border-color: #555;
}

body.dark-mode #toggle-filters-btn:hover {
  background: #4a4a4a;
}

body.dark-mode #simple-mode-btn,
body.dark-mode #detailed-mode-btn {
  background: #2a2a2a;
  color: #e0e0e0;
  border-color: #555;
}

body.dark-mode #simple-mode-btn:hover,
body.dark-mode #detailed-mode-btn:hover {
  background: #333;
}

body.dark-mode #simple-mode-btn.active,
body.dark-mode #detailed-mode-btn.active {
  background: #4a9eff;
  color: white;
  border-color: #4a9eff;
}

body.dark-mode .kanji-info {
  background: #333;
  border-color: #404040;
}

body.dark-mode .rating-buttons button {
  background: #404040;
  color: #e0e0e0;
  border-color: #555;
}

body.dark-mode .rating-buttons button:hover {
  background: #4a4a4a;
}

body.dark-mode .example-item {
  border-color: #404040;
}

body.dark-mode select, body.dark-mode input[type="file"] {
  background: #333;
  color: #e0e0e0;
  border-color: #555;
}

body.dark-mode button {
  background: #404040;
  color: #e0e0e0;
  border-color: #555;
}

body.dark-mode button:hover {
  background: #4a4a4a;
}

body.dark-mode .legend {
  background: #333;
  border-color: #404040;
}

body.dark-mode .legend-item {
  border-color: #404040;
}

body.dark-mode #no-kanji {
  color: #999;
}

body.dark-mode .session-progress {
  color: #999;
}

@media (max-width: 768px) {
  body.dark-mode .study-options label {
    background: #333;
    border-color: #555;
    color: #e0e0e0;
  }
}
