/***************************** Variables. *************************************/

:root {
  --primary: #2c5aa0;
  --accent: #e67e22;
  --text: #333;
  --light: #f8f9fa;
  --border: #ddd;
  --success: #d4edda;
  --error: #f8d7da;
  --status-info: #3498db;
}

/***************************** Base styling. **********************************/

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: #f5f5f5;
  line-height: 1.5;
}

/***************************** Layout. ****************************************/

.banner {
  background: var(--primary);
  color: white;
  padding: 0.5rem 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.site-name {
  font-size: 1.8rem;
  font-weight: bold;
  text-decoration: none;
  color: white;
}

.content {
  max-width: 1000px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.5rem;
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 600;
  background: white;
  border: 2px solid var(--primary);
  color: var(--primary);
  border-radius: 8px;
  transition: all 0.2s;
  min-height: 20px;
}

.control-btn:hover {
  background: var(--primary);
  color: white;
}

.control-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.progress-section h2 {
  margin-bottom: 1rem;
  color: var(--primary);
}

.stroke-diagram {
}

.stroke-diagram svg {
  width: 200px;
  height: 200px;
  max-width: 100%;
  max-height: 100%;
}

/***************************** Components. ************************************/

/** Table. */
.zairyou-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  overflow: hidden;
}

.zairyou-table th,
.zairyou-table td {
  padding: 0.75rem 0.6rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.zairyou-table th {
  background: #f1f3f5;
  font-weight: 600;
  font-size: 0.95rem;
  color: #444;
}

.zairyou-table tr:last-child td {
  border-bottom: none;
}

/** Status bar. */
.status-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 0.9rem 1.2rem;
  margin: 0 auto 1.5rem;
  border-radius: 6px;
  font-weight: 500;
  display: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  width: 100%;
  align-items: center;
  justify-content: space-between;
  background: white;
}

.status-bar.show {
  display: flex;
}

.status-bar.success {
  background-color: var(--success);
}

.status-bar.error {
  background-color: var(--error);
}

.status-bar.info {
  color: var(--status-info);
}

.status-bar-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  font-weight: bold;
  cursor: pointer;
  padding: 0 0.4rem;
  opacity: 0.5;
}

.status-bar-close:hover {
  opacity: 1;
}

/** Reactive styling. */
.table-wide-only { display: table; }
.table-narrow-only { display: none; }

@media (max-width: 720px) {
  .table-wide-only { display: none; }
  .table-narrow-only { display: table; }
}

/***************************** Page-specific. *********************************/

/** Kanji and Radicals. */

.kanji-glyph {
  font-size: 2.2rem;
  font-weight: bold;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
}

.kanji-glyph:hover {
  background: #eef;
}

.view-toggle {
  margin: 1.5rem 0;
  display: flex;
  gap: 0.5rem;
}

.view-toggle button {
  padding: 0.7rem 1.4rem;
  border: 2px solid #ddd;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.view-toggle button.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.view-toggle button:hover:not(.active) {
  border-color: var(--primary);
  background: #f8f9fa;
}

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

.filter-controls input[type="text"] {
  flex: 1;
  min-width: 280px;
  padding: 0.7rem 1rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
}

.filter-controls select {
  padding: 0.7rem 1rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
  background: white;
  min-width: 160px;
}

.filter-controls input:focus,
.filter-controls select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.2);
}

.filter-controls label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
  white-space: nowrap;
  cursor: pointer;
}

.filter-controls input[type="checkbox"] {
  accent-color: var(--primary);
}

/** Learn. */

.learn-options {
  margin-bottom: 2rem;
}

#recommended-grid .kanji-item {
  cursor: default;
  border-color: #bbb;
  background: #f1f3f5;
  box-shadow: none;
}

#recommended-grid .kanji-item:hover {
  transform: none;
}

#all-unlearned-grid .kanji-item {
  cursor: pointer;
}

#all-unlearned-grid .kanji-item:hover {
  border-color: var(--primary);
  transform: scale(1.08);
  background: #f0f7ff;
}

.recommended-section,
.manual-section {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  margin-bottom: 2rem;
}

.recommended-section button {
  padding: 0.6rem 1.2rem;
}

.kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 12px;
  margin: 1.5rem 0;
}

.kanji-grid.large-grid {
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
}

.kanji-item {
  aspect-ratio: 1/1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: bold;
  background: #f8f9fa;
  border: 2px solid #ddd;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.kanji-item:hover {
  border-color: var(--primary);
  transform: scale(1.08);
}

.kanji-item.selected {
  background: #e3f2fd;
  border-color: #2196f3;
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
}

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

.selection-controls button {
  padding: 0.6rem 1.2rem;
}

.batch-desc {
  font-size: 1.05rem;
  color: #555;
  margin-bottom: 1rem;
}

@media (max-width: 720px) {
  .kanji-grid {
    grid-template-columns: repeat(auto-fill, minmax(55px, 1fr));
  }

  .kanji-grid.large-grid {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  }
}

/** Review. */

.review-page {
  max-width: 700px;
}

.review-card {
  background: white;
  padding: 2.5rem 2rem;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  text-align: center;
  min-height: 380px;
  margin-bottom: 2rem;
}

.item-info {
  margin-top: 1.5rem;
  padding: 0.25rem 1rem;
  background: #f8f9fa;
  border-radius: 8px;
  text-align: left;
  display: none; /* Hide, initially. */
}

.huge-kanji {
  font-size: 7.5rem;
  font-weight: bold;
  line-height: 1;
  margin-bottom: 2rem;
}

#prompt {
  font-size: 1.4rem;
  margin-bottom: 1.5rem;
  color: #444;
  font-weight: 500;
}

#answer-input {
  width: 100%;
  max-width: 420px;
  padding: 1rem 1.2rem;
  font-size: 1.3rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  text-align: center;
}

#answer-input.correct {
  background-color: var(--success);
  border-color: #27ae60;
}

#answer-input.incorrect {
  background-color: var(--error);
  border-color: #e74c3c;
}

#answer-input.suspended {
  background-color: #8ccdff;
}

#answer-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.2);
}

.review-controls {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.review-controls button {
  padding: 0.8rem 0.8rem;
  font-size: 1rem;
  border-radius: 6px;
  min-width: auto;
  flex: 1 1 160px;
  max-width: 120px;
}

.review-controls button.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.review-controls button.suspended {
  background-color: #8ccdff;
}

@media (max-width: 720px) {
  .review-controls {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .review-controls button {
    flex: 1 1 auto;
    max-width: none;
  }
}

#review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

/** Settings. */

.settings-section {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  margin-bottom: 2rem;
}

.settings-section h2 {
  margin-top: 0;
  color: var(--primary);
  border-bottom: 2px solid #eee;
  padding-bottom: 0.5rem;
}

.form-group {
  margin-bottom: 1.2rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  color: #444;
}

.form-group input {
  width: 100%;
  max-width: 500px;
  padding: 0.7rem 0.9rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
}

.form-group small {
  display: block;
  margin-top: 0.4rem;
  color: #666;
  font-size: 0.9rem;
}

.form-group select {
  width: 100%;
  max-width: 500px;
  padding: 0.7rem 0.9rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
  background-color: white;
}

.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.2);
}

.actions {
  margin: 1.5rem 0;
}

.actions button {
  padding: 0.8rem 1.5rem;
  margin-right: 1rem;
  font-size: 1rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.actions button:hover {
  background: #1e4a85;
}

#btn-save-settings {
  padding: 0.9rem 2rem;
  font-size: 1.1rem;
  background: #27ae60;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

#btn-save-settings:hover {
  background: #219653;
}

/** Editor. */

.kanji-editor-grid {
  display: grid;
  grid-template-columns: 1fr; /* one column */
  gap: 1.2rem;
}

.kanji-edit-row {
  background: white;
  padding: 1.2rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: grid;
  grid-template-columns: 80px 1fr 1fr 1fr;
  gap: 1rem;
  align-items: center;
}

.kanji-literal {
  font-size: 3rem;
  font-weight: bold;
  text-align: center;
  padding: 0.5rem;
  background: #f8f9fa;
  border-radius: 10px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kanji-edit-row input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
  box-sizing: border-box;
}

.kanji-edit-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.2);
}

.actions {
  margin-bottom: 2rem;
}

/***************************** Responsive adjustments. ************************/

@media (max-width: 720px) {
  .controls {
    flex-direction: column;
  }
  .control-btn {
    min-width: auto;
  }
}
