:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #6b7684;
  --accent: #2f6fed;
  --danger: #e5484d;
  --clock-face: #fffdf7;
  --clock-rim: #2b3440;
  --clock-red: #e5484d;
  --shadow: 0 10px 30px rgba(20, 30, 50, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Segoe UI", Meiryo, sans-serif;
  /* 学校の壁（ページ全体）— うすめ */
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.012) 0 1px, transparent 1px 96px),
    linear-gradient(180deg, #f8f4ea 0%, #f2ecdd 100%);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 18px 110px; /* 下部はフローティングパネルのぶん余白 */
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(1.5) blur(8px);
  -webkit-backdrop-filter: saturate(1.5) blur(8px);
  box-shadow: 0 2px 14px rgba(20, 30, 50, 0.07);
}
/* タイトルと同じグラデーションのアクセントライン */
.app-header::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, #ff8a3d, #e5484d 40%, #7c3aed 75%, #2f6fed);
}
.app-header-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 15px 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.header-icon {
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.12));
}
.app-header h1 {
  margin: 0;
  font-size: 1.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #ff8a3d, #e5484d 40%, #7c3aed 75%, #2f6fed);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ===== 時計 ===== */
.clock-wrap { display: flex; flex-direction: column; align-items: center; margin: 22px 0; }

.clock {
  position: relative;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: var(--clock-face);
  border: 12px solid var(--clock-rim);
  box-shadow: var(--shadow), inset 0 0 0 4px #fff, inset 0 2px 14px rgba(0,0,0,0.05);
}

.tick-marks .tick {
  position: absolute;
  left: 50%;
  top: 6px;
  width: 2px;
  height: 10px;
  background: #99a1ad;
  transform-origin: 50% 144px; /* 半径 300/2 - border(12) - top(6) = 132? -> center distance */
  margin-left: -1px;
}
.tick-marks .tick.major {
  width: 4px;
  height: 16px;
  background: var(--clock-rim);
  margin-left: -2px;
}

.numbers .num {
  position: absolute;
  left: 50%;
  top: 50%;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--clock-rim);
  transform: translate(-50%, -50%);
}

.hand {
  position: absolute;
  left: 50%;
  bottom: 50%;
  transform-origin: 50% 100%;
  border-radius: 6px;
  transition: transform 0.15s cubic-bezier(0.4, 2.1, 0.6, 1);
}
.hand-hour {
  width: 8px;
  height: 70px;
  margin-left: -4px;
  background: var(--clock-rim);
}
.hand-minute {
  width: 6px;
  height: 100px;
  margin-left: -3px;
  background: #3a4453;
}
.hand-second {
  width: 2px;
  height: 118px;
  margin-left: -1px;
  background: var(--clock-red);
}
/* 秒針は連続的に見せたいので個別制御（JSで transition オフ切替） */

.center-cap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  background: var(--clock-rim);
  border: 3px solid var(--clock-red);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
}

/* 時計の中に表示するデジタル時刻 */
.clock .digital {
  position: absolute;
  left: 50%;
  top: 68%;
  transform: translate(-50%, -50%);
  z-index: 4;
  pointer-events: none;
  white-space: nowrap;
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  color: var(--clock-rim);
  /* うすーくカラフルなグラデーション背景 */
  background:
    linear-gradient(100deg,
      rgba(255, 138, 61, 0.16),
      rgba(229, 72, 77, 0.14) 30%,
      rgba(124, 58, 237, 0.14) 65%,
      rgba(47, 111, 237, 0.16));
  padding: 4px 12px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(43, 52, 64, 0.1);
}

/* ===== 黒板 ===== */
/* 黒板まわり（壁は body 全体に適用済みなので、ここは余白のみ） */
.wall {
  margin: 12px 0 22px;
}

.blackboard {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: 520px;
  min-height: 200px;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 14px;
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.05), transparent 60%),
    #2f4a3a; /* 深い緑 */
  border: 13px solid #9a6a35;     /* 木枠 */
  border-radius: 12px;
  box-shadow: var(--shadow), inset 0 0 44px rgba(0,0,0,0.42);
  padding: 24px 26px 28px;
  color: #f3f7f1;
  text-shadow: 0 1px 1px rgba(0,0,0,0.4);
}
.bb-main-area {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
.chalk-line { font-size: 0.95rem; letter-spacing: 0.25em; opacity: 0.85; }
.chalk-main {
  font-size: 2.3rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin: 8px 0 4px;
  line-height: 1.25;
}
.chalk-sub { font-size: 1.1rem; opacity: 0.9; min-height: 1.2em; }

/* 右側：今日の日付を縦書きで */
.chalk-date {
  flex: 0 0 auto;
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  line-height: 1;
  padding-left: 14px;
  border-left: 1px dashed rgba(255, 255, 255, 0.28);
  color: #fdf6e3;
  opacity: 0.95;
  white-space: nowrap;
}
/* 複数桁の数字は横並び（縦中横）のまま */
.chalk-date .tcy {
  text-combine-upright: all;
  -webkit-text-combine: horizontal;
}

/* 黒板消し（左下） */
.eraser {
  position: absolute;
  left: 14px;
  bottom: 12px;
  width: 38px;
  height: 15px;
  border-radius: 3px;
  /* 上=木部、下=フェルト */
  background: linear-gradient(180deg, #caa063 0%, #b98a46 46%, #efeae1 46%, #d8d2c6 100%);
  box-shadow: 0 2px 4px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.45);
}
.eraser::after { /* フェルトの筋 */
  content: '';
  position: absolute;
  left: 4px; right: 4px; bottom: 3px;
  height: 2px;
  background: rgba(0,0,0,0.1);
  border-radius: 2px;
}
.blackboard.ringing { animation: bbpulse 1.1s ease-in-out infinite; }
@keyframes bbpulse {
  50% { box-shadow: var(--shadow), inset 0 0 34px rgba(0,0,0,0.4), 0 0 0 4px rgba(229,72,77,0.55); }
}
@media (prefers-reduced-motion: reduce) {
  .blackboard.ringing { animation: none; }
}

/* ===== 音声バナー ===== */
.audio-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fdecec;
  border: 1px solid #f3b6b8;
  color: #a1211f;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 18px;
  font-size: 0.88rem;
}
.audio-banner.hidden { display: none; }
.audio-banner .btn {
  flex: 0 0 auto;
  white-space: nowrap;      /* 「音を有効にする」を1行で */
}

/* ===== フローティング設定パネル ===== */
.settings-fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  width: min(390px, calc(100vw - 24px));
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 14px 44px rgba(20, 30, 50, 0.24);
  overflow: hidden;
}
.fab-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.fab-toggle:hover { filter: brightness(1.05); }
.fab-caret {
  width: 0; height: 0;
  flex: 0 0 auto;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 7px solid #fff;   /* 開いているとき下向き */
  transition: transform 0.2s ease;
}
.settings-fab.collapsed .fab-caret { transform: rotate(180deg); }

.settings-body {
  padding: 16px 16px 18px;
  max-height: min(64vh, 540px);
  overflow-y: auto;
}
.settings-fab.collapsed .settings-body { display: none; }

.settings-body-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.settings-note { font-size: 0.85rem; color: var(--muted); }

/* ===== 追加フォーム ===== */
.add-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  background: #f6f8fc;
  border: 1px solid #e6eaf2;
  border-radius: 14px;
  padding: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.03em;
}
.field-time { flex: 0 0 auto; }
.field-label { flex: 1 1 200px; }

.add-form input {
  height: 46px;
  box-sizing: border-box;
  width: 100%;
  font-size: 1.05rem;
  padding: 0 14px;
  border: 1px solid #d3d9e2;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.add-form input::placeholder { color: #a6afbd; }
.add-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.16);
}
.btn-add {
  flex: 0 0 auto;
  height: 46px;
  padding: 0 24px;
  font-size: 1rem;
}

/* 時・分のプルダウン */
.time-field { display: flex; align-items: center; gap: 6px; }
.time-field .colon { font-size: 1.2rem; font-weight: 800; color: var(--ink); }
.add-form select,
.edit-fields select {
  height: 46px;
  box-sizing: border-box;
  padding: 0 10px;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  border: 1px solid #d3d9e2;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.edit-fields select { height: 42px; font-size: 1rem; }
.add-form select:focus,
.edit-fields select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.16);
}

@media (max-width: 460px) {
  .field-time, .field-label { flex: 1 1 100%; }
  .btn-add { width: 100%; }
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-test {
  background: #fff;
  color: var(--accent);
  border: 1px solid #cdd8f0;
  padding: 8px 14px;
  font-size: 0.85rem;
}
.btn-test:hover { background: #f2f6ff; }
.btn-danger {
  background: #fdecec;
  color: var(--danger);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
}
.btn-danger:hover { background: #fadada; }
.btn-cancel { background: #eef1f6; color: var(--muted); }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }

.row-actions { display: flex; gap: 6px; flex: 0 0 auto; }

/* インライン編集 */
.time-list li.editing {
  flex-wrap: wrap;
  gap: 10px;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(47, 111, 237, 0.15);
  background: #f7faff;
}
.edit-fields { display: flex; gap: 8px; flex: 1 1 220px; flex-wrap: wrap; }
.edit-fields input {
  height: 42px;
  box-sizing: border-box;
  font-size: 1rem;
  padding: 0 12px;
  border: 1px solid #d3d9e2;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}
.edit-fields input[type="time"] { flex: 0 0 auto; }
.edit-fields input[type="text"] { flex: 1 1 140px; min-width: 0; }
.edit-fields input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.16);
}
.btn-stop {
  background: var(--danger);
  color: #fff;
  font-size: 1rem;
  padding: 12px 22px;
  box-shadow: 0 4px 14px rgba(229, 72, 77, 0.35);
}
.btn-stop:hover { filter: brightness(1.05); }

.control-row { margin-top: 14px; }
.control-row.hidden { display: none; }

.time-list { list-style: none; margin: 18px 0 0; padding: 0; }
.time-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid #e6eaf0;
  border-radius: 12px;
  margin-bottom: 8px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.time-list li.done { opacity: 0.5; }
.time-list li.next {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(47, 111, 237, 0.15);
  background: #f7faff;
}
.time-list .info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 6px;
  margin: -4px -6px;
  transition: background 0.12s ease;
}
.time-list li:not(.editing):hover .info { background: rgba(47, 111, 237, 0.07); }
.time-list .t {
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.time-list .label {
  display: inline-block;
  padding: 3px 12px;
  background: #eef3ff;
  color: #2f5bd0;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}
.time-list .meta { font-size: 0.78rem; color: var(--muted); }
.time-list .empty { color: var(--muted); font-size: 0.9rem; padding: 8px 2px; border: none; background: none; }

.list-tools { display: flex; justify-content: flex-end; margin-top: 10px; }
.list-tools.hidden { display: none; }
.btn-clear {
  background: transparent;
  color: var(--danger);
  border: 1px solid #f3b6b8;
  padding: 8px 14px;
  font-size: 0.85rem;
}
.btn-clear:hover { background: #fdecec; }

.hint { color: var(--muted); font-size: 0.8rem; margin: 12px 2px 0; line-height: 1.5; }

.app-footer { text-align: center; margin-top: 20px; color: var(--muted); font-size: 0.82rem; }
#status.ringing { color: var(--danger); font-weight: 700; }

@media (max-width: 380px) {
  .clock { width: 240px; height: 240px; }
  .hand-hour { height: 56px; }
  .hand-minute { height: 80px; }
  .hand-second { height: 94px; }
}
