/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  background: #f0f4f8;
  min-height: 100vh;
}

/* ===== HEADER ===== */
header {
  background: linear-gradient(135deg, #2c3e50, #3498db);
  color: white;
  padding: 1.25rem 1rem;
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
}

.back-link {
  display: inline-block;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  padding: 0.25rem 0;
  min-height: 44px;
  line-height: 44px;
  transition: color 0.2s;
}

.back-link:hover {
  color: white;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-top: 0.25rem;
}

/* ===== MAIN ===== */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

/* ===== AD UNIT ===== */
.ad-unit {
  margin: 1.25rem 0;
}

/* ===== SECTION CARD ===== */
.section-card {
  background: white;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  margin-bottom: 1rem;
}

/* ===== DECK HEADER ===== */
.deck-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.deck-header h2 {
  flex: 1;
  font-size: 1.1rem;
  color: #2c3e50;
  font-weight: 700;
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: #3498db;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

.btn-primary:hover {
  background: #2980b9;
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: white;
  color: #2c3e50;
  border: 1.5px solid #cdd2d8;
  border-radius: 8px;
  padding: 0.65rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.2s, border-color 0.2s;
  white-space: nowrap;
}

.btn-secondary:hover {
  background: #f8f9fa;
  border-color: #b0b8c1;
}

.btn-ghost {
  background: transparent;
  color: #3498db;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  padding: 0.25rem 0;
  transition: opacity 0.2s;
}

.btn-ghost:hover {
  opacity: 0.7;
}

.btn-sm {
  padding: 0.5rem 0.9rem;
  font-size: 0.875rem;
  min-height: 44px;
}

/* ===== NEW DECK FORM ===== */
.new-deck-form {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.new-deck-form input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  border: 1.5px solid #cdd2d8;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  font-family: inherit;
}

.new-deck-form input:focus {
  outline: none;
  border-color: #3498db;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
}

/* ===== DECK LIST ===== */
.deck-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.deck-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #f8f9fa;
  border: 1.5px solid #e8ecf0;
  border-radius: 10px;
  padding: 0.875rem 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.deck-card:hover {
  border-color: #3498db;
  box-shadow: 0 2px 8px rgba(52, 152, 219, 0.12);
}

.deck-card-info {
  flex: 1;
  min-width: 0;
}

.deck-card-name {
  font-weight: 700;
  font-size: 1rem;
  color: #2c3e50;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.deck-card-meta {
  font-size: 0.8rem;
  color: #666;
  margin-top: 0.15rem;
}

.today-badge {
  display: inline-block;
  background: #e74c3c;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 20px;
  padding: 0.1rem 0.5rem;
  margin-left: 0.4rem;
}

.deck-card-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  color: #888;
}

.btn-icon:hover {
  background: #e8ecf0;
  color: #2c3e50;
}

.btn-icon.btn-delete:hover {
  background: #fdecea;
  color: #e74c3c;
}

.btn-study {
  background: #3498db;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.2s;
  white-space: nowrap;
}

.btn-study:hover {
  background: #2980b9;
}

/* ===== STATS BAR ===== */
.stats-bar-wrapper {
  margin-bottom: 1.25rem;
}

.stats-bar {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  background: #e8ecf0;
  margin-bottom: 0.5rem;
}

.stats-seg {
  height: 100%;
  transition: width 0.4s ease;
}

.seg-new { background: #95a5a6; }
.seg-learning { background: #f39c12; }
.seg-mastered { background: #27ae60; }

.stats-legend {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: #555;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-new { background: #95a5a6; }
.dot-learning { background: #f39c12; }
.dot-mastered { background: #27ae60; }

/* ===== ADD CARD FORM ===== */
.add-card-form {
  background: #f8f9fa;
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.add-card-form h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #2c3e50;
  margin-bottom: 0.75rem;
}

.add-card-form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.25rem;
  margin-top: 0.75rem;
}

.add-card-form label:first-of-type {
  margin-top: 0;
}

textarea {
  width: 100%;
  padding: 0.65rem 0.875rem;
  font-size: 0.95rem;
  border: 1.5px solid #cdd2d8;
  border-radius: 8px;
  font-family: inherit;
  resize: vertical;
  line-height: 1.5;
}

textarea:focus {
  outline: none;
  border-color: #3498db;
}

/* ===== CSV SECTION ===== */
.csv-section {
  border-top: 1px solid #e8ecf0;
  padding-top: 1rem;
  margin-bottom: 1rem;
}

.csv-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #2c3e50;
  margin-bottom: 0.5rem;
}

.csv-hint {
  font-size: 0.82rem;
  color: #777;
  margin-bottom: 0.75rem;
}

.csv-hint code {
  background: #eee;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-family: monospace;
}

.csv-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-file-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: white;
  color: #2c3e50;
  border: 1.5px solid #cdd2d8;
  border-radius: 8px;
  padding: 0.65rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.2s;
}

.btn-file-label:hover {
  background: #f8f9fa;
}

.csv-msg {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
}

.csv-msg.success {
  background: #e8f8f0;
  color: #27ae60;
}

.csv-msg.error {
  background: #fdecea;
  color: #e74c3c;
}

/* ===== CARD LIST ===== */
.card-list-wrapper {
  border-top: 1px solid #e8ecf0;
  padding-top: 1rem;
}

.card-list-wrapper h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #2c3e50;
  margin-bottom: 0.75rem;
}

.badge {
  display: inline-block;
  background: #e8ecf0;
  color: #555;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 20px;
  padding: 0.1rem 0.5rem;
  margin-left: 0.3rem;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 320px;
  overflow-y: auto;
}

.card-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #f8f9fa;
  border: 1px solid #e8ecf0;
  border-radius: 8px;
  padding: 0.6rem 0.875rem;
}

.card-item-texts {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.card-front-preview, .card-back-preview {
  font-size: 0.875rem;
  color: #444;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.card-separator {
  color: #aaa;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.card-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===== STUDY AREA ===== */
.study-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 0.5rem 0;
}

/* ===== FLASHCARD FLIP ===== */
.flashcard {
  width: 100%;
  max-width: 500px;
  height: 200px;
  perspective: 1000px;
  cursor: pointer;
  outline: none;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.flashcard-front, .flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.flashcard-front {
  background: linear-gradient(135deg, #2c3e50, #34495e);
  color: white;
}

.flashcard-back {
  background: linear-gradient(135deg, #27ae60, #229954);
  color: white;
  transform: rotateY(180deg);
}

.card-text {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.4;
  word-break: break-word;
}

.flip-hint {
  position: absolute;
  bottom: 0.75rem;
  font-size: 0.75rem;
  opacity: 0.6;
}

/* ===== REVEAL BUTTON ===== */
.reveal-area {
  width: 100%;
  display: flex;
  justify-content: center;
}

.btn-reveal {
  background: #f39c12;
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0.875rem 2.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  transition: background 0.2s, transform 0.1s;
  width: 100%;
  max-width: 320px;
}

.btn-reveal:hover {
  background: #d68910;
}

.btn-reveal:active {
  transform: scale(0.97);
}

/* ===== RATING AREA ===== */
.rating-area {
  width: 100%;
}

.rating-label {
  text-align: center;
  font-size: 0.875rem;
  color: #666;
  margin-bottom: 0.75rem;
}

.rating-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.btn-rating {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 0.25rem;
  cursor: pointer;
  min-height: 80px;
  font-family: inherit;
  transition: transform 0.1s, filter 0.2s;
}

.btn-rating:active {
  transform: scale(0.95);
}

.btn-again {
  background: #fdecea;
  color: #c0392b;
}

.btn-hard {
  background: #fef9e7;
  color: #d35400;
}

.btn-good {
  background: #e8f4fd;
  color: #1a5276;
}

.btn-easy {
  background: #e8f8f0;
  color: #1e8449;
}

.btn-again:hover { background: #fadbd8; }
.btn-hard:hover { background: #fdebd0; }
.btn-good:hover { background: #d6eaf8; }
.btn-easy:hover { background: #d5f5e3; }

.rating-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.rating-text {
  font-size: 0.85rem;
  font-weight: 700;
}

.rating-sub {
  font-size: 0.72rem;
  opacity: 0.75;
  text-align: center;
}

/* ===== PROGRESS BADGE ===== */
.progress-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: #666;
  background: #e8ecf0;
  border-radius: 20px;
  padding: 0.2rem 0.6rem;
  white-space: nowrap;
}

/* ===== COMPLETE VIEW ===== */
.complete-content {
  text-align: center;
  padding: 1rem 0;
}

.complete-icon {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: 0.75rem;
}

.complete-content h2 {
  font-size: 1.5rem;
  color: #2c3e50;
  margin-bottom: 0.5rem;
}

.complete-msg {
  color: #666;
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.complete-stats {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.c-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.c-stat strong {
  font-size: 1.75rem;
  font-weight: 700;
  color: #2c3e50;
}

.c-stat span {
  font-size: 0.78rem;
  color: #888;
}

.complete-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 320px;
  margin: 0 auto;
}

/* ===== HOWTO SECTION ===== */
.howto-section {
  background: white;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  margin-bottom: 1rem;
}

.howto-section h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #2c3e50;
  margin-bottom: 0.75rem;
  margin-top: 1.25rem;
}

.howto-section h2:first-child {
  margin-top: 0;
}

.howto-section ol {
  padding-left: 1.25rem;
}

.howto-section li {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 0.4rem;
  line-height: 1.6;
}

.howto-section p {
  font-size: 0.9rem;
  color: #555;
  line-height: 1.7;
}

.howto-section code {
  background: #eee;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.88rem;
}

/* ===== FOOTER ===== */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  color: #888;
}

footer a {
  color: #666;
  text-decoration: none;
  transition: color 0.2s;
}

footer a:hover {
  color: #333;
}

/* ===== UTILITY ===== */
.hidden {
  display: none !important;
}

.empty-msg {
  text-align: center;
  color: #aaa;
  font-size: 0.9rem;
  padding: 1.5rem 0;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 640px) {
  header h1 {
    font-size: 1.6rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .section-card {
    padding: 1.75rem;
  }

  .flashcard {
    height: 240px;
  }

  .card-text {
    font-size: 1.5rem;
  }

  .rating-buttons {
    gap: 0.75rem;
  }

  .btn-rating {
    padding: 0.875rem 0.5rem;
    min-height: 88px;
  }

  .rating-text {
    font-size: 0.95rem;
  }
}
