:root{
  --base:#FFFFFF; --base-light:#FAFAFA; --base-dark:#F5F5F5;
  --main:#1e3a5f; --main-light:#2d5a8f; --main-dark:#0f1e3a;
  --accent:#d4af37; --accent-light:#f4cf5f; --accent-dark:#b8941f;
  --text:#2C3E50; --text-light:#7F8C8D; --border:#E8E8E8;
  --danger:#dc2626; --good:#16a34a; --bad:#dc2626;
  --shadow:0 4px 20px rgba(30,58,95,.10);
  --shadow-hover:0 8px 30px rgba(30,58,95,.15);
}
.rf-reduction *{box-sizing:border-box}
.rf-reduction{
  font-family:"Noto Sans JP",system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;
  background:linear-gradient(180deg,#f6f7fb 0%, #eef2ff 100%);
  color:var(--text);
  margin:0;
  padding:14px;
  border-radius:18px;
}

/* ===== Layout ===== */
.rf-reduction .rf-layout{
  display:grid;
  grid-template-columns: 340px 1fr;
  gap:14px;
  align-items:start;
}
.rf-reduction .rf-mob-toggle{
  display:none;
  width:100%;
  margin:4px 0 12px;
  padding:12px 14px;
  border-radius:14px;
  border:2px solid var(--main);
  background:var(--base);
  color:var(--main);
  font-weight:900;
  cursor:pointer;
  box-shadow:0 2px 8px rgba(30,58,95,.10);
}

/* ===== Sidebar ===== */
.rf-reduction .rf-side{
  position:sticky;
  top:12px;
  height:calc(100vh - 24px);
  overflow:auto;
  background:var(--base);
  border:2px solid var(--border);
  border-radius:18px;
  box-shadow:var(--shadow);
}
.rf-reduction .rf-side-inner{ padding:14px; }

.rf-reduction .rf-side-hero{
  background:var(--main);
  border-top:3px solid var(--accent);
  border-bottom:3px solid var(--accent);
  border-radius:16px;
  padding:14px 14px 12px;
  position:relative;
  overflow:hidden;
  box-shadow:0 10px 30px rgba(15,30,58,.20);
}
.rf-reduction .rf-side-hero::before{
  content:'';
  position:absolute; inset:0;
  background:linear-gradient(90deg,transparent,rgba(212,175,55,.12),transparent);
  transform:translateX(-100%);
  animation:rf-rp-shine 3.2s infinite;
}
@keyframes rf-rp-shine{
  0%{transform:translateX(-100%)}
  100%{transform:translateX(100%)}
}
.rf-reduction .rf-side-title{
  margin:0;
  font-size:18px;
  font-weight:900;
  color:#fff;
  text-shadow:0 2px 8px rgba(0,0,0,.25);
  letter-spacing:.02em;
  position:relative;
  z-index:1;
}
.rf-reduction .rf-side-pill{
  display:block;
  margin-top:10px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.35);
  background:rgba(255,255,255,.10);
  font-size:12px;
  color:rgba(255,255,255,.92);
  line-height:1.6;
  position:relative;
  z-index:1;
}

.rf-reduction .sb-card{
  margin-top:12px;
  border:2px solid var(--border);
  border-radius:16px;
  background:var(--base);
  box-shadow:0 2px 10px rgba(30,58,95,.06);
  overflow:hidden;
}
.rf-reduction .sb-card-h{
  padding:10px 12px;
  font-weight:900;
  font-size:13px;
  color:#fff;
  background:linear-gradient(135deg,var(--main-light),var(--main));
}
.rf-reduction .sb-card-b{ padding:12px; }

.rf-reduction .sb-mini{
  display:flex;
  gap:10px;
  align-items:center;
  justify-content:space-between;
  padding:10px 10px;
  border-radius:14px;
  border:1px solid var(--border);
  background:var(--base-light);
  font-weight:900;
}
.rf-reduction .sb-mini .label{
  font-size:12px;
  color:var(--text-light);
  font-weight:800;
}
.rf-reduction .sb-mini .value{
  font-size:16px;
  color:var(--main-dark);
}
.rf-reduction .sb-log{
  margin-top:10px;
  display:flex;
  flex-direction:column;
  gap:8px;
}
.rf-reduction .sb-log-empty{
  font-size:12px;
  color:var(--text-light);
  padding:10px 10px;
  border-radius:14px;
  border:1px dashed var(--border);
  background:var(--base);
}
.rf-reduction .sb-log-item{
  border:1px solid var(--border);
  background:var(--base);
  border-radius:14px;
  padding:10px 10px;
  line-height:1.35;
}
.rf-reduction .sb-log-item .top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  font-weight:900;
}
.rf-reduction .sb-log-item .k{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:64px;
  padding:6px 10px;
  border-radius:999px;
  background:#fffcf5;
  border:1px solid rgba(212,175,55,.45);
  color:var(--main-dark);
}
.rf-reduction .sb-log-item .arrow{ color:var(--text-light); font-weight:900; }
.rf-reduction .sb-log-item .after{ font-weight:900; color:var(--main-dark); }
.rf-reduction .sb-log-item .small{
  margin-top:6px;
  font-size:12px;
  color:var(--text-light);
}

.rf-reduction .sb-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 10px;
  border:1px solid var(--border);
  border-radius:14px;
  background:var(--base-light);
}
.rf-reduction .sb-row .left{ display:flex; flex-direction:column; gap:2px; }
.rf-reduction .sb-row .t{
  font-weight:900;
  color:var(--main-dark);
  font-size:14px;
}
.rf-reduction .sb-row .d{
  font-size:12px;
  color:var(--text-light);
  font-weight:700;
}

/* switch */
.rf-reduction .switch{ position:relative; width:56px; height:32px; flex:0 0 auto; }
.rf-reduction .switch input{ position:absolute; opacity:0; width:0; height:0; }
.rf-reduction .slider{
  position:absolute; inset:0;
  border-radius:999px;
  background:#d1d5db;
  border:2px solid var(--border);
  transition:.2s ease;
  cursor:pointer;
}
.rf-reduction .slider::after{
  content:'';
  position:absolute;
  width:24px; height:24px;
  left:4px; top:50%;
  transform:translateY(-50%);
  background:#fff;
  border-radius:999px;
  box-shadow:0 2px 8px rgba(0,0,0,.15);
  transition:.2s ease;
}
.rf-reduction .switch input:checked + .slider{
  background:rgba(30,90,143,.95);
  border-color:rgba(30,90,143,.35);
}
.rf-reduction .switch input:checked + .slider::after{ left:28px; }

.rf-reduction .rf-side-footer{
  margin-top:12px;
  padding:10px 12px;
  border-top:1px dashed var(--border);
  color:var(--text-light);
  font-size:12px;
}

/* ===== Main area & fullscreen ===== */
.rf-reduction .rf-play{ position:relative; }
.rf-reduction .rf-play:fullscreen{
  background:linear-gradient(180deg,#f6f7fb 0%, #eef2ff 100%);
  padding:14px;
  overflow:auto;
}
.rf-reduction .rf-play:fullscreen .rf-card{ max-width:980px; margin:0 auto; }

/* fullscreen zoom UI */
.rf-reduction .zoom-ui{ display:none; }
.rf-reduction .rf-play:fullscreen .zoom-ui{
  display:flex;
  position:fixed;
  right:14px;
  bottom:14px;
  z-index:2147483647;
  gap:8px;
  padding:10px;
  border-radius:16px;
  background:rgba(255,255,255,.86);
  border:1px solid rgba(15,23,42,.10);
  box-shadow:0 10px 30px rgba(15,23,42,.20);
  backdrop-filter: blur(6px);
}
.rf-reduction .zoom-ui .zlabel{
  display:flex;
  align-items:center;
  justify-content:center;
  min-width:72px;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  background:var(--base);
  font-weight:900;
  color:var(--main-dark);
}
.rf-reduction .zoom-ui button{
  padding:10px 12px;
  border-radius:12px;
  border:2px solid var(--main);
  background:var(--base);
  color:var(--main);
  font-weight:900;
  cursor:pointer;
  box-shadow:0 2px 8px rgba(30,58,95,.10);
}
.rf-reduction .zoom-ui button:hover{ background:var(--main); color:var(--accent); }
.rf-reduction .zoom-ui button:active{ transform:translateY(1px); }

/* Card */
.rf-reduction .rf-card{
  background:var(--base);
  border:2px solid var(--border);
  border-radius:18px;
  padding:22px;
  box-shadow:var(--shadow);
  position:relative;
  overflow:hidden;
}
.rf-reduction .rf-card::before{
  content:'';
  position:absolute; top:0; left:0; right:0; height:4px;
  background:linear-gradient(90deg,var(--accent),var(--accent-light),var(--accent));
}

/* Fraction */
.rf-reduction .frac-area{ display:flex; justify-content:center; margin:6px 0 18px; }
.rf-reduction .frac{
  display:grid;
  grid-template-rows:auto 10px auto;
  justify-items:center;
  align-items:center;
  background:var(--base);
  border:2px solid var(--border);
  border-radius:22px;
  padding:34px 40px;
  box-shadow:0 10px 30px rgba(30,58,95,.12);
  width:min(560px, 100%);
}
.rf-reduction .num,.rf-reduction .den{
  font-size:82px;
  font-weight:900;
  letter-spacing:2px;
  display:inline-flex;
  gap:4px;
  line-height:1;
}
.rf-reduction .bar{
  height:8px;
  background:var(--main-dark);
  border-radius:8px;
  width:160px;
  transition:width .2s ease;
}
.rf-reduction .digit{
  display:inline-block;
  min-width:.6em;
  text-align:center;
  transition:color .2s ease;
}
.rf-reduction .red{ color:var(--danger); font-weight:900; }

/* Buttons */
.rf-reduction .button-group{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  justify-content:center;
  margin:16px 0;
}
.rf-reduction .btn{
  padding:14px 18px;
  border-radius:14px;
  border:2px solid var(--main);
  background:var(--base);
  cursor:pointer;
  font-weight:900;
  font-size:15px;
  color:var(--main);
  min-width:104px;
  box-shadow:0 2px 8px rgba(30,58,95,.10);
  transition:transform .2s ease, box-shadow .2s ease, background .2s ease, color .2s ease;
}
.rf-reduction .btn:hover:not([disabled]){
  transform:translateY(-2px);
  box-shadow:var(--shadow-hover);
  background:var(--main);
  color:var(--accent);
}
.rf-reduction .btn:active:not([disabled]){ transform:translateY(0); }
.rf-reduction .btn[disabled]{ opacity:.5; cursor:not-allowed; }
.rf-reduction .btn.primary{
  background:linear-gradient(135deg,var(--main-light) 0%, var(--main) 100%);
  color:#fff;
  border:none;
  box-shadow:0 4px 12px rgba(30,58,95,.30);
}
.rf-reduction .btn.primary:hover:not([disabled]){
  background:linear-gradient(135deg,var(--main) 0%, var(--main-dark) 100%);
  color:#fff;
}

/* Messages */
.rf-reduction .msg{
  margin-top:12px;
  padding:14px;
  border:2px solid var(--border);
  border-radius:12px;
  background:var(--base);
  line-height:1.8;
  font-size:14px;
  box-shadow:0 2px 10px rgba(30,58,95,.06);
}
.rf-reduction .msg b{ color:var(--accent-dark); font-weight:900; }
.rf-reduction .msg.state-ok{ border-color:rgba(22,163,74,.55); background:rgba(22,163,74,.05); }
.rf-reduction .msg.state-ng{ border-color:rgba(220,38,38,.55); background:rgba(220,38,38,.05); }
.rf-reduction .feedback{ font-weight:900; font-size:16px; }
.rf-reduction .ok{ color:var(--good); }
.rf-reduction .ng{ color:var(--bad); }
.rf-reduction .note{
  font-size:12px;
  color:var(--text-light);
  margin-top:12px;
  padding:10px 12px;
  background:var(--base-dark);
  border:1px solid var(--border);
  border-radius:12px;
}

/* Mobile: sidebar drawer */
@media (max-width: 900px){
  .rf-reduction{ padding:10px; }
  .rf-reduction .rf-layout{ grid-template-columns: 1fr; }
  .rf-reduction .rf-mob-toggle{ display:block; }
  .rf-reduction .rf-side{
    position:fixed;
    left:0; top:0;
    height:100vh;
    width:min(380px, 92vw);
    transform:translateX(-105%);
    transition:transform .22s ease;
    z-index:9999;
    border-radius:0 18px 18px 0;
  }
  .rf-reduction.rf-side-open .rf-side{ transform:translateX(0); }
  .rf-reduction.rf-side-open::after{
    content:'';
    position:fixed;
    inset:0;
    background:rgba(0,0,0,.35);
    z-index:9998;
  }
}
@media (max-width:600px){
  .rf-reduction .num,.rf-reduction .den{ font-size:64px; }
  .rf-reduction .frac{ padding:26px 22px; border-radius:20px; }
  .rf-reduction .btn{ padding:12px 14px; font-size:14px; min-width:94px; }
  .rf-reduction .rf-play:fullscreen .zoom-ui{ right:10px; bottom:10px; padding:8px; border-radius:14px; }
  .rf-reduction .zoom-ui .zlabel{ min-width:64px; padding:9px 10px; }
  .rf-reduction .zoom-ui button{ padding:9px 10px; }
}
