/* ライト配色 */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f3f6f8;
  --ink: #203440;
  --text: #42545f;
  --muted: #617078;
  --accent: #286383;
  --line: #dbe2e5;
  --soft-line: #e9eef1;
  --on-accent: #ffffff;
  --focus: #0a6fa4;
}

/* ダーク配色 */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151c23;
  --surface: #1d2731;
  --ink: #e4ecf1;
  --text: #c3cfd8;
  --muted: #a4b6c3;
  --accent: #8ec8ec;
  --line: #3a4b59;
  --soft-line: #2b3a46;
  --on-accent: #152632;
  --focus: #94d6ff;
}

/* JavaScriptが無効な場合も環境設定に追従 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #151c23;
    --surface: #1d2731;
    --ink: #e4ecf1;
    --text: #c3cfd8;
    --muted: #a4b6c3;
    --accent: #8ec8ec;
    --line: #3a4b59;
    --soft-line: #2b3a46;
    --on-accent: #152632;
    --focus: #94d6ff;
  }
}

/* 非表示要素と読み上げ用の説明 */
[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* 配色切り替えのアイコン */
.theme-switch {
  display: flex;
  flex-shrink: 0;
  gap: 3px;
  align-items: center;
  padding: 0;
  margin: 0;
  border: 0;
  min-width: 0;
}

.theme-switch label {
  position: relative;
  display: block;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.theme-switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.theme-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 50%;
  color: var(--muted);
}

/* HTML内のSVGを現在の文字色で描く． */
.theme-icon svg {
  display: block;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-switch input:checked + .theme-icon {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--surface);
}

.theme-switch input:hover + .theme-icon {
  color: var(--ink);
  background: var(--surface);
}

.theme-switch input:focus-visible + .theme-icon {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

::selection {
  color: var(--on-accent);
  background: var(--accent);
}

/* 印刷時はライト配色 */
@media print {
  :root, :root[data-theme] {
    color-scheme: light !important;
    --bg: #ffffff !important;
    --surface: #f3f6f8 !important;
    --ink: #203440 !important;
    --text: #42545f !important;
    --muted: #617078 !important;
    --accent: #286383 !important;
    --line: #dbe2e5 !important;
    --soft-line: #e9eef1 !important;
    --on-accent: #ffffff !important;
    --focus: #0a6fa4 !important;
  }

  .theme-switch {
    display: none !important;
  }
}
