:root {
  --page: #edf0ec;
  --paper: #ffffff;
  --ink: #1b201d;
  --ink-2: #57605a;
  --line: #d3d9d3;
  --perf: #b9c2ba;
  --dining: #0f766e;
  --trebi: #2563eb;
  --allergen: #b42318;
  --allergen-bg: #fdecea;
  --caution-bg: #fff6dc;
  --caution-ink: #6b4e00;

  --font-round: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
  --font-body: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;

  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-2: 1.4375rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #151916;
    --paper: #1f2521;
    --ink: #e9eee9;
    --ink-2: #a3aea6;
    --line: #333b35;
    --perf: #4a544d;
    --dining: #2dd4bf;
    --trebi: #7aa5ff;
    --allergen: #ff8a80;
    --allergen-bg: #3a2220;
    --caution-bg: #3a3218;
    --caution-ink: #f5d98a;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  /* ダブルタップでの拡大を無効化（ピンチでの拡大はできるまま） */
  touch-action: manipulation;
  /* スクロールバーの幅を常に確保し、出たり消えたりしても横幅が変わらないようにする（PC） */
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
}

:focus-visible {
  outline: 3px solid var(--trebi);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- ヘッダーと曜日バー ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.top-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 16px 4px;
  /* 左：タイトル／中央：今週・来週／右：更新日時 */
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 4px 12px;
}

/* やや狭い画面（375〜389px）では文字と余白を少し詰めて1行に収める */
@media (max-width: 389px) {
  .top-inner {
    column-gap: 8px;
  }

  .brand {
    font-size: 1.0625rem;
  }

  .week-btn {
    padding-inline: 10px;
  }

  .updated {
    font-size: 0.75rem;
  }
}

/* それでも入らない狭い画面では、更新日時だけ次の行の右端へ */
@media (max-width: 374px) {
  .top-inner .updated {
    grid-column: 1 / -1;
  }
}

.brand {
  margin: 0;
  white-space: nowrap;
  font-family: var(--font-round);
  font-weight: 900;
  font-size: var(--step-1);
  letter-spacing: 0.04em;
}

.week-switch {
  position: relative;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  justify-self: center;
  padding: 2px;
  border-radius: 999px;
  background: var(--paper);
  border: 1.5px solid var(--line);
}

.week-switch[hidden] {
  display: none;
}

/* 選択中の週を示す黒い部分。ボタンの下を左右にスライドする */
.week-indicator {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc(50% - 2px);
  border-radius: 999px;
  background: var(--ink);
  transition: transform 0.28s cubic-bezier(0.3, 0.7, 0.2, 1);
}

.week-switch[data-week="next"] .week-indicator {
  transform: translateX(100%);
}

.week-btn {
  position: relative;
  z-index: 1;
  padding: 2px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: var(--step--1);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s;
}

.week-btn[aria-pressed="true"] {
  color: var(--page);
}

@media (prefers-reduced-motion: reduce) {
  .week-indicator,
  .week-btn {
    transition: none;
  }
}

.updated {
  margin: 0;
  justify-self: end;
  white-space: nowrap;
  font-size: var(--step--1);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.days {
  max-width: 1040px;
  margin: 0 auto;
  padding: 6px 12px 10px;
}

.day-tabs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.day-tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 9px 0 7px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  min-height: 52px;
}

.day-tab-key {
  font-family: var(--font-round);
  font-weight: 700;
  font-size: var(--step-1);
  line-height: 1.2;
}

.day-tab-date {
  font-size: 0.75rem;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.day-tab-today {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--page);
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}

.day-tab[aria-selected="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--page);
}

.day-tab[aria-selected="true"] .day-tab-date {
  color: inherit;
  opacity: 0.8;
}

.day-tab[aria-selected="true"] .day-tab-today {
  background: var(--page);
  color: var(--ink);
  box-shadow: 0 0 0 1.5px var(--ink);
}

/* ---------- 本体 ---------- */
.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 16px 0px;
  /* 週切り替えで中身が横にスライドしても、ページ幅が画面を超えないようにする。
     超えると iPhone の Safari がページ全体の倍率を調整し直して画面がガタつく */
  overflow-x: clip;
}

.notice {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--caution-bg);
  color: var(--caution-ink);
  font-size: 0.9rem;
}

.filter {
  margin-bottom: 18px;
  font-size: 0.9rem;
}

.filter summary {
  cursor: pointer;
  color: var(--ink-2);
  font-weight: 600;
  width: fit-content;
}

.filter-count {
  color: var(--allergen);
}

.filter-help {
  margin: 6px 0 8px;
  color: var(--ink-2);
  font-size: var(--step--1);
}

.filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  position: relative;
  display: inline-flex;
}

.chip input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.chip span {
  padding: 4px 12px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
}

.chip input:checked + span {
  border-color: var(--allergen);
  background: var(--allergen-bg);
  color: var(--allergen);
  font-weight: 700;
}

.chip input:focus-visible + span {
  outline: 3px solid var(--trebi);
  outline-offset: 2px;
}

.cafeterias {
  display: grid;
  gap: 32px;
}

@media (min-width: 820px) {
  .cafeterias {
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    align-items: start;
  }
}

/* ---------- 食堂 ---------- */
.caf {
  --accent: var(--dining);
}

.caf[data-caf="cafeteria2"] {
  --accent: var(--trebi);
}

.caf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 3px solid var(--accent);
}

.caf-name {
  margin: 0;
  font-family: var(--font-round);
  font-weight: 900;
  font-size: var(--step-2);
  line-height: 1.3;
}

.caf-source {
  flex-shrink: 0;
  font-size: var(--step--1);
  color: var(--ink-2);
}

.caf-caution {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--caution-bg);
  color: var(--caution-ink);
  font-size: var(--step--1);
}

.caf-caution a {
  margin-left: 4px;
  font-weight: 700;
}

.caf-empty {
  margin: 0;
  padding: 18px 16px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  color: var(--ink-2);
}

.caf-empty p {
  margin: 0;
}

.caf-empty-action {
  margin-top: 12px;
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  .caf-empty-action {
    color: #0f1411;
  }
}

.caf-closed {
  margin: 10px 2px 0;
  font-size: var(--step--1);
  color: var(--ink-2);
}

/* ---------- 食券 ---------- */
.tickets {
  display: grid;
  gap: 12px;
}

.ticket {
  --notch: 9px;
  position: relative;
  display: grid;
  grid-template-columns: 2.4rem 1fr;
  background: var(--paper);
  border-radius: 12px;
  border: 1px solid var(--line);
  /* 半券とのあいだの切り欠き */
  -webkit-mask:
    radial-gradient(circle at 2.4rem 0, transparent var(--notch), #000 calc(var(--notch) + 0.5px)) top / 100% 51% no-repeat,
    radial-gradient(circle at 2.4rem 100%, transparent var(--notch), #000 calc(var(--notch) + 0.5px)) bottom / 100% 51% no-repeat;
  mask:
    radial-gradient(circle at 2.4rem 0, transparent var(--notch), #000 calc(var(--notch) + 0.5px)) top / 100% 51% no-repeat,
    radial-gradient(circle at 2.4rem 100%, transparent var(--notch), #000 calc(var(--notch) + 0.5px)) bottom / 100% 51% no-repeat;
}

.ticket-stub {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
  background: var(--accent);
  color: #fff;
  border-right: 2px dashed var(--perf);
  border-radius: 12px 0 0 12px;
}

.ticket-stub span {
  /* 長い区分名は2列に折り返して食券が縦に伸びすぎないようにする */
  max-inline-size: 7em;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-family: var(--font-round);
  font-weight: 700;
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  line-height: 1;
  max-height: 100%;
}

@media (prefers-color-scheme: dark) {
  .ticket-stub {
    color: #0f1411;
  }
}

.ticket-body {
  padding: 12px 16px 13px;
  min-width: 0;
}

/* 区分名は半券の縦書きで伝えるので、画面読み上げ用にだけ残す */
.ticket-cat {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.ticket-main {
  margin: 0;
  font-family: var(--font-round);
  font-weight: 700;
  font-size: var(--step-1);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.ticket-sides {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 0;
  margin: 3px 0 0;
  padding: 0;
  list-style: none;
  color: var(--ink-2);
  font-size: 0.9375rem;
}

.ticket-sides li::before {
  content: "＋";
  margin-right: 1px;
}

.ticket-sides li + li {
  margin-left: 10px;
}

.ticket-note {
  margin: 8px 0 0;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
  font-size: var(--step--1);
  line-height: 1.5;
}

.ticket-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--ink-2);
}

.kcal b {
  font-size: 0.875rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.allergens {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}

.allergen {
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid color-mix(in srgb, var(--allergen) 35%, transparent);
  color: var(--allergen);
  line-height: 1.6;
}

.allergen.is-hit {
  background: var(--allergen);
  border-color: var(--allergen);
  color: var(--paper);
  font-weight: 700;
}

.ticket-warn {
  margin: 8px 0 0;
  font-size: var(--step--1);
  font-weight: 700;
  color: var(--allergen);
}

.ticket.is-avoided .ticket-main,
.ticket.is-avoided .ticket-sides {
  opacity: 0.45;
}

.ticket.is-avoided .ticket-stub {
  filter: grayscale(1);
  opacity: 0.6;
}

/* ---------- その他 ---------- */
.load-error {
  padding: 20px;
  border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.load-error p {
  margin: 0 0 8px;
}

.foot {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
  font-size: 0.75rem;
  color: var(--ink-2);
}

@media (prefers-reduced-motion: no-preference) {
  .day-tab {
    transition: background-color 0.12s, color 0.12s;
  }
}

.foot p {
  margin-bottom: 0;
}

/* ---------- スクロールバー ---------- */
/* Chrome / Edge / Safari: 上下の矢印ボタンと背景（トラック）を消し、つまみだけ表示 */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  background: transparent;
}

::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-corner {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--ink-2) 45%, transparent);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--ink-2) 70%, transparent);
  background-clip: padding-box;
}

/* Firefox（::-webkit-scrollbar 非対応）。Chrome でこれを指定すると上の設定が無効になるため分けている */
@supports not selector(::-webkit-scrollbar) {
  html {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--ink-2) 45%, transparent) transparent;
  }
}
