:root {
  --paper: #f2eee6;
  --surface: #fffcf6;
  --ink: #1c1712;
  --muted: #746b60;
  --faint: #9a9186;
  --line: #e5dcd0;
  --line-strong: #d3c7b8;
  --accent: #b4451a;
  --danger: #b42318;
  --ok: #3f6b4a;
  --slot: 34px;
  --time-w: 52px;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 23, 18, 0.04), 0 10px 28px rgba(28, 23, 18, 0.07);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #efe6d8 0%, transparent 55%),
    var(--paper);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 20px 28px;
  align-items: end;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-family: Fraunces, "Source Serif 4", serif;
  font-size: 36px;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stats {
  display: flex;
  gap: 22px;
  color: var(--muted);
  font-size: 13px;
}

.stat b {
  display: block;
  font-family: Fraunces, serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.03em;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.seg {
  display: flex;
  padding: 3px;
  background: #e8e0d4;
  border-radius: 999px;
}

.seg-btn {
  border: 0;
  background: transparent;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
}

.seg-btn.is-on {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(28, 23, 18, 0.08);
}

.btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.btn:hover { border-color: #b9aa96; }
.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #f7f1e8;
}
.btn.primary:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #e8c4bf; }
.btn.danger:hover { background: #fbeceb; }

.icon-btn, .text-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--ink);
}
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}
.icon-btn:hover { background: #e8e0d4; }
.text-btn {
  font-size: 13px;
  color: var(--accent);
  padding: 0 6px;
}

.week-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.layout-seg { display: none; }

.week-picker { position: relative; }

.week-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 168px;
  margin: 0;
  padding: 6px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.week-label:hover,
.week-label[aria-expanded="true"] { background: #e8e0d4; }
.week-label-top {
  display: flex;
  align-items: center;
  gap: 6px;
}
.week-label strong { font-size: 15px; }
.week-label .caret {
  font-size: 11px;
  color: var(--muted);
  line-height: 1;
  transform: translateY(1px);
}
.week-label[aria-expanded="true"] .caret { transform: rotate(180deg) translateY(-1px); }
#week-range { font-size: 12px; color: var(--muted); }

.week-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 12;
  width: min(360px, 72vw);
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.week-menu-cap {
  margin: 0 2px 10px;
  font-size: 12px;
  color: var(--muted);
}
.week-menu-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.week-chip {
  border: 1px solid transparent;
  background: #f3ece2;
  border-radius: 10px;
  padding: 8px 2px 7px;
  cursor: pointer;
  text-align: center;
}
.week-chip:hover { border-color: #cbbba6; }
.week-chip b {
  display: block;
  font-family: Fraunces, serif;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.week-chip small {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  color: var(--muted);
}
.week-chip.is-on {
  background: var(--ink);
  color: #f7f1e8;
}
.week-chip.is-on small { color: #d4c8b8; }
.week-chip.is-now:not(.is-on) {
  box-shadow: inset 0 0 0 1px var(--accent);
  color: var(--accent);
}

.view.is-hidden { display: none; }
.empty-hint { color: var(--muted); font-size: 14px; }

.board {
  display: grid;
  grid-template-columns: var(--time-w) repeat(5, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.day-head, .corner {
  padding: 12px 10px 10px;
  border-bottom: 1px solid var(--line);
  background: #faf6ef;
  font-size: 12px;
  color: var(--muted);
}
.day-head.is-today {
  color: var(--accent);
  font-weight: 600;
}
.day-head b {
  display: block;
  font-family: Fraunces, serif;
  font-size: 18px;
  color: var(--ink);
  font-weight: 600;
}
.day-head.is-today b { color: var(--accent); }

.time-col, .day-col {
  position: relative;
  height: calc(var(--slot) * 24);
  border-left: 1px solid var(--line);
}
.time-col { border-left: 0; }

.hour-line, .half-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--line);
  pointer-events: none;
}
.half-line { border-top-style: dotted; opacity: 0.7; }

.time-label {
  position: absolute;
  right: 8px;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--faint);
}

.block {
  position: absolute;
  z-index: 1;
  border: 0;
  border-radius: 10px;
  padding: 7px 9px 8px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  box-shadow: inset 3px 0 0 var(--c);
  background: color-mix(in srgb, var(--c) 16%, white);
  color: var(--ink);
}
.block:hover { filter: brightness(0.97); outline: 1px solid color-mix(in srgb, var(--c) 45%, white); }
.block .name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.block .when {
  margin-top: 4px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.block .where {
  margin-top: 1px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.block.is-compact .name {
  -webkit-line-clamp: 1;
  white-space: nowrap;
  display: block;
  text-overflow: ellipsis;
}
.block.is-compact .where { display: none; }
.block.is-tiny .when,
.block.is-tiny .where { display: none; }

.now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  z-index: 3;
  pointer-events: none;
}
.now-line::before {
  content: "";
  position: absolute;
  left: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.card-head .code {
  font-size: 12px;
  font-weight: 600;
  color: var(--c, var(--accent));
}
.card-head h3 {
  margin: 4px 0 0;
  font-family: Fraunces, serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #efe8dc;
  color: var(--muted);
}
.session {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 4px;
}
.session:first-of-type { border-top: 0; }
.session .when { font-size: 13px; font-weight: 500; }
.session .where { font-size: 12px; color: var(--muted); }
.session-actions { display: flex; gap: 8px; margin-top: 6px; }
.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
}
.link.danger { color: var(--danger); }
.card-foot {
  padding: 10px 16px 14px;
  display: flex;
  gap: 12px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 23, 18, 0.28);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.overlay.is-hidden { display: none; }

.modal {
  width: min(640px, 100%);
  max-height: min(92vh, 860px);
  overflow: auto;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(28, 23, 18, 0.18);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px 8px;
}
.modal-head h2 {
  margin: 0;
  font-family: Fraunces, serif;
  font-size: 22px;
  font-weight: 600;
}

.form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
  padding: 8px 18px 18px;
}
.field { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.span-2 { grid-column: 1 / -1; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--ink);
}
.days {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
}
.days legend { font-size: 12px; color: var(--muted); padding: 0; margin-bottom: 2px; width: 100%; }
.days label { color: var(--ink); font-size: 13px; display: flex; gap: 6px; align-items: center; }
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.grow { flex: 1; }
.is-hidden { display: none !important; }

.conflict {
  grid-column: 1 / -1;
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fbeceb;
  color: var(--danger);
  font-size: 12px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #f7f1e8;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 30;
}

.agenda { display: none; }

.day-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}
.day-tab {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 8px 4px;
  cursor: pointer;
  text-align: center;
}
.day-tab small {
  display: block;
  font-size: 11px;
  color: var(--muted);
}
.day-tab b {
  display: block;
  font-family: Fraunces, serif;
  font-size: 16px;
  font-weight: 600;
  margin-top: 2px;
}
.day-tab.is-on {
  background: var(--ink);
  border-color: var(--ink);
  color: #f7f1e8;
}
.day-tab.is-on small { color: #d4c8b8; }
.day-tab.is-today:not(.is-on) {
  box-shadow: inset 0 0 0 1px var(--accent);
  color: var(--accent);
}

.agenda-list { display: grid; gap: 10px; }
.agenda-card {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  padding: 14px 14px 14px 12px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow), inset 3px 0 0 var(--c);
}
.agenda-card .time {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}
.agenda-card .time span {
  display: block;
  color: var(--muted);
  font-weight: 400;
}
.agenda-card .name {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}
.agenda-card .place {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}
.agenda-empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
}

.install-tip {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.install-tip p {
  margin: 0;
  flex: 1;
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .topbar { grid-template-columns: 1fr; }
  .page { padding: 18px 12px 88px; }
  h1 { font-size: 30px; }
  .stats { gap: 16px; }
  .layout-seg { display: flex; }
  .page.is-grid .agenda,
  .page.is-day .board { display: none !important; }
  .page.is-grid .board {
    display: grid !important;
    min-width: 720px;
  }
  .page.is-grid #view-week { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .page.is-day .agenda { display: block !important; }
  .page.is-day #view-week { overflow-x: visible; }
  .week-label { min-width: 0; }
  .week-menu { width: min(360px, calc(100vw - 24px)); }
  .form { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .modal { width: 100%; max-height: min(94vh, 860px); border-radius: 16px 16px 0 0; }
  .overlay { align-items: end; justify-items: stretch; padding: 0; }
}

@media (min-width: 861px) {
  .install-tip { display: none !important; }
}
