:root {
  --bg: #fff7df;
  --card: #fff;
  --accent: #ff9f1c;
  --accent-2: #2ec4b6;
  --accent-3: #6c63ff;
  --text: #2d2a32;
  --shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  font-family: "Baloo 2", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: linear-gradient(120deg, #ffd166, #ff9f1c);
  color: #1f1300;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.logo {
  font-size: 1.4rem;
}

.header-actions {
  display: flex;
  gap: 8px;
}

header button {
  font-size: 1.2rem;
  background: rgba(255, 255, 255, 0.85);
  border: none;
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
}

main {
  padding: 12px 12px 32px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#home-screen h1 {
  margin: 8px 0 12px;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.tile {
  background: #fff;
  border: none;
  border-radius: 16px;
  padding: 16px;
  text-align: left;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}

.tile.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tile-emoji {
  font-size: 1.8rem;
}

.tile-title {
  font-size: 1.2rem;
  font-weight: 800;
}

.tile-sub {
  color: #5a5564;
  font-size: 0.95rem;
}

#status {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-weight: 600;
}

#voice-warning {
  color: #c0392b;
}

#category-quick-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

#category-quick {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #ddd;
}

#mode-switcher {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-btn {
  border: none;
  background: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-weight: 700;
}

.mode-btn.active {
  background: var(--accent-2);
  color: #fff;
}

#prompt-area {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

#prompt-word {
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 800;
  padding: 12px 16px;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

#speak-btn {
  font-size: 2rem;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--accent-2);
  color: #fff;
  box-shadow: var(--shadow);
}

#feedback {
  min-height: 28px;
  font-size: 1.4rem;
}

.cards {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 12px;
  text-align: center;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  touch-action: manipulation;
}

.card img {
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
}

.card .label-ja {
  font-size: 1.5rem;
  font-weight: 800;
}
.card.kana .label-ja {
  font-size: 2rem;
}

.card .label-en {
  font-size: 1rem;
  color: #5a5564;
}

.card.dragging {
  opacity: 0.6;
  transform: scale(0.98);
}

.card.correct {
  border: 4px solid #2ec4b6;
}

.card.wrong {
  border: 4px solid #ff595e;
}

#dropzone-section {
  display: flex;
  justify-content: center;
}

.dropzone {
  width: min(90vw, 360px);
  height: 200px;
  border: 4px dashed #555;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  text-align: center;
}

#complete-word-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#complete-word-display {
  background: #fff;
  padding: 16px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.letter-cell {
  width: clamp(64px, 18vw, 96px);
  height: clamp(64px, 18vw, 96px);
  display: grid;
  place-items: center;
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  font-weight: 700;
  border-radius: 14px;
  background: #faf3e7;
  color: var(--text);
  user-select: none;
}

.word-section {
  display: inline-flex;
  align-items: center;
  padding: 10px 18px;
  min-height: clamp(64px, 18vw, 96px);
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  font-weight: 700;
  border-radius: 14px;
  background: #faf3e7;
  color: var(--text);
  user-select: none;
  letter-spacing: 0.04em;
}

.blank-slot {
  background: transparent;
  border: 3px dashed #b3a895;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.choices-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 10px;
}

.choice-chip {
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  font-size: 1.4rem;
  text-align: center;
  box-shadow: var(--shadow);
  touch-action: none;
  cursor: grab;
}

.choice-chip.dragging {
  opacity: 0.85;
  cursor: grabbing;
  pointer-events: none;
  z-index: 1100;
  position: relative;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25);
}

.blank-slot.hover {
  background: rgba(46, 196, 182, 0.18);
  border-color: var(--accent-2);
  transform: scale(1.05);
}

#settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

#settings {
  background: #fff;
  padding: 20px;
  border-radius: 16px;
  width: min(480px, 95vw);
  max-height: 90vh;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

#settings label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

#settings select {
  flex: 1;
  padding: 8px;
  border-radius: 10px;
}

#settings button {
  align-self: flex-end;
  padding: 10px 16px;
  border: none;
  border-radius: 12px;
  background: var(--accent-2);
  color: #fff;
}

.settings-subheader {
  font-weight: 800;
  margin-top: 8px;
}

#image-search {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #ddd;
}

.theme-hint {
  font-size: 0.9rem;
  color: #666;
}

.image-list {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.image-card {
  background: #fafafa;
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 8px;
  display: grid;
  gap: 6px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.image-card .image-preview {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  display: grid;
  place-items: center;
}

.image-card .image-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-card .title {
  font-weight: 700;
  font-size: 0.95rem;
}

.image-card .subtitle {
  color: #555;
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

#alphabet-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 8px 0 24px;
}

.alphabet-card {
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.alphabet-emoji {
  font-size: clamp(5rem, 22vw, 8rem);
  line-height: 1;
}

.alphabet-kana {
  font-size: clamp(5rem, 22vw, 8rem);
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}

.alphabet-example {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

#alphabet-example-word {
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  font-weight: 700;
  color: var(--text);
}

#alphabet-example-romaji {
  font-size: clamp(1rem, 4vw, 1.25rem);
  color: #888;
  font-style: italic;
}

#alphabet-example-en {
  font-size: clamp(1.1rem, 4.5vw, 1.4rem);
  color: var(--text);
}

.alphabet-controls {
  display: flex;
  gap: 18px;
  align-items: center;
}

.alphabet-controls button {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--accent-2, #2ec4b6);
  color: white;
  font-size: 1.6rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.alphabet-controls button:disabled {
  opacity: 0.4;
  cursor: default;
}

#alphabet-progress {
  font-size: 1rem;
  color: #888;
}

#alphabet-quiz-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 8px 0 24px;
}

.quiz-card {
  padding: 24px 16px 18px;
  gap: 8px;
}

.quiz-prompt-text {
  font-size: 1rem;
  color: #777;
  font-weight: 500;
}

.quiz-choices {
  width: 100%;
  max-width: 480px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.quiz-choice {
  background: #fff;
  border: none;
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  font-size: clamp(2.4rem, 12vw, 4rem);
  padding: 22px 6px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
  min-height: 100px;
  line-height: 1;
}

.quiz-choice:active {
  transform: scale(0.95);
}

.quiz-choice.correct {
  background: rgba(46, 196, 182, 0.35);
  animation: quiz-pop 0.4s ease;
}

.quiz-choice.wrong {
  background: rgba(230, 57, 70, 0.25);
  animation: quiz-shake 0.35s ease;
}

@keyframes quiz-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes quiz-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(8px); }
  75% { transform: translateX(-4px); }
}

.quiz-feedback {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  min-height: 1.5em;
  text-align: center;
}

#quiz-progress {
  font-size: 1rem;
  color: #888;
}

#install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 1400;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#install-text {
  font-weight: 600;
  color: var(--text);
  flex: 1;
  font-size: 0.95rem;
}

.install-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

#install-btn {
  background: var(--accent-2, #2ec4b6);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
}

#install-dismiss {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  color: #999;
  cursor: pointer;
  padding: 4px 8px;
}

#image-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.image-modal-content {
  background: #fff;
  border-radius: 14px;
  padding: 16px;
  width: min(420px, 95vw);
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}

.image-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.image-modal-header button {
  border: none;
  background: #f3f3f3;
  border-radius: 8px;
  padding: 6px 10px;
}

.image-modal-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 4px;
  border-radius: 12px;
  background: #fafafa;
}

.modal-photo-wrap {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  border: 1px solid #eee;
}

.modal-photo-wrap.default {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: auto;
  padding: 12px;
  grid-column: 1 / -1;
}

.modal-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.modal-photo-wrap.default .modal-photo {
  width: auto;
  max-width: 60%;
  max-height: 140px;
  object-fit: contain;
}

.modal-photo-note {
  font-size: 0.85rem;
  color: #888;
  margin-top: 6px;
}

.modal-photo-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.image-modal-help {
  font-size: 0.85rem;
  color: #888;
}

.library-help {
  font-size: 0.85rem;
  color: #777;
  line-height: 1.4;
}

.library-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.library-actions button {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-weight: 600;
}

.library-actions .reset {
  background: #ffe9e9;
  border-color: #ffb3b3;
}

.library-status {
  font-size: 0.85rem;
  color: #555;
  font-style: italic;
}

.image-card .image-preview {
  position: relative;
}

.image-thumb.stack-0 {
  object-fit: cover;
  z-index: 2;
  position: relative;
}

.image-thumb.stack-1,
.image-thumb.stack-2 {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.image-thumb.stack-1 {
  transform: rotate(4deg) translate(6px, 4px);
  z-index: 1;
  opacity: 0.65;
}

.image-thumb.stack-2 {
  transform: rotate(-4deg) translate(-6px, 4px);
  z-index: 0;
  opacity: 0.45;
}

.image-modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.image-modal-actions button {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.image-modal-actions .reset {
  background: #ffe9e9;
  border-color: #ffb3b3;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill-btn {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
  font-weight: 600;
}

.pill-btn.active {
  background: var(--accent-2);
  color: #fff;
  border-color: var(--accent-2);
}

#wrong-overlay,
#correct-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 1500;
  animation: feedback-pop 0.7s ease-out forwards;
}

#wrong-overlay {
  background: rgba(230, 57, 70, 0.18);
}

#wrong-overlay svg {
  width: min(70vw, 70vh);
  height: min(70vw, 70vh);
  fill: none;
  stroke: #e63946;
  stroke-width: 16;
  stroke-linecap: round;
  filter: drop-shadow(0 8px 24px rgba(230, 57, 70, 0.5));
}

#correct-overlay {
  background: rgba(46, 196, 182, 0.18);
}

#correct-overlay svg {
  width: min(70vw, 70vh);
  height: min(70vw, 70vh);
  fill: none;
  stroke: #1aa37a;
  stroke-width: 16;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 8px 24px rgba(26, 163, 122, 0.5));
}

#correct-overlay svg circle {
  fill: rgba(46, 196, 182, 0.22);
}

@keyframes feedback-pop {
  0% { opacity: 0; transform: scale(0.6); }
  25% { opacity: 1; transform: scale(1.05); }
  60% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

@media (hover: hover) {
  .card:hover {
    transform: translateY(-2px);
    transition: 0.1s;
  }
}
