/* =========================================================
   せかいご — "ことば鳴らしボード" / ぷよっと可愛い
   ---------------------------------------------------------
   コア: 押す→鳴る→言語ごとの音の違い・似てるを聴き比べて遊ぶ。
   国旗=目的地ではなく "鳴らすパッド"。
   - トーン: やわらかいパステル + 丸ゴ(M PLUS Rounded 1c)
   - 背景: ふわふわ漂うパステルのブロブ
   - 触感: ぷよっと沈む(squish) / タップで波紋 / 鳴ってるパッドは脈打つ
   ========================================================= */
:root {
  --bg: #fff6f3;
  --surface: #ffffff;
  --surface-2: #fff0f4;
  --ink: #4a3d59;
  --ink-soft: #6b5c7d;
  --muted: #a99cbb;
  --line: #f2e3ec;

  /* キャンディなパステル */
  --pink: #ff6f9c;
  --pink-bright: #ff89af;
  --pink-soft: #ffe1ec;
  --sky: #45c2ff;
  --sky-soft: #dcf2ff;
  --mint: #1fcaa0;
  --mint-soft: #d4f7ee;
  --lemon: #ffcf4a;
  --on-accent: #ffffff;

  --radius: 28px;
  --radius-sm: 20px;
  --shadow: 0 14px 30px rgba(150, 110, 140, 0.16);
  --shadow-lift: 0 22px 44px rgba(150, 110, 140, 0.26);
  --shadow-soft: 0 8px 18px rgba(150, 110, 140, 0.14);
  --ring: 0 0 0 4px rgba(255, 111, 156, 0.3);

  --font-pop: 'M PLUS Rounded 1c', 'Zen Maru Gothic', system-ui, sans-serif;
  --font-word: 'M PLUS Rounded 1c', 'Zen Maru Gothic', 'Hiragino Sans', 'Noto Sans', system-ui, sans-serif;

  --tap: 46px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181527;
    --surface: #221d38;
    --surface-2: #2a2444;
    --ink: #f3ecfb;
    --ink-soft: #d4c8e8;
    --muted: #a294bd;
    --line: #352c52;

    --pink: #ff7fa8;
    --pink-bright: #ff97ba;
    --pink-soft: #3a2238;
    --sky: #6fd0ff;
    --sky-soft: #1d2f4a;
    --mint: #46e0bb;
    --mint-soft: #16352f;
    --lemon: #ffd96b;
    --on-accent: #1a1430;

    --shadow: 0 14px 30px rgba(0, 0, 0, 0.5);
    --shadow-lift: 0 22px 44px rgba(0, 0, 0, 0.6);
    --shadow-soft: 0 8px 18px rgba(0, 0, 0, 0.45);
    --ring: 0 0 0 4px rgba(255, 127, 168, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-pop);
  color: var(--ink);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  background-color: var(--bg);
  position: relative;
  overflow-x: hidden;
}

/* ふわふわ漂うパステルのブロブ */
body::before {
  content: '';
  position: fixed;
  inset: -20% -10%;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(34% 34% at 12% 18%, rgba(255, 111, 156, 0.32), transparent 60%),
    radial-gradient(36% 36% at 88% 12%, rgba(69, 194, 255, 0.28), transparent 62%),
    radial-gradient(34% 34% at 78% 88%, rgba(31, 202, 160, 0.26), transparent 60%),
    radial-gradient(30% 30% at 22% 82%, rgba(255, 207, 74, 0.26), transparent 60%);
  filter: blur(8px);
  animation: drift 26s ease-in-out infinite alternate;
}

.app {
  max-width: 1020px;
  margin: 0 auto;
  padding: max(clamp(0.9rem, 2.4vw, 1.8rem), env(safe-area-inset-top))
    max(clamp(0.85rem, 2.6vw, 1.6rem), env(safe-area-inset-right))
    calc(2.2rem + env(safe-area-inset-bottom)) max(clamp(0.85rem, 2.6vw, 1.6rem), env(safe-area-inset-left));
  position: relative;
  z-index: 1;
}

/* =========================================================
   ヘッダー
   ========================================================= */
.app__header {
  text-align: center;
  margin-bottom: clamp(1.1rem, 3vw, 1.6rem);
  animation: rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.app__title {
  font-size: clamp(2.1rem, 7.5vw, 3.4rem);
  font-weight: 800;
  line-height: 1.05;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-pop);
  color: var(--ink);
}

.app__globe {
  font-size: 0.95em;
  display: inline-block;
  animation: bob 4s ease-in-out infinite;
  filter: drop-shadow(0 6px 10px rgba(255, 111, 156, 0.3));
}

/* sekaigo = ぷくっとしたパステルのバッジ */
.app__rom {
  font-family: var(--font-pop);
  font-size: 0.34em;
  font-weight: 800;
  color: var(--pink);
  letter-spacing: 0.06em;
  text-transform: lowercase;
  align-self: center;
  padding: 0.3em 0.75em;
  border-radius: 999px;
  background: var(--pink-soft);
  transform: rotate(-3deg);
}

.app__tagline {
  color: var(--ink-soft);
  margin: 0.7rem auto 0;
  font-size: clamp(0.92rem, 2.4vw, 1.06rem);
  line-height: 1.5;
  max-width: 32ch;
  font-family: var(--font-pop);
  font-weight: 500;
}

.app__tagline b {
  color: var(--pink);
  font-weight: 700;
}

.app__note {
  color: var(--mint);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: 0.5rem 0 0;
  font-weight: 700;
}

/* =========================================================
   コントロール
   ========================================================= */
.controls {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1rem, 2.4vw, 1.35rem);
  margin-bottom: clamp(0.95rem, 2.6vw, 1.35rem);
  animation: rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.08s both;
}

.controls__label {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.7rem;
  font-family: var(--font-pop);
}

/* カテゴリタブ = ぷくっとピル */
.cat-tabs {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  flex-wrap: nowrap;
  scrollbar-width: none;
  margin-bottom: 0.75rem;
  padding-bottom: 2px;
}

.cat-tabs::-webkit-scrollbar {
  display: none;
}

.cat-tab {
  flex: 0 0 auto;
  border: none;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--font-pop);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.45rem 1rem;
  min-height: 38px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, transform 0.14s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cat-tab:hover {
  color: var(--ink);
  transform: translateY(-1px);
}

.cat-tab:active {
  transform: scale(0.94);
}

.cat-tab:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.cat-tab--active {
  color: var(--on-accent);
  background: var(--pink);
  box-shadow: 0 8px 16px rgba(255, 111, 156, 0.36);
}

/* 絵文字チップ = ぷよっとキー */
.chips {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  flex-wrap: nowrap;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0.3rem 0.2rem 0.6rem;
  margin: 0 -0.2rem;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  scroll-snap-align: start;
  width: 54px;
  height: 54px;
  padding: 0;
  border: none;
  background: var(--surface-2);
  border-radius: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.18s ease, box-shadow 0.18s ease;
}

.chip:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: var(--shadow);
}

.chip:active {
  transform: scale(0.9);
}

.chip:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.chip--active {
  background: var(--pink-soft);
  transform: scale(1.08) rotate(-3deg);
  box-shadow: 0 10px 20px rgba(255, 111, 156, 0.3);
}

.chip__emoji {
  font-size: 1.6rem;
  line-height: 1;
}

/* =========================================================
   ヒーロー = いま鳴っていることばの大きな表示
   ========================================================= */
.hero-wrap {
  margin-bottom: clamp(0.95rem, 2.8vw, 1.4rem);
  animation: rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.16s both;
}

.hero {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.2rem, 3vw, 1.7rem);
  overflow: hidden;
}

/* 隅にやわらかいパステルのにじみ */
.hero::before {
  content: '';
  position: absolute;
  top: -40%;
  right: -15%;
  width: 60%;
  height: 130%;
  background: radial-gradient(circle, var(--pink-soft), transparent 70%);
  pointer-events: none;
}

.hero--empty {
  text-align: center;
  color: var(--muted);
  font-family: var(--font-pop);
  font-weight: 700;
  font-size: 1.05rem;
  padding: clamp(1.6rem, 6vw, 2.6rem);
}

.hero--empty p {
  margin: 0;
  position: relative;
  z-index: 1;
}

.hero__top {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 0.55rem;
  position: relative;
  z-index: 1;
}

/* ヒーローの国旗 = 丸いバッジ + 鳴っている音の波(リング) */
.hero__flag {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--surface);
  flex: 0 0 auto;
  box-shadow: 0 0 0 2px var(--line), var(--shadow-soft);
  animation: sound 2s ease-out infinite;
}

.hero__meta {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.hero__endonym {
  font-size: 1.2rem;
  font-weight: 800;
  font-family: var(--font-pop);
  color: var(--ink);
}

.hero__nameja {
  font-size: 0.85rem;
  color: var(--muted);
  font-family: var(--font-pop);
  font-weight: 700;
}

.hero__emoji {
  margin-left: auto;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  filter: drop-shadow(0 4px 7px rgba(150, 110, 140, 0.22));
  animation: bob 4s ease-in-out infinite;
}

.hero__word {
  font-family: var(--font-word);
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  font-weight: 800;
  line-height: 1.12;
  margin: 0.2rem 0 0;
  color: var(--ink);
  word-break: break-word;
  overflow-wrap: anywhere;
  position: relative;
  z-index: 1;
  animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.hero__word--muted {
  color: var(--muted);
  font-weight: 700;
  animation: none;
}

.hero__roman {
  color: var(--mint);
  font-family: var(--font-pop);
  font-weight: 700;
  font-size: clamp(1rem, 3.4vw, 1.3rem);
  margin: 0.3rem 0 1rem;
  position: relative;
  z-index: 1;
}

/* もう一度きく = ぷくっと主役。鳴らしたくなる脈打ち */
.hero__speak {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  border: none;
  border-radius: 999px;
  background: var(--pink);
  color: var(--on-accent);
  font-weight: 800;
  font-family: var(--font-pop);
  font-size: 1.02rem;
  padding: 0.65rem 1.4rem;
  min-height: var(--tap);
  cursor: pointer;
  position: relative;
  z-index: 1;
  box-shadow: 0 10px 20px rgba(255, 111, 156, 0.34);
  transition: transform 0.14s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.18s ease, box-shadow 0.18s ease;
}

.hero__speak:hover:not([disabled]) {
  transform: translateY(-2px) scale(1.03);
  background: var(--pink-bright);
  box-shadow: 0 15px 30px rgba(255, 111, 156, 0.44);
}

.hero__speak:active:not([disabled]) {
  transform: scale(0.95);
}

.hero__speak:focus-visible {
  outline: none;
  box-shadow: var(--ring), 0 10px 20px rgba(255, 111, 156, 0.34);
}

.hero__speak[disabled] {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
  box-shadow: none;
}

.hero__speak-icon {
  font-size: 1.18em;
}

/* =========================================================
   国旗グリッド = "鳴らすパッド" の集まり
   ========================================================= */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(184px, 1fr));
  gap: clamp(0.6rem, 1.9vw, 0.9rem);
}

.flag-btn {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-align: left;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s ease, border-color 0.18s ease,
    background 0.18s ease;
  animation: deal 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* 登場を少しずつ遅らせて配る(staggered) */
.flag-btn:nth-child(1) { animation-delay: 0.02s; }
.flag-btn:nth-child(2) { animation-delay: 0.05s; }
.flag-btn:nth-child(3) { animation-delay: 0.08s; }
.flag-btn:nth-child(4) { animation-delay: 0.11s; }
.flag-btn:nth-child(5) { animation-delay: 0.14s; }
.flag-btn:nth-child(6) { animation-delay: 0.17s; }
.flag-btn:nth-child(7) { animation-delay: 0.2s; }
.flag-btn:nth-child(8) { animation-delay: 0.23s; }
.flag-btn:nth-child(n + 9) { animation-delay: 0.26s; }

/* タップで広がる波紋 */
.flag-btn::before {
  content: '';
  position: absolute;
  left: 38px;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--pink);
  opacity: 0;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: none;
}

.flag-btn:active::before {
  animation: ripple 0.55s ease-out;
}

.flag-btn:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: var(--shadow-lift);
}

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

.flag-btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.flag-btn--selected {
  border-color: var(--pink);
  background: var(--pink-soft);
  animation: sound 2s ease-out infinite;
}

.flag-btn--pending {
  opacity: 0.7;
}

/* 国旗 = 丸いパッド */
.flag-btn__flag {
  flex: none;
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1.5px var(--line);
}

.flag-btn__text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 0.1rem;
}

.flag-btn__name {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  font-family: var(--font-pop);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flag-btn__word {
  font-family: var(--font-word);
  font-size: 1.22rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: left;
  color: var(--ink);
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.flag-btn__word--muted {
  color: var(--muted);
  font-weight: 600;
}

.flag-btn__roman {
  font-size: 0.76rem;
  color: var(--mint);
  font-family: var(--font-pop);
  font-weight: 700;
}

.flag-btn__mute {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  font-size: 0.8rem;
  opacity: 0.5;
}

/* =========================================================
   フッター
   ========================================================= */
.app__footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: clamp(1.6rem, 5vw, 2.6rem);
  padding-top: clamp(1rem, 3vw, 1.4rem);
  border-top: 2px dotted var(--line);
  line-height: 1.7;
  font-family: var(--font-pop);
}

.app__footer a {
  color: var(--pink);
  text-decoration: none;
  font-weight: 700;
}

.app__footer a:hover {
  color: var(--pink-bright);
  text-decoration: underline;
}

.app__copyright {
  display: block;
  margin-top: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}

/* =========================================================
   キーフレーム
   ========================================================= */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes deal {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pop {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  60% {
    opacity: 1;
    transform: scale(1.05);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* 押した瞬間の波紋 */
@keyframes ripple {
  0% {
    opacity: 0.45;
    transform: translate(-50%, -50%) scale(0.4);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(9);
  }
}

/* 鳴ってるよ、の音の輪 */
@keyframes sound {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 111, 156, 0.45);
  }
  70%,
  100% {
    box-shadow: 0 0 0 14px rgba(255, 111, 156, 0);
  }
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(0, -3%, 0) scale(1.08);
  }
}

/* =========================================================
   レスポンシブ
   ========================================================= */
@media (max-width: 560px) {
  .app {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }
  .app__header {
    margin-bottom: 0.9rem;
  }
  .app__title {
    font-size: clamp(2rem, 11vw, 2.6rem);
    gap: 0.4rem;
  }
  .app__tagline {
    font-size: 0.92rem;
    max-width: 28ch;
  }
  .controls {
    padding: 1rem;
    border-radius: 24px;
  }
  .cat-tab {
    min-height: 34px;
    padding: 0.4rem 0.85rem;
    font-size: 0.86rem;
  }
  .chip {
    width: 50px;
    height: 50px;
  }
  .chip__emoji {
    font-size: 1.5rem;
  }
  .hero {
    padding: 1.2rem;
  }
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  .flag-btn__flag {
    width: 42px;
    height: 42px;
  }
  .flag-btn__word {
    font-size: 1.08rem;
  }
  .hero__flag {
    width: 54px;
    height: 54px;
  }
  .hero__word {
    font-size: clamp(2rem, 12vw, 3rem);
  }
}

/* ホバー非対応(タッチ)では浮きを抑え、選択状態を再主張 */
@media (hover: none) {
  .flag-btn:hover {
    transform: none;
    box-shadow: var(--shadow-soft);
  }
  .flag-btn--selected:hover {
    border-color: var(--pink);
    background: var(--pink-soft);
  }
  .chip:hover {
    transform: none;
    box-shadow: var(--shadow-soft);
  }
  .chip--active:hover {
    background: var(--pink-soft);
    transform: scale(1.08) rotate(-3deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  body::before {
    animation: none !important;
    transition: none !important;
  }
}
