:root {
  --bg-dark: #0f172a;
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  --primary: #8b5cf6;
  --primary-hover: #7c3aed;
  --secondary: #3b82f6;
  --text-light: #f8fafc;
  --text-muted: #94a3b8;
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --danger: #ef4444;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-light);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Material Icons vertically centered */
.material-icons-round {
  vertical-align: middle;
}

/* Layouts */
#app {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* View Switching */
.view {
  display: none;
  width: 100%;
  min-height: 100vh;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.view.active-view {
  display: flex;
  flex-direction: column;
  opacity: 1;
}

/* Glassmorphism Elements */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.glass-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.glass-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  background: linear-gradient(to right, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  color: transparent;
}

/* Forms & Inputs */
.input-group {
  position: relative;
  margin-bottom: 16px;
}
.input-group .material-icons-round {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}
.input-group input {
  width: 100%;
  padding: 14px 14px 14px 44px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  color: var(--text-light);
  font-size: 1rem;
  transition: border-color 0.3s;
}
.input-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.glass-input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  color: var(--text-light);
  font-size: 1rem;
  margin-bottom: 16px;
  resize: vertical;
}
.glass-input:focus {
  outline: none;
  border-color: var(--primary);
}

textarea.glass-input {
  min-height: 100px;
}

/* Buttons */
.btn {
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, background 0.3s;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: white;
}
.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-block {
  width: 100%;
}
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  border: 1px solid transparent;
  transition: background 0.2s, border-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover {
  background: rgba(255,255,255,0.1);
  border-color: var(--glass-border);
}
.danger-text {
  color: var(--danger) !important;
}

/* Login Screen specific */
.login-card {
  width: 90%;
  max-width: 400px;
  text-align: center;
}
.login-card .logo {
  margin-bottom: 8px;
}
.login-card .subtitle {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 0.9rem;
}

/* Main Content Area */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 80px; /* space for bottom nav */
}

/* Tabs */
.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}
.tab-content.active-tab {
  display: block;
}
.tab-content.active-tab.chat-layout {
  display: flex;
}

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

/* Posts */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.post-card {
  padding: 16px;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.3s;
}
.post-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.3);
}
.post-card h3 {
  margin-bottom: 8px;
  font-size: 1.1rem;
}
.post-meta {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.badge {
  background: rgba(255,255,255,0.1);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--primary);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: flex-end; /* Mobile friendly bottom sheet */
  animation: bgFade 0.3s ease;
}
@keyframes bgFade {
  from { background: rgba(0,0,0,0); }
  to { background: rgba(0,0,0,0.7); }
}
.glass-modal {
  background: var(--bg-dark);
  border-top: 1px solid var(--glass-border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
}

/* Post Detail */
.post-detail-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.detail-title {
  font-size: 1.3rem;
  line-height: 1.4;
}
.detail-meta {
  display: flex;
  justify-content: flex-start;
  gap: 12px;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.detail-image-container img {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 16px;
  margin-top: 8px;
}
.detail-content {
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}
.detail-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}
.btn-like {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
  padding: 8px 16px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
}
.btn-like:hover, .btn-like.liked {
  background: var(--danger);
  color: white;
}
.glass-divider {
  border: 0;
  height: 1px;
  background: var(--glass-border);
  margin: 16px 0;
}

/* Comments */
.comments-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  margin-top: 12px;
}
.comment-item {
  background: rgba(0,0,0,0.2);
  padding: 12px;
  border-radius: 12px;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
}
.comment-author {
  font-weight: bold;
  color: var(--primary);
  margin-bottom: 4px;
  display: block;
  font-size: 0.8rem;
}
.comment-input-area {
  display: flex;
  gap: 8px;
  align-items: center;
}
.comment-input-area .glass-input {
  margin-bottom: 0;
  flex: 1;
}

/* Chat Tab */
.chat-layout {
  flex-direction: column;
  height: calc(100vh - 140px); /* Fill space between header and nav */
}
.chat-header-ext {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.chat-header-ext select {
  flex: 1;
  margin-bottom: 0;
  padding: 8px 12px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
}
.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.5;
  word-break: break-all;
}
.message img {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 8px;
}
.ai-message {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.user-message {
  align-self: flex-end;
  background: var(--primary);
  border: none;
  border-bottom-right-radius: 4px;
}
/* Markdown content styling in AI Chat */
.ai-message p { margin-bottom: 8px; }
.ai-message p:last-child { margin-bottom: 0; }
.ai-message pre { background: rgba(0,0,0,0.5); padding: 10px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
.ai-message code { font-family: monospace; background: rgba(0,0,0,0.3); padding: 2px 4px; border-radius: 4px; }
.ai-message ul, .ai-message ol { margin-left: 20px; margin-bottom: 8px; }

.chat-input-area {
  display: flex;
  padding: 8px;
  align-items: flex-end;
  gap: 8px;
  margin-top: auto;
}
.chat-input-area textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: white;
  resize: none;
  outline: none;
  padding: 8px;
  max-height: 100px;
  font-family: inherit;
}
.send-btn {
  background: var(--primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  margin-bottom: 4px;
}
.send-btn:hover {
  background: var(--primary-hover);
}

/* Settings */
.settings-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.user-info-card {
  display: flex;
  align-items: center;
  gap: 16px;
}
.avatar-icon {
  font-size: 48px;
  color: var(--text-muted);
}
.setting-section h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}
.student-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}
.student-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
}
.student-item select {
  padding: 4px;
  border-radius: 4px;
  background: var(--bg-dark);
  color: white;
  border: 1px solid var(--glass-border);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  width: 100%;
  max-width: 600px;
  height: 64px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 25%;
  height: 100%;
  justify-content: center;
  cursor: pointer;
  transition: color 0.2s;
}
.nav-item span:last-child {
  font-size: 0.7rem;
  font-weight: 500;
}
.nav-item.active {
  color: var(--primary);
}

/* File Upload input */
.file-upload-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  border: 1px dashed var(--glass-border);
  cursor: pointer;
  margin-bottom: 16px;
  justify-content: center;
  color: var(--text-muted);
  transition: 0.2s;
}
.file-upload-label:hover {
  background: rgba(255,255,255,0.15);
  color: white;
}

/* Loader */
.loader-overlay {
  position: fixed;
  top:0; left:0; right:0; bottom:0;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid rgba(255,255,255,0.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--primary);
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-weight: 600;
  opacity: 0;
  z-index: 9999;
  transition: 0.3s;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
