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

:root {
  --bg: #0f1117;
  --card: #1a1d27;
  --card-hover: #242836;
  --primary: #6c63ff;
  --primary-light: #8b83ff;
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --success: #4caf50;
  --danger: #f44336;
  --border: #2a2d3a;
  --radius: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.view {
  display: none;
  padding: 20px;
  padding: 20px env(safe-area-inset-right) 20px env(safe-area-inset-left);
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  animation: fadeIn 0.3s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header */
.header {
  text-align: center;
  padding: 30px 0 20px;
  position: relative;
}

.header h1 {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

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

.subtitle {
  color: var(--text-dim);
  margin-top: 4px;
  font-size: 1rem;
}

/* Back button */
.btn-back {
  position: absolute;
  left: 0;
  top: 35px;
  background: none;
  border: none;
  color: var(--primary-light);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}

.btn-back:active {
  background: rgba(108,99,255,0.15);
}

/* Student Selection */
.card-container {
  margin-top: 40px;
}

.prompt {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 20px;
  font-size: 1.1rem;
}

.student-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.student-btn {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.student-btn:active {
  border-color: var(--primary);
  background: var(--card-hover);
  transform: scale(0.96);
}

@media (hover: hover) {
  .student-btn:hover {
    border-color: var(--primary);
    background: var(--card-hover);
    transform: scale(0.97);
  }
}

.student-btn .emoji {
  font-size: 3.5rem;
  display: block;
  margin-bottom: 14px;
}

.student-btn .name {
  font-size: 1.5rem;
  font-weight: 600;
}

/* Settings button */
.btn-settings {
  display: block;
  margin: 40px auto 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 14px 28px;
  border-radius: 12px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-settings:hover {
  border-color: var(--primary);
  color: var(--text);
}

/* Subject List */
.subject-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.subject-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.subject-card:active:not(.rated) {
  transform: scale(0.98);
  border-color: var(--primary);
}

.subject-card .subject-name {
  font-size: 1.2rem;
  font-weight: 500;
}

.subject-card .subject-status {
  font-size: 1.5rem;
}

.subject-card.rated {
  border-color: var(--success);
  opacity: 0.65;
  cursor: default;
}

.subject-card.rated .subject-name {
  text-decoration: line-through;
  color: var(--text-dim);
}

@media (hover: hover) {
  .subject-card:not(.rated):hover {
    border-color: var(--primary);
    background: var(--card-hover);
  }
}

.btn-history {
  display: block;
  margin: 24px auto 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 0.95rem;
  cursor: pointer;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty-state p {
  font-size: 1.15rem;
  margin-bottom: 20px;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 16px 32px;
  border-radius: 12px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
  background: var(--primary-light);
}

/* Rating Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: var(--card);
  border-radius: 24px;
  padding: 32px 24px;
  width: 100%;
  max-width: 460px;
  text-align: center;
}

.modal-content h3 {
  font-size: 1.4rem;
  margin-bottom: 8px;
}

.modal-content .prompt {
  margin-bottom: 28px;
}

.rating-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.rating-btn {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 20px 10px;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.rating-btn:active {
  transform: scale(0.92);
  border-color: var(--primary);
  background: var(--card-hover);
}

@media (hover: hover) {
  .rating-btn:hover {
    border-color: var(--primary);
    background: var(--card-hover);
  }
}

.rating-btn .rating-emoji {
  font-size: 2.6rem;
}

.rating-btn .rating-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-weight: 500;
}

.btn-cancel {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 12px 24px;
}

/* Success Overlay */
.success-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.success-content {
  text-align: center;
}

.checkmark {
  font-size: 5rem;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

.success-content p {
  margin-top: 16px;
  font-size: 1.4rem;
  font-weight: 600;
}

.success-content .thank-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 20px;
}

.success-content .thank-sub {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-dim);
  margin-top: 10px;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}
}

/* Settings */
.settings-content {
  margin-top: 10px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.form-group select,
.form-group input {
  width: 100%;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1.05rem;
  outline: none;
  -webkit-appearance: none;
}

.form-group select:focus,
.form-group input:focus {
  border-color: var(--primary);
}

.add-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.add-row input {
  flex: 1;
}

.btn-add {
  background: var(--primary);
  color: white;
  border: none;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  font-size: 1.6rem;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.settings-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-item .subject-text {
  font-size: 1.05rem;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 6px 10px;
}

/* History */
.history-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-item .history-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-item .history-subject {
  font-weight: 500;
  font-size: 1.05rem;
}

.history-item .history-date {
  font-size: 0.82rem;
  color: var(--text-dim);
}

.history-item .history-rating {
  font-size: 1.8rem;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Camera permission banner */
.camera-banner {
  background: var(--card);
  border: 1px solid #ff9800;
  border-radius: 12px;
  padding: 14px 18px;
  margin-top: 16px;
  text-align: center;
  font-size: 0.95rem;
  color: #ff9800;
  cursor: pointer;
}

/* ======================== */
/* TABLET (iPad ~768-1024px) */
/* ======================== */
@media (min-width: 600px) {
  .view {
    max-width: 700px;
    padding: 32px;
  }

  .header {
    padding: 40px 0 28px;
  }

  .header h1 {
    font-size: 2.6rem;
  }

  .header h2 {
    font-size: 1.8rem;
  }

  .subtitle {
    font-size: 1.1rem;
  }

  .card-container {
    margin-top: 60px;
  }

  .prompt {
    font-size: 1.2rem;
    margin-bottom: 28px;
  }

  .student-grid {
    gap: 24px;
  }

  .student-btn {
    padding: 60px 24px;
    border-radius: 20px;
  }

  .student-btn .emoji {
    font-size: 4.5rem;
    margin-bottom: 18px;
  }

  .student-btn .name {
    font-size: 1.8rem;
  }

  .subject-list {
    gap: 16px;
  }

  .subject-card {
    padding: 26px 24px;
    border-radius: 18px;
  }

  .subject-card .subject-name {
    font-size: 1.35rem;
  }

  .subject-card .subject-status {
    font-size: 1.7rem;
  }

  .modal-content {
    max-width: 520px;
    padding: 40px 32px;
    border-radius: 28px;
  }

  .modal-content h3 {
    font-size: 1.6rem;
  }

  .rating-grid {
    gap: 16px;
  }

  .rating-btn {
    padding: 26px 12px;
    border-radius: 18px;
    gap: 10px;
  }

  .rating-btn .rating-emoji {
    font-size: 3.2rem;
  }

  .rating-btn .rating-label {
    font-size: 0.9rem;
  }

  .checkmark {
    font-size: 6rem;
  }

  .success-content p {
    font-size: 1.6rem;
  }

  /* Settings tablet */
  .form-group select,
  .form-group input {
    padding: 16px 18px;
    font-size: 1.1rem;
  }

  .btn-add {
    width: 56px;
    height: 56px;
  }

  .settings-item {
    padding: 18px 20px;
  }

  .history-item {
    padding: 18px 22px;
  }

  .history-item .history-subject {
    font-size: 1.15rem;
  }

  .history-item .history-rating {
    font-size: 2rem;
  }
}

/* ====================== */
/* LARGE TABLET / DESKTOP */
/* ====================== */
@media (min-width: 1024px) {
  .view {
    max-width: 800px;
    padding: 40px;
  }

  .student-btn {
    padding: 70px 32px;
  }

  .student-btn .emoji {
    font-size: 5rem;
  }

  .student-btn .name {
    font-size: 2rem;
  }

  .rating-btn .rating-emoji {
    font-size: 3.5rem;
  }
}

/* =================== */
/* SMALL PHONE (<380px) */
/* =================== */
@media (max-width: 380px) {
  .view {
    padding: 14px;
  }

  .student-btn {
    padding: 32px 14px;
  }

  .student-btn .emoji {
    font-size: 2.5rem;
  }

  .student-btn .name {
    font-size: 1.1rem;
  }

  .rating-grid {
    gap: 8px;
  }

  .rating-btn {
    padding: 14px 6px;
  }

  .rating-btn .rating-emoji {
    font-size: 2rem;
  }

  .modal-content {
    padding: 24px 16px;
  }
}
