:root {
  --rug-red: #C10A28;
  --rug-red-dark: #93081e;
  --ink: #1c1c1e;
  --paper: #ffffff;
  --hairline: #e6e3df;
  --muted: #7a7772;
  --warn: #b3550e;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  width: 340px;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app { display: flex; flex-direction: column; }

.header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--rug-red);
  color: #fff;
}
.header .logo { width: 24px; height: 24px; border-radius: 5px; }
.header .title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  flex: 1;
}
.icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  opacity: 0.9;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); opacity: 1; }

.card {
  padding: 14px;
  border-bottom: 1px solid var(--hairline);
}
.card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.day-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-btn {
  background: none;
  border: 1px solid var(--hairline);
  color: var(--ink);
  width: 22px;
  height: 22px;
  line-height: 1;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.nav-btn:hover { border-color: var(--rug-red); color: var(--rug-red); }
.day-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  min-width: 78px;
  text-align: center;
}

.hint {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
}
.hint.error { color: var(--rug-red-dark); }
.hint a { color: var(--rug-red); font-weight: 600; }
.hidden { display: none !important; }

/* MFA */
.mfa-display { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.mfa-code {
  font-family: var(--mono);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.12em;
  background: none;
  border: none;
  color: var(--ink);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  transition: background 0.15s ease, transform 0.08s ease;
}
.mfa-code:hover { background: #f4ede9; }
.mfa-code:active { transform: scale(0.97); }

.durability-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
}
.durability-track {
  flex: 1;
  height: 6px;
  border-radius: 4px;
  background: var(--hairline);
  overflow: hidden;
}
.durability-bar {
  height: 100%;
  width: 100%;
  background: var(--rug-red);
  transition: width 1s linear, background-color 0.3s ease;
}
.durability-bar.urgent { background: var(--warn); }
.durability-text {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  min-width: 26px;
  text-align: right;
}

/* Schedule */
.schedule-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 190px;
  overflow-y: auto;
}
.schedule-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-left: 3px solid var(--rug-red);
  padding: 4px 0 4px 8px;
}
.schedule-time {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  padding-top: 1px;
  min-width: 78px;
}
.schedule-info { display: flex; flex-direction: column; }
.schedule-summary { font-size: 13px; font-weight: 600; line-height: 1.3; }
.schedule-location { font-size: 12px; color: var(--muted); }

/* Brightspace button */
.brightspace-btn {
  display: block;
  margin: 12px 14px 14px;
  padding: 10px 12px;
  text-align: center;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s ease;
}
.brightspace-btn:hover { background: #333; }
.brightspace-btn .sub {
  display: block;
  font-weight: 400;
  font-size: 10.5px;
  color: #cfcfcf;
  margin-top: 2px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* Courses / books / notes */
.books-card { border-bottom: none; }

.courses-list { display: flex; flex-direction: column; gap: 8px; }

.course-item {
  border: 1px solid var(--hairline);
  border-radius: 9px;
  overflow: hidden;
}
.course-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  background: #faf8f6;
  cursor: pointer;
  user-select: none;
}
.course-header .chevron {
  font-size: 10px;
  color: var(--muted);
  transition: transform 0.15s ease;
}
.course-item.open .course-header .chevron { transform: rotate(90deg); }
.course-header .course-title {
  font-size: 13px;
  font-weight: 700;
  flex: 1;
}
.course-header .course-meta {
  font-size: 10.5px;
  color: var(--muted);
}

.course-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.course-item:not(.open) .course-body { display: none; }

.book-link-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.book-link {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--hairline);
  border-radius: 7px;
  text-decoration: none;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  background: #fff;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}
.book-link:hover { border-color: var(--rug-red); color: var(--rug-red); }
.book-link .book-icon { font-size: 13px; }

.notes-section .notes-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.note-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.note-item {
  background: #fdf6ee;
  border: 1px solid #f0e4d3;
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 12.5px;
  line-height: 1.4;
}
.note-text { white-space: pre-wrap; word-break: break-word; }
.note-actions {
  display: flex;
  gap: 10px;
  margin-top: 5px;
}
.note-actions button {
  background: none;
  border: none;
  padding: 0;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
}
.note-actions button:hover { color: var(--rug-red); }
.note-actions .confirm-delete { color: var(--rug-red-dark); }

.note-edit-area {
  width: 100%;
  font-family: inherit;
  font-size: 12.5px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 6px 8px;
  resize: vertical;
  min-height: 44px;
}
.note-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.note-edit-actions button {
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 6px;
  border: 1px solid var(--hairline);
  background: #fff;
  cursor: pointer;
}
.note-edit-actions .save-note-btn { border-color: var(--rug-red); color: var(--rug-red); font-weight: 700; }

.add-note-row { display: flex; flex-direction: column; gap: 6px; }
.add-note-row textarea {
  font-family: inherit;
  font-size: 12.5px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 6px 8px;
  resize: vertical;
  min-height: 40px;
}
.add-note-btn {
  align-self: flex-end;
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 7px;
  border: none;
  background: var(--rug-red);
  color: #fff;
  cursor: pointer;
}
.add-note-btn:hover { background: var(--rug-red-dark); }

/* Mobile standalone layout */
html{min-height:100%;background:#f7f5f2}body{width:100%;min-width:0;max-width:600px;margin:0 auto;min-height:100vh;padding-bottom:env(safe-area-inset-bottom);background:#fff}.header{padding:calc(16px + env(safe-area-inset-top)) 18px 16px;gap:12px}.header .logo{width:36px;height:36px}.header .title{font-size:18px}.icon-btn{font-size:24px;min-width:44px;min-height:44px}.card{padding:20px 18px}.card-title{font-size:13px}.nav-btn{width:38px;height:38px;font-size:22px}.day-label{min-width:68px;text-align:center}.mfa-code{touch-action:manipulation}.book-link,.course-header,button,a{touch-action:manipulation}.foot{font-size:12px;color:#78716c;text-align:center;padding:22px 12px}.foot a{color:#93081e}.schedule-card{min-height:120px}@media(min-width:650px){body{box-shadow:0 4px 25px #0000000d}}

/* Book library v3: tap-to-open, attach PDF or link without leaving the app */
.course-header{width:100%;text-align:left;border:0;font:inherit;color:inherit;min-height:48px}
.book-help{font-size:12px;line-height:1.5;color:var(--muted);margin:10px 0 14px}
.book-list-item{border:1px solid var(--hairline);border-radius:9px;padding:4px 4px 10px;list-style:none}
.book-list-item .book-link{border:0;padding:12px 9px;min-height:54px}
.book-link-title{display:flex;flex-direction:column;gap:4px;overflow-wrap:anywhere;flex:1}
.book-source{font-size:11px;font-weight:400;color:var(--muted)}
.book-unavailable{opacity:.7;cursor:default}
.book-actions{display:flex;flex-wrap:wrap;gap:8px;padding:0 8px}
.book-manage-btn{border:1px solid #ddd1d3;border-radius:7px;background:#fff;font-size:12px;color:#80243a;padding:8px 10px;min-height:38px;cursor:pointer}
.book-manage-btn:disabled{opacity:.5}
.book-primary{background:var(--rug-red);color:white;border-color:var(--rug-red)}
.book-link-editor{display:flex;gap:6px;flex-wrap:wrap;padding:8px 8px 0}
.book-link-editor:empty{display:none}
.book-link-editor input,.book-add-form input{width:100%;min-width:0;font-size:16px;border:1px solid #cfc9c9;border-radius:8px;padding:11px}
.book-add-box{border-top:1px solid #eee;padding:14px 2px 2px;font-size:13px}
.book-add-box summary{color:var(--rug-red);font-weight:700;cursor:pointer;min-height:30px;list-style-position:inside}
.book-add-form{display:grid;gap:8px;padding:12px 0}
.book-add-box>.pdf-upload-inline{display:block;margin:0 0 12px}
.book-add-box>.pdf-upload-inline button{width:100%}
.visually-hidden{position:absolute;overflow:hidden;width:1px;height:1px;clip:rect(0 0 0 0);white-space:nowrap;clip-path:inset(50%)}
