/**
 * 約分の練習（赤い数字に注目！） v2.0.0
 * 修正: 標準UIテンプレ（固定ヘッダー＋分数カード＋右下縦ツールバー＋モーダル）に全面刷新
 * すべてのセレクタは .rf-reduction 配下にスコープ（Cocoonテーマ干渉防止）
 */

.rf-reduction {
  --rf-base: #FFFFFF;
  --rf-base-light: #FAFAFA;
  --rf-base-dark: #F5F5F5;
  --rf-main: #1e3a5f;
  --rf-main-light: #2d5a8f;
  --rf-main-dark: #0f1e3a;
  --rf-accent: #d4af37;
  --rf-accent-light: #f4cf5f;
  --rf-accent-dark: #b8941f;
  --rf-text: #2C3E50;
  --rf-text-light: #7F8C8D;
  --rf-border: #E8E8E8;
  --rf-danger: #dc2626;
  --rf-good: #16a34a;
  --rf-shadow: 0 4px 20px rgba(30, 58, 95, 0.10);
}

.rf-reduction,
.rf-reduction * { box-sizing: border-box !important; }

.rf-reduction {
  position: relative;
  z-index: 999999;
  margin: 0;
  font-family: "BIZ UDGothic", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--rf-text);
}

.rf-reduction .rf-app {
  position: relative;
  display: flex !important;
  flex-direction: column !important;
  min-height: 620px;
  background: var(--rf-base-light);
  border: 2px solid var(--rf-border);
  border-radius: 18px;
  overflow: hidden;
}

/* CSS疑似フルスクリーン（iPad Safari など Fullscreen API 非対応向け） */
.rf-reduction .rf-app.rf-css-fs {
  position: fixed !important;
  inset: 0 !important;
  z-index: 999999 !important;
  border-radius: 0;
  border: none;
  min-height: 100vh;
  min-height: 100dvh;
}
.rf-reduction .rf-app:fullscreen {
  background: var(--rf-base-light);
}

/* ===== 固定ヘッダー ===== */
.rf-reduction .rf-header {
  flex: 0 0 auto;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--rf-main);
  border-bottom: 3px solid var(--rf-accent);
}
.rf-reduction .rf-header-title {
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.03em;
}
.rf-reduction .rf-header-status {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.30);
  color: #fff;
}
.rf-reduction .rf-header-status .lbl {
  font-size: 12px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
}
.rf-reduction .rf-header-status .val {
  font-size: 16px;
  font-weight: 900;
}
.rf-reduction .rf-header-status .val b {
  color: var(--rf-accent-light);
  font-size: 20px;
}

/* ===== メイン ===== */
.rf-reduction .rf-main {
  flex: 1 1 auto;
  display: flex !important;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 16px 90px; /* 下部はツールバー分の余白 */
  overflow: auto;
}
.rf-reduction .rf-card {
  width: min(760px, 100%);
  background: var(--rf-base);
  border: 2px solid var(--rf-border);
  border-radius: 18px;
  padding: 24px 22px;
  box-shadow: var(--rf-shadow);
}

/* ===== 約分チェーン（分数→矢印→分数） ===== */
/* 修正: 単一分数表示から、板書風のチェーン表示に変更 */
.rf-reduction .rf-chain-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 4px 0 18px;
  padding: 6px 4px 10px;
}
.rf-reduction .rf-chain {
  display: flex !important;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  width: max-content;
  min-width: 100%;
  margin: 0 auto;
}
/* 1手も約分していない時（分数1つ）は中央寄せ */
.rf-reduction .rf-chain > .rf-frac:only-child {
  margin: 0 auto;
}

.rf-reduction .rf-frac {
  display: grid !important;
  grid-template-rows: auto 8px auto;
  justify-items: center;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 10px 8px;
  border-radius: 16px;
  border: 3px solid transparent;
}
/* 既約になった最後の分数を金色で強調 */
.rf-reduction .rf-frac-done {
  border-color: var(--rf-accent);
  background: rgba(212, 175, 55, 0.08);
  box-shadow: 0 4px 16px rgba(212, 175, 55, 0.30);
}
.rf-reduction .rf-num,
.rf-reduction .rf-den {
  font-size: clamp(48px, 8vw, 80px);
  font-weight: 900;
  line-height: 1;
  display: inline-flex;
  gap: 3px;
}
.rf-reduction .rf-bar {
  height: 7px;
  background: var(--rf-main-dark);
  border-radius: 8px;
  width: 100px;
  transition: width 0.2s ease;
}
.rf-reduction .rf-digit {
  display: inline-block;
  min-width: 0.6em;
  text-align: center;
}
.rf-reduction .rf-red {
  color: var(--rf-danger);
}

/* 青い矢印（上＝分子側、下＝分母側） */
.rf-reduction .rf-arrow {
  flex: 0 0 auto;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center;
  gap: 14px;
  color: #2058c7; /* 板書の青ペン色 */
}
.rf-reduction .rf-arrow-svg {
  display: block;
  width: 96px;
  height: 58px;
}
.rf-reduction .rf-arrow-svg text {
  font-family: inherit;
  font-size: 22px;
  font-weight: 900;
  fill: currentColor;
}

/* ヒント */
.rf-reduction .rf-hint {
  margin: 0 auto 16px;
  padding: 12px 16px;
  max-width: 620px;
  border: 2px solid var(--rf-border);
  border-radius: 14px;
  background: var(--rf-base-light);
  font-size: 15px;
  line-height: 1.8;
  text-align: center;
}
.rf-reduction .rf-hint b { color: var(--rf-accent-dark); }

/* ボタン列（タブレットで押しやすい大きめサイズ） */
.rf-reduction .rf-btn-row {
  display: flex !important;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 14px 0 0;
}
.rf-reduction .rf-btn {
  min-width: 118px;
  min-height: 60px;
  padding: 14px 18px;
  border-radius: 16px;
  border: 2px solid var(--rf-main);
  background: var(--rf-base);
  color: var(--rf-main);
  font-family: inherit;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(30, 58, 95, 0.10);
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.rf-reduction .rf-btn:hover { background: var(--rf-main); color: var(--rf-accent); }
.rf-reduction .rf-btn:active { transform: translateY(2px); }
.rf-reduction .rf-btn-primary {
  background: linear-gradient(135deg, var(--rf-main-light), var(--rf-main));
  color: #fff;
  border: none;
  min-width: 220px;
  box-shadow: 0 4px 14px rgba(30, 58, 95, 0.30);
}
.rf-reduction .rf-btn-primary:hover {
  background: linear-gradient(135deg, var(--rf-main), var(--rf-main-dark));
  color: #fff;
}
/* 既約になったら割るボタンを薄く */
.rf-reduction .rf-btn-row.is-done .rf-btn { opacity: 0.35; pointer-events: none; }

/* 判定メッセージ */
.rf-reduction .rf-judge {
  margin: 16px auto 0;
  max-width: 620px;
  padding: 0;
  font-size: 15px;
  line-height: 1.8;
  text-align: center;
}
.rf-reduction .rf-judge.is-ok,
.rf-reduction .rf-judge.is-ng {
  padding: 14px 16px;
  border-radius: 14px;
  border: 2px solid var(--rf-border);
  background: var(--rf-base);
}
.rf-reduction .rf-judge.is-ok { border-color: rgba(22, 163, 74, 0.55); background: rgba(22, 163, 74, 0.05); }
.rf-reduction .rf-judge.is-ng { border-color: rgba(220, 38, 38, 0.55); background: rgba(220, 38, 38, 0.05); }
.rf-reduction .rf-fb { font-weight: 900; font-size: 18px; }
.rf-reduction .rf-fb-ok { color: var(--rf-good); }
.rf-reduction .rf-fb-ng { color: var(--rf-danger); }
.rf-reduction .rf-note {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  color: var(--rf-text-light);
}
.rf-reduction .rf-note b { color: var(--rf-accent-dark); }

/* ===== 右下 縦ツールバー ===== */
.rf-reduction .rf-toolbar {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex !important;
  flex-direction: column !important;
  gap: 10px;
  z-index: 10;
}
.rf-reduction .rf-app.rf-css-fs .rf-toolbar,
.rf-reduction .rf-app:fullscreen .rf-toolbar {
  position: fixed;
}
.rf-reduction .rf-tb-btn {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  border: 2px solid var(--rf-main);
  background: rgba(255, 255, 255, 0.92);
  color: var(--rf-main);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(30, 58, 95, 0.18);
  transition: transform 0.15s ease, background 0.15s ease;
}
.rf-reduction .rf-tb-btn:hover { background: var(--rf-main); color: var(--rf-accent); }
.rf-reduction .rf-tb-btn:active { transform: translateY(2px); }
.rf-reduction .rf-tb-btn.is-active {
  background: var(--rf-main);
  color: var(--rf-accent);
  border-color: var(--rf-accent);
}

/* ===== モーダル共通 ===== */
.rf-reduction .rf-modal {
  position: absolute;
  inset: 0;
  display: none !important;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 30, 58, 0.55);
  z-index: 20;
}
.rf-reduction .rf-app.rf-css-fs .rf-modal,
.rf-reduction .rf-app:fullscreen .rf-modal {
  position: fixed;
}
.rf-reduction .rf-modal.is-open { display: flex !important; }

.rf-reduction .rf-modal-card {
  width: min(480px, 100%);
  max-height: 85%;
  overflow: auto;
  background: var(--rf-base);
  border: 2px solid var(--rf-border);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(15, 30, 58, 0.35);
}
.rf-reduction .rf-modal-head {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--rf-main);
  border-bottom: 3px solid var(--rf-accent);
}
.rf-reduction .rf-modal-title {
  font-size: 16px;
  font-weight: 900;
  color: #fff;
}
.rf-reduction .rf-modal-close {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.rf-reduction .rf-modal-body { padding: 16px; }

/* スタートモーダル */
.rf-reduction .rf-start-card {
  text-align: center;
  padding: 34px 26px 30px;
  border-top: 4px solid var(--rf-accent);
}
.rf-reduction .rf-start-title {
  font-size: 28px;
  font-weight: 900;
  color: var(--rf-main-dark);
}
.rf-reduction .rf-start-sub {
  margin: 8px 0 24px; /* 修正: 説明文削除に合わせて余白調整 */
  font-size: 16px;
  font-weight: 900;
  color: var(--rf-danger);
}
.rf-reduction .rf-btn-start {
  font-size: 20px;
  min-height: 64px;
}

/* 設定行・スイッチ */
.rf-reduction .rf-set-row {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--rf-border);
  border-radius: 14px;
  background: var(--rf-base-light);
}
.rf-reduction .rf-set-t { font-weight: 900; color: var(--rf-main-dark); font-size: 15px; }
.rf-reduction .rf-set-d { font-size: 12px; color: var(--rf-text-light); margin-top: 2px; }

.rf-reduction .rf-switch { position: relative; width: 58px; height: 34px; flex: 0 0 auto; }
.rf-reduction .rf-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.rf-reduction .rf-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d1d5db;
  transition: 0.2s ease;
  cursor: pointer;
}
.rf-reduction .rf-slider::after {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: #fff;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  transition: 0.2s ease;
}
.rf-reduction .rf-switch input:checked + .rf-slider { background: var(--rf-main-light); }
.rf-reduction .rf-switch input:checked + .rf-slider::after { left: 28px; }

/* きろく一覧 */
.rf-reduction .rf-log-list {
  display: flex !important;
  flex-direction: column !important;
  gap: 8px;
}
.rf-reduction .rf-log-empty {
  padding: 14px;
  border: 1px dashed var(--rf-border);
  border-radius: 14px;
  font-size: 13px;
  color: var(--rf-text-light);
  text-align: center;
}
.rf-reduction .rf-log-item {
  display: flex !important;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--rf-border);
  border-radius: 14px;
  background: var(--rf-base);
  font-size: 15px;
}
.rf-reduction .rf-log-k {
  flex: 0 0 auto;
  min-width: 60px;
  text-align: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: #fffcf5;
  border: 1px solid rgba(212, 175, 55, 0.45);
  color: var(--rf-main-dark);
  font-weight: 900;
}
.rf-reduction .rf-log-flow { font-weight: 700; }
.rf-reduction .rf-log-flow b { color: var(--rf-main-dark); }

/* ===== レスポンシブ ===== */
@media (max-width: 600px) {
  .rf-reduction .rf-app { min-height: 560px; }
  .rf-reduction .rf-header-title { font-size: 16px; }
  .rf-reduction .rf-card { padding: 18px 14px; }
  .rf-reduction .rf-main { padding: 14px 10px 84px; }
  .rf-reduction .rf-btn { min-width: 96px; min-height: 56px; font-size: 16px; padding: 12px 12px; }
  .rf-reduction .rf-tb-btn { width: 48px; height: 48px; font-size: 20px; }
  /* 修正: 小さい画面ではチェーンをコンパクトに */
  .rf-reduction .rf-num,
  .rf-reduction .rf-den { font-size: 44px; }
  .rf-reduction .rf-arrow-svg { width: 72px; height: 46px; }
  .rf-reduction .rf-arrow { gap: 8px; }
}
