/* General Styles */
:root {
  --primary-color: #4a90e2;
  --secondary-color: #f5f6fa;
  --text-color: #2c3e50;
  --border-color: #dcdde1;
  --success-color: #27ae60;
  --danger-color: #e74c3c;
}

body {
  font-family: "Meiryo UI", "Segoe UI", Arial, sans-serif;
  line-height: 1.6;
  margin: 0;
  padding: 0;
  background-color: #f0f2f5;
  color: var(--text-color);
  font-size: 14px;
}

/* Utility for screen-reader-only text */
.visually-hidden {
  position: absolute !important;
  height: 1px; width: 1px;
  overflow: hidden; clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

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

/* Header Styles */
header {
  background-color: white;
  padding: 12px;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin-bottom: 10px;
}

.table-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 10px;
  padding: 10px;
  background-color: var(--secondary-color);
  border-radius: 8px;
}

.control-row {
  display: flex;
  justify-content: start;
  align-items: center;
  margin-top: 10px;
  padding: 6px;
  background-color: var(--secondary-color);
  border-radius: 8px;
	gap: 10px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.header-top > h1 {
  line-height: 1;
  font-size: 28px;
}

.footer-text {
	text-align: center;
	font-size: 16px;
	padding: 20px
}

.logo {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
}

h1 {
  text-align: center;
  color: var(--primary-color);
  margin-bottom: 20px;
}

h2 {
  color: var(--text-color);
  margin-bottom: 10px;
  text-align: center;
}

.stats {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 15px;
	font-weight: bold;
}

.stat-box {
  background-color: var(--secondary-color);
  padding: 6px;
  border-radius: 8px;
  flex: 1;
  /* min-width: 200px; */
  text-align: center;
  font-size: 16px;
}

.controls {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 15px;
  position: relative;
}

.select-wrapper {
  display: flex;
  align-items: center;
  gap: 5px;
}

.search-input {
  position: relative;
  display: flex;
  align-items: center;
	flex-basis: 100%;
}

.search-input input[type="search"] {
  padding: 9px 33px 9px 32px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  min-width: 400px;
}

/* Hide native browser search clear buttons so only the custom clear (X) is shown */
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
  display: none;
}
input[type="search"]::-ms-clear,
input[type="search"]::-ms-reveal {
  display: none;
  width: 0;
  height: 0;
}
input[type="search"] {
  -webkit-appearance: textfield;
  appearance: textfield;
}

.search-input .search-btn {
  position: absolute;
  left: 0px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
}

.search-clear {
  position: absolute;
  right: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 18px;
}

.search-spinner {
  position: absolute;
  right: 54px;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-top: 2px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.results-wrapper {
  margin-right: 12px;
  font-size: 14px;
  color: var(--text-color);
}

mark {
  background-color: #ffd54f;
  padding: 0 2px;
  border-radius: 2px;
}

/* highlight animation */
mark {
  display: inline-block;
  animation: highlight-pop 300ms ease-out;
}

@keyframes highlight-pop {
  0% {
    transform: scale(0.98);
    opacity: 0;
  }
  60% {
    transform: scale(1.03);
    opacity: 0.95;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.select-wrapper > label {
  font-weight: bold;
}

.right-align {
  margin-left: auto;
}

.btn-danger {
  background-color: var(--danger-color);
  color: white;
  padding: 8px 16px;
}

.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 5px;
}

.checkbox-wrapper input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.checkbox-wrapper > label {
  cursor: pointer;
  user-select: none;
}

.learned-words-controls {
  display: flex;
  align-items: center;
  gap: 15px;
}

.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 5px;
}

.checkbox-wrapper input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.checkbox-wrapper label {
  cursor: pointer;
  user-select: none;
}

.btn-danger {
  background-color: var(--danger-color);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-danger:hover {
  background-color: #c0392b;
}

.btn-danger:active {
  transform: translateY(1px);
}

select {
  padding: 6px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  font-size: 14px;
  min-width: 120px;
	width: 100%;
}

/* Column Toggles */
.column-toggles {
  display: flex;
  align-items: center;
  gap: 10px;
}

.column-toggles > label {
  font-weight: bold;
}

.toggle-group {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

/* Font Size Control */
.font-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.font-controls > label {
  font-weight: bold;
}

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

.learned-words-controls > label {
  font-weight: bold;
}

/* Checkbox Design */
.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Table Styles */
table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background-color: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

th,
td {
  padding: 4px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);

  /* overflow: hidden;
  text-overflow: ellipsis; */
  white-space: nowrap;
}

th {
  padding: 10px;
}

/* Column widths */
th:nth-child(1),
td:nth-child(1) {
  /* Serial No. */
  width: 50px;
}

th:nth-child(2),
td:nth-child(2) {
  /* Word */
  width: 12%;
}

th:nth-child(3),
td:nth-child(3) {
  /* Furigana */
  width: 15%;
}

th:nth-child(4),
td:nth-child(4) {
  /* Romaji */
  width: 15%;
}

th:nth-child(5),
td:nth-child(5) {
  /* Meaning */
  width: 43%;
  word-break: normal;
  white-space: normal;
}

th:nth-child(6),
td:nth-child(6) {
  /* Actions */
  width: 100px;
}

th {
  background-color: var(--primary-color);
  color: white;
  font-weight: 500;
}

tr:hover {
  background-color: var(--secondary-color);
}

/* Action Buttons */
.action-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.btn {
  padding: 3px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  transition: opacity 0.2s;
}

.btn:hover {
  opacity: 0.8;
}

.btn-check {
  color: var(--success-color);
  background: none;
}

.btn-x {
  color: var(--danger-color);
  background: none;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 10px 0;
  justify-content: space-between; /* results left, controls right */
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pagination button {
  padding: 5px;
  min-width: 60px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.pagination button:disabled {
  background-color: var(--border-color);
  cursor: not-allowed;
}

.pagination button:hover:not(:disabled) {
  background-color: #357abd;
}

/* Hide/Show Columns */
.hidden {
  display: none;
}

#currentPageInput {
  width: 50px;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid lightgray;
}

legend {
	font-weight: bold;
}

/* Responsive Design */
@media (max-width: 480px) {
  .control-row {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }
  .toggle-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }
  .toggle-group > label {
    flex: 1 0 48%;
  }
  .column-toggles > label {
    font-weight: bold;
    font-size: 14px;
    white-space: nowrap;
  }
  .stats,
  .controls {
    flex-direction: column;
  }

  .table-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .select-wrapper {
    width: 100%;
  }

  .search-input input[type="search"] {
    min-width: auto;
    width: 100%;
  }

  .search-input .search-btn {
    left: 0px;
  }
  .search-clear {
    right: 36px;
  }
  .search-spinner {
    right: 64px;
  }

  .results-wrapper {
    margin: 8px 0;
  }

  .page-controls {
    justify-content: flex-end;
    width: 100%;
  }

  .pagination {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .stat-box {
    width: 100%;
  }

  table {
    display: block;
    overflow-x: auto;
  }

  th,
  td {
    min-width: 120px;
    white-space: normal;
  }
}

@media (max-width: 768px) {
  .header-top > h1 {
    font-size: 18px;
  }
  .stats,
  .controls {
    flex-direction: column;
    gap: 8px;
  }

  .table-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .select-wrapper {
    width: 100%;
  }

  .search-input input[type="search"] {
    min-width: auto;
    width: 100%;
  }

  /* .search-input .search-btn {
    right: 8px;
  } */
  .search-clear {
    right: 4px;
  }
  .search-spinner {
    right: 32px;
  }

  .results-wrapper {
    margin: 8px 0;
  }

  .page-controls {
    justify-content: center;
    width: 100%;
  }

  .pagination {
    flex-direction: column;
    gap: 10px;
    align-items: center;
  }

  .stat-box {
    width: 97%;
  }

  table {
    display: block;
    overflow-x: auto;
  }

  th,
  td {
    min-width: 120px;
    white-space: normal;
  }
}
