/* リセットと基本設定 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* 全体レイアウト */
body.board-body {
  margin: 0;
  padding: 0;
  font-family: 'Noto Sans JP', 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: #f8fafc;
  color: #1e293b;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  display: flex;
  justify-content: center;
  align-items: stretch;
  width: 100vw;
  height: 100dvh;
}

.board-app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 16px;
  box-sizing: border-box;
  overflow: hidden;
  flex: 1 1 auto;
}

/* 1. トップナビゲーション */
.board-top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 4px;
  flex-shrink: 0;
}

.nav-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: 9999px;
  background-color: #ffffff;
  color: #0284c7;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  border: 1px solid #bae6fd;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: background-color 0.15s, transform 0.1s;
}

.nav-back-btn:active {
  background-color: #e0f2fe;
  transform: scale(0.97);
}

.nav-back-icon {
  font-size: 20px;
  line-height: 1;
}

.board-page-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: 0.5px;
}

.layout-toggle-btn {
  padding: 6px 12px;
  border-radius: 9999px;
  border: 1px solid #cbd5e1;
  background-color: #ffffff;
  color: #475569;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  transition: all 0.15s;
}

.layout-toggle-btn:hover {
  background-color: #f1f5f9;
}

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

/* 2. 入力欄 & アクションボタン エリア */
.board-input-section {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.board-input-box-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 2px solid #cbd5e1;
  border-radius: 14px;
  padding: 8px 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  transition: border-color 0.15s;
  min-height: 80px;
}

.board-input-box-wrapper:focus-within {
  border-color: #0284c7;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.board-text-display {
  flex: 1;
  min-height: 40px;
  font-size: 24px;
  font-weight: 700;
  color: #0f172a;
  word-break: break-all;
  outline: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.board-text-display:empty::before {
  content: attr(placeholder);
  color: #94a3b8;
  font-size: 16px;
  font-weight: 400;
}

/* カーソル（キャレット） */
.board-text-display::after {
  content: "";
  display: inline-block;
  width: 3px;
  height: 24px;
  background-color: #0284c7;
  margin-left: 2px;
  animation: blink 1s step-end infinite;
  vertical-align: middle;
}

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

.board-input-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #f1f5f9;
}

.board-action-btn {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s;
}

.board-action-btn:active {
  transform: scale(0.95);
  background-color: #e2e8f0;
}

.btn-toggle-char {
  background-color: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

.btn-backspace {
  background-color: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

.btn-clear-all {
  background-color: #fff1f2;
  border-color: #ffe4e6;
  color: #e11d48;
}

/* 話すボタン（大きく目立たせる） */
.board-speak-bar {
  display: flex;
  align-items: stretch;
}

.board-speak-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 20px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.35);
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
  min-width: 90px;
}

.board-speak-btn:hover {
  background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
}

.board-speak-btn:active {
  transform: scale(0.95);
  box-shadow: 0 2px 5px rgba(2, 132, 199, 0.2);
}

.speak-icon {
  font-size: 26px;
  line-height: 1;
}

.speak-text {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 1px;
}

/* 3. 予測入力候補表示欄 */
.predict-bar-section {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 6px 10px;
  margin-bottom: 8px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  overflow: hidden;
  height: 48px;
  width: 100%;
  box-sizing: border-box;
}

.predict-bar-label {
  flex-shrink: 0;
}

.predict-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  background-color: #e0f2fe;
  color: #0369a1;
  font-size: 12px;
  font-weight: 800;
}

.predict-candidate-list {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  padding: 2px 0;
}

/* 候補チップ */
.candidate-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  background-color: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #0f172a;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.candidate-chip:hover {
  background-color: #e0f2fe;
  border-color: #7dd3fc;
  color: #0284c7;
}

.candidate-chip:active {
  transform: scale(0.94);
  background-color: #bae6fd;
}

.candidate-chip.chip-ngram {
  background-color: #fefce8;
  border-color: #fef08a;
  color: #854d0e;
}

.candidate-chip.chip-learned {
  background-color: #fdf2f8;
  border-color: #fbcfe8;
  color: #9d174d;
}

.candidate-hint-tag {
  font-size: 10px;
  font-weight: 800;
  opacity: 0.7;
  text-transform: uppercase;
}

/* 4. キーボード本体コンテナ */
.board-keyboard-container {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 4-A. タブレット用 50音表（右から左へ並ぶ医療用配置） */
.tablet-kana-grid {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 100%;
  height: 100%;
  padding: 4px 0;
  box-sizing: border-box;
}

.kana-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 0;
  width: 0;
  min-width: 0;
}

.kana-key {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  background-color: #ffffff;
  color: #0f172a;
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: background-color 0.1s, transform 0.08s, box-shadow 0.1s;
  touch-action: manipulation;
}

.kana-key:hover {
  background-color: #f8fafc;
}

.kana-key:active, .kana-key.is-pressed {
  background-color: #bae6fd;
  border-color: #0284c7;
  color: #0369a1;
  transform: translateY(2px) scale(0.97);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.key-func {
  background-color: #f1f5f9;
  border-color: #94a3b8;
  color: #334155;
  font-size: 18px;
}

#key-tab-daku, #key-tab-handaku {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

#key-tab-small {
  font-size: 18px;
  font-weight: 700;
}

.key-spacer {
  flex: 1;
  visibility: hidden;
}

/* 4-B. スマホ用 3×4 テンキー（フリック対応） */
.mobile-flick-grid {
  display: none; /* デフォルトは非表示、メディアクエリまたはクラスで表示 */
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 4px;
  box-sizing: border-box;
}

.flick-key {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background-color: #ffffff;
  border: 1px solid #cbd5e1;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.06);
  cursor: pointer;
  touch-action: none; /* フリック検知のためブラウザ標準スクロールを無効化 */
  transition: background-color 0.1s, transform 0.08s;
  user-select: none;
}

.flick-key:active, .flick-key.is-flicking {
  background-color: #e0f2fe;
  border-color: #38bdf8;
}

.flick-key-main {
  font-size: 26px;
  font-weight: 800;
  color: #0f172a;
}

.flick-key-sub {
  font-size: 11px;
  color: #64748b;
  position: absolute;
  bottom: 4px;
}

.flick-func-key {
  background-color: #f1f5f9;
  border-color: #94a3b8;
}

.flick-func-key .flick-key-main {
  font-size: 18px;
  color: #334155;
}

.flick-symbol-key .flick-key-main {
  font-size: 20px;
}

/* フリック方向ガイド（控えめな文字） */
.flick-guide {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  pointer-events: none;
}

.guide-top {
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
}

.guide-left {
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
}

.guide-right {
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
}

.guide-bottom {
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
}

/* 5. フリック展開ポップアップ (Flower Flick Overlay) */
.flick-flower-popup {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  width: 190px;
  height: 190px;
  transform: translate(-50%, -50%);
}

.flower-petal {
  position: absolute;
  width: 58px;
  height: 58px;
  border-radius: 12px;
  background-color: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid #bae6fd;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 900;
  color: #0f172a;
  transition: background-color 0.1s, transform 0.1s, color 0.1s, border-color 0.1s;
}

.petal-center {
  top: 66px;
  left: 66px;
  background-color: #f0f9ff;
  border-color: #38bdf8;
}

.petal-top {
  top: 2px;
  left: 66px;
}

.petal-left {
  top: 66px;
  left: 2px;
}

.petal-right {
  top: 66px;
  right: 2px;
}

.petal-bottom {
  bottom: 2px;
  left: 66px;
}

/* 選択された花びらの強調アニメーション */
.flower-petal.petal-active {
  background-color: #0284c7;
  border-color: #0369a1;
  color: #ffffff;
  transform: scale(1.15);
  box-shadow: 0 10px 25px rgba(2, 132, 199, 0.4);
}

/* レスポンシブ切り替えルール */
/* スマホ縦向き画面（幅 < 768px または縦長向き） */
@media (max-width: 767px), (orientation: portrait) and (max-width: 900px) {
  .tablet-kana-grid {
    display: none;
  }
  .mobile-flick-grid {
    display: grid;
  }
}

/* 明示的にクラスで強制切り替えされた場合 */
.force-flick .tablet-kana-grid {
  display: none !important;
}
.force-flick .mobile-flick-grid {
  display: grid !important;
}

.force-tablet .tablet-kana-grid {
  display: flex !important;
}
.force-tablet .mobile-flick-grid {
  display: none !important;
}
