/* 文字画像APNGメーカー */
:root {
  --bg: #f5f7fb;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --panel-soft: rgba(255, 255, 255, 0.6);
  --field: #ffffff;
  --ink: #1f2a3a;
  --muted: #66758a;
  --line: rgba(76, 100, 132, 0.18);
  --line-strong: rgba(76, 100, 132, 0.32);
  --blue: #3a78d8;
  --blue-deep: #245bb0;
  --blue-soft: rgba(58, 120, 216, 0.1);
  --cyan: #6ad6ff;
  --accent: #e0703c;
  --accent-deep: #c4541f;
  --ok: #1f9d6b;
  --warn: #c97a00;
  --danger: #cf3d3d;
  --shadow: 0 18px 44px rgba(25, 43, 76, 0.12);
  --shadow-soft: 0 6px 18px rgba(25, 43, 76, 0.08);
  --radius: 22px;
  --radius-sm: 14px;
  --checker-a: #dfe4ec;
  --checker-b: #f6f8fb;
  --seg-in: #4f8ff0;
  --seg-hold: #9aa9bd;
  --seg-out: #ee8a52;
}

body.is-dark {
  --bg: #07111f;
  --panel: rgba(12, 25, 43, 0.9);
  --panel-solid: #0d1b2f;
  --panel-soft: rgba(255, 255, 255, 0.04);
  --field: rgba(255, 255, 255, 0.05);
  --ink: #eef6ff;
  --muted: #9fb0c6;
  --line: rgba(168, 204, 255, 0.16);
  --line-strong: rgba(168, 204, 255, 0.3);
  --blue: #69a8ff;
  --blue-deep: #377de0;
  --blue-soft: rgba(105, 168, 255, 0.14);
  --accent: #f08a55;
  --accent-deep: #d86a33;
  --ok: #3cc98f;
  --warn: #f0b046;
  --danger: #ff7272;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 6px 18px rgba(0, 0, 0, 0.3);
  --checker-a: #1a2536;
  --checker-b: #243248;
  --seg-hold: #5d6d85;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
/* 韓国語は単語（空白で区切られたまとまり）の途中で改行しない */
html:lang(ko) body { word-break: keep-all; overflow-wrap: anywhere; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(106, 214, 255, 0.2), transparent 32%),
    radial-gradient(circle at 90% 12%, rgba(58, 120, 216, 0.18), transparent 28%),
    var(--bg);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
h1, h2, h3, p { margin-top: 0; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

.app-header, .drawer, .workspace, .legal-footer {
  width: 100%;
  max-width: 1440px;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- ヘッダー ---------- */

.app-header {
  position: relative;
  display: grid;
  /* タイトルは1行の幅をとり、入りきらないときはボタンの側を折り返す（タイトルを語の途中で改行しない） */
  grid-template-columns: auto minmax(min-content, 1fr);
  /* 説明文はボタン列の下まで使い、1行に収めてヘッダーを低くする */
  grid-template-areas: "title actions" "lead lead";
  column-gap: 1rem;
  row-gap: 0;
  padding: 22px 26px 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(235, 244, 255, 0.74));
  box-shadow: var(--shadow);
}

body.is-dark .app-header { background: linear-gradient(135deg, rgba(16, 32, 55, 0.95), rgba(9, 18, 32, 0.8)); }

.title-block { grid-area: title; min-width: 0; }

.eyebrow, .panel-kicker {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

h1 {
  margin-bottom: 7px;
  font-size: clamp(1.5rem, 3vw, 2.3rem);
  line-height: 1.1;
  /* 「メーカ｜ー」のような語の途中の改行をしない（どうしても入らない狭さのときだけ折り返す） */
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* 見出しが折り返すときは行の長さをそろえ、日本語は文節の途中で切らない（対応ブラウザのみ） */
h2, h3 { text-wrap: balance; }
html:lang(ja) :is(h2, h3) { word-break: auto-phrase; }

.lead {
  grid-area: lead;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.6;
  font-feature-settings: "palt";
}

.header-actions {
  grid-area: actions;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  align-content: flex-start;
  gap: 8px;
}

/* ボタンが2行に分かれるとき、テーマの切り替えだけが次の行に残らないよう、ショートカットと組にする */
.header-actions-end { display: inline-flex; align-items: center; gap: 8px; }

.header-nav-link, .ghost-button, .x-share-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.1rem;
  padding: 0.38rem 0.78rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 5px 12px rgba(25, 43, 76, 0.06);
  transition: transform .15s ease, background .15s ease, border-color .15s ease, color .15s ease;
}

.header-nav-link:hover, .ghost-button:not(:disabled):hover, .x-share-link:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--blue) 58%, transparent);
  color: var(--blue-deep);
  background: var(--blue-soft);
}

body.is-dark .header-nav-link:hover, body.is-dark .ghost-button:not(:disabled):hover, body.is-dark .x-share-link:hover { color: #dfeeff; }

.x-share-link { min-width: 2.1rem; padding: 0; font-size: 1rem; }

.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 2.1rem;
  padding: 0 0.5rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
}

.lang-choice-button {
  padding: 0.25rem 0.35rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.lang-choice-button.is-active { color: var(--blue); }
.lang-divider { color: var(--line-strong); font-size: 0.78rem; }

.theme-button { min-width: 56px; padding: 0 3px; }

.theme-toggle-track {
  position: relative;
  display: block;
  width: 48px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
}

.theme-toggle-thumb {
  position: absolute;
  top: 1px;
  left: 1px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #ffffff;
  color: #f59e0b;
  font-size: 0.72rem;
  box-shadow: 0 2px 7px rgba(25, 43, 76, 0.18);
  transition: transform .18s ease;
}

body.is-dark .theme-toggle-track { background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(30, 64, 175, 0.72)); }
body.is-dark .theme-toggle-thumb { transform: translateX(24px); background: #e2e8f0; color: #334155; }

.version-engrave {
  position: absolute;
  right: 26px;
  bottom: 10px;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  opacity: 0.6;
}

/* ---------- ドロワー ---------- */

.drawer {
  position: relative;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.drawer h2 { margin-bottom: 12px; font-size: 1rem; }

.drawer-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: rgba(106, 214, 255, 0.16);
  color: var(--blue);
  font-size: 1.15rem;
  font-weight: 900;
}

.guide-list, .guide-notes { display: grid; gap: 7px; }
.guide-notes { margin-top: 10px; }

.guide-list p, .guide-notes p {
  margin: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
  font-size: 0.84rem;
  line-height: 1.5;
}

.guide-list p { font-weight: 700; }
.guide-notes p { color: var(--muted); }

.shortcut-grid {
  display: grid;
  grid-template-columns: minmax(260px, auto) 1fr;
  gap: 7px 9px;
}

.shortcut-grid > div, .shortcut-grid > span {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
  font-size: 0.82rem;
  font-weight: 700;
}

.shortcut-grid kbd {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  padding: 2px 7px;
  border: 1px solid rgba(106, 214, 255, 0.42);
  border-radius: 999px;
  background: rgba(106, 214, 255, 0.14);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 900;
}

.shortcut-grid b { color: var(--muted); }

/* ---------- ワークスペース ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 540px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-title { margin: 0; font-size: 1.02rem; }

.preview-panel {
  position: sticky;
  top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 28px);
  overflow: auto;
  scrollbar-gutter: stable;
}

/* ---------- モード ---------- */

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mode-tab {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 0;
  padding: 9px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--panel-soft);
  color: var(--ink);
  text-align: left;
  transition: border-color .15s ease, background .15s ease, transform .15s ease, box-shadow .15s ease;
}

.mode-tab:hover { transform: translateY(-1px); border-color: var(--line-strong); }

.mode-tab.is-active {
  border-color: var(--blue);
  background: linear-gradient(160deg, var(--blue-soft), transparent 80%), var(--panel-solid);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent), var(--shadow-soft);
}

.mode-head { display: flex; align-items: center; gap: 6px; min-width: 0; }

.mode-icon {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--muted);
  transition: color .15s ease;
}

.mode-tab.is-active .mode-icon, .mode-tab:hover .mode-icon { color: var(--blue); }
.mode-name { min-width: 0; font-size: 0.92rem; font-weight: 900; line-height: 1.25; }
.mode-desc { max-width: 100%; color: var(--muted); font-size: 0.68rem; line-height: 1.35; font-feature-settings: "palt"; }

/* 短い説明やラベルが折り返すときは、行の長さをそろえ（1〜2文字だけが次の行に残らないように）、
   日本語は文節の途中で切らない（どちらも対応ブラウザのみ。ほかのブラウザは通常の折り返し） */
.mode-desc, .template-hint, .field-label, .field-row > label, .toggle-field, .toggle-inline { text-wrap: balance; }
html:lang(ja) :is(.mode-desc, .template-hint, .field-label, .field-row > label, .toggle-field, .toggle-inline) { word-break: auto-phrase; }

/* ---------- テンプレート ---------- */

.template-block {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-soft);
}

.template-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.template-hint { margin: 2px 0 8px; color: var(--muted); font-size: 0.74rem; }

.link-button {
  padding: 2px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.link-button:hover { color: var(--blue); background: var(--blue-soft); }

/* テンプレートの分類（メッセージのみ）。分類を選ぶと、その分類の場面に切り替わる */
.template-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin: 0 0 8px;
  padding: 3px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field);
}

.template-groups[hidden] { display: none; }

.template-group {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.template-group:hover { color: var(--blue); }
.template-group.is-active { background: var(--blue); color: #ffffff; box-shadow: var(--shadow-soft); }

/* 分類の下のシステムの段（判定のみ）。分類より一段控えめな見た目にする */
.template-systems {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin: -2px 0 8px;
  padding: 0 2px;
}

.template-systems[hidden] { display: none; }
.template-systems-label { margin-right: 2px; color: var(--muted); font-size: 0.72rem; font-weight: 800; }

.template-system {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--field);
  color: var(--ink);
  font-size: 0.74rem;
  font-weight: 800;
  white-space: nowrap;
  transition: border-color .15s ease, background .15s ease;
}

.template-system:hover { border-color: var(--line-strong); }
.template-system.is-active { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-deep); }
body.is-dark .template-system.is-active { color: #dfeeff; }

/* 2段分の高さを確保しても（main.js の reserveTemplateRows）、段は上に詰めてチップ自体は伸ばさない */
.template-strip { display: flex; flex-wrap: wrap; align-content: flex-start; align-items: flex-start; gap: 4px; }

.template-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--panel-solid);
  font-size: 0.8rem;
  font-weight: 800;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.template-chip:hover { transform: translateY(-1px); border-color: var(--line-strong); }
.template-chip.is-active { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-deep); }
body.is-dark .template-chip.is-active { color: #dfeeff; }
.template-icon {
  flex: none;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--muted);
  transition: color .15s ease;
}

.template-chip.is-active .template-icon, .template-chip:hover .template-icon { color: var(--blue); }

/* ---------- 設定タブ ---------- */

.settings-tabs {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  gap: 4px;
  margin: 14px -4px 0;
  padding: 6px 4px;
  overflow-x: auto;
  background: var(--panel-solid);
  border-radius: 14px;
  scrollbar-width: none;
}

.settings-tabs::-webkit-scrollbar { display: none; }

.settings-tab {
  flex: 1 0 auto;
  padding: 8px 12px;
  border: 1.5px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
}

.settings-tab:hover { color: var(--ink); background: var(--blue-soft); }
.settings-tab.is-active { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-deep); }
body.is-dark .settings-tab.is-active { color: #dfeeff; }

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
}

/* ---------- フィールド ---------- */

.control-section {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-soft);
  overflow: hidden;
}

.control-section.is-off { background: transparent; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
}

.section-title { margin: 0; font-size: 0.88rem; font-weight: 900; }

.section-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 12px 12px;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.field-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.field-heading {
  margin: 6px 0 -2px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: 0.86rem;
  font-weight: 900;
}

.field-note {
  margin: 0;
  padding: 7px 10px;
  border-radius: 10px;
  background: var(--blue-soft);
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre-line;
}

.field-note.is-dynamic { background: color-mix(in srgb, var(--warn) 12%, transparent); }

.text-input, .select-input, .number-input {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font-size: 0.88rem;
}

textarea.text-input { resize: vertical; min-height: 60px; line-height: 1.6; }
.text-input:focus, .select-input:focus, .number-input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
.select-input { padding-right: 28px; }
body.is-dark .select-input option, body.is-dark .select-input optgroup { background: #0d1b2f; color: #eef6ff; }

.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.number-box { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.number-box .number-input { width: 72px; min-height: 28px; padding: 3px 6px; text-align: right; font-size: 0.8rem; }
.number-suffix { color: var(--muted); font-size: 0.72rem; font-weight: 700; min-width: 1.6em; }

.range-input { width: 100%; margin: 0; accent-color: var(--blue); }

.segment-group, .chip-group { display: flex; flex-wrap: wrap; gap: 5px; }

.segment-group {
  flex-wrap: nowrap;
  padding: 3px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field);
}

.segment {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.segment.is-active { background: var(--blue); color: #ffffff; box-shadow: var(--shadow-soft); }

.chip {
  padding: 5px 10px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--field);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  transition: border-color .15s ease, background .15s ease;
}

.chip:hover { border-color: var(--line-strong); }
.chip.is-active { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-deep); }
body.is-dark .chip.is-active { color: #dfeeff; }
.chip-group.compact .chip { padding: 3px 8px; font-size: 0.74rem; }

.toggle-field, .toggle-inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.switch { position: relative; display: inline-flex; flex: none; }
.switch-input { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }

.switch-track {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background .15s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform .15s ease;
}

.switch-input:checked + .switch-track { background: var(--blue); }
.switch-input:checked + .switch-track::after { transform: translateX(16px); }
.switch-input:focus-visible + .switch-track { outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent); outline-offset: 2px; }
.switch-input:disabled { cursor: not-allowed; }
.switch-input:disabled + .switch-track { opacity: 0.5; }
.toggle-inline.is-disabled { color: var(--muted); cursor: not-allowed; }

.color-row { display: flex; flex-wrap: wrap; gap: 8px; }

.color-field {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 128px;
  padding: 5px 8px 5px 5px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  cursor: pointer;
}

.color-input {
  width: 34px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
}

.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 1px solid var(--line-strong); border-radius: 7px; }
.color-input::-moz-color-swatch { border: 1px solid var(--line-strong); border-radius: 7px; }
.color-meta { display: flex; flex-direction: column; line-height: 1.2; }
.color-label { color: var(--muted); font-size: 0.7rem; font-weight: 800; }
.color-hex { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.76rem; font-weight: 700; }
.color-field.is-empty .color-input { opacity: 0.25; }
.color-field.is-empty .color-hex { color: var(--muted); font-family: inherit; }

.color-clear {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-left: auto;
  border: 0;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 900;
  line-height: 1;
}

.swatch-group { display: flex; flex-wrap: wrap; gap: 6px; }

.swatch {
  width: 30px;
  height: 30px;
  border: 2px solid var(--panel-solid);
  border-radius: 999px;
  box-shadow: 0 0 0 1.5px var(--line-strong);
  transition: transform .15s ease;
}

.swatch:hover { transform: scale(1.1); }

.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.mini-button:hover { border-color: var(--blue); color: var(--blue-deep); }

/* ---------- 効果カード ---------- */

.effect-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 7px;
}

.effect-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 5px 5px 6px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  text-align: left;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}

.effect-card:hover { transform: translateY(-1px); border-color: var(--line-strong); }

.effect-card.is-active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 22%, transparent);
}

.effect-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  background: linear-gradient(160deg, #26324a, #151c2c);
}

.effect-meta { display: flex; flex-direction: column; gap: 1px; padding: 0 2px; }
.effect-name { font-size: 0.75rem; font-weight: 800; line-height: 1.25; }
.effect-badge { color: var(--muted); font-size: 0.64rem; font-weight: 700; }

/* ---------- フォント選択 ---------- */

.font-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  text-align: left;
}

.font-current:hover, .font-current[aria-expanded="true"] { border-color: var(--blue); }
.font-current-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.font-current-name { color: var(--muted); font-size: 0.74rem; font-weight: 800; }
.font-current-sample { font-size: 1.35rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-caret { color: var(--muted); }

.font-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
  padding: 10px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--panel-soft);
}

.font-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 6px;
  max-height: 340px;
  overflow: auto;
  padding: 2px;
}

.font-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 9px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: var(--field);
  text-align: left;
}

.font-card:hover { border-color: var(--line-strong); }
.font-card.is-active { border-color: var(--blue); background: var(--blue-soft); }
.font-card-sample { font-size: 1.2rem; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.35; transition: opacity .2s ease; }
.font-card.is-loaded .font-card-sample, .font-card[data-font^="upload:"] .font-card-sample, .font-card[data-font^="local:"] .font-card-sample { opacity: 1; }
.font-card-name { color: var(--muted); font-size: 0.7rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 自作フォント（マイフォント）の登録・解除 */
.font-register-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 6px; }
.font-register { cursor: pointer; }
.font-register-note { flex: 1 1 220px; color: var(--muted); font-size: 0.7rem; line-height: 1.45; }
.font-card-wrap { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); }
.font-card-wrap .font-card { padding-right: 30px; }
.font-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1;
}
.font-remove:hover, .font-remove:focus-visible { border-color: var(--danger); color: var(--danger); }
.font-remove.is-armed { border-color: var(--danger); background: var(--danger); color: #fff; font-size: 0.68rem; }

.font-extras { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; border-top: 1px dashed var(--line); }
.font-extra-row { display: flex; gap: 6px; }
.font-extra-row .text-input { flex: 1; min-height: 34px; }

/* ---------- 配置 ---------- */

.anchor-grid {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(3, 28px);
  gap: 4px;
  width: max-content;
  padding: 6px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field);
}

.anchor-cell {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
}

.anchor-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--line-strong); }
.anchor-cell.is-active { border-color: var(--blue); background: var(--blue-soft); }
.anchor-cell.is-active .anchor-dot { width: 12px; height: 12px; background: var(--blue); }

.size-custom { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.size-custom .number-input { width: 96px; }

/* ---------- プレビュー ---------- */

.preview-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.font-status {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-deep);
  font-size: 0.72rem;
  font-weight: 800;
}

body.is-dark .font-status { color: #dfeeff; }

.preview-bg { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.preview-bg-label { color: var(--muted); font-size: 0.74rem; font-weight: 800; }

.preview-stage-wrap { display: flex; justify-content: center; width: 100%; }

.preview-stage {
  position: relative;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background-color: #202634;
  background-position: center;
  background-size: cover;
  box-shadow: var(--shadow-soft);
}

.preview-stage[data-bg="checker"] {
  background-color: var(--checker-b);
  background-image: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%);
  background-size: 22px 22px;
  background-position: 0 0;
}

.preview-stage[data-bg="dark"] { background-color: #0b0d12; }
.preview-stage[data-bg="light"] { background-color: #fbfbfd; }
.preview-stage[data-bg="gray"] { background-color: #7c8594; }

.preview-stage canvas { display: block; width: 100%; height: 100%; }

/* ---------- 再生操作 ---------- */

.transport { display: flex; flex-direction: column; gap: 6px; }
.transport-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.transport-toggles { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-left: 4px; }

.primary-button, .accent-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  color: #ffffff;
  font-weight: 900;
  text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}

.primary-button { background: linear-gradient(135deg, var(--blue), var(--blue-deep)); box-shadow: 0 8px 18px color-mix(in srgb, var(--blue) 30%, transparent); }
.accent-button { background: linear-gradient(135deg, var(--accent), var(--accent-deep)); box-shadow: 0 8px 18px color-mix(in srgb, var(--accent) 32%, transparent); }
.primary-button:not(:disabled):hover, .accent-button:not(:disabled):hover { transform: translateY(-1px); filter: brightness(1.05); }
/* ナイトモードでは暗い背景に光がにじんで見えやすいので、ボタンの下の光を控えめにする */
body.is-dark .accent-button { box-shadow: 0 4px 10px color-mix(in srgb, var(--accent) 14%, transparent); }
body.is-dark .accent-button:not(:disabled):hover { filter: brightness(1.03); }

.play-button { min-width: 116px; }

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--field);
  font-size: 1.05rem;
  font-weight: 900;
}

.icon-button:hover { border-color: var(--blue); color: var(--blue); }

.time-label {
  margin-left: auto;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 700;
}

.timeline {
  --playhead: 0%;
  position: relative;
  height: 24px;
  border-radius: 8px;
  background: var(--field);
  border: 1px solid var(--line);
  overflow: hidden;
}

.timeline .seg { position: absolute; top: 6px; bottom: 6px; border-radius: 4px; opacity: 0.85; }
.timeline .seg-in { background: var(--seg-in); }
.timeline .seg-hold { background: var(--seg-hold); }
.timeline .seg-out { background: var(--seg-out); }

.timeline .playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--playhead);
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
  pointer-events: none;
  z-index: 1;
}

.scrub-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
  z-index: 2;
}

.timeline-legend { display: flex; gap: 12px; color: var(--muted); font-size: 0.7rem; font-weight: 700; }
.legend { display: inline-flex; align-items: center; gap: 5px; }
.legend::before { content: ""; width: 10px; height: 10px; border-radius: 3px; }
.legend-in::before { background: var(--seg-in); }
.legend-hold::before { background: var(--seg-hold); }
.legend-out::before { background: var(--seg-out); }

/* ---------- 書き出し ---------- */

.export-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-soft);
}

.export-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px; }
.info-line { margin: 0; color: var(--muted); font-size: 0.78rem; font-weight: 700; }

/* 書き出しの設定：選択肢の文字が欠けないよう、それぞれの欄はいちばん長い選択肢の幅より狭くせず、
   横に入りきらない欄は次の行へ回す（パネルの幅や言語が変わっても、パネルの外へはみ出さない） */
.export-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 10px;
}

.export-grid > .field { flex: 1 1 auto; min-width: auto; max-width: 100%; }
.export-grid .select-input { width: auto; }
.export-grid > .fps-field { flex-grow: 0.5; }
.export-grid > .loop-count-field { flex: 0 0 5.5rem; }
.export-grid > .wide { flex: 1 1 100%; }
.compact-field .select-input, .compact-field .number-input, .compact-field .text-input { min-height: 34px; padding: 5px 8px; font-size: 0.84rem; }

.field-label-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-height: 22px; }
.file-auto-badge {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-deep);
  font-size: 0.68rem;
  font-weight: 800;
}
body.is-dark .file-auto-badge { color: #dfeeff; }
.file-auto-button { margin-left: auto; padding: 1px 6px; font-size: 0.72rem; }

.export-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.export-main { min-width: 190px; font-size: 1rem; }

.export-progress { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.export-progress-bar { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--blue), var(--cyan)); transition: width .2s ease; }

.export-status-row { display: flex; align-items: center; gap: 8px; }
.export-status { flex: 1; margin: 0; min-height: 1.2em; color: var(--muted); font-size: 0.8rem; font-weight: 700; }

.clear-button {
  padding: 6px 12px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--field);
  font-size: 0.78rem;
  font-weight: 800;
}

.clear-button:hover { border-color: var(--danger); color: var(--danger); }

.export-result {
  padding: 12px;
  border: 1.5px solid color-mix(in srgb, var(--ok) 40%, var(--line));
  border-radius: 14px;
  background: color-mix(in srgb, var(--ok) 6%, var(--panel-solid));
}

.export-result h3 { margin-bottom: 8px; font-size: 0.9rem; }
.result-body { display: flex; flex-wrap: wrap; gap: 12px; }

.result-preview {
  flex: 0 0 auto;
  width: min(100%, 240px);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background-color: var(--checker-b);
  background-image: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%);
  background-size: 16px 16px;
}

.result-preview img { display: block; width: 100%; height: auto; }
.result-info { display: flex; flex: 1 1 200px; flex-direction: column; gap: 8px; min-width: 0; }
.result-meta { margin: 0; font-size: 0.8rem; font-weight: 700; word-break: break-all; }
.result-note { margin: 0; padding: 7px 10px; border-radius: 10px; font-size: 0.76rem; font-weight: 700; line-height: 1.5; }
.result-note.is-ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.result-note.is-warning { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.result-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: auto; }

/* ---------- トースト ---------- */

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: min(420px, calc(100vw - 36px));
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 12px;
  background: var(--panel-solid);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s ease, transform .25s ease;
}

.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.has-action { display: flex; align-items: center; gap: 12px; pointer-events: auto; }

.toast-action {
  flex: none;
  padding: 6px 12px;
  border: 1.5px solid var(--blue);
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-deep);
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.toast-action:hover { background: var(--blue); color: #ffffff; }
body.is-dark .toast-action { color: #dfeeff; }
body.is-dark .toast-action:hover { color: #ffffff; }
.toast-success { border-left-color: var(--ok); }
.toast-warning { border-left-color: var(--warn); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--blue); }

/* ---------- 利用ルール（ドロワーと terms.html で共通） ---------- */

.rules-body { display: grid; gap: 10px; font-size: 0.84rem; line-height: 1.65; }
.rules-body p { margin: 0; }
.rules-intro { font-weight: 700; }
.rules-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.rules-card { padding: 10px 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel-soft); }
.rules-card h3 { margin: 0 0 6px; font-size: 0.86rem; }
.rules-card ul { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.rules-card li { display: grid; grid-template-columns: 1.3em minmax(0, 1fr); }
.rules-mark { font-weight: 900; }
.rules-card.is-allow h3, .rules-card.is-allow .rules-mark { color: var(--ok); }
.rules-card.is-deny h3, .rules-card.is-deny .rules-mark { color: var(--danger); }
.rules-note, .rules-where, .rules-translation { color: var(--muted); }
.rules-credit { padding: 10px 13px; border: 1px solid color-mix(in srgb, var(--blue) 30%, var(--line)); border-radius: 13px; background: var(--blue-soft); }
.rules-credit h3 { margin: 0 0 4px; color: var(--blue-deep); font-size: 0.86rem; }
body.is-dark .rules-credit h3 { color: var(--blue); }
.rules-credit-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 7px 0; }
.rules-credit-line code { padding: 5px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--field); font-family: inherit; font-weight: 800; user-select: all; }
.rules-copy { min-height: 1.9rem; padding: 0.25rem 0.8rem; font-size: 0.78rem; }
.rules-where { font-size: 0.8rem; }
.rules-foot { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; }
.rules-foot a { color: var(--blue); font-weight: 800; text-decoration: none; }
.rules-foot a:hover { text-decoration: underline; }
.rules-translation { font-size: 0.76rem; }

.link-button { padding: 0; border: 0; background: none; color: var(--blue); font: inherit; font-weight: 800; cursor: pointer; }
.link-button:hover { text-decoration: underline; }
.result-rule { margin: 8px 0 0; color: var(--muted); font-size: 0.76rem; line-height: 1.55; }
.result-rule-actions { display: inline-flex; flex-wrap: wrap; gap: 4px 12px; margin-left: 6px; }

/* 利用規約ページ */
.rules-page .app-header, .rules-page .legal-footer, .rules-doc, .rules-lang-note { width: 100%; max-width: 980px; margin-left: auto; margin-right: auto; }
.rules-lang-note { margin-top: -4px; margin-bottom: -4px; color: var(--muted); font-size: 0.78rem; }
.rules-doc { padding: 22px 26px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow-soft); }
.rules-doc > h2 { margin: 0 0 12px; font-size: 1.12rem; }
.rules-doc .rules-body { font-size: 0.9rem; }
.rules-terms { display: grid; gap: 16px; font-size: 0.9rem; line-height: 1.8; }
.rules-terms h3 { margin: 0 0 4px; font-size: 0.96rem; }
.rules-terms p { margin: 0; }
.rules-terms p + p { margin-top: 6px; }

/* ---------- フッター ---------- */

.legal-footer {
  padding: 16px 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.7;
}

.legal-footer h2 { margin-bottom: 6px; color: var(--ink); font-size: 0.88rem; }
.legal-footer p { margin: 0; }
.legal-footer p + p { margin-top: 4px; }
.legal-footer a { color: var(--blue); font-weight: 800; text-decoration: none; }
.legal-footer a:hover { text-decoration: underline; }

body.is-exporting .settings-body { pointer-events: none; opacity: 0.7; }

/* ---------- レスポンシブ ---------- */

@media (max-width: 1080px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .preview-panel { position: static; max-height: none; overflow: visible; order: -1; }
}

@media (max-width: 760px) {
  .rules-grid { grid-template-columns: 1fr; }
  .rules-doc { padding: 18px 16px; }
  .app-shell { padding: 10px; gap: 10px; }
  .app-header { grid-template-columns: minmax(0, 1fr); grid-template-areas: "title" "lead" "actions"; row-gap: 10px; padding: 16px 16px 28px; }
  .header-actions { justify-content: flex-start; }
  .version-engrave { right: 16px; }
  .panel { padding: 12px; border-radius: 18px; }
  .mode-tab { min-height: 0; padding: 8px; }
  .mode-desc { display: none; }
  .shortcut-grid { grid-template-columns: 1fr; }
  .shortcut-grid > span { margin-bottom: 4px; }
  .export-main { width: 100%; }
  .settings-tab { padding: 7px 8px; font-size: 0.8rem; }
  .template-chip { padding: 5px 9px; font-size: 0.78rem; }
  .time-label { margin-left: 0; width: 100%; }
  .effect-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
}

/* スマートフォンの狭い幅（320px まで）：語の途中で折り返したり、パネルの外へはみ出したりしないようにする */
@media (max-width: 420px) {
  /* カテゴリの名前はアイコンの下に置く */
  .mode-tab { align-items: center; padding: 8px 5px; text-align: center; }
  .mode-head { flex-direction: column; gap: 3px; }
  .mode-name { font-size: 0.84rem; word-break: keep-all; }
  /* 設定のタブは5つとも1行に収める */
  .settings-tabs { gap: 2px; }
  .settings-tab { padding: 7px 4px; font-size: 0.76rem; }
  .font-register { max-width: 100%; white-space: normal; }
}

@media (max-width: 350px) {
  h1 { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
