:root {
  --primary: #2f6fed;
  --primary-dark: #1f52c0;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7684;
  --danger: #e0483e;
  --success: #1f9d55;
  --border: #e2e6ee;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}
header.appbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}
header.appbar h1 { font-size: 16px; margin: 0; }
header.appbar .user { font-size: 13px; color: var(--muted); }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}
h2 { font-size: 18px; margin-top: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; margin-top: 12px; }
input[type=text], input[type=password] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
}
.comment-box {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
}
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
}
button.primary { background: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.secondary { background: #eef1f7; color: var(--text); }
button.danger { background: #fdeceb; color: var(--danger); }
button.danger.active { background: var(--danger); color: #fff; }
button.flagged { background: var(--primary); color: #fff; }
button.flagged:hover { background: var(--primary-dark); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.full { width: 100%; }
.row { display: flex; gap: 10px; }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; }
.muted { color: var(--muted); font-size: 13px; }
a.link { color: var(--primary); text-decoration: none; font-size: 14px; }

.upload-box {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}
.upload-box.dragover { border-color: var(--primary); background: #eef4ff; }
.preview-img { max-width: 100%; border-radius: 10px; margin-top: 12px; }

.crop-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  touch-action: none;
  line-height: 0;
}
.crop-stage img {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
  border-radius: 8px;
}
.crop-box {
  position: absolute;
  border: 2px solid var(--primary);
  box-sizing: border-box;
  background: rgba(47, 111, 237, 0.15);
  touch-action: none;
  cursor: move;
}
.crop-handle {
  position: absolute;
  width: 26px;
  height: 26px;
  background: var(--primary);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  touch-action: none;
}
.crop-handle.nw { top: -13px; left: -13px; cursor: nwse-resize; }
.crop-handle.ne { top: -13px; right: -13px; cursor: nesw-resize; }
.crop-handle.sw { bottom: -13px; left: -13px; cursor: nesw-resize; }
.crop-handle.se { bottom: -13px; right: -13px; cursor: nwse-resize; }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid #ffffff66;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.explanation {
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: 15px;
  background: #f8f9fc;
  border-radius: 10px;
  padding: 16px;
  margin-top: 14px;
}

.student-comment {
  white-space: pre-wrap;
  font-size: 14px;
  background: #fff8ec;
  border: 1px solid #f5e3c0;
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 10px;
}
.student-comment hr { border: none; border-top: 1px dashed #e0c98f; margin: 8px 0; }

.q-item { border-bottom: 1px solid var(--border); padding: 14px 0; }
.q-item:last-child { border-bottom: none; }
.q-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.q-row { display: flex; gap: 12px; align-items: flex-start; }
.q-meta { flex: 1; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fdeceb;
  color: var(--danger);
  margin-left: 6px;
}
.badge.resolved { background: #e8f7ee; color: var(--success); }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button { background: transparent; color: var(--muted); border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 4px; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.flag-card { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; background: var(--card); }
.flag-card .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.flag-card .student-name { font-weight: 700; }
.flag-card .date { color: var(--muted); font-size: 12px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 33, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal-box {
  background: var(--card);
  border-radius: 14px;
  padding: 24px;
  max-width: 560px;
  width: 100%;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: #eef1f7;
  color: var(--text);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}
.flag-card img { max-width: 160px; border-radius: 8px; border: 1px solid var(--border); }
