/* ============================================================
   中学英語だけで話せる英会話アプリ - スマホ縦画面専用
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  --primary: #4f6ef7;
  --primary-dark: #3d58d4;
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #222633;
  --sub: #7a8095;
  --user-bubble: #4f6ef7;
  --ai-bubble: #ffffff;
  --danger: #e05555;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { display: flex; flex-direction: column; min-height: 100dvh; }

/* ---- ヘッダー ---- */
header {
  background: var(--card);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #e6e8f0;
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 17px; font-weight: 700; flex: 1; }
.back-link {
  text-decoration: none; color: var(--primary);
  font-size: 15px; font-weight: 600; padding: 6px 8px 6px 0;
}
#streak {
  font-size: 13px; color: #d97706; font-weight: 700;
  background: #fef3e2; padding: 5px 10px; border-radius: 999px;
  white-space: nowrap;
}

/* ---- メイン ---- */
main { flex: 1; padding: 16px; width: 100%; max-width: 560px; margin: 0 auto; }

/* ---- 入口ページ ---- */
.hero { text-align: center; padding: 22px 0 8px; }
.hero .logo { font-size: 44px; }
.hero p { color: var(--sub); font-size: 13px; margin-top: 6px; line-height: 1.6; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
.mode-btn {
  display: block; background: var(--card); border: 1px solid #e6e8f0;
  border-radius: 16px; padding: 22px 10px; text-align: center;
  text-decoration: none; color: var(--text);
  box-shadow: 0 1px 3px rgba(30, 40, 90, .06);
}
.mode-btn:active { transform: scale(.97); }
.mode-btn .icon { font-size: 34px; display: block; margin-bottom: 8px; }
.mode-btn .label { font-size: 15px; font-weight: 700; }
.mode-btn .desc { font-size: 11px; color: var(--sub); margin-top: 4px; display: block; }

/* ---- ログイン ---- */
.login-card {
  background: var(--card); border-radius: 16px; padding: 24px 20px;
  margin-top: 24px; border: 1px solid #e6e8f0;
}
.login-card label { font-size: 14px; font-weight: 700; display: block; margin-bottom: 10px; }
.login-card input {
  width: 100%; font-size: 22px; letter-spacing: 6px; text-align: center;
  padding: 12px; border: 2px solid #d8dcea; border-radius: 12px;
  -webkit-appearance: none; appearance: none;
}
.login-card input:focus { outline: none; border-color: var(--primary); }

/* ---- 共通ボタン ---- */
.btn {
  display: block; width: 100%; padding: 15px; margin-top: 14px;
  background: var(--primary); color: #fff; font-size: 16px; font-weight: 700;
  border: none; border-radius: 14px; cursor: pointer;
}
.btn:active { background: var(--primary-dark); }
.btn:disabled { opacity: .5; }
.btn-sub {
  background: #eef1fb; color: var(--primary);
}
.btn-sub:active { background: #dfe5f8; }

/* ---- 場面選択（英会話） ---- */
.scene-list { display: grid; gap: 10px; margin-top: 8px; }
.scene-btn {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid #e6e8f0; border-radius: 14px;
  padding: 16px; font-size: 15px; font-weight: 700; color: var(--text);
  cursor: pointer; width: 100%; text-align: left;
}
.scene-btn:active { transform: scale(.98); }
.scene-btn .icon { font-size: 26px; }

/* ---- チャット（LINE風） ---- */
.chat-page #chat-view { display: flex; flex-direction: column; padding: 0; max-width: 100%; }
#chat-log {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
  max-width: 560px; width: 100%; margin: 0 auto;
}
.bubble-row { display: flex; }
.bubble-row.user { justify-content: flex-end; }
.bubble {
  max-width: 78%; padding: 10px 14px; border-radius: 18px;
  font-size: 15px; line-height: 1.5; word-break: break-word; white-space: pre-wrap;
}
.bubble-row.ai .bubble {
  background: var(--ai-bubble); border: 1px solid #e6e8f0;
  border-top-left-radius: 6px;
}
.bubble-row.user .bubble {
  background: var(--user-bubble); color: #fff;
  border-top-right-radius: 6px;
}
.bubble-tools { display: flex; gap: 6px; margin-top: 6px; }
.mini-btn {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid #d8dcea; background: #fff; color: var(--sub); cursor: pointer;
}
.mini-btn:active { background: #eef1fb; }
.mini-btn.loading { opacity: .6; }

.typing { color: var(--sub); font-size: 13px; padding: 0 4px; }

/* ---- チャット下部バー ---- */
#chat-bar {
  position: sticky; bottom: 0; background: var(--card);
  border-top: 1px solid #e6e8f0;
  padding: 10px 14px calc(12px + var(--safe-bottom));
}
.chat-bar-inner {
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center; gap: 18px;
}
#mic-btn {
  width: 76px; height: 76px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 32px;
  border: none; cursor: pointer;
  box-shadow: 0 4px 14px rgba(79, 110, 247, .4);
  flex-shrink: 0;
}
#mic-btn:active { background: var(--primary-dark); }
#mic-btn.recording { background: var(--danger); animation: pulse 1s infinite; }
#mic-btn:disabled { opacity: .5; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(224, 85, 85, .5); }
  70% { box-shadow: 0 0 0 16px rgba(224, 85, 85, 0); }
  100% { box-shadow: 0 0 0 0 rgba(224, 85, 85, 0); }
}
.side-btn {
  width: 58px; height: 58px; border-radius: 50%;
  background: #eef1fb; color: var(--primary); font-size: 12px; font-weight: 700;
  border: none; cursor: pointer;
}
.side-btn:active { background: #dfe5f8; }

/* ---- テキスト入力フォールバック ---- */
#text-fallback { display: none; gap: 8px; max-width: 560px; margin: 10px auto 0; }
#text-fallback.show { display: flex; }
#text-fallback input {
  flex: 1; font-size: 16px; padding: 11px 14px;
  border: 1.5px solid #d8dcea; border-radius: 999px;
  -webkit-appearance: none; appearance: none;
}
#text-fallback input:focus { outline: none; border-color: var(--primary); }
#text-fallback button {
  padding: 0 18px; border-radius: 999px; border: none;
  background: var(--primary); color: #fff; font-size: 15px; font-weight: 700;
}

/* ---- ヒントパネル ---- */
#hint-panel {
  display: none; max-width: 560px; margin: 0 auto 8px;
  background: #fff8e6; border: 1px solid #f2dfae; border-radius: 12px;
  padding: 12px 14px; font-size: 14px; position: relative;
}
#hint-panel.show { display: block; }
#hint-panel .en { font-weight: 700; }
#hint-panel .ja { color: var(--sub); font-size: 13px; margin-top: 4px; }
#hint-close {
  position: absolute; top: 6px; right: 10px; border: none; background: none;
  font-size: 16px; color: var(--sub); cursor: pointer; padding: 4px;
}

/* ---- カード（日記・翻訳・フレーズ帳） ---- */
.card {
  background: var(--card); border: 1px solid #e6e8f0; border-radius: 16px;
  padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 14px; color: var(--sub); font-weight: 700; margin-bottom: 8px; }
textarea, .input-lg {
  width: 100%; font-size: 16px; padding: 12px; line-height: 1.6;
  border: 1.5px solid #d8dcea; border-radius: 12px; resize: none;
  font-family: inherit; -webkit-appearance: none; appearance: none;
}
textarea:focus, .input-lg:focus { outline: none; border-color: var(--primary); }

.result-block { margin-top: 10px; }
.result-block .label {
  font-size: 12px; font-weight: 700; color: var(--primary);
  margin-bottom: 4px;
}
.result-block .body { font-size: 15px; line-height: 1.7; white-space: pre-wrap; }
.result-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---- フレーズ帳リスト ---- */
.phrase-item {
  background: var(--card); border: 1px solid #e6e8f0; border-radius: 14px;
  padding: 14px; margin-bottom: 10px;
}
.phrase-item .en { font-size: 15px; font-weight: 700; line-height: 1.5; }
.phrase-item .ja { font-size: 13px; color: var(--sub); margin-top: 4px; }
.phrase-item .meta {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
}
.phrase-item .date { font-size: 11px; color: var(--sub); flex: 1; }
.empty-note { text-align: center; color: var(--sub); font-size: 14px; padding: 40px 0; line-height: 1.8; }

/* ---- 日記履歴 ---- */
.diary-item { margin-bottom: 12px; }
.diary-item summary {
  font-size: 14px; font-weight: 700; cursor: pointer; padding: 4px 0;
}
.diary-item .orig { color: var(--sub); font-size: 13px; margin: 8px 0; white-space: pre-wrap; }

/* ---- トースト ---- */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(34, 38, 51, .92); color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 999px; opacity: 0;
  transition: all .25s; pointer-events: none; z-index: 100;
  max-width: 88vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
