body {
  font-family: sans-serif;
  /* Reserve default safe space for bottom banner to avoid initial overlap. JS will update this variable to the exact height. */
  --bottom-banner-height: 56px;
  /* Push content up so bottom banner won't overlap content; individual components maintain spacing. */
  padding: 1rem 1rem calc(var(--bottom-banner-height)) 1rem;
  background: #f0f4f8;
}

h1 {
  text-align: left;
  margin: 0;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  /* header sits naturally below the body padding (no extra margin needed) */
  margin-top: 0;
}

.header-left h1 {
  font-size: 1.6rem;
}

.user-area {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* Make the Google Sign-In button container narrower so the displayed button appears shorter. */
#g_id_button {
  width: 140px; /* desired visible width */
  height: 40px; /* match typical button height */
  overflow: hidden;
  display: inline-block;
}

/* The Google button renders inside an iframe; scale it down slightly to fit narrower container.
   We target the iframe using a descendant selector; note this is best-effort because iframe contents
   are cross-origin. Scaling the iframe element itself reduces visible size. */
#g_id_button iframe {
  transform-origin: left center;
  transform: scale(0.85);
  height: 48px; /* keep native height so scale looks correct */
}


.user-icon {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #e0e0e0;
  font-size: 18px;
}

.signout {
  background: transparent;
  color: #007bff;
  border: 1px solid #007bff;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
}

.signout:hover {
  background: #007bff;
  color: #fff;
}

.word-header {
  display: flex;
  align-items: center;
  gap: 30px; /* 要素間の余白 */
}

.word-header h2 {
  font-size: 1.7rem; /* 文字を大きくする */
  margin: 0;        /* 不要な余白を消す */
}

.word-card {
  background: rgb(255, 255, 255);
  padding: 1rem;
  margin: 1rem 0;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Virtualized list container: scrollable area */
#word-container {
  max-height: 75vh;
  overflow-y: auto;
}

button {
  background: #007bff;
  color: rgb(253, 253, 253);
  border: none;
  padding: 0.5rem 1rem;
  margin-top: 0.5rem;
  border-radius: 4px;
}

.meaning {
  transition: all 0.3s ease;
}

#progress-bar-container {
  margin: 1rem 0;
}

#progress-bar {
  width: 100%;
  height: 20px;
  background: #ddd;
  border-radius: 10px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  width: 0%;
  transition: width 0.3s ease, background-color 0.3s ease;
  background-color: red; /* 初期色（0%） */
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

form input, form button {
  padding: 0.5rem;
  font-size: 1rem;
}

/* Sticky header: filter controls (top) and nav (below it) stay visible while scrolling.
   We set a fixed top offset for nav to sit just below #filter-controls. If you change
   the height of #filter-controls, update the `top` value on `nav` accordingly. */
#filter-controls {
  position: sticky;
  top: 0; /* stick to top of viewport */
  z-index: 1001; /* above nav */
  background: #ffffff; /* keep header opaque so content doesn't show through */
  padding: 0.5rem 0.5rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

nav {
  display: flex;
  gap: 1rem;
  margin-bottom: 0; /* handled by sticky spacing */
  position: sticky;
  top: 48px; /* below filter-controls */
  z-index: 1000;
  background: #ffffff;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid rgba(0,0,0,0.04);
}

/* Bottom banner styles */
#bottom-banner {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  background: linear-gradient(90deg,#0d6efd,#6610f2);
  color: #fff;
  z-index: 1100;
  height: 56px;
  /* keep layout stable when inserting img/iframe */
  box-sizing: border-box;
  overflow: hidden;
  /* remove shadow so there's no visual gap above the banner */
  box-shadow: none;
}

#bottom-banner .banner-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* Reduce vertical padding to minimize gap with header above */
  padding: 0 12px;
}

#bottom-banner .banner-content {
  font-size: 14px;
}


section {
  margin-top: 1rem;
}

.scrollable {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  white-space: nowrap;
  padding: 0.3em 0;
  cursor: text;
  border-bottom: 1px dashed #ccc;
}

.row {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}

/* GSI fallback banner (non-intrusive) */
#gsi-fallback-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  top: 72px;
  z-index: 1200;
  background: #fff8e1;
  color: #6a4f00;
  border: 1px solid #ffe08a;
  padding: 10px 12px;
  border-radius: 6px;
  display: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  font-size: 14px;
  display: flex;
  gap: 8px;
  align-items: center;
}

#gsi-fallback-banner.visible { display: flex; }

.gsi-manual-btn {
  background: #0d6efd;
  color: #fff;
  border: none;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.gsi-help-link {
  margin-left: auto;
  color: #0d6efd;
  text-decoration: underline;
}

.label {
  width: 7em;
  flex-shrink: 0;
  font-weight: bold;
}

.value {
  flex-grow: 1;
  min-width: 0; /* ✅ これが重要！スクロール領域の幅制限を防ぐ */
}

/* 📱 Mobile 対策 */
@media (max-width: 768px) {
  body {
    padding: 0.5rem 0.5rem calc(var(--bottom-banner-height) + 0.5rem) 0.5rem;
  }

  .word-card {
    padding: 0.75rem;
    margin: 0.75rem 0;
  }

  .word-header h2 {
    font-size: 1.4rem;
  }

  button {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
  }

  nav {
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  #filter-controls {
    gap: 0.3rem;
    flex-wrap: wrap;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .user-area {
    width: 100%;
    justify-content: space-between;
  }

  /* ✅ スマホで word-container が必ず表示されるように */
  #word-container {
    min-height: 50vh;
    width: 100%;
  }

  #loading {
    min-height: 50vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
  }
}

/* ========== Flip-Card Quiz Styles ========== */
.flip-card {
  perspective: 1000px;
  width: 100%;
  max-width: 400px;
  height: 70px;
  margin: 2rem auto;
  cursor: pointer;
}

.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

.flip-card.flipped .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-front, .flip-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  text-align: center;
  padding: 0.75rem;
  box-sizing: border-box;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.flip-card-front {
  background: #007bff;
  color: white;
  font-size: 1.2rem;
  font-weight: bold;
}

.flip-card-back {
  background: #0056b3;
  color: white;
  font-size: 1rem;
  font-weight: bold;
  transform: rotateY(180deg);
}

/* Sentence/Memorize cards use richer content and need larger readable layout. */
.text-heavy-card {
  min-height: 190px;
  height: 190px;
}

.text-heavy-card .flip-card-front,
.text-heavy-card .flip-card-back {
  align-items: flex-start;
  justify-content: flex-start;
  text-align: left;
  padding: 14px 16px;
  overflow-y: auto;
  line-height: 1.45;
  font-size: 1rem;
  font-weight: 600;
}

.text-heavy-card .flip-card-back {
  background: #0b4ea2;
}

.memorize-front-word,
.sentence-back-word {
  font-size: 1.05rem;
  font-weight: 700;
}

.memorize-front-example,
.sentence-front-example,
.memorize-back-meaning,
.sentence-back-meaning {
  font-size: 0.98rem;
  font-weight: 500;
  line-height: 1.5;
}

.memorize-front-example {
  margin-top: 0.65rem;
  color: #eaf2ff;
}

.memorize-back-meaning {
  color: #f3f8ff;
}

.sentence-back-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100%;
}

.sentence-back-meaning {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(255, 255, 255, 0.35);
  color: #e8f1ff;
}

.sentence-back-example-ja-label {
  margin-top: 0.85rem;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: #bed8ff;
  text-transform: uppercase;
}

.sentence-back-example-ja {
  margin-top: 0.35rem;
  padding-top: 0.45rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.3);
  color: #f8fbff;
  font-size: 0.95rem;
  font-weight: 500;
}

.quiz-answer-hint {
  font-size: 0.9rem;
  opacity: 0.8;
  margin-top: 0.5rem;
}

#quiz-area {
  transition: background-color 0.3s ease;
  padding: 1rem;
  border-radius: 8px;
  min-height: 200px;
}

.quiz-card-container {
  width: 100%;
  max-width: 400px;
  margin: 2rem auto;
  padding: 0.5rem;
  border-radius: 8px;
  transition: background-color 0.3s ease;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quiz-controls {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  justify-content: center;
  flex-wrap: wrap;
}

.quiz-controls button {
  padding: 0.7rem 1.5rem;
  font-size: 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: bold;
}

.quiz-correct {
  background: #4CAF50;
  color: white;
}

.quiz-correct:hover {
  background: #45a049;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.quiz-incorrect {
  background: #f44336;
  color: white;
}

.quiz-incorrect:hover {
  background: #da190b;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.quiz-stats {
  text-align: center;
  margin: 1rem 0;
  font-size: 1.1rem;
}

.quiz-stats-correct {
  color: #4CAF50;
  font-weight: bold;
}

.quiz-stats-incorrect {
  color: #f44336;
  font-weight: bold;
}

.quiz-mode-toggle {
  text-align: center;
  margin: 2rem 0;
}

.quiz-mode-toggle button {
  padding: 0.7rem 1.5rem;
  font-size: 1rem;
  background: #2196F3;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s;
}

.quiz-mode-toggle button:hover {
  background: #0b7dda;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}