/*!
 * 時間割マネージャー — 共通スタイル
 * 外部フォント・外部リソースは一切読み込みません（プライバシー重視）。
 */

:root {
  --bg: #f4f6fb;
  --bg-glow-a: rgba(91, 91, 214, 0.10);
  --bg-glow-b: rgba(18, 169, 113, 0.08);
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --surface-3: #e9edf6;
  --text: #171a24;
  --text-muted: #6b7280;
  --border: #e7e9f2;
  --border-strong: #d3d8e6;
  --primary: #5b5bd6;
  --primary-strong: #4a4ac4;
  --primary-weak: #ededfd;
  --success: #12a971;
  --success-weak: #dcf5ea;
  --warning: #dd9220;
  --danger: #e5484d;
  /* 表示モードのアクセント配線（JS が --display-accent / --accent を上書き）。
   * 継承で body まで届くよう :root で既定を持つ。body 側で再定義しないこと
   * （再定義すると <html> のインライン指定が継承で届かなくなる）。 */
  --display-accent: var(--primary);
  --accent: var(--display-accent);
  --shadow-sm: 0 1px 2px rgba(21, 26, 45, 0.05);
  --shadow: 0 1px 2px rgba(21, 26, 45, 0.05), 0 12px 30px -14px rgba(21, 26, 45, 0.22);
  --shadow-lg: 0 30px 70px -24px rgba(21, 26, 45, 0.45);
  --radius: 16px;
  --radius-sm: 11px;
  --ring: 0 0 0 3px color-mix(in srgb, var(--primary) 24%, transparent);
  /* 共通ページナビの高さ（被りを避けるためのオフセット基準）。
   * --nav-top-h: デスクトップ上部バー、--nav-tab-h: モバイル下部タブバー。 */
  --nav-top-h: 57px;
  --nav-tab-h: 68px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", Meiryo, "Noto Sans JP", Roboto, sans-serif;
}

:root[data-theme='dark'] {
  --bg: #0e1016;
  --bg-glow-a: rgba(119, 119, 245, 0.12);
  --bg-glow-b: rgba(53, 210, 155, 0.08);
  --surface: #171a22;
  --surface-2: #1f232d;
  --surface-3: #262b37;
  --text: #eef1f7;
  --text-muted: #98a1b3;
  --border: #262b36;
  --border-strong: #333a48;
  --primary: #8f8ff5;
  --primary-strong: #a3a3ff;
  --primary-weak: #232441;
  --success: #35d29b;
  --success-weak: #17352c;
  --warning: #edb84b;
  --danger: #f0736b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 34px -18px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 34px 80px -28px rgba(0, 0, 0, 0.8);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme='auto'] {
    --bg: #0e1016;
    --bg-glow-a: rgba(119, 119, 245, 0.12);
    --bg-glow-b: rgba(53, 210, 155, 0.08);
    --surface: #171a22;
    --surface-2: #1f232d;
    --surface-3: #262b37;
    --text: #eef1f7;
    --text-muted: #98a1b3;
    --border: #262b36;
    --border-strong: #333a48;
    --primary: #8f8ff5;
    --primary-strong: #a3a3ff;
    --primary-weak: #232441;
    --success: #35d29b;
    --success-weak: #17352c;
    --warning: #edb84b;
    --danger: #f0736b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 34px -18px rgba(0, 0, 0, 0.7);
    --shadow-lg: 0 34px 80px -28px rgba(0, 0, 0, 0.8);
  }
}

* {
  box-sizing: border-box;
}

/* hidden 属性は常に優先する（display を持つ要素でも確実に隠す） */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
}

::selection {
  background: color-mix(in srgb, var(--primary) 28%, transparent);
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 12px;
}

/* ---------------- アプリバー ---------------- */

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand .logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.brand .logo .icon {
  width: 19px;
  height: 19px;
}

.app-bar-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--border);
}

.icon-btn:active {
  transform: scale(0.95);
}

/* ---------------- ポップアップ ---------------- */

body.popup {
  width: 348px;
  min-height: 320px;
}

.popup-main {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.status-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--primary);
}

.status-card.is-current::before {
  background: var(--success);
}

/* 授業中じゃない状態（次回待ち・終了）はアクセントを淡くする */
.status-card.is-idle::before {
  background: var(--border-strong);
}

.status-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--primary-weak);
  color: var(--primary);
}

.status-card.is-current .chip {
  background: var(--success-weak);
  color: var(--success);
}

.countdown {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* 授業開始が5分前を切ったら注意色で目立たせる */
.status-card.is-soon {
  border-color: color-mix(in srgb, var(--warning) 48%, var(--border));
}

.status-card.is-soon::before {
  background: var(--warning);
}

.status-card.is-soon .chip {
  background: color-mix(in srgb, var(--warning) 18%, transparent);
  color: var(--warning);
}

.status-card.is-soon .countdown {
  color: var(--warning);
}

.subject {
  font-size: 26px;
  letter-spacing: -0.01em;
  line-height: 1.2;
  word-break: break-word;
}

.period-time {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.progress {
  margin-top: 12px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--success);
  transition: none;
}

.meta {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.next-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  line-height: 1.4;
}

.next-label {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-weak);
  border-radius: 6px;
  padding: 1px 8px;
  line-height: 1.6;
}

.next-subject {
  font-weight: 700;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}

.next-time {
  flex: none;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.next-in {
  flex: none;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: none;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.today-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.today-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
}

.today-item.is-current {
  border-color: var(--success);
  background: var(--success-weak);
}

.today-item .dot {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex: none;
}

.today-item .ti-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.today-item .ti-time {
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 16px;
}

.popup-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px 11px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
}

.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* ---------------- ボタン ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 15px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.08s;
}

.btn:hover {
  background: var(--surface-2);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* アイコンボタン・タブなどにもキーボードフォーカスを明示する */
.icon-btn:focus-visible,
.tab:focus-visible,
.settings-menu-item:focus-visible,
.tt-cell-more:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--primary) 92%, #fff), var(--primary));
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--primary) 75%, transparent);
}

.btn.primary:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

.btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 42%, var(--border));
}

.btn.danger:hover {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

.btn.small {
  padding: 5px 11px;
  font-size: 12px;
  border-radius: 9px;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.btn.ghost:hover {
  background: var(--surface-2);
}

/* ---------------- フォーム ---------------- */

label {
  font-weight: 600;
}

input[type='text'],
input[type='search'],
input[type='time'],
input[type='number'],
input[type='date'],
select,
textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 8px 10px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

textarea {
  resize: vertical;
  min-height: 56px;
  line-height: 1.5;
}

input::placeholder,
textarea::placeholder {
  color: color-mix(in srgb, var(--text-muted) 72%, transparent);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}

input[type='color'] {
  width: 38px;
  height: 32px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface);
  cursor: pointer;
}

input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ---------------- 設定 / 一覧ページ ---------------- */

body.page {
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 12% -8%, var(--bg-glow-a), transparent 60%),
    radial-gradient(900px 460px at 100% 0%, var(--bg-glow-b), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

.page-wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 26px 18px 88px;
}

.page-title {
  font-size: 24px;
  margin-bottom: 5px;
}

.page-subtitle {
  color: var(--text-muted);
  margin-bottom: 22px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card > h2 {
  font-size: 16px;
  margin-bottom: 4px;
}

.card > .card-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}

.row:last-child {
  border-bottom: none;
}

.row .row-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.row .row-label .hint {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
}

.row .row-control {
  flex: none;
  min-width: 120px;
  max-width: 55%;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.row .row-control input[type='number'] {
  width: 90px;
}

.tabs {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tab {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.08s;
}

.tab:hover {
  background: var(--surface-2);
}

.tab.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 8px 18px -10px color-mix(in srgb, var(--primary) 80%, transparent);
}

.grid-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.grid-table th,
.grid-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0;
  text-align: center;
  vertical-align: middle;
}

.grid-table tr:last-child th,
.grid-table tr:last-child td {
  border-bottom: none;
}

.grid-table th:last-child,
.grid-table td:last-child {
  border-right: none;
}

.grid-table thead th {
  background: var(--surface-2);
  font-size: 12px;
  padding: 8px 4px;
  font-weight: 700;
}

.grid-table th.time-col {
  width: 92px;
  min-width: 92px;
  max-width: 92px;
}

.grid-table .period-cell {
  background: var(--surface-2);
  padding: 6px 4px;
  font-size: 12px;
  line-height: 1.3;
}

.grid-table .period-cell .pname {
  font-weight: 700;
}

.grid-table .period-cell .ptime {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.grid-table td.cell {
  height: 46px;
}

/* 時限の入力欄に付く警告 */
.cell-note {
  font-size: 11px;
  line-height: 1.3;
  color: var(--danger);
  padding: 2px 4px 4px;
  white-space: nowrap;
}

.cell-note:empty {
  display: none;
}


/* 時限の時刻が未設定のときの警告 */
.warn-box {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 0 0 12px;
  font-size: 12.5px;
  line-height: 1.6;
}

.grid-table input.cell-input {
  border: none;
  border-radius: 0;
  background: transparent;
  text-align: center;
  font-weight: 600;
  height: 100%;
  padding: 8px 4px;
  width: 100%;
}

.grid-table input.cell-input:focus {
  box-shadow: inset 0 0 0 2px var(--primary);
  border-radius: 6px;
}

/* 設定の時間割グリッドの選択式セル */
.grid-table select.cell-input {
  border: none;
  border-radius: 0;
  background: transparent;
  text-align: center;
  font-weight: 600;
  height: 100%;
  padding: 8px 4px;
  width: 100%;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.grid-table select.cell-input:focus {
  box-shadow: inset 0 0 0 2px var(--primary);
  border-radius: 6px;
  outline: none;
}

.grid-table select.cell-input.is-empty {
  color: var(--text-muted);
  font-weight: 400;
}

.grid-table th.is-today {
  color: var(--primary);
  background: var(--primary-weak);
}

.grid-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
}

/* ---------------- 科目カード（授業の詳細） ---------------- */

.subject-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.subject-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 13px 15px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.subject-card:focus-within {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow: var(--shadow);
}

.subject-head {
  display: flex;
  align-items: center;
  gap: 11px;
}

.subject-head .s-name {
  font-weight: 700;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.s-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-weak);
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.s-badge.is-unused {
  color: var(--text-muted);
  background: var(--surface-3);
}

/* 科目の追加・整理 */
.subject-add {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.subject-add input {
  flex: 1;
  min-width: 0;
}

.subject-add .btn {
  flex: none;
}

.subject-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

/* 色パレット */
.subject-palette {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.palette-dot {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}

.palette-dot:hover {
  transform: scale(1.12);
}

.palette-dot.is-active {
  border-color: var(--text);
}

.palette-dot:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* 名前変更中の入力 */
.rename-input {
  flex: 1;
  min-width: 0;
  padding: 5px 9px;
  font-weight: 700;
}

.subject-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  font-weight: 400;
}

.field-wide {
  grid-column: 1 / -1;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.2s, transform 0.2s;
  z-index: 999;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.callout {
  border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
  border-left: 4px solid var(--primary);
  background: var(--primary-weak);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 16px;
}

/* ---------------- 時間割表ページ ---------------- */

.tt-now {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 17px;
  box-shadow: var(--shadow);
  min-width: 230px;
}

.tt-now .tn-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--success);
}

.tt-now .tn-subject {
  font-size: 20px;
  font-weight: 700;
  margin: 2px 0;
}

.tt-now .tn-time {
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.tt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 15px;
  margin-top: 18px;
  color: var(--text-muted);
  font-size: 12px;
}

.tt-legend .lg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tt-legend .lg .dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

/* ---------------- 表示モード（サイネージ） ----------------
 * Apple 風のデザイン方針:
 *  - 大きな余白、0.5px の細い罫線、VERY soft な影
 *  - 半透明 + ぼかしの「ガラス」パネル
 *  - 大きな文字は weight 600/700 と 狭い letter-spacing
 *  - 色は控えめに、アクセントは科目色の淡い霧と進捗バーだけ
 * ------------------------------------------ */

body.display {
  min-height: 100vh;
  --glass: color-mix(in srgb, var(--surface) 66%, transparent);
  --glass-strong: color-mix(in srgb, var(--surface) 86%, transparent);
  --hairline: color-mix(in srgb, var(--border-strong) 58%, transparent);
  /* 実効アクセント色 --accent の既定は :root で定義（設定色→primaryへ継承で解決）。
   * ここで再定義すると <html> のインライン指定を遮るため定義しない。 */
  color: var(--text);
  /* 日本語はプロポーショナル字幅（palt）で Apple's 日本語組版に寄せる */
  font-feature-settings: 'palt' 1;
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 700px at 4% -14%, color-mix(in srgb, var(--primary) 13%, transparent), transparent 62%),
    radial-gradient(900px 620px at 98% -8%, color-mix(in srgb, var(--success) 11%, transparent), transparent 60%),
    radial-gradient(1000px 720px at 72% 114%, color-mix(in srgb, var(--primary) 8%, transparent), transparent 62%);
  background-attachment: fixed;
}

.display-wrap {
  max-width: 1420px;
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(22px, 3.2vw, 60px);
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 2.4vw, 34px);
}

.display-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(16px, 2vw, 28px);
  flex-wrap: wrap;
}

.display-brand {
  display: flex;
  align-items: center;
  gap: clamp(12px, 1.5vw, 20px);
  min-width: 0;
}

/* アプリアイコン風（角丸の四角 + ぼかし） */
.display-mark {
  flex: none;
  display: grid;
  place-items: center;
  width: clamp(46px, 5vw, 68px);
  height: clamp(46px, 5vw, 68px);
  border-radius: 28%;
  color: var(--primary);
  background: linear-gradient(160deg, var(--glass-strong), var(--glass));
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--shadow-sm), inset 0 0 0 0.5px var(--hairline);
}

.display-mark .icon {
  width: 46%;
  height: 46%;
}

.display-heading {
  min-width: 0;
}

.display-title {
  font-size: clamp(21px, 2.5vw, 32px);
  font-weight: 700;
  letter-spacing: -0.028em;
  line-height: 1.16;
  word-break: break-word;
}

.display-sub {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: clamp(12px, 1.2vw, 15px);
}

.display-clock {
  text-align: right;
}

.dc-time {
  font-size: clamp(38px, 6.4vw, 88px);
  font-weight: 600;
  letter-spacing: -0.045em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.dc-date {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: clamp(12px, 1.4vw, 17px);
}

.display-warn {
  padding: clamp(12px, 1.4vw, 18px) clamp(16px, 1.8vw, 24px);
  border-radius: clamp(14px, 1.6vw, 20px);
  background: color-mix(in srgb, var(--danger) 12%, var(--glass));
  box-shadow: var(--shadow-sm),
    inset 0 0 0 0.5px color-mix(in srgb, var(--danger) 36%, transparent);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  color: var(--danger);
  font-size: clamp(13px, 1.4vw, 19px);
  line-height: 1.5;
}

.display-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: clamp(16px, 1.8vw, 28px);
  align-items: stretch;
}

/* ガラスパネル共通 */
.display-now,
.display-today {
  position: relative;
  border-radius: clamp(24px, 2.6vw, 36px);
  background: var(--glass);
  backdrop-filter: blur(34px) saturate(180%);
  -webkit-backdrop-filter: blur(34px) saturate(180%);
  box-shadow: var(--shadow-lg), inset 0 0 0 0.5px var(--hairline);
}

/* ---- 現在の授業 ---- */

.display-now {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: clamp(24px, 3.4vw, 54px);
}

/* 科目色の淡い霧（--accent は JS が科目色で上書きする） */
.display-now::after {
  content: '';
  position: absolute;
  inset: -30% -16% auto -16%;
  height: 74%;
  background: radial-gradient(
    56% 62% at 26% 100%,
    color-mix(in srgb, var(--accent) 22%, transparent),
    transparent 72%
  );
  pointer-events: none;
}

.dn-head,
.dn-subject,
.dn-time,
.dn-meta,
.dn-progress {
  position: relative;
  z-index: 1;
}

.dn-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(10px, 1.4vw, 20px);
  flex-wrap: wrap;
}

.dn-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 15px;
  border-radius: 999px;
  font-size: clamp(13px, 1.25vw, 17px);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--display-accent, var(--primary));
  background: color-mix(in srgb, var(--display-accent, var(--primary)) 13%, transparent);
}

.display-now.is-current .dn-chip {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 15%, transparent);
}

.display-now.is-idle .dn-chip {
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.dn-count {
  font-size: clamp(17px, 2.1vw, 28px);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.dn-subject {
  margin: clamp(12px, 1.6vw, 24px) 0 0;
  font-size: clamp(40px, 7.4vw, 112px);
  font-weight: 700;
  /* 日本語のdisplay 字は詰すぎると窮屈になるので -0.03em までに抑える */
  letter-spacing: -0.03em;
  line-height: 1.04;
  word-break: break-word;
}

.dn-time {
  margin-top: clamp(10px, 1.4vw, 20px);
  font-size: clamp(19px, 2.5vw, 34px);
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.dn-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px clamp(20px, 2.4vw, 34px);
  margin: clamp(18px, 2.2vw, 32px) 0 clamp(20px, 2.6vw, 40px);
  padding: clamp(12px, 1.5vw, 20px) clamp(14px, 1.8vw, 24px);
  background: color-mix(in srgb, var(--text) 5%, transparent);
  border: 0.5px solid var(--hairline);
  border-radius: 16px;
  font-size: clamp(16px, 1.85vw, 24px);
}

.dn-meta .m {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}

.dn-meta .m-label {
  color: var(--text-muted);
  font-size: 0.68em;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: color-mix(in srgb, var(--text) 7%, transparent);
  border-radius: 7px;
  padding: 1px 8px;
}

.dn-meta .m-value {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.dn-progress {
  margin-top: auto;
  height: clamp(6px, 0.7vw, 10px);
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  overflow: hidden;
}

.dn-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 20px color-mix(in srgb, var(--accent) 55%, transparent);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- 今日の時間割 ---- */

.display-today {
  display: flex;
  flex-direction: column;
  padding: clamp(18px, 2.2vw, 32px);
}

.display-section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 clamp(8px, 1vw, 14px);
  font-size: clamp(15px, 1.55vw, 21px);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
}

/* 「今日の時間割」のコマ数（右端に寄せる） */
.display-section-count {
  margin-left: auto;
  flex: none;
  font-size: 0.82em;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.display-list {
  list-style: none;
  margin: 0 calc(-1 * clamp(8px, 1vw, 14px));
  padding: 0;
  display: flex;
  flex-direction: column;
}

.display-item {
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.3vw, 18px);
  padding: clamp(12px, 1.5vw, 20px) clamp(10px, 1.2vw, 16px);
  border-radius: clamp(12px, 1.3vw, 18px);
  border: 1px solid transparent;
}

.display-item + .display-item {
  border-top: 0.5px solid var(--hairline);
}

.display-item.is-current {
  background: color-mix(in srgb, var(--success) 14%, transparent);
  border-color: color-mix(in srgb, var(--success) 38%, transparent);
  border-top-color: color-mix(in srgb, var(--success) 38%, transparent);
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--success) 85%, transparent);
}

.display-item.is-next {
  background: color-mix(in srgb, var(--display-accent, var(--primary)) 9%, transparent);
  border-color: color-mix(in srgb, var(--display-accent, var(--primary)) 30%, transparent);
  border-top-color: color-mix(in srgb, var(--display-accent, var(--primary)) 30%, transparent);
  box-shadow: inset 3px 0 0 var(--display-accent, var(--primary));
}

.display-item.is-done {
  opacity: 0.55;
}

.display-item .dot {
  flex: none;
  width: clamp(12px, 1.15vw, 15px);
  height: clamp(12px, 1.15vw, 15px);
  border-radius: 50%;
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.45), 0 1px 4px rgba(0, 0, 0, 0.18);
}

.display-item .di-period {
  flex: none;
  min-width: 3.2em;
  text-align: center;
  font-size: clamp(12px, 1.2vw, 15px);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  background: color-mix(in srgb, var(--text) 8%, transparent);
  border: 0.5px solid var(--hairline);
  border-radius: 999px;
  padding: 3px 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.display-item.is-current .di-period {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 16%, transparent);
  border-color: color-mix(in srgb, var(--success) 40%, transparent);
}

.display-item.is-next .di-period {
  color: var(--display-accent, var(--primary));
  background: color-mix(in srgb, var(--display-accent, var(--primary)) 13%, transparent);
  border-color: color-mix(in srgb, var(--display-accent, var(--primary)) 34%, transparent);
}

.display-item .di-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.display-item .di-namerow {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.display-item .di-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(18px, 2vw, 28px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

.display-item.is-done .di-name {
  font-weight: 600;
}

.display-item .di-badge {
  flex: none;
  font-size: clamp(10px, 1vw, 12px);
  font-weight: 800;
  letter-spacing: 0.06em;
  border-radius: 999px;
  padding: 2px 9px;
}

.display-item .di-badge.is-now {
  color: #fff;
  background: var(--success);
}

.display-item .di-badge.is-nextbadge {
  color: var(--display-accent, var(--primary));
  background: color-mix(in srgb, var(--display-accent, var(--primary)) 14%, transparent);
}

.display-item .di-sub {
  color: var(--text-muted);
  font-size: clamp(13px, 1.35vw, 18px);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.display-item .di-time {
  color: var(--text);
  font-size: clamp(14px, 1.6vw, 22px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border-radius: 9px;
  padding: 4px 10px;
}

.display-item.is-done .di-time {
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
}

.display-list .empty {
  text-align: left;
  font-size: clamp(14px, 1.5vw, 20px);
}

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

.display-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-muted);
  font-size: clamp(11px, 1vw, 13px);
}

.display-foot .icon-btn {
  width: clamp(34px, 3vw, 44px);
  height: clamp(34px, 3vw, 44px);
  border-radius: 13px;
  font-size: clamp(15px, 1.4vw, 19px);
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: var(--shadow-sm), inset 0 0 0 0.5px var(--hairline);
}

.display-foot .icon-btn:hover {
  background: var(--glass-strong);
  border-color: var(--hairline);
}

@media (max-width: 980px) {
  .display-main {
    grid-template-columns: 1fr;
  }

  .display-clock {
    text-align: left;
  }

  .display-item .di-sub {
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .dn-progress-bar {
    transition: none;
  }
}

/* コマ単位上書きパネルの「科目の既定」表示 */
.modal-defaults {
  color: var(--text-muted);
  font-size: 12px;
  margin: 14px 0 0;
  padding: 9px 11px;
  background: var(--surface-2);
  border-radius: 9px;
  white-space: pre-line;
  word-break: break-word;
}

@media (max-width: 720px) {
  .grid-table input.cell-input {
    min-width: 64px;
  }

  .row .row-control {
    max-width: 60%;
  }
}

/* ================================================================== *
 * インライン SVG アイコン
 * 絵文字を使わないため、大きさ・色・位置をすべて CSS で制御する。
 * ================================================================== */

.icon {
  width: 1em;
  height: 1em;
  display: block;
  flex: none;
}

.icon-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  line-height: 0;
}

.btn .icon-slot .icon {
  width: 1.05em;
  height: 1.05em;
}

.btn.icon-only {
  padding: 5px 7px;
  gap: 0;
}

.btn.icon-only .icon {
  width: 15px;
  height: 15px;
}

.icon-btn .icon {
  width: 18px;
  height: 18px;
}

/* ポップアップのメタ情報（教室・担当・持ち物・説明） */
.meta .m {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.meta .m .icon-slot {
  color: var(--text-muted);
}

.meta .m .icon {
  width: 13px;
  height: 13px;
}

.meta .m .m-label {
  color: var(--text-muted);
  font-size: 11px;
}

.meta .m .m-value {
  color: var(--text);
  font-weight: 600;
}

/* 説明（memo）は改行をそのまま表示し、折り返す */
.meta .m.is-memo {
  flex-basis: 100%;
  align-items: flex-start;
}

.meta .m-value.is-memo {
  white-space: pre-line;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-weight: 500;
  line-height: 1.6;
}

/* ステータスチップの状態ドット */
.chip::before,
.dn-chip::before,
.tn-chip::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

/* 未設定コマの警告 */
.warn-box {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.warn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  margin-top: 1px;
}

.warn-icon .icon {
  width: 1em;
  height: 1em;
}

/* プライバシー callout / フッター注記 */
.callout {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.callout-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  color: var(--primary);
  margin-top: 1px;
}

.callout-icon .icon {
  width: 16px;
  height: 16px;
}

.footer-note {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

input:disabled,
select:disabled,
textarea:disabled,
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.footer-note .icon {
  width: 12px;
  height: 12px;
}

/* 時間割表のコマ内の小アイコン */
.micro-icon {
  flex: none;
  display: inline-flex;
  color: var(--text-muted);
}

.micro-icon .icon {
  width: 12px;
  height: 12px;
}

.slot-items,
.slot-memo {
  display: flex;
  align-items: center;
  gap: 4px;
}

.slot-items > span:last-child,
.slot-memo > span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 時間割表の「今/次」チップの色分け */
.tt-now.is-next .tn-chip {
  color: var(--primary);
}

.tt-now.is-idle .tn-chip {
  color: var(--text-muted);
}

/* ================================================================== *
 * 表示モード（サイネージ）の調整
 * ================================================================== */

/* 今日の時間割が長くてもパネルからはみ出さず、必要ならスクロールさせる */
.display-today {
  min-height: 0;
  overflow: hidden;
}

.display-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 授業中に添える「次の授業」 */
.dn-next {
  position: relative;
  z-index: 1;
  margin-top: clamp(14px, 1.8vw, 26px);
  padding-top: clamp(12px, 1.5vw, 20px);
  border-top: 0.5px solid var(--hairline);
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px clamp(12px, 1.4vw, 20px);
}

.dn-next-label {
  flex: none;
  font-size: clamp(12px, 1.1vw, 15px);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--display-accent, var(--primary));
  background: color-mix(in srgb, var(--display-accent, var(--primary)) 12%, transparent);
  border-radius: 999px;
  padding: 3px 11px;
}

.dn-next-subject {
  font-size: clamp(16px, 1.7vw, 24px);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.dn-next-time {
  font-size: clamp(13px, 1.35vw, 19px);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.dn-meta .m .icon {
  width: 0.78em;
  height: 0.78em;
}

.dn-meta .m .meta-icon {
  color: var(--text-muted);
}

/* 全画面ボタンのアイコンを少し大きめに */
.display-foot .icon-btn .icon {
  width: 1.05em;
  height: 1.05em;
}

/* フッター左の注記（幅が狭いときは省略してボタンを優先） */
.display-foot-note {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* 読み込み中はカードを淡くして、まだ確定値でないことを示す */
body.display.is-loading .display-now,
body.display.is-loading .display-today {
  opacity: 0.6;
}

body.display.is-loading .dn-chip {
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

body.display.is-loading .dn-progress-bar {
  transition: none;
}

/* 今日のコマの強調（左のアクセントバーで現在地を示す） */
.display-item.is-current {
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--success) 78%, transparent);
}

@media (max-width: 640px) {
  .display-item {
    flex-wrap: wrap;
  }

  .display-item .di-time {
    margin-left: auto;
  }
}

/* ================================================================== *
 * 設定ページ（左サイドバー）
 * ================================================================== */

/* 設定レイアウトは全幅にし、カテゴリのサイドバーを常に画面の左端に寄せる。
 * 1200px で中央寄せしていた頃は、広い画面で左に余白ができて
 * カテゴリが中央付近に表示されていた。読みやすさのための幅制限は
 * 本文（.settings-main）側で行う。 */
.settings-layout {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100vh;
  margin: 0;
  max-width: none;
}

.settings-nav {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
}

/* サイドバーはページ内カテゴリの切り替え専用であることを明示する見出し。
 * 上部バー（ページ間の移動）との役割分担を一目で分かるようにする。 */
.settings-menu-caption {
  margin: 0;
  padding: 2px 11px 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.settings-menu {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.settings-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.settings-menu-item .icon {
  width: 18px;
  height: 18px;
}

.settings-menu-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.settings-menu-item.is-active {
  background: var(--primary-weak);
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 30%, transparent);
}

.settings-main {
  min-width: 0;
  max-width: 940px;
  padding: 28px 32px 90px;
}

.settings-topbar {
  margin-bottom: 20px;
}

.settings-content .settings-section {
  margin-bottom: 16px;
}

.subhead {
  font-size: 13px;
  font-weight: 700;
  margin: 24px 0 8px;
  padding-top: 4px;
}

.settings-section .row-control input[type='text'] {
  min-width: 220px;
}

@media (max-width: 820px) {
  .settings-layout {
    grid-template-columns: 1fr;
  }

  .settings-nav {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .settings-menu {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .settings-menu-item {
    width: auto;
    white-space: nowrap;
  }

  .settings-main {
    padding: 20px 16px 80px;
  }
}

/* ================================================================== *
 * 時間割表ページ（インライン編集）
 * ================================================================== */

.page-wrap.tt-page {
  max-width: 1180px;
}

.tt-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tt-week-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tt-week-info {
  margin-left: 8px;
}

.tt-week-info .page-title {
  font-size: 20px;
  margin-bottom: 2px;
}

.tt-hint {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  margin: 0 0 14px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 12.5px;
}

.tt-hint .hint-icon .icon {
  width: 15px;
  height: 15px;
}

.tt-hint strong {
  color: var(--text);
}

.tt-grid-table {
  width: 100%;
  min-width: 880px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 6px;
}

.tt-grid-table th {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  padding: 4px;
  min-width: 0;
  overflow: hidden;
}

.tt-grid-table th.is-today {
  color: var(--primary);
  background: var(--primary-weak);
  border-radius: 9px;
}

.tt-grid-table th.time-col {
  width: 78px;
  min-width: 78px;
  max-width: 78px;
}

.tt-time-cell {
  width: 78px;
  min-width: 78px;
  max-width: 78px;
  height: 66px;
  min-height: 66px;
  background: var(--surface-2);
  border-radius: 11px;
  padding: 8px 9px;
  text-align: right;
  vertical-align: middle;
  font-size: 12px;
  overflow: hidden;
}

.tt-time-cell .tt-pname {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tt-time-cell .tt-ptime {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* マス（直接編集できるセル）。全マスを均等な高さ・幅に保つため、
 * td が無視する min-height ではなく height で固定し、
 * バッジ分の下余白とサブ行の最小高さを常に確保する。 */
.tt-cell {
  position: relative;
  vertical-align: middle;
  min-width: 108px;
  height: 66px;
  min-height: 66px;
  padding: 6px 8px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--surface-3);
  border-radius: 11px;
  transition: border-color 0.15s, box-shadow 0.15s;
  overflow: hidden;
}

.tt-cell.is-filled {
  border-left-color: var(--cell-color, var(--border));
  box-shadow: var(--shadow-sm);
}

.tt-cell:hover {
  border-color: var(--border-strong);
}

.tt-cell:focus-within {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.tt-cell.is-current {
  box-shadow: 0 0 0 2px var(--success);
  background: var(--success-weak);
}

.tt-cell-input {
  display: block;
  width: 100%;
  min-height: 24px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 5px;
  background: transparent;
  box-shadow: none;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.3;
}

.tt-cell-input:focus {
  outline: none;
  box-shadow: none;
  border: none;
}

.tt-cell-input::placeholder {
  color: color-mix(in srgb, var(--text-muted) 55%, transparent);
  font-weight: 600;
}

/* 選択式のセル（select）。タップで科目を選べる。
 * 右端の「…」ボタン（22px）と重ならないよう余白を常に確保する。 */
.tt-cell-select,
.tt-cell-new {
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 24px;
  margin: 0;
  padding: 1px 28px 1px 0;
  border: none;
  border-radius: 5px;
  background: transparent;
  box-shadow: none;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.3;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  box-sizing: border-box;
}

.tt-cell-new {
  cursor: text;
  border-bottom: 1px solid var(--primary);
  border-radius: 0;
}

.tt-cell-select:focus,
.tt-cell-new:focus {
  outline: none;
  box-shadow: none;
  border-color: var(--primary);
}

.tt-cell-select:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

/* 空きマスは選択を促す色にする */
.tt-cell:not(.is-filled) .tt-cell-select {
  color: var(--text-muted);
  font-weight: 600;
}

.tt-cell-sub {
  margin-top: 2px;
  min-height: 15px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tt-cell-sub:empty {
  visibility: hidden;
}

.tt-cell-more {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 7px;
  background: var(--surface-3);
  color: var(--text-muted);
}

.tt-cell.is-filled .tt-cell-more,
.tt-cell:hover .tt-cell-more,
.tt-cell:focus-within .tt-cell-more {
  display: inline-flex;
}

.tt-cell-more:hover {
  background: var(--primary-weak);
  color: var(--primary);
}

.tt-cell-more .icon {
  width: 13px;
  height: 13px;
}

.tt-cell .now-badge {
  position: absolute;
  bottom: 5px;
  right: 6px;
  max-width: calc(50% - 8px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.5;
  color: #fff;
  background: var(--success);
  border-radius: 999px;
  padding: 1px 7px;
}

/* コマの詳細パネル（画面中央モーダル） */
.tt-editor-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: color-mix(in srgb, #05060a 46%, transparent);
}

.tt-editor-backdrop[hidden] {
  display: none;
}

body.has-editor-open {
  overflow: hidden;
}

.tt-editor {
  position: fixed;
  z-index: 901;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 32px));
  max-height: min(86vh, 800px);
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0;
  padding: 20px 22px 18px;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--primary) 34%, var(--border));
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

@media (max-width: 480px) {
  .tt-editor {
    width: calc(100vw - 24px);
    padding: 16px 16px 14px;
  }
}

.tt-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.tt-editor-kicker {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
}

.tt-editor-title {
  font-size: 20px;
}

.tt-editor .subject-fields {
  margin-top: 4px;
}

/* ================================================================== *
 * 表示モードの見た目バリエーション（設定で切り替え）
 * ================================================================== */

body.display[data-bg='plain'] {
  background-image: none;
}

body.display[data-bg='dark'] {
  --bg: #0b0d12;
  --surface: #171a22;
  --surface-2: #1f232d;
  --surface-3: #262b37;
  --text: #eef1f7;
  --text-muted: #98a1b3;
  --border: #262b36;
  --border-strong: #333a48;
  --primary: #8f8ff5;
  background-color: var(--bg);
  background-image: none;
}

.display-main.is-single {
  grid-template-columns: minmax(0, 1fr);
}

.display-item .dot.dot-accent {
  background: var(--display-accent, var(--primary));
}

.dn-meta:empty {
  display: none;
}

/* ================================================================== *
 * ダイアログ（confirm / alert の代替）
 * ================================================================== */

.dialog-root {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
}

.dialog-root[hidden] {
  display: none;
}

.dialog-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, #05060a 46%, transparent);
}

.dialog-panel {
  width: min(420px, 100%);
  padding: 20px 22px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.dialog-title {
  margin: 0 0 8px;
  font-size: 17px;
}

.dialog-message {
  margin: 0;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.7;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ================================================================== *
 * ロック画面（データが暗号化されているときに全ページを覆う）
 * ================================================================== */

.lock-root {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  /* 中身が透けないよう、本体と同系の不透明な背景で全面を覆う */
  background:
    radial-gradient(1100px 520px at 12% -8%, var(--bg-glow-a), transparent 60%),
    radial-gradient(900px 460px at 100% 0%, var(--bg-glow-b), transparent 55%),
    var(--bg);
}

.lock-root[hidden] {
  display: none;
}

.lock-card {
  width: min(400px, 100%);
  padding: 26px 24px 22px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.lock-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  color: var(--primary);
  background: var(--primary-weak);
  border-radius: 50%;
}

.lock-badge .icon {
  width: 26px;
  height: 26px;
}

.lock-title {
  margin: 14px 0 8px;
  font-size: 17px;
}

.lock-desc {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.7;
}

.lock-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lock-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 20px;
  font-family: inherit;
  letter-spacing: 0.3em;
  text-align: center;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
}

.lock-input:focus {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.lock-input:disabled {
  opacity: 0.6;
}

.lock-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
}

.lock-error[hidden] {
  display: none;
}

.lock-submit {
  width: 100%;
}

.lock-note {
  margin: 16px 0 0;
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.7;
}

/* 設定ページ: ロック状態の表示とフォームエラー */
.lock-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 999px;
}

.lock-pill.is-on {
  color: var(--success);
  background: var(--success-weak);
}

.lock-pill.is-off {
  color: var(--text-muted);
  background: var(--surface-2);
}

.lock-form-error {
  margin: 4px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.lock-form-error[hidden] {
  display: none;
}

/* ================================================================== *
 * コマの詳細パネル: 適用範囲と、この日だけの変更
 * ================================================================== */

.editor-scope {
  display: inline-flex;
  gap: 6px;
  margin: 4px 0 10px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 999px;
}

.editor-scope .scope-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.editor-scope .scope-option input {
  margin: 0;
}

.editor-scope .scope-option:has(input:checked) {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* この日だけの変更が入ったマス / 休講のマス */
.tt-cell.is-exception {
  border-style: dashed;
}

.tt-cell.is-canceled {
  opacity: 0.72;
}

.tt-cell.is-canceled .tt-cell-input,
.tt-cell.is-canceled .tt-cell-select {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* 詳細モーダルの休講チェック */
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0;
  padding: 9px 11px;
  background: var(--surface-2);
  border-radius: 9px;
  font-weight: 600;
  cursor: pointer;
}

.check-row input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.tt-cell-badge {
  position: absolute;
  bottom: 5px;
  left: 6px;
  max-width: calc(50% - 8px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1.5;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--primary-weak);
  color: var(--primary);
}

.tt-cell-badge.is-cancel {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
}

/* ================================================================== *
 * 表示モード v6（中央フォーカス + サイド一覧）
 * 画面中央に現在の授業を大きく表示、右サイドに今日の一覧。
 * 100vh固定・1行・自動縮小。
 * ================================================================== */

body.display{
  margin: 0;
  height: 100vh;
  height: 100svh;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}

body.display[data-bg='dark']{
  --surface: #000;
  --text: #f2f2f2;
  --text-muted: #999;
  --border: #222;
  --border-strong: #333;
  background: #000;
}

body.display .screen{
  display: grid;
  grid-template-areas:
    "top  top"
    "body side"
    "ftr  ftr";
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr) clamp(240px, 30vw, 480px);
  height: 100vh;
  height: 100svh;
}

/* ---- topbar ---- */
body.display .topbar{
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: clamp(8px, 1.5vh, 16px) clamp(12px, 2vw, 32px);
  border-bottom: 1px solid var(--border);
}
body.display .tb-left{ display: flex; align-items: center; gap: 14px; min-width: 0; }
body.display .tb-ttl{ font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.display .tb-right{ flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 0; }
body.display .tb-clock{ font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
body.display .tb-date{ color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ---- center ---- */
body.display .center{
  grid-area: body;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1.2vh, 14px);
  padding: clamp(8px, 2vh, 32px) clamp(16px, 4vw, 64px);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

body.display .c-date{ margin: 0; color: var(--text-muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.display .c-clock{ margin: 0; font-weight: 700; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; line-height: 1; text-align: center; }

body.display .c-subj{ display: flex; flex-direction: column; align-items: center; gap: clamp(4px, 1vh, 10px); min-width: 0; width: 100%; }
body.display .chip{ font-size: clamp(12px, 1.4vh, 16px); font-weight: 700; letter-spacing: 0.14em; color: var(--text-muted); }
body.display .center.is-live .chip{ color: var(--accent); }
body.display .center.is-next .chip{ color: var(--accent); }
body.display .c-name{ margin: 0; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; }
body.display .c-time{ font-size: clamp(13px, 1.6vh, 20px); color: var(--text-muted); font-variant-numeric: tabular-nums; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; }
body.display .c-count{ font-weight: 700; color: var(--text-muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; }
body.display .center.is-live .c-count{ color: var(--text); }
body.display .center.is-next .c-count{ color: var(--accent); }

body.display .c-prog{ width: min(100%, 720px); }
body.display .c-prog[hidden]{ display: none; }
body.display .c-prog-bar{ height: clamp(4px, 1vh, 10px); width: 0%; background: var(--accent); transition: width 0.6s linear; }

body.display .c-next{ width: min(100%, 720px); margin-inline: auto; padding-top: clamp(6px, 1vh, 12px); border-top: 1px solid var(--border); display: flex; align-items: baseline; justify-content: center; gap: 0.55em; text-align: center; color: var(--text-muted); white-space: nowrap; overflow: hidden; line-height: 1.4; }
body.display .c-next[hidden]{ display: none; }
body.display .c-next-label{ flex: none; font-size: 0.62em; font-weight: 700; letter-spacing: 0.08em; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 999px; padding: 0.15em 0.8em; transform: translateY(-0.1em); }
body.display .c-next-subj{ min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 700; color: var(--text); }
body.display .c-next-time{ flex: none; max-width: 55%; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

body.display .c-meta{ width: min(100%, 720px); display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: 0.4em clamp(10px, 1.6vw, 24px); color: var(--text-muted); overflow: hidden; line-height: 1.5; }
body.display .c-meta[hidden]{ display: none; }
body.display .mi{ display: inline-flex; align-items: baseline; gap: 6px; min-width: 0; max-width: 100%; overflow: hidden; white-space: nowrap; }
body.display .mi-l{ font-size: 0.72em; font-weight: 700; letter-spacing: 0.08em; color: var(--text-muted); flex: none; }
body.display .mi-v{ font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 説明（memo）は改行をそのまま表示する。中央に寄せつつ本文は左揃えで読みやすく */
body.display .mi.is-memo{ flex-basis: 100%; justify-content: center; align-items: flex-start; white-space: normal; }
body.display .mi-v.is-memo{ white-space: pre-line; word-break: break-word; overflow-wrap: anywhere; overflow: visible; text-overflow: clip; text-align: left; font-weight: 500; line-height: 1.6; }

/* ---- side ---- */
body.display .side{
  grid-area: side;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  padding: clamp(8px, 1.5vh, 16px) clamp(8px, 1.4vw, 20px);
  overflow: hidden;
}

body.display .side-hdr{ display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex: none; padding-bottom: clamp(4px, 0.8vh, 10px); border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
body.display .side-ttl{ font-size: clamp(11px, 1.2vh, 13px); font-weight: 600; letter-spacing: 0.06em; color: var(--text-muted); opacity: 0.85; }
body.display .side-cnt{ font-size: clamp(10px, 1.1vh, 12px); color: var(--text-muted); font-variant-numeric: tabular-nums; opacity: 0.8; }

body.display .grid{
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(2px, 0.6vh, 6px);
  padding-top: clamp(4px, 1vh, 10px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

body.display .row{
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 10px;
  padding: clamp(5px, 1vh, 10px) clamp(8px, 1vw, 14px);
  border: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
  flex-shrink: 0;
  min-width: 0;
}

body.display .row.cur{ background: var(--success-weak); border-color: var(--success); }
body.display .row.done{ opacity: 0.38; }
body.display .row.canceled{ opacity: 0.62; border-style: dashed; }
body.display .row.canceled .nm{ text-decoration: line-through; }

body.display .rp{ font-weight: 600; font-size: 0.86em; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; opacity: 0.9; }
body.display .row.cur .rp{ color: var(--success); opacity: 1; }
body.display .rt{ color: var(--text-muted); font-size: 0.86em; font-variant-numeric: tabular-nums; white-space: nowrap; opacity: 0.85; }

body.display .nm{ font-weight: 500; color: color-mix(in srgb, var(--text) 78%, var(--text-muted)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
body.display .row.cur .nm{ font-weight: 800; color: var(--text); }

/* ---- footer ---- */
body.display .ftr{
  grid-area: ftr;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: clamp(5px, 1vh, 12px) clamp(12px, 2vw, 32px);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: clamp(12px, 1.5vh, 15px);
}
body.display .warn{ min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.display .ico{ flex: none; width: clamp(32px, 4vh, 44px); height: clamp(32px, 4vh, 44px); border-radius: 8px; background: transparent; border: 1px solid transparent; box-shadow: none; }
body.display .ico:hover{ border-color: var(--border); }

/* fullscreen idle */
body.display.fs.idle{ cursor: none; }
body.display.fs.idle .ftr{ opacity: 0; pointer-events: none; }
body.display.loading .center{ opacity: 0.5; }

/* fit helper（.c-meta は説明の改行のため折り返し可とする） */
body.display .tb-ttl, body.display .tb-clock, body.display .tb-date, body.display .c-date, body.display .c-clock, body.display .c-name, body.display .c-time, body.display .c-count, body.display .c-next, body.display .nm{
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 700px) {
  body.display .screen{
    grid-template-areas:
      "top"
      "body"
      "side"
      "ftr";
    grid-template-rows: auto minmax(0, 1.15fr) minmax(0, 1fr) auto;
    grid-template-columns: minmax(0, 1fr);
  }

  body.display .side{ border-left: none; border-top: 1px solid var(--border); }
}

@media (prefers-reduced-motion: reduce) {
  body.display .c-prog-bar{ transition: none; }
}

/* 一覧非表示時は中央を全幅に */
body.display.no-side .screen {
  grid-template-areas:
    "top"
    "body"
    "ftr";
  grid-template-columns: minmax(0, 1fr);
}

/* ================================================================== *
 * 共通ページナビ（拡張 / Web 共通・src/nav.js が差し込む）
 * マウス操作では上部バー、タッチ操作では下部タブバーを表示する。
 * ================================================================== */

/* タブバー表示時の余白（タブバーが出る条件と一致させる） */
@media (hover: none) and (max-width: 860px), (pointer: coarse) and (max-width: 860px) {
  body.has-page-nav {
    padding-bottom: 76px;
  }

  /* 下部タブバーに被らないよう、固定表示の通知類を持ち上げる */
  .toast {
    bottom: calc(96px + env(safe-area-inset-bottom));
  }

  .mini-toast {
    bottom: calc(96px + env(safe-area-inset-bottom));
  }
}

.nav-topbar {
  display: none;
}

.nav-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.nav-tabbar a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px 2px 6px;
  border-radius: 10px;
  line-height: 1.3;
}

.nav-tabbar a.is-active {
  color: var(--text);
  background: var(--surface-2, rgba(127, 127, 127, 0.12));
  font-weight: 700;
}

/* PC扱い: マウス操作、または横幅が十分 → 上部バー。
 * 幅条件を併用するのは、タッチ画面付きPCなどでポインタ判定が
 * coarse になる場合でもPCナビを出すため。
 * 注意: 上の .nav-tabbar より後に置くこと（同詳細度のため順序で勝たせる）。 */
@media (hover: hover) and (pointer: fine), (min-width: 861px) {
  .nav-tabbar {
    display: none;
  }

  body.has-page-nav {
    padding-bottom: 0;
  }

  .nav-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: var(--nav-top-h);
    box-sizing: border-box;
    padding: 10px 20px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
  }

  /* 上部バーと .app-bar（sticky top:0）の二重吸着で被らないよう、
   * ナビがあるページでは .app-bar をナビの高さ分だけ下げる。
   * （上部バーが無いページではずらさない。:has は Chrome 105+ で対応） */
  body.has-page-nav:has(.nav-topbar) .app-bar {
    top: var(--nav-top-h);
  }

  .nav-topbar-brand {
    font-weight: 800;
    margin-right: 16px;
    white-space: nowrap;
  }

  .nav-topbar a.nav-top-link {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 14px;
    padding: 8px 14px;
    border-radius: 10px;
    white-space: nowrap;
  }

  .nav-topbar a.nav-top-link:hover {
    background: var(--surface-2, rgba(127, 127, 127, 0.12));
    color: var(--text);
  }

  .nav-topbar a.nav-top-link.is-active {
    color: var(--text);
    background: var(--surface-2, rgba(127, 127, 127, 0.12));
    font-weight: 700;
  }

  /* 「表示モード」だけ右端に寄せる */
  .nav-topbar a.nav-top-link.is-right {
    margin-left: auto;
  }
}

/* 設定ページの左サイドバー（sticky top:0）が上部バーに隠れないよう、
 * 位置と高さをナビ分だけずらす。レイアウト全体の最小高さも補正する。
 *
 * ただしこれは「2カラム（サイドバーあり）」の幅でのみ適用する。
 * 1カラム（〜820px）ではサイドバーは通常フローの横並びメニューなので、
 * ここで height:100dvh を当てると下部に巨大な空白ができる。
 * 上部バーが出る条件（hover:fine または 幅861px以上）と併せて判定する。 */
@media (min-width: 861px), (min-width: 821px) and (hover: hover) and (pointer: fine) {
  body.has-page-nav:has(.nav-topbar) .settings-nav {
    top: var(--nav-top-h);
    height: calc(100vh - var(--nav-top-h));
    height: calc(100dvh - var(--nav-top-h));
  }

  body.has-page-nav:has(.nav-topbar) .settings-layout {
    min-height: calc(100vh - var(--nav-top-h));
  }
}

@media (pointer: coarse) {
  .nav-tabbar a {
    padding: 10px 2px 8px;
    font-size: 13px;
  }

  /* iOS Safari は 16px 未満の入力欄にフォーカスすると自動ズームする。
   * タッチ操作では入力系を 16px 以上にして、編集のたびに画面が
   * 拡大縮小しないようにする。 */
  body.page input,
  body.page select,
  body.page textarea,
  body.popup input,
  body.popup select,
  body.popup textarea {
    font-size: 16px;
  }
}

/* キーボードフォーカスの明示（ナビ等の共通要素向け） */
.nav-tabbar a:focus-visible,
.nav-topbar a:focus-visible {
  outline: 2px solid #5b7cfa;
  outline-offset: 2px;
}

/* ================================================================== *
 * UX 向上バンドル（popup / timetable / options / display 追加分）
 * ================================================================== */

/* ---- popup: サマリー・次回・コピー・CTA ---- */

.day-summary {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  line-height: 1.5;
}

.setup-cta {
  background: var(--primary-weak);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.setup-cta p {
  margin: 0;
  flex: 1;
}

.next-card.is-upcoming {
  border-style: dashed;
}

.next-card.is-upcoming .next-label {
  background: var(--surface-3);
  color: var(--text-muted);
}

.today-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.today-item .ti-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.today-item .ti-room {
  flex: none;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-3);
  border-radius: 6px;
  padding: 0 6px;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.today-item.is-next {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
}

.today-item.is-canceled {
  opacity: 0.72;
  border-style: dashed;
}

.today-item.is-canceled .ti-name {
  text-decoration: line-through;
}

.mini-toast {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.18s;
}

.mini-toast.show {
  opacity: 1;
}

/* ---- timetable: ツールバー・絞り込み・sticky・サマリー ---- */

.tt-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.tt-search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 240px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
}

.tt-search input {
  border: none;
  background: transparent;
  padding: 2px 0;
  box-shadow: none;
  flex: 1;
  min-width: 0;
}

.tt-search input:focus {
  box-shadow: none;
  border: none;
  outline: none;
}

.tt-search:focus-within {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.tt-tool-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tt-summary {
  margin: 0 0 10px;
}

/* ---- timetable: 操作ヘルプ・空状態 ---- */

.tt-help {
  margin: 0 0 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.tt-help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.tt-help-title {
  margin: 0;
  font-size: 15px;
}

.tt-help-grid {
  margin: 0;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 16px;
  font-size: 13px;
}

.tt-help-grid dt {
  font-weight: 700;
  white-space: nowrap;
}

.tt-help-grid dd {
  margin: 0;
  color: var(--text-muted);
}

.tt-empty {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  padding: 14px 16px;
  background: var(--primary-weak);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-radius: var(--radius);
  font-size: 13px;
}

.tt-empty p {
  margin: 0;
  flex: 1;
  min-width: 0;
}

@media (max-width: 560px) {
  .tt-help-grid {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }

  .tt-help-grid dt {
    margin-top: 6px;
  }

  .tt-empty {
    flex-wrap: wrap;
  }
}

.tt-cell.is-dim {
  opacity: 0.32;
}

.tt-cell.is-hit {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.tt-cell.is-today-col {
  background: color-mix(in srgb, var(--primary) 6%, var(--surface));
}

/* sticky ヘッダー＋時限列（長い週でも見出しを見失わない） */
.grid-scroll {
  max-height: min(72vh, 640px);
  overflow: auto;
}

.tt-grid-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-2);
}

.tt-grid-table .tt-time-cell {
  position: sticky;
  left: 0;
  z-index: 2;
}

/* ---- options: 検索・チェックリスト・プリセット ---- */

.settings-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
}

.settings-topbar-title {
  flex: 1 1 240px;
  min-width: 0;
}

.settings-topbar .page-subtitle {
  margin-bottom: 0;
}

.settings-search {
  flex: 0 1 280px;
  min-width: 200px;
  display: flex;
  padding-top: 2px;
}

.settings-search input {
  width: 100%;
  min-width: 0;
}

.settings-menu-item.is-search-hit {
  color: var(--primary);
}

.setup-checklist {
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
}

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

.setup-checklist-head h2 {
  margin: 0;
}

.checklist {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.check-item.is-done {
  opacity: 0.65;
}

.check-item.is-done .check-label {
  text-decoration: line-through;
}

.check-dot {
  flex: none;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-3);
  font-size: 12px;
  font-weight: 700;
}

.check-item.is-done .check-dot {
  background: var(--success-weak);
  color: var(--success);
}

.check-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.check-label {
  font-weight: 700;
}

.preset-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.preset-row select {
  flex: 1;
  min-width: 0;
}

/* ---- display: 休み時間プログレス ---- */

.c-prog-bar.is-break {
  background: var(--display-accent, var(--primary));
  box-shadow: none;
}

@media (max-width: 640px) {
  .tt-tools {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-search {
    flex: 1 1 100%;
    min-width: 0;
  }

  .settings-search input {
    width: 100%;
  }
}

/* ==================================================================
 * UX 改善（拡張 / Web 共通）: enhance.js と設定ページの追加 UI
 * ================================================================== */

/* スクリーンリーダー専用（見た目には出さない） */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* 通知・バッジの「何分前」プリセット */
.minute-presets {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
}

.minute-chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  cursor: pointer;
}

.minute-chip:hover {
  background: var(--surface-2);
  color: var(--text);
}

.minute-chip.is-active {
  background: var(--primary-weak);
  border-color: var(--primary);
  color: var(--primary);
}

/* 設定ページの保存インジケータ */
.save-state {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  opacity: 0;
  transition: opacity 0.2s;
}

.save-state.is-visible {
  opacity: 1;
}

/* 通知の許可状態 */
.perm-state {
  color: var(--text-muted);
}

/* 科目の絞り込み */
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.filter-row input {
  flex: 1;
  min-width: 0;
}

.filter-count {
  flex: none;
  white-space: nowrap;
}

/* トーストの「元に戻す」 */
.toast.show {
  pointer-events: auto;
}

.toast-undo {
  pointer-events: auto;
  margin-left: 10px;
  border: none;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  background: color-mix(in srgb, var(--bg) 22%, transparent);
  color: inherit;
}

.toast-undo:hover {
  background: color-mix(in srgb, var(--bg) 34%, transparent);
}

/* 複数時間割（パターン）のツールバー */
.pattern-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.pattern-pick {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
}

.pattern-pick select {
  min-width: 180px;
}

.pattern-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* 週ごとの切替（ローテーション） */
.rotation-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--surface-2);
}

.rotation-body {
  margin-top: 8px;
}

.rotation-body[hidden] {
  display: none;
}

.rotation-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rotation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.rotation-item .ri-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rotation-item .ri-index {
  flex: none;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--primary-weak);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

/* 自動バックアップ */
.backup-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.backup-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}

.backup-item .bk-info {
  flex: 1;
  min-width: 0;
}

.backup-item .bk-label {
  font-weight: 600;
}

.backup-item .bk-when {
  color: var(--text-muted);
  font-size: 12px;
}

/* ポップアップの「今日を操作」 */
.quick-actions {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.quick-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.quick-target {
  font-weight: 700;
  font-size: 13px;
}

.quick-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-room {
  display: flex;
  gap: 6px;
}

.quick-room input {
  flex: 1;
  min-width: 0;
}

/* ミニトースト内の「元に戻す」 */
.mini-toast .mini-undo {
  pointer-events: auto;
  margin-left: 8px;
  border: none;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  background: color-mix(in srgb, var(--bg) 22%, transparent);
  color: inherit;
}

.mini-toast.show {
  pointer-events: auto;
}
