/* === Reset & Base === */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: #f5f5f4;
  color: #1e1e1e;
  line-height: 1.5;
  min-height: 100vh;
}

/* === App Shell === */

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 0 0.75rem;
  border-bottom: 1px solid #ddd;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
  letter-spacing: -0.01em;
}

#logout-btn {
  font-size: 0.8rem;
  color: #888;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0.25rem 0.5rem;
}

#logout-btn:hover {
  color: #555;
}

/* === Navigation Tabs === */

.nav-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #ddd;
  margin-bottom: 1.5rem;
}

.nav-tab {
  padding: 0.7rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #777;
  cursor: pointer;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.nav-tab:hover {
  color: #444;
}

.nav-tab.active {
  color: #1a1a1a;
  border-bottom-color: #1a1a1a;
}

.nav-tab .lock-icon {
  font-size: 0.7rem;
  margin-left: 0.25rem;
  opacity: 0.5;
}

/* === Panels === */

.panel {
  display: none;
  padding-bottom: 3rem;
}

.panel.active {
  display: block;
}

/* === Buttons === */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

.btn-primary:hover:not(:disabled) {
  background: #333;
}

.btn-secondary {
  background: #fff;
  color: #333;
  border-color: #ccc;
}

.btn-secondary:hover:not(:disabled) {
  background: #f0f0f0;
}

.btn-danger {
  background: #fff;
  color: #c0392b;
  border-color: #e0c4c0;
}

.btn-danger:hover:not(:disabled) {
  background: #fdf0ef;
}

.btn-text {
  background: none;
  border: none;
  color: #666;
  padding: 0.25rem 0.5rem;
}

.btn-text:hover:not(:disabled) {
  color: #222;
}

/* === Empty States === */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #888;
}

.empty-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.empty-hint {
  font-size: 0.8rem;
  color: #aaa;
  margin-top: 0.35rem;
}

/* === Section Titles === */

.section-subtitle {
  font-size: 0.85rem;
  color: #888;
  margin-top: 0.15rem;
  margin-bottom: 1.25rem;
}

/* === Take Start Screen === */

.take-start {
  max-width: 400px;
  padding-top: 2rem;
}

.take-start h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.take-meta {
  font-size: 0.8rem;
  color: #999;
  margin-bottom: 1.5rem;
}

.name-field {
  margin-bottom: 1.25rem;
}

.name-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.3rem;
}

.name-field input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}

.name-field input:focus {
  border-color: #888;
}

.question-count {
  font-size: 0.75rem;
  color: #999;
}

/* === Quiz Page (single-page layout) === */

.quiz-page {
  max-width: 620px;
}

.quiz-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #eee;
}

.quiz-page-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.quiz-page-user {
  font-size: 0.8rem;
  color: #999;
  margin-top: 0.15rem;
}

.take-question-block {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.take-question-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.take-question-num {
  font-size: 0.85rem;
  font-weight: 700;
  color: #555;
}

.take-question-text {
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 1rem;
  line-height: 1.45;
}

/* === Video Embed === */

.video-embed {
  margin-bottom: 0.35rem;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  position: relative;
  padding-top: 56.25%; /* 16:9 */
}

.video-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.video-fallback {
  margin-bottom: 1rem;
}

.video-fallback a {
  font-size: 0.75rem;
  color: #888;
  text-decoration: none;
}

.video-fallback a:hover {
  color: #444;
  text-decoration: underline;
}

.quiz-submit-area {
  padding: 1.25rem 0 2rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.unanswered-notice {
  font-size: 0.8rem;
  color: #999;
}

/* === Section Headers (Take) === */

.take-section-header {
  margin: 1.75rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid #ddd;
}

.take-section-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #444;
}

.take-section-header:first-child {
  margin-top: 0;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.choice-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.choice-btn:hover {
  border-color: #aaa;
  background: #fafafa;
}

.choice-btn.selected {
  border-color: #1a1a1a;
  background: #f5f5f0;
}

.choice-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: #eee;
  font-size: 0.75rem;
  font-weight: 600;
  color: #666;
  flex-shrink: 0;
}

.choice-btn.selected .choice-letter {
  background: #1a1a1a;
  color: #fff;
}

.point-badge {
  font-size: 0.65rem;
  background: #eee;
  color: #777;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  margin-left: 0.4rem;
  font-weight: 600;
  vertical-align: middle;
}

/* === Text Answer === */

.text-answer-area {
  margin-bottom: 2rem;
}

.text-answer-input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  border: 1px solid #ddd;
  border-radius: 8px;
  outline: none;
  resize: vertical;
  min-height: 100px;
  transition: border-color 0.15s;
  line-height: 1.5;
}

.text-answer-input:focus {
  border-color: #888;
}

/* === Quiz Result === */

.quiz-result {
  text-align: center;
  padding: 2rem 0;
}

.quiz-result h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.result-name {
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 1.5rem;
}

.result-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.score-number {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.score-label {
  font-size: 0.85rem;
  color: #999;
}

.result-pending {
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 2rem;
}

.result-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

/* === Review Panel === */

.review-list h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.attempt-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.attempt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
}

.attempt-header:hover {
  background: #fafafa;
}

.attempt-info h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.attempt-date {
  font-size: 0.75rem;
  color: #999;
}

.attempt-score {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 4px;
  white-space: nowrap;
}

.score-good {
  background: #e8f5e9;
  color: #2e7d32;
}

.score-ok {
  background: #fff3e0;
  color: #e65100;
}

.score-low {
  background: #fce4ec;
  color: #c62828;
}

.attempt-details {
  border-top: 1px solid #eee;
  padding: 0.5rem 1.25rem 1rem;
}

.detail-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid #f0f0f0;
}

.detail-score-total {
  font-size: 0.85rem;
  color: #555;
}

.detail-score-total strong {
  font-size: 1rem;
}

.graded-badge {
  font-size: 0.65rem;
  background: #e8f5e9;
  color: #2e7d32;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-weight: 600;
  margin-left: 0.35rem;
}

.detail-section-header {
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
  padding: 0.75rem 0 0.25rem;
  margin-top: 0.25rem;
  border-top: 1px solid #eee;
}

.detail-awarded {
  font-size: 0.75rem;
  color: #999;
  margin-top: 0.2rem;
}

.attempt-total-score {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 4px;
  white-space: nowrap;
}

.score-input-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.score-input-row label {
  font-size: 0.75rem;
  color: #777;
  font-weight: 600;
}

.manual-score-input {
  width: 3.5rem;
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  text-align: center;
  outline: none;
}

.manual-score-input:focus {
  border-color: #888;
}

.score-max {
  font-size: 0.75rem;
  color: #999;
}

.score-save-status {
  font-size: 0.7rem;
  margin-left: 0.25rem;
}

.score-save-status.saving {
  color: #999;
}

.score-save-status.saved {
  color: #2e7d32;
}

.score-save-status.error {
  color: #c62828;
}

.btn-small {
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
}

.detail-row {
  display: flex;
  gap: 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f5f5f5;
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-status {
  font-size: 0.9rem;
  width: 1.25rem;
  flex-shrink: 0;
  text-align: center;
  padding-top: 0.1rem;
}

.detail-row.correct .detail-status {
  color: #2e7d32;
}

.detail-row.incorrect .detail-status {
  color: #c62828;
}

.detail-question {
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.detail-answer {
  font-size: 0.8rem;
  color: #666;
}

.no-answer {
  color: #aaa;
  font-style: italic;
}

.detail-pts {
  font-size: 0.7rem;
  color: #aaa;
  font-weight: 400;
}

.detail-text-response {
  font-size: 0.8rem;
  color: #333;
  background: #f8f8f7;
  border: 1px solid #eee;
  border-radius: 5px;
  padding: 0.5rem 0.65rem;
  margin-top: 0.3rem;
  white-space: pre-wrap;
  line-height: 1.45;
}

.detail-row.text-response .detail-status {
  color: #888;
}

.detail-content .video-embed {
  margin-top: 0.4rem;
  margin-bottom: 0.5rem;
  max-width: 360px;
}

.attempt-score-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.attempt-auto-score {
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
}

.attempt-manual-badge {
  font-size: 0.7rem;
  background: #fff3e0;
  color: #e65100;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  font-weight: 500;
}

/* === Edit Panel === */

.edit-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
}

.edit-header-row h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.edit-quiz-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 0.85rem 1.25rem;
  margin-bottom: 0.5rem;
}

.edit-quiz-info h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.edit-quiz-actions {
  display: flex;
  gap: 0.5rem;
}

/* === Quiz Editor === */

.quiz-editor {
  max-width: 600px;
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.editor-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.editor-field {
  margin-bottom: 1rem;
}

.editor-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.3rem;
}

.optional {
  font-weight: 400;
  color: #aaa;
}

.editor-field input[type="text"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}

.editor-field input[type="text"]:focus {
  border-color: #888;
}

.questions-section {
  margin-top: 1.75rem;
}

.questions-section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.question-block {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}

.section-block {
  background: #f8f8f7;
  border-style: dashed;
}

.question-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.question-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
}

.choices-editor {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.choice-editor-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.radio-label {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.radio-label input[type="radio"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid #ccc;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.radio-label input[type="radio"]:checked {
  border-color: #1a1a1a;
}

.radio-label input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 8px;
  height: 8px;
  background: #1a1a1a;
  border-radius: 50%;
}

.radio-custom {
  display: none;
}

.choice-letter-small {
  font-size: 0.7rem;
  font-weight: 600;
  color: #aaa;
  width: 1rem;
  text-align: center;
  flex-shrink: 0;
}

.choice-editor-row input[type="text"] {
  flex: 1;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  border: 1px solid #ddd;
  border-radius: 5px;
  outline: none;
}

.choice-editor-row input[type="text"]:focus {
  border-color: #888;
}

.correct-hint {
  font-size: 0.7rem;
  color: #bbb;
  margin-top: 0.4rem;
}

.text-q-note {
  font-size: 0.75rem;
  color: #aaa;
  font-style: italic;
}

.question-type-tag {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #aaa;
  background: #f0f0f0;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  margin-left: 0.35rem;
  letter-spacing: 0.03em;
}

.question-block-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.points-label {
  font-size: 0.75rem;
  color: #999;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.points-input {
  width: 3rem;
  padding: 0.2rem 0.3rem;
  font-size: 0.8rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  text-align: center;
  outline: none;
}

.points-input:focus {
  border-color: #888;
}

.add-question-row {
  display: flex;
  gap: 0.5rem;
}

.editor-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid #eee;
}

.save-feedback {
  margin-top: 1rem;
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.save-feedback.success {
  background: #e8f5e9;
  color: #2e7d32;
}

.save-feedback.error {
  background: #fce4ec;
  color: #c62828;
}

/* === Access Overlay === */

.access-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.access-dialog {
  background: #fff;
  border-radius: 10px;
  padding: 2rem;
  width: 340px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.access-dialog h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.access-dialog p {
  font-size: 0.8rem;
  color: #888;
  margin-bottom: 1.25rem;
}

.access-dialog input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  outline: none;
  margin-bottom: 0.5rem;
  transition: border-color 0.15s;
}

.access-dialog input[type="password"]:focus {
  border-color: #888;
}

.access-error {
  font-size: 0.8rem;
  color: #c62828;
  margin-bottom: 0.5rem;
}

.access-dialog .btn {
  width: 100%;
  justify-content: center;
  margin-top: 0.5rem;
}

/* === Utilities === */

.loading-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #999;
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

.shake {
  animation: shake 0.35s ease;
}

/* === Responsive === */

@media (max-width: 540px) {
  .attempt-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .result-actions {
    flex-direction: column;
  }
}
