:root {
  color-scheme: light;
  --bg: #f7fbf8;
  --surface: #ffffff;
  --surface-strong: #eff7f2;
  --line: #d9e6dd;
  --text: #17211b;
  --muted: #66746b;
  --accent: #0f8f72;
  --accent-strong: #08745d;
  --accent-soft: #dff5ed;
  --warn: #b4542d;
  --danger: #b3261e;
  --shadow: 0 12px 30px rgba(19, 52, 39, 0.08);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101815;
  --surface: #18231f;
  --surface-strong: #1e2f29;
  --line: #2f433b;
  --text: #eef7f2;
  --muted: #9cafaa;
  --accent: #17a783;
  --accent-strong: #6ee2c4;
  --accent-soft: #143b32;
  --warn: #d49367;
  --danger: #e16d66;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(223, 245, 237, 0.72), rgba(247, 251, 248, 0) 280px),
    var(--bg);
}

:root[data-theme="dark"] body {
  background:
    linear-gradient(180deg, rgba(20, 59, 50, 0.75), rgba(16, 24, 21, 0) 280px),
    var(--bg);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.shell {
  width: min(100%, 760px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.login-view {
  display: grid;
  align-content: center;
  min-height: calc(100svh - 42px);
  gap: 24px;
}

.brand-block {
  display: grid;
  gap: 8px;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 11vw, 4.2rem);
  line-height: 0.96;
  letter-spacing: 0;
}

h2 {
  font-size: 1.05rem;
  line-height: 1.2;
}

.login-copy {
  color: var(--muted);
  font-size: 1rem;
}

.login-form,
.text-form {
  display: grid;
  gap: 12px;
}

.login-form {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

input {
  min-height: 48px;
  padding: 0 13px;
}

textarea {
  min-height: 132px;
  padding: 12px 13px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 143, 114, 0.14);
}

.primary-button,
.ghost-button,
.item-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.ghost-button,
.item-action {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.ghost-button:active,
.item-action:active,
.primary-button:active {
  transform: translateY(1px);
}

.form-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 0.9rem;
}

.app-view {
  display: grid;
  gap: 5px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
  overflow: hidden;
  max-height: 120px;
}

.topbar.topbar-ready {
  transition: max-height 180ms ease, opacity 160ms ease, margin-bottom 180ms ease;
}

.topbar.topbar-collapsed {
  max-height: 0;
  margin-bottom: -14px;
  opacity: 0;
  pointer-events: none;
}

.topbar h1 {
  font-size: clamp(1.82rem, 9vw, 3.4rem);
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.student-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

:root[data-theme="dark"] .student-badge {
  background: rgba(24, 35, 31, 0.82);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

:root[data-theme="dark"] .tabs {
  background: rgba(24, 35, 31, 0.78);
}

.tabs button {
  min-width: 0;
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.12;
}

.tabs button.active {
  background: var(--accent);
  color: #fff;
}

.panel {
  display: grid;
  gap: 10px;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 148px;
  padding: 18px;
  border: 1.5px dashed #82b7a8;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, var(--surface-strong));
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: center;
}

:root[data-theme="dark"] .drop-zone {
  background: linear-gradient(180deg, #16221e, var(--surface-strong));
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-title {
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 900;
}

.drop-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

#fileInput {
  display: none;
}

.upload-status {
  min-height: 22px;
  color: var(--muted);
  font-size: 0.9rem;
}

.text-panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.list-section {
  display: grid;
  gap: 12px;
  padding-top: 2px;
  min-height: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}

.heading-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.theme-toggle {
  min-width: 64px;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.items-list {
  display: grid;
  gap: 16px;
  height: auto;
  min-height: 150px;
  overflow: visible;
  overscroll-behavior: contain;
  padding: 0 0 10px;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}

.date-group {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.date-title {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 900;
}

.date-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 12px;
  min-width: 0;
}

.swipe-row {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  min-width: 0;
  touch-action: pan-y pinch-zoom;
}

.delete-action {
  position: absolute;
  inset: 0 0 0 auto;
  display: grid;
  place-items: center;
  width: 86px;
  border: 0;
  border-radius: 0 8px 8px 0;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
  font-weight: 900;
}

.delete-action:disabled {
  cursor: wait;
  opacity: 0.72;
}

.item-card {
  position: relative;
  display: grid;
  grid-template-rows: auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(20, 43, 34, 0.05);
  transition: transform 160ms ease;
  will-change: transform;
  z-index: 1;
}

.swipe-row,
.item-card {
  height: 220px;
}

.item-card {
  overflow: hidden;
}

.swipe-row.revealed .item-card {
  transform: translateX(-86px);
}

.item-main {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-width: 0;
  overflow: hidden;
}

.media-card .item-main {
  grid-template-columns: 1fr;
  align-content: start;
}

.file-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 900;
}

.media-card .file-mark {
  display: none;
}

.media-thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: calc(100% + 20px);
  height: auto;
  aspect-ratio: 16 / 9;
  margin: -10px -10px 0;
  min-height: 0;
  overflow: hidden;
  border: 0;
  border-radius: 8px 8px 0 0;
  background: #0c1410;
  cursor: pointer;
  padding: 0;
}

.media-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(135deg, rgba(15, 143, 114, 0.16), rgba(255, 255, 255, 0.04)),
    #0c1410;
  color: #c9eee3;
  font-size: 0.9rem;
  font-weight: 900;
}

.thumb-play {
  position: absolute;
  inset: auto auto 8px 8px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

.thumb-play::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 53%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 10px solid var(--accent-strong);
}

.content-thumb {
  align-content: start;
  justify-items: stretch;
  gap: 6px;
  padding: 10px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  text-align: left;
}

.content-kind {
  display: inline-grid;
  place-items: center;
  justify-self: start;
  min-width: 36px;
  height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 900;
}

.content-preview {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.item-name {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
  font-size: 0.86rem;
  font-weight: 900;
  line-height: 1.2;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 8px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.item-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  align-self: end;
}

.item-actions.one {
  grid-template-columns: 1fr;
}

.item-action {
  min-width: 0;
  min-height: 28px;
  padding: 0 8px;
  font-size: 0.84rem;
}

.text-content {
  max-height: 180px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.link-content {
  color: var(--accent-strong);
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  font-weight: 800;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 150px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  width: min(calc(100% - 28px), 520px);
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 8px;
  background: #17211b;
  color: #fff;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
  font-weight: 800;
  text-align: center;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(9, 17, 13, 0.72);
  cursor: pointer;
}

.preview-dialog {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(100%, 920px);
  max-height: calc(100svh - 28px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.preview-header h2 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-body {
  display: grid;
  place-items: center;
  min-height: 180px;
  background: #07110c;
}

.preview-body video,
.preview-body img {
  display: block;
  width: 100%;
  max-height: calc(100svh - 112px);
  object-fit: contain;
}

[hidden] {
  display: none !important;
}

@media (min-width: 700px) {
  .shell {
    padding-top: 34px;
  }

  .login-view {
    grid-template-columns: minmax(0, 0.95fr) minmax(320px, 0.7fr);
    align-items: center;
  }

  .date-grid {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 12px;
  }

  .swipe-row,
  .item-card {
    height: 318px;
  }

  .item-card {
    grid-template-rows: auto minmax(84px, 1fr) 42px;
  }

  .media-thumb {
    height: auto;
    width: calc(100% + 26px);
    margin: -13px -13px 0;
  }

  .item-card {
    gap: 10px;
    padding: 13px;
  }

  .item-name {
    font-size: 0.98rem;
  }

  .item-meta {
    font-size: 0.8rem;
  }

  .item-action {
    min-height: 40px;
    padding: 0 10px;
    font-size: 0.9rem;
  }
}
