* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: system-ui, -apple-system, sans-serif; color: #1a1a2e; }

a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

/* Mỗi trang = 1 màn hình, không cuộn cả trang */
.page-full {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}

.landing { background: linear-gradient(135deg, #667eea, #764ba2); }
.landing h1 { color: #fff; font-size: 2.5rem; margin: 1rem 0 0.5rem; }
.landing p { color: rgba(255,255,255,.8); margin-bottom: 2rem; line-height: 1.6; }
.landing-hero {
  width: min(520px, 92vw);
  max-height: 42vh;
  object-fit: cover;
  border-radius: 20px;
  box-shadow: 0 14px 36px rgba(0,0,0,.25);
  border: 4px solid rgba(255,255,255,.16);
}
.home-actions { margin-top: 0.5rem; }
.home-actions .btn { min-width: 220px; }

.form-page { background: linear-gradient(135deg, #2193b0, #6dd5ed); }
.form-wrap { width: 100%; max-width: 420px; }

/* Trang đăng bài — full chiều ngang, cuộn dọc khi nội dung dài */
.write-page {
  min-height: 100vh;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  text-align: left;
  padding: 0.85rem 0.75rem 2rem;
}
.write-page .write-wrap {
  width: 100%;
  max-width: none;
  margin: 0;
  flex: 1 1 auto;
}
.write-page .back {
  align-self: flex-start;
  margin-bottom: 0.75rem;
  padding-left: 0.15rem;
}
.write-page .write-card {
  width: 100%;
  max-width: none;
  margin: 0 0 1rem;
  padding: 1.15rem 1rem 1.35rem;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
}
.write-card { text-align: left; }
.write-page .write-card h2,
.write-page .write-card .sub {
  text-align: left;
}
.write-page .write-card .sub {
  margin-bottom: 1rem;
  line-height: 1.5;
}
.write-page .editor {
  min-height: min(52vh, 560px);
  width: 100%;
}
.write-page .toolbar {
  width: 100%;
}
@media (min-width: 640px) {
  .write-page {
    padding: 1rem 1.25rem 2.5rem;
  }
  .write-page .write-card {
    padding: 1.35rem 1.5rem 1.75rem;
  }
}
@media (min-width: 1024px) {
  .write-page {
    padding: 1.25rem 1.5rem 2.5rem;
  }
  .write-page .write-card {
    padding: 1.5rem 2rem 2rem;
  }
  .write-page .editor {
    min-height: min(58vh, 640px);
  }
}
.editor:empty::before {
  content: attr(data-placeholder);
  color: #9ca3af;
}

.board-toast {
  flex-shrink: 0; background: #d1fae5; color: #065f46;
  text-align: center; padding: 0.6rem; font-weight: 600;
  opacity: 0; transition: opacity .3s;
}
.teacher-link { color: rgba(255,255,255,.85); font-size: 0.95rem; text-decoration: underline; }
.teacher-link:hover { color: #fff; }
.setup-note { font-size: 0.85rem; color: #6b7280; margin-bottom: 1rem; line-height: 1.5; background: #f0f9ff; padding: 0.75rem; border-radius: 10px; }

.fab {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  width: 56px; height: 56px; border-radius: 50%;
  background: #4f46e5; color: #fff; border: none; font-size: 1.5rem;
  cursor: pointer; box-shadow: 0 4px 20px rgba(79,70,229,.4); z-index: 20;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none;
}

.btn-row { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; }

.btn {
  padding: 0.75rem 1.5rem; border-radius: 12px; border: none;
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: all .2s;
}
.btn-primary { background: #fff; color: #4f46e5; }
.btn-primary:hover { background: #eef2ff; }
.btn-secondary { background: #f3f4f6; color: #374151; }
.btn-ghost { background: rgba(255,255,255,.2); color: #fff; }
.btn-ghost:hover { background: rgba(255,255,255,.3); }
.btn-danger { background: #ef4444; color: #fff; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; }

.card {
  background: #fff; border-radius: 24px; padding: 2rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
}
.card h2 { text-align: center; margin-bottom: 0.5rem; }
.card .sub { text-align: center; color: #6b7280; font-size: 0.9rem; margin-bottom: 1.5rem; }

.field { margin-bottom: 1rem; text-align: left; }
.field label, .field-label { display: block; font-size: 0.85rem; font-weight: 600; color: #374151; margin-bottom: 0.4rem; }
.field input { width: 100%; padding: 0.75rem 1rem; border: 1px solid #e5e7eb; border-radius: 12px; font-size: 1rem; }
.field input:focus { outline: none; border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.code-input { text-transform: uppercase; text-align: center; font-family: monospace; font-size: 1.2rem; letter-spacing: 4px; }

.error { background: #fef2f2; border: 1px solid #fecaca; color: #dc2626; padding: 0.75rem; border-radius: 12px; font-size: 0.9rem; margin-bottom: 1rem; }
.success { background: #d1fae5; border: 1px solid #a7f3d0; color: #065f46; padding: 0.75rem; border-radius: 12px; font-size: 0.9rem; margin-bottom: 1rem; }
.back { color: rgba(255,255,255,.9); text-decoration: none; font-size: 0.9rem; margin-bottom: 1rem; display: inline-block; }

/* Trang danh sách phòng — giáo viên */
.teacher-dash-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #2193b0, #6dd5ed);
  padding: 1.25rem 1rem 2rem;
}
.teacher-dash-wrap { max-width: 640px; margin: 0 auto; }
.teacher-dash-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  margin-bottom: 1.25rem; color: #fff;
}
.teacher-dash-header h1 { font-size: 1.5rem; margin-bottom: 0.35rem; }
.teacher-dash-header .sub { color: rgba(255,255,255,.85); font-size: 0.9rem; }
.teacher-class-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.25rem; }
.teacher-loading, .teacher-empty {
  text-align: center; color: rgba(255,255,255,.9); padding: 2rem 1rem;
  background: rgba(255,255,255,.12); border-radius: 16px; line-height: 1.6;
}
.teacher-class-card {
  position: relative; width: 100%; text-align: left; background: #fff; border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); transition: transform .15s, box-shadow .15s;
}
.teacher-class-card:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0,0,0,.16); }
.teacher-class-body { padding: 1rem 1.15rem; cursor: pointer; }
.teacher-class-delete {
  position: absolute; top: 0.65rem; right: 0.65rem; z-index: 2;
  padding: 0.3rem 0.55rem; border: 1px solid #fecaca; border-radius: 8px;
  background: #fef2f2; color: #dc2626; font-size: 0.8rem; font-weight: 600; cursor: pointer;
}
.teacher-class-delete:hover { background: #fee2e2; }
.teacher-class-top { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.4rem; padding-right: 4.5rem; }
.teacher-class-card h3 { font-size: 1.05rem; color: #1f2937; }
.teacher-class-code {
  font-family: monospace; font-weight: 700; letter-spacing: 2px; font-size: 0.85rem;
  background: #eef2ff; color: #4f46e5; padding: 0.2rem 0.55rem; border-radius: 8px; flex-shrink: 0;
}
.teacher-class-meta { font-size: 0.85rem; color: #6b7280; }
.teacher-class-enter { display: inline-block; margin-top: 0.5rem; font-size: 0.85rem; font-weight: 600; color: #4f46e5; }
.teacher-create-btn { width: 100%; display: flex; align-items: center; justify-content: center; text-decoration: none; }
.teacher-dash-page .error { background: #fef2f2; }
.confirm-modal { max-width: 420px; text-align: center; }
.confirm-modal h3 { margin-bottom: 0.75rem; color: #1f2937; }
.confirm-text { color: #374151; line-height: 1.5; margin-bottom: 0.5rem; }
.confirm-warn { color: #dc2626; font-size: 0.9rem; margin-bottom: 1.25rem; line-height: 1.5; }
.confirm-actions { display: flex; gap: 0.5rem; }
.confirm-actions .btn { flex: 1; }

/* Board = header cố định + vùng bài cuộn riêng */
.board-layout {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #667eea, #764ba2);
}

.board-header {
  flex-shrink: 0;
  background: rgba(0,0,0,.2);
  backdrop-filter: blur(8px);
  padding: 0.75rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem;
}
.board-header h1 { color: #fff; font-size: 1.2rem; }
.board-title-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; justify-content: flex-start; }
.board-code-badge {
  font-family: monospace; font-size: 0.95rem; font-weight: 700; letter-spacing: 3px;
  background: rgba(255,255,255,.2); color: #fff; padding: 0.2rem 0.65rem;
  border-radius: 8px; border: 1px solid rgba(255,255,255,.35); cursor: pointer;
}
.board-code-badge:hover { background: rgba(255,255,255,.3); }
.board-header .meta { color: rgba(255,255,255,.7); font-size: 0.85rem; }
.board-teacher { margin-top: 0.35rem; color: rgba(255,255,255,.9); font-size: 0.9rem; }
.board-header .actions { display: flex; gap: 0.5rem; }

/* Banner mã lớp - giáo viên */
.code-banner {
  flex-shrink: 0;
  background: rgba(255,255,255,.95);
  padding: 1rem 1.5rem 1.35rem;
  border-bottom: 3px solid #fbbf24;
}
.code-banner-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: stretch; gap: 0;
}
.code-banner-top {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 1rem; width: 100%;
}
.code-banner-left { flex: 1 1 240px; min-width: 0; }
.join-qr-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin-top: 1.1rem;
  padding: 1.25rem 1rem 1rem;
  background: #fff;
  border: 2px solid #c7d2fe;
  border-radius: 16px;
  box-shadow: 0 4px 18px rgba(79,70,229,.1);
}
.join-qr-label {
  font-size: 1.05rem;
  font-weight: 800;
  color: #312e81;
  margin-bottom: 0.75rem;
}
.join-qr-box {
  line-height: 0;
  border-radius: 12px;
  overflow: hidden;
  padding: 0.5rem;
  background: #fff;
  border: 1px solid #e5e7eb;
}
.join-qr-box img,
.join-qr-box canvas {
  display: block;
  width: min(420px, 86vw) !important;
  height: min(420px, 86vw) !important;
  max-width: 100%;
}
.join-qr-hint {
  font-size: 0.9rem;
  color: #4b5563;
  margin-top: 0.75rem;
  max-width: 36rem;
  line-height: 1.45;
}
@media (min-width: 900px) {
  .join-qr-box img,
  .join-qr-box canvas {
    width: 460px !important;
    height: 460px !important;
  }
}
.code-label { font-weight: 700; color: #1f2937; margin-bottom: 0.5rem; }
.code-display {
  font-size: 2rem; font-weight: 800; font-family: monospace;
  letter-spacing: 8px; color: #4f46e5;
  border: 2px dashed #c7d2fe; border-radius: 12px;
  padding: 0.5rem 1.5rem; width: 280px; text-align: center;
  background: #eef2ff; cursor: pointer;
}
.code-hint { font-size: 0.8rem; color: #6b7280; margin-top: 0.4rem; }
.code-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.copy-toast {
  text-align: center; color: #059669; font-weight: 600; font-size: 0.9rem;
  margin-top: 0.5rem; opacity: 0; transition: opacity .3s;
}
.copy-toast.show { opacity: 1; }

.board-main {
  flex: 1;
  overflow-y: auto;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

.masonry { columns: 1; column-gap: 1rem; }
@media (min-width: 640px) { .masonry { columns: 2; } }
@media (min-width: 1024px) { .masonry { columns: 3; } }

.post-card {
  break-inside: avoid; margin-bottom: 1rem; border-radius: 16px; padding: 1.25rem;
  cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.1); transition: transform .2s;
  position: relative;
}
.post-card.post-pinned { box-shadow: 0 4px 16px rgba(79,70,229,.25); outline: 2px solid rgba(79,70,229,.35); }
.pin-badge {
  position: absolute; top: 0.75rem; right: 0.75rem;
  background: rgba(79,70,229,.15); color: #4338ca;
  font-size: 0.75rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px;
}
.post-card:hover { transform: translateY(-4px); }
.post-card .author { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.post-card .avatar {
  width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,.5);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.post-card h3 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.post-card .preview-html {
  font-size: 0.9rem;
  line-height: 1.5;
  color: #1f2937;
}
.post-card .preview-html p { margin: 0 0 0.4em; }
.post-card .preview-html p:last-child { margin-bottom: 0; }
.post-card .preview-html .img-center-line { text-align: center; margin: 0.35em 0; }
.post-card .preview-html img,
.post-card .preview-html .preview-card-img {
  display: block;
  max-width: 100%;
  max-height: 120px;
  width: auto !important;
  height: auto !important;
  margin: 0.35em auto;
  border-radius: 8px;
  object-fit: contain;
  image-rendering: auto;
}
.post-card .preview-html .img-center-line img {
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.post-card .preview-text { font-size: 0.9rem; line-height: 1.5; color: #1f2937; }
.post-card .stats { margin-top: 0.75rem; padding-top: 0.5rem; border-top: 1px solid rgba(0,0,0,.1); font-size: 0.85rem; display: flex; gap: 0.75rem; }

.empty {
  height: 100%; display: none; flex-direction: column;
  align-items: center; justify-content: center; color: #fff; text-align: center;
}
.empty .icon { font-size: 4rem; margin-bottom: 1rem; }

.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50; align-items: center; justify-content: center; padding: 1rem; }
.overlay.open { display: flex; }
.modal { background: #fff; width: 100%; max-width: 700px; max-height: 90vh; overflow-y: auto; border-radius: 20px; padding: 1.5rem; }
.modal-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 1rem; }
.modal-close { background: #f3f4f6; border: none; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; }
.modal-content { line-height: 1.6; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.modal-actions .btn { flex: 1; }
.view-time { color: #9ca3af; font-size: 0.85rem; margin-left: 0.5rem; }

.like-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border-radius: 999px; border: 2px solid #e5e7eb;
  background: #f9fafb; cursor: pointer;
}
.like-btn.active { border-color: #f87171; background: #fef2f2; }

.comments { margin-top: 1.5rem; }
.comments h3 { margin-bottom: 0.75rem; }
.comment { display: flex; gap: 0.75rem; margin-bottom: 0.75rem; }
.comment .c-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #eef2ff; color: #4f46e5;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.comment .c-body { background: #f9fafb; border-radius: 12px; padding: 0.6rem 1rem; }
.comment-form { display: flex; gap: 0.5rem; margin-top: 1rem; }
.comment-form input { flex: 1; padding: 0.6rem 1rem; border: 1px solid #e5e7eb; border-radius: 12px; }
.no-comments { color: #9ca3af; text-align: center; padding: 1rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.toolbar button { padding: 0.35rem 0.6rem; border: 1px solid #e5e7eb; border-radius: 8px; background: #f9fafb; cursor: pointer; }
.toolbar button sup { font-size: 0.65em; }
.editor { min-height: 150px; max-height: none; border: 1px solid #e5e7eb; border-radius: 12px; padding: 1rem; overflow: visible; }
.editor p { margin: 0 0 0.65em; min-height: 1.35em; }
.editor p:last-child { margin-bottom: 0; }
.editor img { max-width: 100%; height: auto; cursor: pointer; image-rendering: auto; }

.fraction {
  display: inline-block;
  line-height: 1.1;
  text-align: center;
  vertical-align: middle;
  margin: 0 0.15em;
}
.fraction .top {
  border-bottom: 1px solid currentColor;
  display: block;
  padding: 0 0.2em 0.08em;
}
.fraction .bottom {
  display: block;
  padding: 0.08em 0.2em 0;
}

.img-center-line {
  text-align: center;
  margin: 0.5rem 0;
  width: 100%;
}
.editor .img-center-line .img-resize-box,
.editor .img-center-line img {
  display: inline-block;
  vertical-align: bottom;
}

/* Resize ảnh trong editor */
.img-resize-box {
  display: inline-block;
  position: relative;
  line-height: 0;
  max-width: 100%;
  vertical-align: bottom;
  margin: 0.5rem 0;
}
.img-resize-box.selected {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
  border-radius: 4px;
}
.img-handle {
  display: none;
  position: absolute;
  width: 12px;
  height: 12px;
  background: #4f46e5;
  border: 2px solid #fff;
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  z-index: 5;
}
.img-resize-box.selected .img-handle { display: block; }
.img-delete-btn {
  display: none;
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 0.2rem 0.55rem;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  white-space: nowrap;
}
.img-delete-btn:hover { background: #dc2626; }
.img-resize-box.selected .img-delete-btn { display: block; }
.img-handle-nw { top: -6px; left: -6px; cursor: nwse-resize; }
.img-handle-ne { top: -6px; right: -6px; cursor: nesw-resize; }
.img-handle-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.img-handle-se { bottom: -6px; right: -6px; cursor: nwse-resize; }

.modal-content img,
.view-content img,
#view-content img,
#view-content .view-full-img {
  max-width: 100%;
  width: auto !important;
  height: auto !important;
  border-radius: 8px;
  image-rendering: auto;
}
.modal-content .img-center-line,
.view-content .img-center-line,
#view-content .img-center-line {
  text-align: center;
  margin: 0.5rem 0;
}
.modal-content .img-center-line img,
#view-content .img-center-line img {
  display: inline-block;
}
.modal-content .fraction,
.view-content .fraction,
#view-content .fraction,
.editor .fraction {
  display: inline-block;
  line-height: 1.1;
  text-align: center;
  vertical-align: middle;
  margin: 0 0.15em;
}
.badge { background: rgba(250,204,21,.3); color: #92400e; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; margin-left: 0.5rem; }
