/*
  sirubedon.com に移したツールの共通部品。
  各ツールの index.html で、ツール固有のCSSのあとに読み込む。続けて /tools/nav.js と /tools/tool-frame.js を <head> で読み込む。<body class="tool-frame"> を付けたツールに効く。

  色の使い分け（コントラストの都合で決めている）
  - 主ボタン・リンク …… バイオレットに白文字（約7.8:1）
  - 選択中 ……………… アクアにインク文字（約8.1:1）。色だけに頼らず、太字や罫線でも分かるようにする
  - レモン ……………… 入力欄の面・注意の通知
  - ティール …………… 罫線・アイコン・大きな見出しだけ。通常の文字色には使わない（4.5:1 に届かない）
  形：角丸0、大きなカード・ずらし影なし。罫線と余白で区切る。
  文字：本文は M PLUS 1、見出しと短いラベルだけ DotGothic16。

  部品の一覧
  .tf-btn（主）/ .tf-btn.is-sub（副）/ .tf-btn.is-quiet（文字だけ）/ .tf-btn.is-danger（消す操作）/ .tf-btn.is-small
  .tf-input / .tf-select / .tf-textarea、.tf-field（ラベル＋入力のまとまり）、.tf-label（ドット文字の小見出し）
  .tf-choices > label.tf-choice（ラジオを札にしたもの。:has(:checked) か .is-selected で選択の見た目）
  .tf-tabs > .tf-tab（[aria-selected="true"] か .is-active で選択）
  .tf-range（スライダー）、.tf-check（チェックボックスとラベル）
  .tf-note（画面内のお知らせ。.is-warn / .is-error / .is-ok）
  .tf-toast（右下に出て消えるお知らせ。tool-frame.js の tfNotify() が作る）
  .tf-h1 / .tf-h2、.tf-rule（区切り線）、.tf-soft（薄い文字）、.tf-kbd
  .tf-page（1列のページの幅。--tf-content）

  上のメニューと左のツール一覧（.tf-shell）は tool-frame.js が組み立てる。場所はこのCSSが先に空ける。
  画面いっぱいに使うツールは、高さを 100dvh ではなく var(--tf-view-h) にする（上のメニューのぶんを引いた高さ）。
*/
:root {
  --tf-bg: #fcfcf7;
  --tf-surface: #ffffff;
  --tf-lemon: #fff6cf;
  --tf-aqua: #3fc4c9;
  --tf-teal: #198c9b;
  --tf-violet: #4a44a8;
  --tf-violet-hover: #3a3590;
  --tf-ink: #1b1b22;
  --tf-ink-soft: #5e5e68;
  --tf-line: rgba(27, 27, 34, 0.18);
  --tf-danger: #b3261e;
  --tf-ok: #1f6b3a;
  --tf-sans: 'M PLUS 1', system-ui, sans-serif;
  --tf-dot: 'DotGothic16', ui-monospace, monospace;
}

/* 暗いとき（テキストコンバーターのダークモード）。<body data-theme="dark"> で切り替わる */
body.tool-frame[data-theme="dark"] {
  --tf-bg: #17171d;
  --tf-surface: #202028;
  --tf-lemon: #2c2a1c;
  --tf-aqua: #3fc4c9;
  --tf-teal: #3fb2bf;
  --tf-violet: #8e88f0;
  --tf-violet-hover: #a7a2f5;
  --tf-ink: #ececf1;
  --tf-ink-soft: #a9a9b6;
  --tf-line: rgba(236, 236, 241, 0.2);
  --tf-danger: #ff8a80;
  --tf-ok: #7fd49a;
}

/* 部品は枠線・余白込みの大きさで扱う（width: 100% ではみ出さないように） */
.tf-btn,
.tf-input,
.tf-select,
.tf-textarea,
.tf-choice,
.tf-tab,
.tf-note,
.tf-toast,
.tf-range {
  box-sizing: border-box;
}

body.tool-frame {
  font-family: var(--tf-sans);
  background-color: var(--tf-bg);
  color: var(--tf-ink);
}
html:has(> body.tool-frame) {
  background-color: var(--tf-bg);
}
body.tool-frame :focus-visible {
  outline: 2px solid var(--tf-violet);
  outline-offset: 2px;
}
body.tool-frame a:not([class]) {
  color: var(--tf-violet);
}

/* ---- 見出し・文字 ---- */
.tf-h1 {
  margin: 0;
  font-family: var(--tf-sans);
  font-weight: 800;
  font-size: 1.5rem;
  line-height: 1.3;
}
.tf-h1 .tf-en {
  display: block;
  font-family: var(--tf-dot);
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--tf-teal);
  letter-spacing: 0.04em;
}
.tf-h2 {
  margin: 0 0 8px;
  padding-bottom: 4px;
  font-family: var(--tf-dot);
  font-weight: 400;
  font-size: 1rem;
  border-bottom: 1px solid var(--tf-ink);
}
.tf-label {
  display: block;
  margin: 0 0 4px;
  font-family: var(--tf-dot);
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--tf-ink);
}
.tf-soft {
  color: var(--tf-ink-soft);
}
.tf-rule {
  border: 0;
  border-top: 1px solid var(--tf-line);
  margin: 16px 0;
}
.tf-kbd {
  display: inline-block;
  padding: 0 4px;
  font-family: var(--tf-dot);
  font-size: 0.8em;
  border: 1px solid var(--tf-ink);
  background: var(--tf-surface);
}

/* ---- ボタン ---- */
.tf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px;
  font-family: var(--tf-sans);
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.3;
  color: #fff;
  background: var(--tf-violet);
  border: 1px solid var(--tf-violet);
  border-radius: 0;
  box-shadow: none;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.12s;
}
.tf-btn:hover {
  background: var(--tf-violet-hover);
  border-color: var(--tf-violet-hover);
}
body.tool-frame[data-theme="dark"] .tf-btn:not(.is-sub):not(.is-quiet):not(.is-danger) {
  color: #17171d;
}
.tf-btn.is-sub {
  color: var(--tf-ink);
  background: var(--tf-surface);
  border-color: var(--tf-ink);
}
.tf-btn.is-sub:hover {
  background: var(--tf-lemon);
}
.tf-btn.is-quiet {
  min-height: 32px;
  padding: 4px 8px;
  color: var(--tf-ink);
  background: transparent;
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.tf-btn.is-quiet:hover {
  background: var(--tf-lemon);
}
.tf-btn.is-danger {
  color: var(--tf-danger);
  background: var(--tf-surface);
  border-color: var(--tf-danger);
}
.tf-btn.is-danger:hover {
  color: #fff;
  background: var(--tf-danger);
}
.tf-btn.is-small {
  min-height: 30px;
  padding: 2px 10px;
  font-size: 0.82rem;
}
.tf-btn.is-block {
  display: flex;
  width: 100%;
}
.tf-btn:disabled,
.tf-btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}
.tf-btn i,
.tf-btn .fas,
.tf-btn .far {
  font-size: 0.9em;
}

/* ---- 入力 ---- */
.tf-input,
.tf-select,
.tf-textarea {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 6px 10px;
  font-family: var(--tf-sans);
  font-size: 1rem; /* 16px 未満だと iPhone で入力時に拡大される */
  line-height: 1.5;
  color: var(--tf-ink);
  background: var(--tf-lemon);
  border: 1px solid var(--tf-ink);
  border-radius: 0;
  box-shadow: none;
}
.tf-textarea {
  min-height: 6em;
  resize: vertical;
}
.tf-select {
  appearance: none;
  padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, var(--tf-ink) 50%), linear-gradient(-45deg, transparent 50%, var(--tf-ink) 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.tf-input::placeholder,
.tf-textarea::placeholder {
  color: var(--tf-ink-soft);
  opacity: 1;
}
.tf-input:focus,
.tf-select:focus,
.tf-textarea:focus {
  outline: 2px solid var(--tf-violet);
  outline-offset: 0;
}
.tf-input[type="color"] {
  padding: 2px;
  background: var(--tf-surface);
  cursor: pointer;
}
.tf-field {
  display: block;
  margin: 0 0 12px;
}
.tf-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.tf-row > .tf-field {
  flex: 1 1 0;
  min-width: 0;
  margin-bottom: 0;
}

/* ---- 札型のラジオ（選択肢） ---- */
.tf-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tf-choice {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 4px 12px;
  font-size: 0.9rem;
  color: var(--tf-ink);
  background: var(--tf-surface);
  border: 1px solid var(--tf-line);
  border-radius: 0;
  cursor: pointer;
  user-select: none;
}
.tf-choice:hover {
  border-color: var(--tf-ink);
}
.tf-choice input[type="radio"],
.tf-choice input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.tf-choice:has(input:checked),
.tf-choice.is-selected {
  color: #1b1b22;
  font-weight: 700;
  background: var(--tf-aqua);
  border-color: var(--tf-ink);
  box-shadow: inset 0 0 0 1px var(--tf-ink);
}
.tf-choice:has(input:focus-visible) {
  outline: 2px solid var(--tf-violet);
  outline-offset: 2px;
}

/* ---- タブ ---- */
.tf-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--tf-ink);
}
.tf-tab {
  padding: 8px 14px;
  font-family: var(--tf-sans);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--tf-ink-soft);
  background: transparent;
  border: 0;
  border-radius: 0;
  cursor: pointer;
}
.tf-tab:hover {
  color: var(--tf-ink);
  background: var(--tf-lemon);
}
.tf-tab[aria-selected="true"],
.tf-tab.is-active {
  color: #1b1b22;
  background: var(--tf-aqua);
}

/* ---- スライダー ---- */
.tf-range {
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.tf-range::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--tf-ink);
}
.tf-range::-moz-range-track {
  height: 4px;
  background: var(--tf-ink);
}
.tf-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 20px;
  margin-top: -8px;
  background: var(--tf-aqua);
  border: 1px solid var(--tf-ink);
  border-radius: 0;
}
.tf-range::-moz-range-thumb {
  width: 14px;
  height: 18px;
  background: var(--tf-aqua);
  border: 1px solid var(--tf-ink);
  border-radius: 0;
}

/* ---- チェックボックス ---- */
.tf-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.tf-check input[type="checkbox"],
.tf-check input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--tf-violet);
}

/* ---- 画面内のお知らせ ---- */
.tf-note {
  margin: 8px 0;
  padding: 8px 12px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--tf-ink);
  background: var(--tf-surface);
  border: 1px solid var(--tf-ink);
  border-left-width: 6px;
}
.tf-note.is-warn {
  background: var(--tf-lemon);
}
.tf-note.is-error {
  border-color: var(--tf-danger);
  border-left-color: var(--tf-danger);
}
.tf-note.is-ok {
  border-left-color: var(--tf-teal);
}
.tf-note[hidden] {
  display: none;
}

/* 右下に出て、しばらくすると消えるお知らせ（tfNotify） */
.tf-toasts {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  max-width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}
.tf-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  font-family: var(--tf-sans);
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--tf-ink);
  background: var(--tf-surface);
  border: 1px solid var(--tf-ink);
  border-left: 6px solid var(--tf-teal);
  pointer-events: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.tf-toast.is-warn {
  background: var(--tf-lemon);
  border-left-color: var(--tf-ink);
}
.tf-toast.is-error {
  border-color: var(--tf-danger);
  border-left-color: var(--tf-danger);
}
.tf-toast-close {
  flex: none;
  margin: -2px -4px 0 auto;
  padding: 0 4px;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--tf-ink);
  background: transparent;
  border: 0;
  cursor: pointer;
}

/* ---- 1列のページの幅 ----
   読み込み前の画面や、入力して結果を受け取るだけのツールは、この幅にそろえる */
.tf-page {
  box-sizing: border-box;
  width: 100%;
  max-width: calc(var(--tf-content) + 80px);
  margin-inline: auto;
  padding: 28px 40px 48px;
}
/* ページの見出しの下に太い線（1列のページで共通） */
.tf-page > .tf-h1 {
  margin-bottom: 8px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--tf-ink);
}

/* ================================================================
   がわ：上のメニュー（サイト共通）と、左のツール一覧
   色はサイト（src/layouts/Base.astro）と同じ値を、ここに直接書いている。
   ツールの暗い表示（data-theme="dark"）でも、上の帯はサイトと同じ色のままにする。
   文字の大きさは px。ツールごとに rem の基準や下ごしらえ（リセット）が違っても崩れないように。
   ================================================================ */
:root {
  --tf-top: 48px;
  --tf-rail: 200px;
  --tf-content: 1040px;
  /* 上のメニューを引いた、画面の高さ */
  --tf-view-h: calc(100vh - var(--tf-top));
  scroll-padding-top: calc(var(--tf-top) + 12px);
}
@supports (height: 100dvh) {
  :root {
    --tf-view-h: calc(100dvh - var(--tf-top));
  }
}
:root.tf-rail-closed {
  --tf-rail: 0px;
}

body.tool-frame {
  max-width: none;
  margin: 0;
  padding: var(--tf-top) 0 0 var(--tf-rail);
}
/* スクリプトが組み立てる前から、帯の色だけ出しておく */
body.tool-frame::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 89;
  box-sizing: border-box;
  height: var(--tf-top);
  background: #fff6cf;
  border-bottom: 2px solid #1b1b22;
}

.tf-shell,
.tf-shell * {
  box-sizing: border-box;
}
.tf-shell {
  font-family: var(--tf-sans);
  font-size: 15px;
  line-height: 1.5;
  color: #1b1b22;
}
.tf-shell a {
  color: inherit;
  text-decoration: none;
}
.tf-shell p,
.tf-shell ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.tf-shell :focus-visible {
  outline: 2px solid #4a44a8;
  outline-offset: -2px;
}

/* 上のメニュー */
.tf-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--tf-top);
  padding: 0 16px 2px 0;
}
.tf-top-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: stretch;
  margin: 0;
  padding: 0 14px 0 16px;
  font-family: var(--tf-dot);
  font-size: 14px;
  line-height: 1;
  color: #1b1b22;
  background: transparent;
  border: 0;
  border-right: 1px solid rgba(27, 27, 34, 0.3);
  border-radius: 0;
  cursor: pointer;
}
.tf-top-toggle:hover {
  background: #fcfcf7;
}
.tf-top-toggle[aria-expanded='true'] {
  color: #fcfcf7;
  background: #1b1b22;
}
/* 三本線 */
.tf-top-bars {
  width: 14px;
  height: 10px;
  border-block: 2px solid currentColor;
  background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat;
}
.tf-top-logo {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 800;
}
.tf-top-menu {
  display: flex;
  align-self: stretch;
  min-width: 0;
}
.tf-top-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}
a.tf-top-item:hover {
  background: #fcfcf7;
}
.tf-top-item.is-off {
  font-weight: 400;
  color: #5e5e68;
  cursor: default;
}
.tf-top-item[aria-current='page'] {
  color: #fcfcf7;
  background: #1b1b22;
}
.tf-shell .tf-num {
  font-family: var(--tf-dot);
  font-size: 13px;
  font-weight: 400;
  color: #147783;
}
.tf-top-item[aria-current='page'] .tf-num {
  color: #7ce5ec;
}
.tf-shell .tf-top-links {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.tf-top-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  background: #fcfcf7;
  border: 1px solid #1b1b22;
}
.tf-top-link:hover {
  color: #fcfcf7;
  background: #1b1b22;
}
.tf-top-link.is-more {
  font-family: var(--tf-dot);
  font-size: 12px;
}

/* 左のツール一覧。色はツールの地に合わせる（暗い表示でもなじむように） */
.tf-rail {
  position: fixed;
  top: var(--tf-top);
  bottom: 0;
  left: 0;
  z-index: 88;
  width: 200px;
  padding: 12px 0 24px;
  overflow-y: auto;
  color: var(--tf-ink);
  background: var(--tf-bg);
  border-right: 1px solid var(--tf-ink);
}
:root.tf-rail-closed .tf-rail {
  display: none;
}
.tf-rail-site,
.tf-rail-scrim {
  display: none;
}
.tf-shell .tf-rail-h {
  margin: 16px 0 2px;
  padding: 0 14px;
  font-family: var(--tf-dot);
  font-size: 12px;
  color: var(--tf-teal);
}
.tf-rail-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 14px;
  font-size: 14px;
  line-height: 1.4;
}
a.tf-rail-item:hover {
  background: var(--tf-lemon);
}
.tf-rail-item[aria-current='page'] {
  font-weight: 700;
  color: #1b1b22;
  background: var(--tf-aqua);
  box-shadow: inset 4px 0 0 var(--tf-ink);
}
.tf-rail-item.is-off {
  color: var(--tf-ink-soft);
}
.tf-rail-all {
  font-family: var(--tf-dot);
}
.tf-rail-ext {
  margin-left: auto;
  font-family: var(--tf-dot);
  font-size: 11px;
  color: var(--tf-ink-soft);
}

/* 中くらいの画面（1200px 未満）：ツール一覧は出したままにせず、「ツール」ボタンで左から重ねて出す。
   ツールの画面の幅を削らないため。ツール側のスマホ向けの切り替え（960px・768px など）ともぶつからない */
@media (max-width: 1199px) {
  :root {
    --tf-rail: 0px;
  }
  .tf-rail,
  :root.tf-rail-closed .tf-rail {
    display: none;
    z-index: 100001;
    width: min(280px, 84vw);
  }
  :root.tf-rail-open .tf-rail {
    display: block;
  }
  :root.tf-rail-open .tf-rail-scrim {
    display: block;
    position: fixed;
    inset: var(--tf-top) 0 0 0;
    z-index: 100000;
    background: rgba(27, 27, 34, 0.5);
  }
}
/* メニューとアイコンが並びきらない幅では、アイコンをしまう */
@media (max-width: 1000px) {
  .tf-shell .tf-top-links {
    display: none;
  }
}

/* 狭い画面：上はボタンとロゴだけ。サイトのメニューも、ツール一覧と一緒に左から出す */
@media (max-width: 860px) {
  :root {
    --tf-top: 44px;
  }
  .tf-top-menu {
    display: none;
  }
  .tf-top {
    gap: 12px;
  }
  .tf-rail,
  :root.tf-rail-closed .tf-rail {
    padding-top: 0;
  }
  .tf-rail-site {
    display: block;
    padding: 6px 0;
    color: #1b1b22;
    background: #fff6cf;
    border-bottom: 1px solid #1b1b22;
  }
  .tf-rail-site .tf-rail-item {
    font-weight: 700;
  }
  .tf-rail-site a.tf-rail-item:hover {
    background: #fcfcf7;
  }
  .tf-rail-site .tf-rail-item[aria-current='page'] {
    color: #fcfcf7;
    background: #1b1b22;
    box-shadow: none;
  }
  .tf-rail-item {
    padding: 10px 16px;
    font-size: 15px;
  }
  .tf-shell .tf-rail-h {
    padding: 0 16px;
  }
  .tf-page {
    padding: 16px 16px 40px;
  }
}

@media print {
  body.tool-frame {
    padding: 0;
  }
  body.tool-frame::before,
  .tf-shell,
  .tf-toasts {
    display: none;
  }
}
