/* 基盤・デザイントークン */
body.xml-format-page {
  color-scheme: light;

  /* ページと共通コントロールの配色 */
  --xml-page: #f3f6f9;
  --xml-panel: #ffffff;
  --xml-control: #f7f9fb;
  --xml-text: #172033;
  --xml-muted: #5d6b7d;
  --xml-border: #cbd5e1;
  --xml-border-strong: #aebaca;
  --xml-primary: #086bd8;
  --xml-primary-hover: #075bb6;
  --xml-focus: #086bd8;
  --xml-on-primary: #ffffff;
  --xml-success: #087a45;
  --xml-warning: #9a5a00;
  --xml-error: #b42318;
  --xml-info-bg: #e8f4ff;
  --xml-info-text: #07579e;
  --xml-info-border: #9dd5ff;
  --xml-message-bg: #f5f7fa;
  --xml-disabled-text: #8994a3;
  --xml-disabled-background: #e9edf2;
  --xml-toolbar-background: #fbfcfd;
  --xml-error-border: #fecaca;
  --xml-error-background: #fff5f5;
  --xml-error-code: #7f1d1d;
  --xml-inline-code-background: #eef2f6;

  /* レイアウト寸法 */
  --xml-content-width: 1500px;
  --xml-page-gutter: 32px;
  --xml-page-gutter-mobile: 20px;
  --xml-panel-gap: 14px;
  --xml-panel-padding: 14px;
  --xml-panel-radius: 10px;
  --xml-control-radius: 6px;
  --xml-control-height: 36px;
  --xml-toolbar-height: 56px;
  --xml-editor-heading-height: 50px;
  --xml-line-number-width: 58px;
  --xml-file-name-width: 260px;
  --xml-range-width: 105px;
  --xml-range-output-width: 48px;
  --xml-editor-padding: 14px;
  --xml-message-height: 42px;
  --xml-about-padding: 22px;
  --xml-border-width: 1px;
  --xml-control-gap: 8px;
  --xml-focus-ring-width: 3px;
  --xml-drag-ring-width: 3px;
  --xml-inline-code-radius: 4px;

  /* フォント */
  --xml-font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --xml-font-code: "Cascadia Code", Consolas, monospace;
  box-sizing: border-box;
  margin: 0;
  color: var(--xml-text);
  background: var(--xml-page);
  font-family: var(--xml-font-ui);
  font-size: 14px;
  line-height: 1.6;
}

.xml-format-page * {
  box-sizing: border-box;
}

.xml-format-main {
  width: min(var(--xml-content-width), calc(100% - var(--xml-page-gutter)));
  margin: 0 auto;
  padding-block: 26px 48px;
}

/* ページヘッダー */
.xml-format-page-header {
  margin-block-end: 16px;
}

.xml-format-page-title {
  margin: 8px 0 2px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.25;
}

.xml-format-page-description,
.xml-format-panel-description {
  margin: 4px 0 0;
  color: var(--xml-muted);
}

.xml-format-breadcrumb {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
}

.xml-format-breadcrumb-link {
  color: var(--xml-primary);
}

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

/* パネル・共通操作 */
.xml-format-notice,
.xml-format-panel {
  border: var(--xml-border-width) solid var(--xml-border);
  border-radius: var(--xml-panel-radius);
  background: var(--xml-panel);
}

.xml-format-notice {
  margin-block-end: var(--xml-panel-gap);
  padding: 12px var(--xml-panel-padding);
  color: var(--xml-info-text);
  background: var(--xml-info-bg);
}

.xml-format-panel {
  margin-block-end: var(--xml-panel-gap);
  overflow: hidden;
}

.xml-format-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: var(--xml-panel-padding);
  border-block-end: var(--xml-border-width) solid var(--xml-border);
}

.xml-format-panel-title,
.xml-format-editor-title,
.xml-format-error-title,
.xml-format-about-title,
.xml-format-about-subtitle,
.xml-format-diagnostics-title {
  margin: 0;
}

.xml-format-panel-title {
  font-size: 18px;
}

.xml-format-actions,
.xml-format-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--xml-control-gap);
}

.xml-format-actions--push {
  margin-inline-start: auto;
}

.xml-format-control {
  min-height: var(--xml-control-height);
  border: var(--xml-border-width) solid var(--xml-border-strong);
  border-radius: var(--xml-control-radius);
  color: var(--xml-text);
  background: var(--xml-control);
  font: inherit;
}

.xml-format-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  font-weight: 600;
  cursor: pointer;
}

.xml-format-button--primary {
  border-color: var(--xml-primary);
  color: var(--xml-on-primary);
  background: var(--xml-primary);
}

/* 操作状態 */
.xml-format-button:hover:not(:disabled) {
  border-color: var(--xml-primary);
}

.xml-format-button--primary:hover:not(:disabled) {
  background: var(--xml-primary-hover);
}

.xml-format-control:disabled {
  color: var(--xml-disabled-text);
  background: var(--xml-disabled-background);
  cursor: not-allowed;
}

.xml-format-control:focus-visible,
.xml-format-textarea:focus-visible,
.xml-format-check-input:focus-visible,
.xml-format-range-input:focus-visible {
  outline: var(--xml-focus-ring-width) solid color-mix(in srgb, var(--xml-focus) 35%, transparent);
  outline-offset: 1px;
}

.xml-format-toolbar {
  min-height: var(--xml-toolbar-height);
  padding: 10px var(--xml-panel-padding);
  border-block-end: var(--xml-border-width) solid var(--xml-border);
}

.xml-format-toolbar--options,
.xml-format-toolbar--display {
  background: var(--xml-toolbar-background);
}

.xml-format-setting,
.xml-format-range-setting,
.xml-format-check,
.xml-format-file-name {
  display: inline-flex;
  align-items: center;
  gap: var(--xml-control-gap);
  color: var(--xml-muted);
  white-space: nowrap;
}

.xml-format-select,
.xml-format-input {
  min-width: 130px;
  padding: 6px 10px;
}

.xml-format-range-input {
  width: var(--xml-range-width);
}

.xml-format-range-output {
  min-width: var(--xml-range-output-width);
  color: var(--xml-text);
  font-variant-numeric: tabular-nums;
}

.xml-format-check-input {
  width: 16px;
  height: 16px;
  accent-color: var(--xml-primary);
}

/* エディタ */
.xml-format-workspace,
.xml-format-editor-pane,
.xml-format-code-stage {
  min-width: 0;
}

.xml-format-workspace {
  --xml-font-size: 14px;
  --xml-editor-height: 620px;
  --xml-input-ratio: 50%;
  --xml-output-ratio: 50%;
  display: grid;
  grid-template-columns: var(--xml-input-ratio) var(--xml-output-ratio);
  color: var(--editor-text);
  background: var(--editor-background);
  font-family: var(--xml-font-code);
  font-size: var(--xml-font-size);
  line-height: 1.65;
}

.xml-format-workspace[data-font="consolas"] {
  font-family: Consolas, "Courier New", monospace;
}

.xml-format-workspace[data-font="monospace"] {
  font-family: monospace;
}

/* ライトテーマのエディタ面とXML構文色 */
.xml-format-editor-panel[data-theme="light"] {
  /* エディタ面 */
  --editor-background: #ffffff;
  --editor-heading: #f7f9fb;
  --editor-gutter: #eef2f6;
  --editor-text: #1f2328;
  --editor-muted: #657080;
  --editor-border: #cbd5e1;
  --editor-selection: rgba(38, 139, 210, 0.24);

  /* XML構文色 */
  --token-element: #800000;
  --token-attribute: #ff0000;
  --token-value: #0451a5;
  --token-text: #1f2328;
  --token-comment: #008000;
  --token-cdata: #a31515;
  --token-declaration: #af00db;
  --token-doctype: #795e26;
  --token-punctuation: #1f2328;
}

/* ダークテーマのエディタ面とXML構文色 */
.xml-format-editor-panel[data-theme="dark"] {
  color-scheme: dark;

  /* エディタ面 */
  --editor-background: #1e1e1e;
  --editor-heading: #181c22;
  --editor-gutter: #181818;
  --editor-text: #d4d4d4;
  --editor-muted: #9aa6b4;
  --editor-border: #3b414b;
  --editor-selection: rgba(38, 139, 210, 0.38);

  /* XML構文色 */
  --token-element: #569cd6;
  --token-attribute: #9cdcfe;
  --token-value: #ce9178;
  --token-text: #d4d4d4;
  --token-comment: #6a9955;
  --token-cdata: #ce9178;
  --token-declaration: #c586c0;
  --token-doctype: #dcdcaa;
  --token-punctuation: #808080;
}

.xml-format-editor-pane {
  color: var(--editor-text);
  background: var(--editor-background);
}

.xml-format-editor-pane--output {
  border-inline-start: var(--xml-border-width) solid var(--editor-border);
}

.xml-format-editor-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--xml-editor-heading-height);
  padding: 9px var(--xml-panel-padding);
  border-block-end: var(--xml-border-width) solid var(--editor-border);
  background: var(--editor-heading);
}

.xml-format-editor-heading-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.xml-format-editor-title {
  font-family: var(--xml-font-ui);
  font-size: 15px;
  white-space: nowrap;
}

.xml-format-editor-meta {
  overflow: hidden;
  color: var(--editor-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.xml-format-editor-body {
  display: grid;
  grid-template-columns: var(--xml-line-number-width) minmax(0, 1fr);
  height: var(--xml-editor-height);
  min-height: 0;
  overflow: hidden;
}

.xml-format-line-numbers,
.xml-format-highlight,
.xml-format-textarea {
  margin: 0;
  border: 0;
  font: inherit;
  line-height: inherit;
  tab-size: 4;
  white-space: pre;
}

.xml-format-line-numbers {
  min-height: 100%;
  padding: var(--xml-editor-padding) 10px;
  overflow: hidden;
  color: var(--editor-muted);
  background: var(--editor-gutter);
  text-align: end;
  user-select: none;
}

.xml-format-code-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--editor-background);
}

.xml-format-highlight,
.xml-format-textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: var(--xml-editor-padding);
}

.xml-format-highlight {
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  overflow: visible;
  color: var(--editor-text);
  pointer-events: none;
}

.xml-format-textarea {
  z-index: 1;
  resize: none;
  overflow: auto;
  color: transparent;
  background: transparent;
  caret-color: var(--editor-text);
  -webkit-text-fill-color: transparent;
}

/* ドロップ・選択・大容量入力時の表示状態 */
.xml-format-editor-pane--input.is-dragging {
  box-shadow: inset 0 0 0 var(--xml-drag-ring-width) var(--xml-primary);
}

.xml-format-textarea::selection {
  color: transparent;
  background: var(--editor-selection);
}

.xml-format-textarea::placeholder {
  color: var(--editor-muted);
  -webkit-text-fill-color: var(--editor-muted);
}

.xml-format-code-stage.is-plain .xml-format-highlight {
  display: none;
}

.xml-format-code-stage.is-plain .xml-format-textarea {
  color: var(--editor-text);
  -webkit-text-fill-color: var(--editor-text);
}

/* XML構文トークン */
.xml-token--element {
  color: var(--token-element);
}

.xml-token--attribute {
  color: var(--token-attribute);
}

.xml-token--value {
  color: var(--token-value);
}

.xml-token--text {
  color: var(--token-text);
}

.xml-token--comment {
  color: var(--token-comment);
}

.xml-token--cdata {
  color: var(--token-cdata);
}

.xml-token--declaration {
  color: var(--token-declaration);
}

.xml-token--doctype {
  color: var(--token-doctype);
}

.xml-token--punctuation {
  color: var(--token-punctuation);
}

/* 状態表示・結果 */
.xml-message {
  min-height: var(--xml-message-height);
  margin: 0;
  padding: 10px var(--xml-panel-padding);
  border-block-start: var(--xml-border-width) solid var(--xml-border);
  color: var(--xml-muted);
  background: var(--xml-message-bg);
}

.xml-message--success {
  color: var(--xml-success);
}

.xml-message--warning {
  color: var(--xml-warning);
}

.xml-message--error {
  color: var(--xml-error);
}

.xml-error {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: var(--xml-panel-padding);
  border-block-start: var(--xml-border-width) solid var(--xml-error-border);
  color: var(--xml-error);
  background: var(--xml-error-background);
}

.xml-format-error-summary {
  margin: 4px 0;
}

.xml-format-error-excerpt {
  max-width: min(900px, 75vw);
  margin: 6px 0 0;
  overflow: auto;
  color: var(--xml-error-code);
}

.xml-format-diagnostics {
  padding: 12px var(--xml-panel-padding);
  border-block-start: var(--xml-border-width) solid var(--xml-border);
  background: var(--xml-message-bg);
}

.xml-format-diagnostics-title {
  font-size: 14px;
}

.xml-format-diagnostics-list {
  margin: 0;
  padding-inline-start: 22px;
}

.xml-format-diagnostics li[data-severity="error"] {
  color: var(--xml-error);
}

.xml-format-diagnostics li[data-severity="warning"] {
  color: var(--xml-warning);
}

/* hidden属性を部品固有のdisplay指定より優先する */
.xml-error[hidden],
.xml-format-diagnostics[hidden],
.xml-format-result-panel[hidden] {
  display: none;
}

.xml-format-file-name {
  flex-wrap: wrap;
}

.xml-format-file-name-input {
  width: var(--xml-file-name-width);
}

.xml-format-stats {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  margin: 0;
}

.xml-format-stat {
  min-width: 0;
  padding: var(--xml-panel-padding);
  border-inline-end: var(--xml-border-width) solid var(--xml-border);
}

.xml-format-stat:last-child {
  border-inline-end: 0;
}

.xml-format-stat-label {
  color: var(--xml-muted);
  font-size: 12px;
}

.xml-format-stat-value {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

/* ツール説明 */
.xml-format-about {
  padding: var(--xml-about-padding);
}

.xml-format-about-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
}

.xml-format-about-list > li + li {
  margin-block-start: 4px;
}

.xml-format-inline-code {
  padding: 1px 4px;
  border-radius: var(--xml-inline-code-radius);
  background: var(--xml-inline-code-background);
}

.xml-format-privacy {
  padding: 12px;
  border: var(--xml-border-width) solid var(--xml-info-border);
  border-radius: var(--xml-control-radius);
  color: var(--xml-info-text);
  background: var(--xml-info-bg);
}

/* レスポンシブ */
/* タブレット幅ではエディタと統計を段組みし直す */
@media (max-width: 1000px) {
  .xml-format-panel-heading,
  .xml-error {
    align-items: stretch;
    flex-direction: column;
  }

  .xml-format-actions--push {
    margin-inline-start: 0;
  }

  .xml-format-workspace {
    grid-template-columns: 1fr;
  }

  .xml-format-editor-pane--output {
    border-block-start: var(--xml-border-width) solid var(--editor-border);
    border-inline-start: 0;
  }

  .xml-format-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .xml-format-stat:nth-child(4n) {
    border-inline-end: 0;
  }
}

/* スマートフォン幅では操作部と説明欄を1列にする */
@media (max-width: 580px) {
  .xml-format-main {
    width: calc(100% - var(--xml-page-gutter-mobile));
  }

  .xml-format-toolbar,
  .xml-format-actions,
  .xml-format-setting,
  .xml-format-range-setting,
  .xml-format-file-name {
    flex-direction: column;
    align-items: stretch;
  }

  .xml-format-button,
  .xml-format-select,
  .xml-format-input,
  .xml-format-file-name-input,
  .xml-format-range-input {
    width: 100%;
  }

  .xml-format-stats,
  .xml-format-about-grid {
    grid-template-columns: 1fr;
  }

  .xml-format-stat,
  .xml-format-stat:nth-child(4n) {
    border-block-end: var(--xml-border-width) solid var(--xml-border);
    border-inline-end: 0;
  }
}

/* OSの視覚効果設定を優先する */
@media (prefers-reduced-motion: reduce) {
  .xml-format-page * {
    scroll-behavior: auto !important;
  }
}
