* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #dce8f0;
  min-height: 100vh;
}
.header {
  background: #4a7fba;
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.header .back {
  color: white;
  text-decoration: none;
  font-size: 17px;
}
.header h1 {
  font-size: 18px;
  font-weight: 600;
}
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 16px;
}
.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}
.tile {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 28px 16px;
  text-align: center;
  text-decoration: none;
  color: #222;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.1s;
}
.tile:active {
  transform: scale(0.97);
}
.tile.highlight {
  background: #fef9e7;
}
.tile-icon {
  font-size: 52px;
  line-height: 1;
}
.tile-label {
  font-size: 15px;
  font-weight: 500;
  color: #333;
}
.offline-panel {
  margin-top: 18px;
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.offline-panel p {
  font-size: 14px;
  color: #444;
  line-height: 1.45;
}
.offline-btn {
  margin-top: 10px;
  background: #4a7fba;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.offline-btn:disabled {
  opacity: 0.65;
  cursor: default;
}
.offline-status {
  font-size: 12px;
  color: #777;
  margin-top: 8px;
}
select,
input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ccd;
  border-radius: 8px;
  font-size: 15px;
  background: white;
  margin-bottom: 12px;
}
.card-box {
  background: white;
  border-radius: 14px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 32px 20px;
  text-align: center;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 16px 0;
}
.card-native {
  font-size: 40px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #111;
}
.card-romanization {
  font-size: 18px;
  color: #666;
  margin-bottom: 8px;
}
.card-english {
  font-size: 22px;
  font-weight: 600;
  color: #2a5fa8;
  margin-bottom: 12px;
}
.card-example {
  font-size: 14px;
  color: #555;
  margin-bottom: 6px;
}
.card-notes {
  font-size: 13px;
  color: #888;
  font-style: italic;
}
.btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 12px 0;
}
.btn {
  padding: 10px 22px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary {
  background: #4a7fba;
  color: white;
}
.btn-success {
  background: #28a745;
  color: white;
}
.btn-danger {
  background: #dc3545;
  color: white;
}
.btn-secondary {
  background: #e0e0e0;
  color: #333;
}
.progress-bar {
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  margin: 12px 0;
}
.progress-fill {
  height: 100%;
  background: #28a745;
  border-radius: 3px;
  transition: width 0.3s;
}
.counter {
  text-align: center;
  color: #666;
  font-size: 14px;
  margin-bottom: 8px;
}
.glossary-item {
  background: white;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.glossary-item .native {
  font-size: 20px;
  font-weight: 700;
  color: #111;
}
.glossary-item .romanization {
  font-size: 13px;
  color: #888;
}
.glossary-item .english {
  font-size: 15px;
  color: #2a5fa8;
  font-weight: 500;
}
.glossary-item .details {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #eee;
  font-size: 13px;
  color: #555;
}
.glossary-item.open .details {
  display: block;
}
.result-count {
  font-size: 13px;
  color: #888;
  margin-bottom: 10px;
}
.audio-placeholder {
  text-align: center;
  padding: 40px 20px;
}
.audio-icon {
  font-size: 80px;
  margin-bottom: 16px;
}
.audio-placeholder h2 {
  font-size: 22px;
  color: #333;
  margin-bottom: 10px;
}
.audio-placeholder p {
  color: #666;
  font-size: 15px;
  line-height: 1.6;
}
.details-section {
  background: white;
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 14px;
}
.details-section h2 {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 10px;
}
.part-list {
  list-style: none;
}
.part-list li {
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
  color: #444;
  display: flex;
  justify-content: space-between;
}
.part-list li:last-child {
  border-bottom: none;
}

/* Quiz */
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}
.quiz-option {
  background: white;
  border: 2px solid #ddd;
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 16px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  width: 100%;
}
.quiz-option:hover {
  border-color: #4a7fba;
  background: #f0f6ff;
}
.quiz-option.correct {
  border-color: #28a745 !important;
  background: #d4edda !important;
}
.quiz-option.wrong {
  border-color: #dc3545 !important;
  background: #f8d7da !important;
}
.quiz-question {
  font-size: 30px;
  font-weight: 700;
  text-align: center;
  margin: 16px 0;
  color: #111;
  line-height: 1.3;
}
.quiz-sub {
  font-size: 14px;
  color: #888;
  text-align: center;
  margin-bottom: 4px;
}
.score-card {
  background: white;
  border-radius: 14px;
  padding: 32px 20px;
  text-align: center;
  margin-top: 16px;
}
.score-big {
  font-size: 64px;
  font-weight: 700;
  color: #4a7fba;
}
.score-label {
  font-size: 16px;
  color: #666;
  margin-top: 6px;
}
.wrong-item {
  background: white;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 8px;
  border-left: 4px solid #dc3545;
}
.wrong-item .wi-native {
  font-size: 20px;
  font-weight: 700;
  color: #111;
}
.wrong-item .wi-correct {
  font-size: 14px;
  color: #28a745;
  margin-top: 4px;
}
/* SRS */
.srs-btns {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.btn-again {
  background: #dc3545;
  color: white;
  font-size: 13px;
}
.btn-hard {
  background: #fd7e14;
  color: white;
  font-size: 13px;
}
.btn-good {
  background: #4a7fba;
  color: white;
  font-size: 13px;
}
.btn-easy {
  background: #28a745;
  color: white;
  font-size: 13px;
}
.srs-info {
  text-align: center;
  font-size: 13px;
  color: #888;
  margin: 6px 0;
}
.mode-toggle {
  display: flex;
  border: 1px solid #4a7fba;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
}
.mode-toggle button {
  flex: 1;
  padding: 8px;
  border: none;
  background: white;
  color: #4a7fba;
  font-size: 14px;
  cursor: pointer;
}
.mode-toggle button.active {
  background: #4a7fba;
  color: white;
}
/* Writing practice */
.writing-wrap {
  background: white;
  border-radius: 14px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  margin: 12px 0;
}
#writingCanvas {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  border: 1px solid #eee;
  border-radius: 8px;
  touch-action: none;
  cursor: crosshair;
  display: block;
  margin: 0 auto;
}
.char-ref {
  font-size: 52px;
  text-align: center;
  color: #333;
  margin: 8px 0;
  line-height: 1.3;
  word-break: keep-all;
}
/* Situation finder */
.situation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.situation-card {
  background: white;
  border-radius: 12px;
  padding: 16px 12px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  text-align: center;
  transition: transform 0.1s;
}
.situation-card:active {
  transform: scale(0.97);
}
.s-icon {
  font-size: 34px;
  margin-bottom: 6px;
}
.s-name {
  font-size: 13px;
  font-weight: 600;
  color: #333;
  line-height: 1.3;
}
.s-count {
  font-size: 11px;
  color: #aaa;
  margin-top: 3px;
}
/* Glossary */
.glossary-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #dce8f0;
  padding-bottom: 8px;
  margin: -4px 0 12px;
}
.glossary-toolbar input[type="text"] {
  margin-bottom: 8px;
}
.glossary-subtitle {
  font-size: 13px;
  color: #666;
  margin-bottom: 12px;
  line-height: 1.4;
}
.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar {
  display: none;
}
.chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border: 1px solid #ccd;
  border-radius: 999px;
  background: white;
  color: #444;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.chip.active {
  background: #4a7fba;
  border-color: #4a7fba;
  color: white;
}
.glossary-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
@media (min-width: 720px) {
  .glossary-list.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
}
.glossary-row {
  background: white;
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.glossary-row-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.glossary-row-main {
  flex: 1;
  min-width: 0;
}
.glossary-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: flex-start;
}
.glossary-row .native {
  font-size: 20px;
  font-weight: 700;
  color: #111;
  line-height: 1.2;
}
.glossary-row .romanization {
  font-size: 12px;
  color: #888;
  margin-top: 1px;
}
.glossary-row .english {
  font-size: 14px;
  color: #333;
  font-weight: 500;
  margin-top: 2px;
}
.glossary-audio-btn {
  min-width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: #4a7fba;
  color: white;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.glossary-audio-btn.playing {
  background: #28a745;
}
.glossary-audio-btn.missing {
  background: #e8e8e8;
  color: #aaa;
  cursor: default;
}
.glossary-expand-btn {
  min-width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: white;
  color: #666;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s;
}
.glossary-expand-btn.open {
  transform: rotate(180deg);
  border-color: #4a7fba;
  color: #4a7fba;
}
.glossary-row-details {
  display: none;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #eee;
  font-size: 13px;
  color: #555;
  line-height: 1.5;
}
.glossary-row.open .glossary-row-details {
  display: block;
}
.glossary-row-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.part-badge {
  font-size: 11px;
  color: #4a7fba;
  background: #e8f4fd;
  padding: 2px 8px;
  border-radius: 999px;
}
.glossary-study-link {
  font-size: 12px;
  color: #4a7fba;
  font-weight: 600;
  text-decoration: none;
}
.glossary-study-link:hover {
  text-decoration: underline;
}
.glossary-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 16px 0 8px;
}
.glossary-pagination button {
  padding: 8px 16px;
  border: 1px solid #ccd;
  border-radius: 8px;
  background: white;
  font-size: 14px;
  cursor: pointer;
}
.glossary-pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}
.glossary-pagination span {
  font-size: 13px;
  color: #666;
  text-align: center;
}
.glossary-empty {
  text-align: center;
  color: #888;
  padding: 32px 16px;
  font-size: 14px;
  line-height: 1.6;
}
/* Responsive layout */
@media (min-width: 768px) {
  .container {
    max-width: 960px;
  }
  .tile-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .situation-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  #writingCanvas {
    aspect-ratio: 3 / 2;
  }
}
@media (min-width: 1100px) {
  .container {
    max-width: 1100px;
  }
  .tile-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .situation-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .glossary-list.two-col {
    grid-template-columns: repeat(3, 1fr);
  }
  #writingCanvas {
    aspect-ratio: 16 / 9;
  }
}
