/* simeq.css — 連立方程式計算機。すべて .sq 配下にスコープ（サイトのCSSと干渉しない）。
   デザイン: 方眼ノートに青インクで書き、答えだけ赤ペンで丸をつける。
   ダークは .sq[data-sq-theme="dark"] で切替（サイト本番は常にライト）。 */
.sq {
  --sq-paper: #ffffff;
  --sq-ground: #f3f6fc;
  --sq-ink: #1a2657;
  --sq-sub: #55618a;
  --sq-line: #d3daee;
  --sq-grid: rgba(70, 100, 190, .10);
  --sq-accent: #2f52c4;
  --sq-accent-ink: #ffffff;
  --sq-red: #d23c50;
  --sq-ok: #23784a;
  --sq-warn-bg: #fff3ef;
  --sq-warn: #a63a26;
  --sq-key: #eef2fb;
  --sq-key-op: #dfe6f8;
  --sq-font: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", Meiryo, sans-serif;
  --sq-math: "Hiragino Mincho ProN", "BIZ UDPMincho", "Yu Mincho", "Noto Serif JP", "Times New Roman", serif;
  box-sizing: border-box;
  max-width: 680px;
  margin: 0 auto;
  color: var(--sq-ink);
  font-family: var(--sq-font);
  font-size: 16px;
  line-height: 1.7;
  text-align: left;
}
.sq[data-sq-theme="dark"] {
  --sq-paper: #182036;
  --sq-ground: #0f1526;
  --sq-ink: #e4e9fb;
  --sq-sub: #a2aed3;
  --sq-line: #303c66;
  --sq-grid: rgba(140, 165, 245, .09);
  --sq-accent: #8fa8ff;
  --sq-accent-ink: #0f1526;
  --sq-red: #ff7d8e;
  --sq-ok: #6fd39a;
  --sq-warn-bg: #3a2320;
  --sq-warn: #ffb4a3;
  --sq-key: #222c4a;
  --sq-key-op: #2c3861;
}
.sq *, .sq *::before, .sq *::after { box-sizing: border-box; }
.sq i { font-family: var(--sq-math); font-style: italic; font-weight: 500; }
:where(.sq button) { font: inherit; color: inherit; cursor: pointer; } /* :where で優先度0＝個別指定が必ず勝つ */
.sq :focus-visible { outline: 3px solid var(--sq-accent); outline-offset: 2px; }

.sq-card {
  background: var(--sq-paper);
  border: 1px solid var(--sq-line);
  border-radius: 14px;
  padding: 16px;
}
.sq-grid {
  background-image:
    linear-gradient(var(--sq-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--sq-grid) 1px, transparent 1px);
  background-size: 22px 22px;
  background-color: var(--sq-paper);
}
.sq-h { margin: 0 0 8px; font-size: 15px; font-weight: 700; color: var(--sq-sub); letter-spacing: .04em; }

/* 入力 */
.sq-row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.sq-lab { flex: none; width: 34px; height: 44px; display: grid; place-items: center; font-size: 22px; font-weight: 700; color: var(--sq-accent); }
.sq-fieldw { flex: 1; min-width: 0; }
.sq-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 2px solid var(--sq-line);
  border-radius: 10px;
  background: var(--sq-paper);
  color: var(--sq-ink);
  font-family: var(--sq-math);
  font-size: 22px;
  letter-spacing: .02em;
}
.sq-input:focus { border-color: var(--sq-accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--sq-accent) 25%, transparent); }
.sq-prev { min-height: 34px; padding: 2px 4px 0; font-family: var(--sq-math); font-size: 21px; color: var(--sq-sub); overflow-x: auto; white-space: nowrap; }
.sq-prev:empty::before { content: "式のプレビュー"; font-family: var(--sq-font); font-size: 13px; color: var(--sq-line); }

/* 分数 */
.sq-fr { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 .12em; line-height: 1.05; font-size: .92em; }
.sq-fr > span:first-child { padding: 0 .18em .04em; border-bottom: 1.5px solid currentColor; }
.sq-fr > span:last-child { padding: .04em .18em 0; }

/* キーパッド */
.sq-pad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 12px; }
.sq-key.w2 { grid-column: span 2; }
.sq-key {
  height: 48px;
  border: 1px solid var(--sq-line);
  border-radius: 10px;
  background: var(--sq-key);
  font-family: var(--sq-math);
  font-size: 22px;
  touch-action: manipulation;
  user-select: none;
}
.sq-key:active { transform: translateY(1px); background: var(--sq-key-op); }
.sq-key.op { background: var(--sq-key-op); }
.sq-key.var { font-style: italic; color: var(--sq-accent); font-weight: 700; }
.sq-key.fn { font-family: var(--sq-font); font-size: 14px; }

/* 例題 */
.sq-ex { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; padding: 0; list-style: none; }
.sq-chip {
  min-height: 36px; padding: 0 12px;
  border: 1px solid var(--sq-line); border-radius: 999px;
  background: var(--sq-paper); font-size: 13px; color: var(--sq-sub);
}
.sq-chip:hover { border-color: var(--sq-accent); color: var(--sq-ink); }

/* 方法・実行 */
.sq-ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 16px; }
.sq-seg { display: inline-flex; border: 2px solid var(--sq-line); border-radius: 12px; overflow: hidden; background: var(--sq-paper); }
.sq-seg button { min-height: 44px; padding: 0 14px; border: 0; background: transparent; font-size: 14px; font-weight: 700; color: var(--sq-sub); }
.sq-seg button + button { border-left: 1px solid var(--sq-line); }
.sq-seg button[aria-pressed="true"] { background: var(--sq-accent); color: var(--sq-accent-ink); }
.sq-go {
  flex: 1 1 140px; min-height: 52px; border: 0; border-radius: 12px;
  background: var(--sq-accent); color: var(--sq-accent-ink);
  font-size: 20px; font-weight: 700; letter-spacing: .12em;
}
.sq .sq-go { color: var(--sq-accent-ink); font-weight: 700; }
.sq-go:active { transform: translateY(1px); }
.sq-clear { min-height: 44px; padding: 0 14px; border: 0; background: transparent; color: var(--sq-sub); text-decoration: underline; font-size: 14px; }

.sq-err { margin: 14px 0 0; padding: 12px 14px; border-radius: 10px; background: var(--sq-warn-bg); color: var(--sq-warn); font-size: 15px; }

/* 結果 */
.sq-out { margin-top: 18px; display: grid; gap: 16px; }
.sq-why { margin: 0; font-size: 14px; color: var(--sq-sub); }
.sq-why b { color: var(--sq-ink); }
.sq-ans { display: grid; place-items: center; padding: 8px 0; }
.sq-ring {
  display: grid; justify-items: start; gap: 2px;
  padding: 16px 40px 18px;
  border: 4px solid var(--sq-red);
  border-radius: 52% 48% 55% 45% / 58% 50% 50% 42%;
  transform: rotate(-1.6deg);
  color: var(--sq-red);
  font-family: var(--sq-math);
  font-size: clamp(30px, 8vw, 40px);
  font-weight: 700;
  line-height: 1.35;
}
.sq-ring.msg { justify-items: center; font-family: var(--sq-font); font-size: clamp(22px, 6vw, 28px); padding: 16px 32px; }
.sq-ringnote { margin: 4px 0 0; font-size: 14px; color: var(--sq-sub); text-align: center; }

.sq-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.sq-switch { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0; border: 0; background: transparent; font-size: 14px; font-weight: 700; }
.sq-sw { position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--sq-line); transition: background .15s; }
.sq-sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--sq-paper); transition: transform .15s; }
.sq-switch[aria-pressed="true"] .sq-sw { background: var(--sq-accent); }
.sq-switch[aria-pressed="true"] .sq-sw::after { transform: translateX(18px); }
.sq-tool { min-height: 44px; padding: 0 12px; border: 1px solid var(--sq-line); border-radius: 10px; background: var(--sq-paper); font-size: 14px; }

.sq-steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.sq-step { display: grid; grid-template-columns: 34px 1fr; gap: 12px; padding: 14px 14px 14px 12px; }
.sq-n { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--sq-accent); color: var(--sq-accent-ink); font-size: 14px; font-weight: 700; }
.sq-sb { min-width: 0; }
.sq-st { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.5; }
.sq-note { margin: 2px 0 6px; font-size: 14px; color: var(--sq-sub); }
.sq-math { display: grid; gap: 2px; font-family: var(--sq-math); font-size: 21px; overflow-x: auto; padding: 2px 0; }
.sq-ml { white-space: nowrap; }
.sq-ok { color: var(--sq-ok); font-family: var(--sq-font); margin-left: .4em; }
.sq-new { animation: sq-in .25s ease-out; }
@keyframes sq-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .sq-new { animation: none; } .sq-sw, .sq-sw::after { transition: none; } }

/* 筆算 */
.sq-calc { display: inline-grid; grid-template-columns: auto auto auto auto auto; column-gap: .55em; align-items: baseline; margin: 6px 0 2px; font-family: var(--sq-math); font-size: 22px; font-variant-numeric: tabular-nums; }
.sq-calc > span { white-space: nowrap; text-align: right; padding: 1px 0; }
.sq-calc .op { color: var(--sq-accent); text-align: center; font-weight: 700; min-width: 1.6em; }
.sq-calc .eqs { text-align: center; }
.sq-calc .rule { grid-column: 1 / -1; height: 0; border-top: 2px solid var(--sq-ink); margin: 3px 0; padding: 0; }
.sq-calc .res { color: var(--sq-accent); font-weight: 700; }

.sq-hintbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.sq-next { flex: 1 1 160px; min-height: 48px; border: 2px dashed var(--sq-accent); border-radius: 12px; background: transparent; color: var(--sq-accent); font-weight: 700; }
.sq-share { font-size: 13px; color: var(--sq-sub); }

@media (max-width: 480px) { .sq-math { font-size: 18px; } .sq-calc { font-size: 19px; } .sq-ring { padding-inline: 28px; } }
.sq-k-check .sq-ml { white-space: normal; }

/* テーマ（SWELL）の見出し・リスト装飾が入っても崩れないための防御 */
.sq .sq-st { padding: 0; border: 0; background: none; }
.sq .sq-st::before, .sq .sq-st::after { content: none; }
.sq .sq-steps, .sq .sq-ex { margin: 0; padding: 0; list-style: none; }
.sq .sq-steps > li, .sq .sq-ex > li { margin: 0; }
.sq .sq-steps > li::before, .sq .sq-steps > li::after, .sq .sq-ex > li::before, .sq .sq-ex > li::after { content: none; }
.sq .sq-note, .sq .sq-why { margin-block: 0; }

/* 文字の数の切替・hidden（サイトのCSSに [hidden] の指定が無くても隠れるように） */
.sq [hidden] { display: none !important; }
.sq-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 8px; }
.sq-head .sq-h { margin: 0; }
.sq-head .sq-seg button { min-height: 38px; }

/* 練習問題 */
.sq-prac { margin-top: 16px; border: 2px dashed var(--sq-accent); }
.sq-prac[hidden] { display: none !important; }
.sq-prac-h { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.sq-prac-h .sq-h { margin: 0 auto 0 0; }
.sq-prac-h .sq-seg button { min-height: 38px; padding: 0 10px; font-size: 13px; }
.sq-x { width: 38px; height: 38px; border: 0; border-radius: 50%; background: transparent; font-size: 24px; line-height: 1; color: var(--sq-sub); }
.sq-prob { display: grid; gap: 4px; padding: 12px 14px; margin: 4px 0 12px; border-radius: 10px; background: var(--sq-ground); font-family: var(--sq-math); font-size: 22px; overflow-x: auto; }
.sq-plab { display: inline-block; width: 1.6em; color: var(--sq-accent); font-weight: 700; }
.sq-ansrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.sq-ain { display: inline-flex; align-items: center; gap: 6px; font-family: var(--sq-math); font-size: 22px; }
.sq-aninput { width: 92px; height: 44px; padding: 0 10px; border: 2px solid var(--sq-line); border-radius: 10px; background: var(--sq-paper); color: var(--sq-ink); font-family: var(--sq-math); font-size: 22px; text-align: center; }
.sq-aninput:focus { border-color: var(--sq-accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--sq-accent) 25%, transparent); }
.sq-mini { display: inline-flex; gap: 6px; }
.sq-mk { width: 44px; height: 44px; border: 1px solid var(--sq-line); border-radius: 10px; background: var(--sq-key-op); font-family: var(--sq-math); font-size: 22px; }
.sq-pbtns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.sq-pbtns .sq-tool:first-child { background: var(--sq-accent); color: var(--sq-accent-ink); border-color: var(--sq-accent); font-weight: 700; }
#sq-verdict { margin-top: 10px; }
.sq-vd { margin: 0 0 8px; font-size: 16px; font-weight: 700; }
.sq-vd.ok { color: var(--sq-ok); font-size: 20px; }
.sq-vd.ng { color: var(--sq-warn); }
.sq-vd.warn { color: var(--sq-sub); font-weight: 400; }
.sq-maru { display: inline-grid; place-items: center; width: 34px; height: 34px; margin-right: 8px; border: 3px solid var(--sq-red); border-radius: 50%; color: var(--sq-red); font-size: 20px; line-height: 1; }
