/* ============================================
   焚き火の部屋 - スタイルシート
   Premium Dark Theme with Glassmorphism
   ============================================ */

/* --- CSS Variables (デザイントークン) --- */
:root {
  --bg-deep: #0a0a12;
  --bg-dark: #0f0f1a;
  --glass-bg: rgba(20, 18, 30, 0.65);
  --glass-border: rgba(255, 160, 60, 0.12);
  --glass-shadow: rgba(0, 0, 0, 0.5);
  --fire-orange: #ff6b1a;
  --fire-amber: #ffaa33;
  --fire-gold: #ffd97a;
  --fire-red: #e83e2e;
  --fire-glow: rgba(255, 120, 30, 0.15);
  --text-primary: #f0e6d8;
  --text-secondary: rgba(240, 230, 216, 0.55);
  --text-placeholder: rgba(240, 230, 216, 0.3);
  --font-main: 'Zen Kaku Gothic New', 'Noto Sans JP', sans-serif;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --transition-smooth: 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* --- App Container --- */
#app {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}

/* --- Canvas (全画面背景) --- */
#fireCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* --- 焚き火の温かい光 --- */
#ambientGlow {
  position: fixed;
  bottom: 15%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(
    ellipse at center,
    rgba(255, 120, 30, 0.08) 0%,
    rgba(255, 80, 20, 0.04) 30%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 1;
  animation: glowPulse 3s ease-in-out infinite alternate;
}

@keyframes glowPulse {
  0% { opacity: 0.7; transform: translateX(-50%) scale(1); }
  100% { opacity: 1; transform: translateX(-50%) scale(1.08); }
}

/* --- 燃やすテキスト表示エリア --- */
#burningTextContainer {
  position: fixed;
  bottom: 45%; /* 入力カードの上に見えるように位置を上げる */
  left: 50%;
  transform: translateX(-50%);
  z-index: 20; /* 入力カード（z-index: 10）より手前に表示する */
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  max-width: 80%;
  pointer-events: none;
}

.burning-char {
  display: inline-block;
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--fire-gold);
  text-shadow: 0 0 20px rgba(255, 200, 80, 0.8), 0 0 40px rgba(255, 120, 30, 0.5);
  opacity: 0;
  transform: translateY(30px);
  animation: charAppear 0.4s ease-out forwards;
}

@keyframes charAppear {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.burning-char.ignite {
  animation: charIgnite 0.8s ease-in forwards;
}

@keyframes charIgnite {
  0% {
    opacity: 1;
    color: var(--fire-gold);
    text-shadow: 0 0 20px rgba(255, 200, 80, 0.8);
    transform: translateY(0) scale(1);
  }
  30% {
    color: #fff;
    text-shadow: 0 0 45px rgba(255, 255, 255, 0.95), 0 0 90px rgba(255, 180, 50, 0.95);
    transform: translateY(-12px) scale(1.15); /* 少し上に浮かびながら明るく燃える */
  }
  100% {
    opacity: 0;
    color: var(--fire-red);
    text-shadow: 0 0 10px rgba(255, 60, 20, 0.5);
    transform: translateY(-90px) scale(0.1); /* 炎の方向（上）へ吸い込まれて消える */
    filter: blur(2px);
  }
}

/* --- 入力エリア --- */
#inputArea {
  position: relative;
  z-index: 10;
  width: 100%;
  padding: 0 20px 40px;
  display: flex;
  justify-content: center;
}

#inputCard {
  width: 100%;
  max-width: 460px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 28px 24px 24px;
  box-shadow:
    0 8px 32px var(--glass-shadow),
    0 0 80px rgba(255, 120, 30, 0.03),
    inset 0 1px 0 rgba(255, 200, 120, 0.06);
  transition: box-shadow var(--transition-smooth);
}

#inputCard:focus-within {
  box-shadow:
    0 12px 48px var(--glass-shadow),
    0 0 120px rgba(255, 120, 30, 0.06),
    inset 0 1px 0 rgba(255, 200, 120, 0.1);
}

/* --- タイトル & サブタイトル --- */
#appTitle {
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-align: center;
  color: var(--text-primary);
  margin-bottom: 6px;
}

#appSubtitle {
  font-size: 0.9rem; /* 文字を少し大きく */
  text-align: center;
  color: rgba(255, 240, 225, 0.9); /* 明るくしてハッキリ見せる */
  margin-bottom: 20px;
  letter-spacing: 0.08em; /* 文字間隔を広げて読みやすく */
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6); /* 背景に埋もれないように影をつける */
}

/* --- テキストエリア --- */
#textareaWrapper {
  position: relative;
  margin-bottom: 16px;
}

#textInput {
  width: 100%;
  min-height: 80px;
  padding: 14px 16px;
  padding-bottom: 28px;
  background: rgba(10, 10, 18, 0.5);
  border: 1px solid rgba(255, 160, 60, 0.08);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 300;
  line-height: 1.7;
  letter-spacing: 0.03em;
  resize: none;
  outline: none;
  transition: border-color var(--transition-smooth), box-shadow var(--transition-smooth);
  -webkit-appearance: none;
}

#textInput::placeholder {
  color: var(--text-placeholder);
  font-weight: 300;
}

#textInput:focus {
  border-color: rgba(255, 160, 60, 0.25);
  box-shadow: 0 0 0 3px rgba(255, 120, 30, 0.06);
}

#charCount {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 0.7rem;
  color: var(--text-placeholder);
  pointer-events: none;
  transition: color var(--transition-smooth);
}

#charCount.near-limit {
  color: var(--fire-orange);
}

/* --- 「火にくべる」ボタン --- */
#burnBtn {
  width: 100%;
  padding: 14px 24px;
  background: linear-gradient(135deg, rgba(255, 107, 26, 0.2), rgba(255, 170, 51, 0.15));
  border: 1px solid rgba(255, 150, 50, 0.2);
  border-radius: var(--radius-sm);
  color: var(--fire-amber);
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  cursor: pointer;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

#burnBtn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 180, 80, 0.1),
    transparent
  );
  transition: left 0.6s ease;
}

#burnBtn:not(:disabled):hover {
  background: linear-gradient(135deg, rgba(255, 107, 26, 0.35), rgba(255, 170, 51, 0.25));
  border-color: rgba(255, 150, 50, 0.4);
  box-shadow: 0 4px 24px rgba(255, 100, 20, 0.15), 0 0 60px rgba(255, 120, 30, 0.08);
  transform: translateY(-1px);
}

#burnBtn:not(:disabled):hover::before {
  left: 100%;
}

#burnBtn:not(:disabled):active {
  transform: translateY(0);
  box-shadow: 0 2px 12px rgba(255, 100, 20, 0.1);
}

#burnBtn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

#btnIcon {
  font-size: 1.1rem;
  transition: transform var(--transition-smooth);
}

#burnBtn:not(:disabled):hover #btnIcon {
  transform: scale(1.2);
  animation: flicker 0.3s ease-in-out infinite alternate;
}

@keyframes flicker {
  0% { transform: scale(1.2) rotate(-3deg); }
  100% { transform: scale(1.3) rotate(3deg); }
}

#burnBtn.burning {
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 80, 20, 0.5), rgba(255, 140, 30, 0.4));
  border-color: rgba(255, 120, 40, 0.6);
  box-shadow: 0 0 40px rgba(255, 80, 20, 0.3);
}

/* --- 音声トグル --- */
#soundToggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 20;
  width: 40px;
  height: 40px;
  background: rgba(20, 18, 30, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  transition: all var(--transition-smooth);
}

#soundToggle:hover {
  background: rgba(30, 28, 40, 0.7);
  border-color: rgba(255, 160, 60, 0.2);
  color: var(--text-primary);
}

/* --- スタートオーバーレイ --- */
#startOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.8s ease, visibility 0.8s ease;
}

#startOverlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#startContent {
  text-align: center;
}

#startFlame {
  font-size: 4rem;
  animation: startFlameFloat 2s ease-in-out infinite alternate;
  margin-bottom: 24px;
}

@keyframes startFlameFloat {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-12px) scale(1.1); }
}

#startText {
  font-size: 1rem;
  color: var(--text-secondary);
  letter-spacing: 0.15em;
  animation: startTextPulse 2.5s ease-in-out infinite;
}

@keyframes startTextPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* --- 完了メッセージ --- */
.release-message {
  position: fixed;
  bottom: 70%; /* 炎の上部、夜空の広いエリアに配置 */
  left: 50%;
  transform: translateX(-50%);
  z-index: 20; /* 最前面に表示 */
  font-size: 1.6rem; /* 文字を大きく修正 */
  font-weight: 400; /* 文字の太さを少し太くして視認性をアップ */
  color: var(--fire-gold);
  letter-spacing: 0.25em; /* 文字の間隔を広げて優雅な印象に */
  opacity: 0;
  text-shadow: 0 0 20px rgba(255, 180, 50, 0.7), 0 0 40px rgba(255, 100, 20, 0.4);
  animation: releaseAppear 2.5s ease-in-out forwards;
  pointer-events: none;
  white-space: nowrap;
}

@keyframes releaseAppear {
  0% { opacity: 0; transform: translateX(-50%) translateY(20px); }
  20% { opacity: 1; transform: translateX(-50%) translateY(0); }
  80% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-20px); }
}

/* --- レスポンシブ（スマホ対応） --- */
@media (max-width: 480px) {
  #inputArea {
    padding: 0 14px 28px;
  }

  #inputCard {
    padding: 22px 18px 20px;
    border-radius: 16px;
  }

  #appTitle {
    font-size: 1.15rem;
  }

  #appSubtitle {
    font-size: 0.85rem; /* スマホでも見やすいように少し大きく */
    margin-bottom: 16px;
  }

  #textInput {
    font-size: 0.88rem;
    min-height: 70px;
    padding: 12px 14px;
    padding-bottom: 26px;
  }

  #burnBtn {
    padding: 13px 20px;
    font-size: 0.92rem;
  }

  #ambientGlow {
    width: 400px;
    height: 400px;
  }

  .burning-char {
    font-size: 1.1rem;
  }

  .release-message {
    font-size: 1.2rem; /* スマホ画面の幅に合わせて少し縮小 */
    bottom: 68%; /* スマホ用に表示位置を微調整 */
    letter-spacing: 0.2em;
  }
}

@media (max-height: 600px) {
  #inputArea {
    padding-bottom: 16px;
  }

  #inputCard {
    padding: 16px 16px 14px;
  }

  #appTitle {
    font-size: 1.05rem;
    margin-bottom: 2px;
  }

  #appSubtitle {
    font-size: 0.72rem;
    margin-bottom: 10px;
  }

  #textInput {
    min-height: 56px;
  }
}

/* --- セーフエリア対応 (iPhone ノッチ等) --- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #inputArea {
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
  }
}
