/* css/style.css */
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css");

:root {
  --bg-color: #f8f9fa;
  --text-color: #2d3436;
  --text-sub: #636e72;
  --accent-color: #6c5ce7;
  --accent-hover: #5649c0;
  --card-bg: #ffffff;
  --border-color: #dfe6e9;
  --input-bg: #f1f2f6;
  --modal-bg: rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* Font sizes */
  --font-base: 16px;
  --font-sm: 0.875rem; /* 14px */
  --font-md: 1rem;     /* 16px */
  --font-lg: 1.125rem; /* 18px */
  --font-xl: 1.5rem;   /* 24px */
  --font-xxl: 2rem;    /* 32px */
}

[data-theme='dark'] {
  --bg-color: #1e1e2e;
  --text-color: #cdd6f4;
  --text-sub: #a6adc8;
  --accent-color: #cba6f7;
  --accent-hover: #b4befe;
  --card-bg: #313244;
  --border-color: #45475a;
  --input-bg: #45475a;
  --modal-bg: rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Base Styles */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Pretendard', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.5;
  transition: background 0.3s, color 0.3s;
  font-size: var(--font-md);
  -webkit-text-size-adjust: 100%; /* Prevent font scaling on orientation change */
}

/* Typography */
h1, h2, h3, h4, h5, h6 { font-weight: 800; line-height: 1.2; margin-bottom: 0.5em; }
h1 { font-size: var(--font-xxl); }
h2 { font-size: var(--font-xl); }
h3 { font-size: var(--font-lg); }

p { margin-bottom: 1em; }
a { color: var(--accent-color); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header & Navigation */
header {
  position: sticky;
  top: 0;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  z-index: 100;
  padding: 0.8rem 1rem;
}

.nav-container {
  max-width: 1024px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-weight: 800;
  font-size: var(--font-lg);
  color: var(--accent-color);
  text-decoration: none;
}

.nav-tabs {
  display: flex;
  gap: 0.5rem;
}

.nav-link {
  padding: 0.5rem 1rem;
  text-decoration: none;
  color: var(--text-sub);
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  white-space: nowrap; /* Prevent tabs from breaking */
}

.nav-link:hover, .nav-link.active {
  background: var(--accent-color);
  color: #fff;
}

.theme-toggle {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background 0.2s;
  color: var(--text-color); /* Ensure visibility */
}
.theme-toggle:hover { background: var(--input-bg); }

/* Main Content Area */
main {
  max-width: 1024px;
  margin: 2rem auto;
  padding: 0 1rem;
  min-height: 80vh;
}

/* Global Components */
.btn {
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.2s, transform 0.2s;
}
.btn-primary { background: var(--accent-color); color: #fff; }
.btn-secondary { background: var(--input-bg); color: var(--text-color); }
.btn-outline { background: transparent; border: 1px solid var(--accent-color); color: var(--accent-color); }
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.full-width { width: 100%; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1.5rem; }
.hidden { display: none !important; }
.text-sub { color: var(--text-sub); }
.highlight { color: var(--accent-color); font-weight: 700; }
.btn-danger { background: #e74c3c; color: #fff; border: none; }
.btn-danger:hover { filter: brightness(1.05); }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.85rem; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  padding: 1.5rem;
  text-decoration: none;
  color: var(--text-color);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: block;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--accent-color); }

.input {
  width: 100%;
  padding: 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text-color);
  margin-bottom: 0.5rem;
  font-family: inherit;
  font-size: var(--font-md);
}
.input:focus { outline: none; border-color: var(--accent-color); box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.2); }
.textarea { min-height: 120px; resize: vertical; }

.page-title {
  font-size: var(--font-xl);
  font-weight: 800;
  margin-bottom: 1.5rem;
  text-align: center;
}
.page-title small {
  font-size: var(--font-md);
  color: var(--text-sub);
  margin-left: 0.5rem;
}

/* Home View */
.hero { text-align: center; margin-bottom: 3rem; padding: 2rem 1rem; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); margin-bottom: 0.5rem; }
.hero p { font-size: var(--font-lg); color: var(--text-sub); }

.notice-banner {
  background: var(--input-bg);
  padding: 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 2rem;
  border-left: 4px solid var(--accent-color);
  font-size: var(--font-sm);
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* Adjusted min-width for mobile */
  gap: 1.5rem;
}
.entry-card { text-align: center; }
.card-icon { font-size: 2.5rem; margin-bottom: 1rem; }
.entry-card h3 { font-size: var(--font-lg); }
.entry-card p { font-size: var(--font-sm); color: var(--text-sub); }


/* Games View */
.game-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  overflow-x: auto; /* Scrollable tabs on small screens */
  padding-bottom: 0.5rem; /* Space for scrollbar */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  scrollbar-width: none; /* Hide scrollbar Firefox */
}
.game-tabs::-webkit-scrollbar { display: none; } /* Hide scrollbar Chrome/Safari */

.tab-btn {
  flex-shrink: 0; /* Prevent buttons from shrinking */
  padding: 0.8rem 1.2rem; /* Adjusted padding */
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  font-size: var(--font-sm); /* Smaller font for tabs */
}
.tab-btn.active { background: var(--accent-color); color: #fff; border-color: var(--accent-color); }

.game-container {
  background: var(--card-bg);
  padding: 1.5rem; /* Reduced padding for mobile */
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  min-height: 350px; /* Reduced min-height */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* Specific Game Styles - Reaction Game */
.reaction-area {
  width: 100%;
  max-width: 400px; /* Constrain width on larger screens */
  height: 250px; /* Reduced height */
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--input-bg);
  cursor: pointer;
  transition: background 0.2s;
  user-select: none;
}
.reaction-area.waiting { background: #e74c3c; color: white; }
.reaction-area.ready { background: #2ecc71; color: white; }
.reaction-area .game-title { font-size: var(--font-lg); }
.reaction-area .game-status { font-size: var(--font-md); }
.reaction-area .game-result { font-size: var(--font-sm); margin-top: 1rem; }

/* Specific Game Styles - Memory Game */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem; /* Reduced gap */
  width: 100%;
  max-width: 320px; /* Max width for mobile-friendly grid */
  margin: 1rem auto;
}
.memory-card {
  aspect-ratio: 1;
  background: var(--input-bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem; /* Reduced font size */
  transition: transform 0.3s;
}
.memory-card .back { display: none; }
.memory-card.flip .front { display: none; }
.memory-card.flip .back { display: block; }
.memory-card.flip { background: var(--card-bg); border: 1px solid var(--accent-color); }

/* Specific Game Styles - Rhythm Game */
.rhythm-area {
    position: relative;
    width: 100%;
    max-width: 400px; /* Constrain width */
    height: 250px; /* Reduced height */
    background: #111;
    overflow: hidden;
    border-radius: var(--radius-md);
}
.rhythm-note { width: 40px; height: 15px; } /* Smaller notes */

/* Specific Game Styles - Puzzle Game */
.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px; /* Reduced gap */
    width: 100%;
    max-width: 300px; /* Max width for mobile-friendly grid */
    height: 300px;
    background: var(--border-color);
    margin: 0 auto 1rem;
    padding: 3px; /* Reduced padding */
    border-radius: var(--radius-sm);
}
.puzzle-tile { font-size: var(--font-lg); } /* Adjusted font size */


/* Lounge View */
.lounge-layout {
  display: grid;
  grid-template-columns: 1fr; /* Default to single column for mobile */
  gap: 1.5rem;
}
.lounge-layout .sidebar {
  padding: 1rem;
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}
.lounge-layout .sidebar h3 { font-size: var(--font-lg); margin-bottom: 1rem; }
.category-list {
  display: flex;
  flex-wrap: wrap; /* Allow categories to wrap */
  gap: 0.5rem;
}
.cat-btn {
  text-align: left;
  padding: 0.5rem 0.8rem;
  background: none;
  border: 1px solid var(--border-color); /* Added border */
  color: var(--text-sub);
  cursor: pointer;
  border-radius: 1rem; /* Pill shape */
  transition: all 0.2s;
  font-size: var(--font-sm);
}
.cat-btn:hover, .cat-btn.active {
  background: var(--accent-color); /* Use accent color for active */
  color: #fff;
  border-color: var(--accent-color);
  font-weight: bold;
}
.post-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); /* Adjusted min-width */
  gap: 1rem;
}
.post-card {
  background: var(--card-bg);
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: border 0.2s;
}
.post-card:hover { border-color: var(--accent-color); }
.post-header { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-sub); margin-bottom: 0.5rem; }
.post-title { margin: 0 0 0.5rem 0; font-size: var(--font-md); }
.post-footer { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-sub); }

/* Community View */
.post-list-table {
  display: flex;
  flex-direction: column;
  gap: 1rem; /* Add gap between mobile cards */
}
.post-row {
  display: flex;
  flex-direction: column; /* Stack elements on mobile */
  align-items: flex-start;
  gap: 0.2rem;
  padding: 1rem;
  border-bottom: none; /* No bottom border for stacked cards */
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.post-row:hover { background: var(--input-bg); border-color: var(--accent-color); }
.post-row .col-cat { order: 1; font-size: var(--font-sm); } /* Reorder for mobile */
.post-row .col-title { order: 2; font-size: var(--font-lg); font-weight: 600; margin-top: 0.2rem; }
.post-row .col-author { order: 3; font-size: var(--font-sm); color: var(--text-sub); }
.post-row .col-meta { order: 4; font-size: var(--font-sm); color: var(--text-sub); margin-top: 0.5rem; }

/* Profile & Admin */
.profile-section,
.admin-section {
  max-width: 900px;
  margin: 0 auto;
}
.profile-card,
.profile-details,
.admin-card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}
.admin-dashboard {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.empty {
  text-align: center;
  color: var(--text-sub);
  padding: 2rem 0;
  font-size: var(--font-sm);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--modal-bg);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 1rem;
  animation: fadeIn 0.3s ease-out;
}
.modal {
  background: var(--card-bg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh; /* Allow scrolling within modal */
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Hide scrollbar for internal content */
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease-out;
}
.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0; /* Prevent header from shrinking */
}
.modal-body { 
  padding: 1.5rem; 
  overflow-y: auto; /* Enable scroll for modal content */
  flex-grow: 1; /* Allow body to take available space */
}
.modal-footer { 
  padding: 1rem 1.5rem; 
  border-top: 1px solid var(--border-color); 
  text-align: right; 
  flex-shrink: 0; /* Prevent footer from shrinking */
}
.close-btn { background: none; border: none; font-size: var(--font-xl); cursor: pointer; color: var(--text-sub); }
.view-title { font-size: var(--font-xl); }
.view-meta { font-size: var(--font-sm); color: var(--text-sub); margin-bottom: 1rem; }
.view-content { font-size: var(--font-md); margin-bottom: 2rem; }
.comments-section h4 { font-size: var(--font-lg); margin-bottom: 1rem; }
.comment { 
  background: var(--input-bg); 
  padding: 0.8rem; 
  border-radius: var(--radius-sm); 
  margin-bottom: 0.5rem; 
  font-size: var(--font-sm);
}
.comment strong { color: var(--accent-color); }
.comment .date { font-size: 0.75rem; color: var(--text-sub); margin-left: 0.5rem; }
.comment p { margin-top: 0.2rem; margin-bottom: 0; }
.comment-form { display: flex; gap: 0.5rem; margin-top: 1rem; }
.comment-form .input.small { width: 100px; flex-shrink: 0; }
.comment-form .input { flex-grow: 1; }
.comment-form .btn { flex-shrink: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; } /* For multiple buttons in footer */


/* Utility Classes */
.chip {
  background: var(--input-bg);
  padding: 0.2em 0.7em;
  border-radius: 1em;
  font-size: 0.8em;
  color: var(--text-sub);
  white-space: nowrap;
}
.chip.micro { font-size: 0.7em; padding: 0.1em 0.5em; }
.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-sub);
  margin: 1.5rem 0;
}
.divider::before,
.divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-color);
}
.divider:not(:empty)::before { margin-right: .5em; }
.divider:not(:empty)::after { margin-left: .5em; }

.fade-in { animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateY(-20px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* Desktop Specific Overrides (for 768px and up) */
@media (min-width: 769px) {
  .lounge-layout { grid-template-columns: 200px 1fr; } /* Revert to 2 columns */
  .category-list { flex-direction: column; flex-wrap: nowrap; }
  .cat-btn { text-align: left; } /* Align text to left in desktop sidebar */
  .post-table-header { 
    display: grid; /* Show table header */
    grid-template-columns: 60px 1fr 100px 100px;
    gap: 1rem;
    padding: 0.8rem;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    font-weight: bold; 
    background: var(--input-bg); 
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  }
  .post-list-table { gap: 0; } /* Remove gap for table rows */
  .post-row {
    grid-template-columns: 60px 1fr 100px 100px; /* Revert to table layout */
    flex-direction: row;
    align-items: center;
    border: none; /* No border for table rows */
    border-radius: 0;
    border-bottom: 1px solid var(--border-color); /* Add bottom border back */
    padding: 0.8rem;
    background: transparent; /* No background for table rows */
  }
  .post-row:hover { background: var(--input-bg); border-color: initial; } /* Hover effect */
  .post-row .col-cat, .post-row .col-title, .post-row .col-author, .post-row .col-meta {
    order: initial; /* Reset order */
    font-size: initial;
    margin-top: 0;
    color: initial;
  }
  .col-meta { text-align: right; }
  .col-cat { font-size: var(--font-sm); color: var(--accent-color); } /* Keep category chip size */
  .col-title { font-size: var(--font-md); font-weight: normal; }
  .col-author { font-size: var(--font-sm); color: var(--text-sub); }
}

/* Specific Mobile Adjustments (under 768px) */
@media (max-width: 768px) {
  .nav-container { flex-wrap: wrap; justify-content: center; }
  .logo { margin-bottom: 0.5rem; width: 100%; text-align: center; }
  .nav-tabs { width: 100%; justify-content: center; }
  .theme-toggle { 
    position: static; /* Move to flow */
    margin-left: auto; /* Push to right */
    padding: 0.5rem;
    font-size: 1rem;
  }

  .hero { padding: 1.5rem 1rem; }
  .hero h1 { font-size: 1.8rem; }
  .hero p { font-size: var(--font-md); }

  .game-tabs { padding-bottom: 0; } /* No extra padding if scrollbar is hidden */

  .comments-section .comment-form { flex-direction: column; gap: 0.8rem; }
  .comment-form .input.small { width: 100%; } /* Full width for nickname input */
}
