/* えいごずかん v2 */

@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('assets/fonts/fredoka-latin.woff2') format('woff2');
}

:root {
  --bg: #FFF6E9;            /* warm cream */
  --card: #FFFFFF;
  --ink: #3E3A33;
  --muted: #8B8478;
  --accent: #FF8A3D;        /* single cheerful accent */
  --accent-deep: #F0731D;
  --shadow: 0 4px 14px rgba(120, 90, 40, 0.14);
  --shadow-pop: 0 2px 6px rgba(120, 90, 40, 0.10), 0 12px 32px rgba(120, 90, 40, 0.16);
  --radius: 22px;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100vh;   /* fallback */
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Fredoka", "Hiragino Maru Gothic ProN", "Hiragino Sans", system-ui, sans-serif;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

img { max-width: 100%; }

.is-hidden { display: none !important; }

/* ===== Screens ===== */
.screen {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: none;
  padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 16px)
           calc(var(--safe-bottom) + 24px) calc(var(--safe-left) + 16px);
}

.screen-full {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== Home ===== */
.home-header {
  padding: 40px 0 8px;
  text-align: center;
}

.app-title {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent-deep);
}

.gear-btn {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  right: calc(var(--safe-right) + 10px);
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  -webkit-touch-callout: none;
}

.gear-icon {
  font-size: 1.7rem;
  opacity: 0.55;
  pointer-events: none;
}

.gear-ring {
  position: absolute;
  inset: 4px;
  pointer-events: none;
  transform: rotate(-90deg);
  opacity: 0;
}

.gear-ring .ring-track,
.gear-ring .ring-fill {
  fill: none;
  stroke-width: 5;
}

.gear-ring .ring-track { stroke: rgba(240, 115, 29, 0.18); }

.gear-ring .ring-fill {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 175.93; /* 2 * pi * 28 */
  stroke-dashoffset: 175.93;
}

.gear-btn.is-charging .gear-ring { opacity: 1; }
.gear-btn.is-charging .ring-fill { animation: ring-fill 2s linear forwards; }

@keyframes ring-fill {
  to { stroke-dashoffset: 0; }
}

/* Mode toggle */
.mode-toggle {
  display: flex;
  max-width: 400px;
  margin: 14px auto 20px;
  background: #F4E8D4;
  border-radius: 999px;
  padding: 5px;
}

.mode-btn {
  flex: 1;
  min-height: 72px;
  border-radius: 999px;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--muted);
}

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

/* Level tabs（複数レベルがあるときだけ表示） */
.level-bar {
  display: flex;
  gap: 10px;
  max-width: 400px;
  margin: 0 auto 18px;
}

.level-btn {
  flex: 1;
  min-height: 72px;
  border-radius: 22px;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--muted);
  background: #F4E8D4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.level-name {
  font-size: 1.08rem;
  line-height: 1.1;
}

.level-meta {
  font-size: 0.72rem;
  line-height: 1.1;
  font-weight: 700;
}

.level-btn.is-active {
  background: #fff;
  color: var(--accent);
  box-shadow: var(--shadow);
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

/* Category grid */
.category-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  max-width: 440px;
  margin: 0 auto;
  padding-bottom: 24px;
}

.category-btn {
  min-height: 96px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 2.5px solid var(--cat-tint, transparent);
  font-size: 1.18rem;
  font-weight: 800;
  line-height: 1.3;
  padding: 12px 10px;
  transition: transform 0.16s var(--spring);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  animation: pop-rise 0.42s var(--spring) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}

.category-btn:active { transform: scale(0.94); }

/* カテゴリ表紙のまるいサムネ */
.category-thumb {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--cat-tint, #F4E8D4);
  border: 3px solid var(--cat-tint, #F4E8D4);
  box-shadow: 0 2px 8px rgba(120, 90, 40, 0.16);
  flex-shrink: 0;
}

.category-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.category-text { display: block; text-align: center; }

.category-name { display: block; }

.category-count {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 10px 2px;
  border-radius: 999px;
  background: var(--cat-tint, #F4E8D4);
  color: var(--cat-deep, var(--muted));
  font-size: 0.78rem;
  font-weight: 700;
}

@keyframes pop-rise {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

/* アニメーションを切っている環境でもカードが必ず見えるように */
@media (prefers-reduced-motion: reduce) {
  .category-btn, .zukan-card, .flash-card.is-in .flash-imgwrap,
  .start-category, .end-title, .confetti i {
    animation: none !important;
  }
}

/* ===== Flash start ===== */
.start-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
}

.start-category {
  font-size: 1.7rem;
  font-weight: 800;
  text-align: center;
  color: var(--cat-deep, var(--ink));
  animation: pop-rise 0.4s var(--spring) both;
}

.start-count {
  margin-top: -20px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
}

.set-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  max-width: min(88vw, 390px);
}

.set-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #F4E8D4;
  color: var(--muted);
  font-size: 1.35rem;
  font-weight: 800;
}

.set-btn.is-active {
  color: #fff;
  background: var(--accent);
  box-shadow: var(--shadow);
}

.start-btn {
  width: min(76vw, 330px);
  min-height: 110px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 2.1rem;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(240, 115, 29, 0.4);
  transition: transform 0.1s ease;
}

.start-btn:active { transform: scale(0.96); }

/* ===== Flash play ===== */
/* カテゴリの色世界を敷く（フラッシュ準備・再生・終了・ずかん） */
#screen-flash-start,
#screen-flash-play,
#screen-flash-end,
#screen-zukan {
  background:
    radial-gradient(120% 90% at 50% -20%, var(--cat-tint, var(--bg)) 0%, var(--bg) 78%);
}

.play-surface {
  -webkit-user-select: none;
  user-select: none;
  align-items: center;
  justify-content: center;
}

.flash-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.flash-card.is-in .flash-imgwrap {
  animation: card-in 0.26s var(--spring) both;
}

@keyframes card-in {
  from { opacity: 0.4; transform: scale(0.955); }
  to   { opacity: 1; transform: none; }
}

.flash-imgwrap {
  height: 64vh;
  height: 64dvh;
  width: min(92vw, 560px);
  background: var(--card);
  border-radius: 30px;
  border: 4px solid #fff;
  box-shadow: var(--shadow-pop);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#flash-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 26px;
}

.flash-en {
  font-family: "Fredoka", "Hiragino Maru Gothic ProN", sans-serif;
  font-size: clamp(2.4rem, 13vw, 3.6rem);
  font-weight: 600;
  letter-spacing: 0.015em;
  line-height: 1.1;
  text-align: center;
  color: var(--cat-deep, var(--ink));
}

/* 進捗ドット（数字なしの控えめな進捗） */
.flash-progress {
  position: absolute;
  top: calc(var(--safe-top) + 16px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  z-index: 10;
  pointer-events: none;
}

.p-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(120, 90, 40, 0.16);
  transition: background 0.25s ease, transform 0.25s var(--spring);
}

.p-dot.is-done { background: var(--cat-deep, var(--accent)); opacity: 0.45; }

.p-dot.is-now {
  background: var(--cat-deep, var(--accent));
  transform: scale(1.5);
}

.flash-ja {
  font-size: 1.15rem;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.pause-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(62, 58, 51, 0.22);
  pointer-events: none;
}

.pause-mark {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent-deep);
  font-size: 2.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 8px;
  box-shadow: var(--shadow);
}

.flash-exit {
  position: absolute;
  top: calc(var(--safe-top) + 8px);
  left: calc(var(--safe-left) + 8px);
  z-index: 30;
}

/* ===== Flash end ===== */
.end-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.end-title {
  font-size: 2.1rem;
  font-weight: 800;
  margin-bottom: 14px;
  text-align: center;
  animation: pop-rise 0.5s var(--spring) both;
}

/* 紙吹雪（終了画面が表示されるたびに一回だけ舞う） */
.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  top: -14px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  opacity: 0;
  animation: confetti-fall 2.6s ease-in both;
}

.confetti i:nth-child(1)  { left: 6%;  background: #FF8A3D; animation-delay: 0s;    }
.confetti i:nth-child(2)  { left: 14%; background: #4E9A3D; animation-delay: 0.25s; width: 8px; }
.confetti i:nth-child(3)  { left: 24%; background: #2380B9; animation-delay: 0.1s;  }
.confetti i:nth-child(4)  { left: 33%; background: #D24B77; animation-delay: 0.4s;  width: 12px; }
.confetti i:nth-child(5)  { left: 42%; background: #BB8C13; animation-delay: 0.05s; }
.confetti i:nth-child(6)  { left: 51%; background: #7D4FB2; animation-delay: 0.32s; width: 8px; }
.confetti i:nth-child(7)  { left: 60%; background: #2E8C7E; animation-delay: 0.18s; }
.confetti i:nth-child(8)  { left: 68%; background: #FF8A3D; animation-delay: 0.45s; }
.confetti i:nth-child(9)  { left: 76%; background: #C74E64; animation-delay: 0.08s; width: 12px; }
.confetti i:nth-child(10) { left: 84%; background: #3F62B7; animation-delay: 0.3s;  }
.confetti i:nth-child(11) { left: 91%; background: #6C9A24; animation-delay: 0.15s; width: 8px; }
.confetti i:nth-child(12) { left: 97%; background: #D6532B; animation-delay: 0.5s;  }

@keyframes confetti-fall {
  0%   { opacity: 0; transform: translateY(0) rotate(0deg); }
  8%   { opacity: 1; }
  100% { opacity: 0.9; transform: translateY(105vh) rotate(540deg); }
}

.big-btn {
  width: min(80vw, 340px);
  min-height: 78px;
  background: var(--card);
  border-radius: 999px;
  font-size: 1.35rem;
  font-weight: 800;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease;
}

.big-btn:active { transform: scale(0.96); }

.big-btn.primary {
  background: var(--accent);
  color: #fff;
}

/* ===== Back button ===== */
.back-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--accent-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.screen-full > .back-btn {
  position: absolute;
  top: calc(var(--safe-top) + 8px);
  left: calc(var(--safe-left) + 8px);
  z-index: 30;
}

/* ===== Zukan ===== */
.zukan-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.zukan-category {
  font-size: 1.3rem;
  font-weight: 800;
  padding: 8px 20px 9px;
  border-radius: 999px;
  background: var(--card);
  color: var(--cat-deep, var(--ink));
  border: 2.5px solid var(--cat-tint, transparent);
  box-shadow: var(--shadow);
}

.zukan-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 520px;
  margin: 0 auto;
  padding-bottom: 30px;
}

.zukan-card {
  min-height: 118px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px;
  -webkit-user-select: none;
  user-select: none;
  animation: pop-rise 0.4s var(--spring) both;
  animation-delay: calc(var(--i, 0) * 36ms);
}

.zukan-card img {
  width: 100%;
  height: 74px;
  object-fit: contain;
  border-radius: 12px;
  pointer-events: none;
}

.zukan-card span {
  font-family: "Fredoka", "Hiragino Maru Gothic ProN", sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.zukan-card .zukan-ja {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.zukan-card.is-bouncing { animation: bounce 0.45s ease; }

@keyframes bounce {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.14); }
  55%  { transform: scale(0.94); }
  75%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ===== Settings modal ===== */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(62, 58, 51, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.settings-panel {
  width: min(92vw, 400px);
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: 0 10px 34px rgba(60, 40, 10, 0.3);
  padding: 24px 20px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.settings-title {
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.setting-row-col {
  flex-direction: column;
  align-items: stretch;
}

.setting-label {
  font-size: 1.05rem;
  font-weight: 800;
}

.seg-group {
  display: flex;
  background: #F4E8D4;
  border-radius: 999px;
  padding: 4px;
}

.seg-btn {
  min-width: 64px;
  min-height: 72px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--muted);
}

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

.toggle-btn {
  min-width: 96px;
  min-height: 72px;
  border-radius: 999px;
  background: #E8DECB;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 800;
}

.toggle-btn.is-on {
  background: var(--accent);
  color: #fff;
}

.url-input {
  width: 100%;
  min-height: 72px;
  border: 2px solid #E8DECB;
  border-radius: 14px;
  background: var(--card);
  font-family: inherit;
  font-size: 16px; /* prevents iOS focus zoom */
  padding: 8px 14px;
  color: var(--ink);
}

.url-input:focus {
  outline: none;
  border-color: var(--accent);
}

.settings-note {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.settings-note a,
.credits-link {
  color: var(--accent-deep);
  font-weight: 800;
}

.credits-link {
  min-height: 72px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
}

/* ===== Data error ===== */
.error-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  text-align: center;
}

.error-face { font-size: 3.5rem; }

.error-title {
  max-width: 300px;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.5;
}

@media (max-width: 380px) {
  .setting-row-speed {
    flex-direction: column;
    align-items: stretch;
  }

  .setting-row-speed .setting-label { text-align: center; }
  .setting-row-speed .seg-group { justify-content: center; }
}
